Hi Renoir,
Thanks for your test program. In Java3D
antialiasing line/point are rendered as transparency
object with depth buffer disable. Since depth buffer
is disable, the depth value is not set and the background
color is used to draw in the gap for the minimum square
enclosed but not part of the point. So the rendering order
is very important in this test pgoram which draw
antialiasing point in front of a transparent sphere.
The correct order is drawing the sphere first
before the point. We can force this by using
OrderedGroup. See the modified test program attached.
Without using OrderedGroup, the order in which
they are drawn are undefined. In v1.2.1 it works
just because sphere is draw first by chance.
In v1.3 beta1 the antialiasing point is draw
first so you see this artifact. (Note that
this will not happen under D3D because it draws
point as square, not circle).
Another way to fix the program is to use
the new API in v1.3 - depth sort transparency
by adding one line:
universe.getViewer().getView().
setTransparencySortingPolicy(View.TRANSPARENCY_SORT_GEOMETRY);
This should works without using OrderedGroup, however
there is currently a bug
4532504 - Antialiasing Point/Line are not depth sort correctly
which prevent it working properly. This should fix before
release.
Thanks.
- Kelvin
------------------
Java 3D Team
Sun Microsystems Inc.
>Delivered-To: [EMAIL PROTECTED]
>X-Accept-Language: en
>MIME-Version: 1.0
>Date: Wed, 28 Nov 2001 16:13:54 +0200
>From: Renoir Sewjee <[EMAIL PROTECTED]>
>Subject: Re: [JAVA3D] AntiAliasing Problem 1.3 beta
>To: [EMAIL PROTECTED]
>
>Hi Kelvin,
>
>I've attached source code to illustrate the bug.
>
>Thanks,
>Renoir
>
>Kelvin Chung wrote:
>
>> Hi Renoir,
>>
>> Thanks for your bug report. Please send us a
>> test program for investigation so that we can fix
>> it before release.
>>
>> - Kelvin
>> ------------
>> Java 3D Team
>> Sun Microsystems Inc.
>>
>> >Delivered-To: [EMAIL PROTECTED]
>> >X-Accept-Language: en
>> >MIME-Version: 1.0
>> >Date: Mon, 26 Nov 2001 15:21:43 +0200
>> >From: Renoir Sewjee <[EMAIL PROTECTED]>
>> >Subject: [JAVA3D] AntiAliasing Problem 1.3 beta
>> >To: [EMAIL PROTECTED]
>> >
>> >Hi,
>> >
>> >There seems to be an antialiasing problem in j3d 1.3 beta (see attached
>> >picture) - the areas that are supposed to be transparent are filled with
>> >the background colour. My setup is WinNT, NVidia Vanta, j2sdk 1.3.1_01
>> >(also tested on 1.4 beta 3, same results).
>> >
>> >Regards,
>> >Renoir
>> >
>> >--
>> >Renoir Sewjee
>> >Software Engineer
>> >ISS International (Welkom)
>> >Tel: +27 (0)57 912 2702
>> >Fax: +27 (0)57 912 2652
>> >--
>> >
>
>--
>Renoir Sewjee
>Software Engineer
>ISS International (Welkom)
>Tel: +27 (0)57 912 2702
>Fax: +27 (0)57 912 2652
>--
>
import java.awt.Dimension;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.vecmath.*;
import javax.media.j3d.*;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;
/**
* Illustrates an antialiasing problem in 1.3 beta: when antialiased geometry is in
front of
* geometry that allows transparency, the parts of the antialiased geometry that are
supposed to
* be transparent are rendered in the background colour.
*
* As an example,
* A point array with antialiased points in drawn in front of a sphere, when the
sphere can be
* transparent (transparency att set and transparency mode != none) you will see a
border around the points.
*
*/
public class AntiAliasingBug extends JFrame
{
public AntiAliasingBug(boolean sphereTransparent)
{
super();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
BoundingSphere everywhere = new BoundingSphere(new Point3d(),
Double.MAX_VALUE);
Canvas3D canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
canvas.setDoubleBufferEnable(true);
getContentPane().add(canvas, BorderLayout.CENTER);
SimpleUniverse universe = new SimpleUniverse(canvas);
universe.getViewingPlatform().setNominalViewingTransform();
// This should work without using OrderedGroup after bug
// 4532504 is fixed when v1.3 release.
universe.getViewer().getView().setTransparencySortingPolicy(View.TRANSPARENCY_SORT_GEOMETRY);
BranchGroup lights = new BranchGroup();
DirectionalLight directionalLight = new DirectionalLight();
directionalLight.setInfluencingBounds(everywhere);
lights.addChild(directionalLight);
AmbientLight ambientLight = new AmbientLight();
ambientLight.setInfluencingBounds(everywhere);
lights.addChild(ambientLight);
universe.getViewingPlatform().getViewPlatformTransform().addChild(lights);
BranchGroup root = new BranchGroup();
Background background = new Background(1, 1, 1);
background.setApplicationBounds(everywhere);
root.addChild(background);
OrderedGroup og = new OrderedGroup();
root.addChild(og);
/*
* Sphere.
*
*/
Material sphereMaterial = new Material();
sphereMaterial.setDiffuseColor(1, 0, 1);
Appearance sphereAppearance = new Appearance();
sphereAppearance.setMaterial(sphereMaterial);
if (sphereTransparent)
// Sphere can be transparent.
sphereAppearance.setTransparencyAttributes(new
TransparencyAttributes(TransparencyAttributes.NICEST, 0.0f));
else
// Sphere cannot be transparent - could even leave out the following
statement.
sphereAppearance.setTransparencyAttributes(new
TransparencyAttributes(TransparencyAttributes.NONE, 0.0f));
og.addChild(new Sphere(0.5f, Sphere.GENERATE_NORMALS, sphereAppearance));
/*
* Point Array.
*
*/
PointAttributes pointAttributes = new PointAttributes(10, true);
Appearance pointAppearance = new Appearance();
pointAppearance.setPointAttributes(pointAttributes);
Point3f point = new Point3f();
Color3f colour = new Color3f();
// make sure point is in front of sphere
float zpos = 1.5f;
PointArray pointArray = new PointArray(5, PointArray.COORDINATES |
PointArray.COLOR_3);
point.set(0.0f, 0.0f, zpos);
colour.set(0, 1, 0);
pointArray.setCoordinate(0, point);
pointArray.setColor(0, colour);
point.set(0.0f, 0.1f, zpos);
colour.set(1, 0, 0);
pointArray.setCoordinate(1, point);
pointArray.setColor(1, colour);
point.set(0.0f, -0.1f, zpos);
colour.set(1, 0, 0);
pointArray.setCoordinate(2, point);
pointArray.setColor(2, colour);
point.set(0.1f, 0.0f, zpos);
colour.set(0, 0, 1);
pointArray.setCoordinate(3, point);
pointArray.setColor(3, colour);
point.set(-0.1f, 0.0f, zpos);
colour.set(0, 0, 1);
pointArray.setCoordinate(4, point);
pointArray.setColor(4, colour);
og.addChild(new Shape3D(pointArray, pointAppearance));
/*
* Orbit Behaviour.
*
*/
OrbitBehavior orbitter = new OrbitBehavior(canvas, OrbitBehavior.REVERSE_ALL);
orbitter.setSchedulingBounds(everywhere);
orbitter.setViewingPlatform(universe.getViewingPlatform());
root.addChild(orbitter);
root.compile();
universe.addBranchGraph(root);
}
public static void main(String[] args)
{
boolean sphereTransparent = true;
if (args.length >= 1)
{
if (args[0].toLowerCase().equals("true")) sphereTransparent = true;
if (args[0].toLowerCase().equals("false")) sphereTransparent = false;
}
else
{
System.err.println();
System.err.println("usage: java AntiAliasingBug [true | false]");
System.err.println("A first argument of true allows the sphere to have
transparency (the default).");
System.err.println();
}
AntiAliasingBug app = new AntiAliasingBug(sphereTransparent);
app.setTitle("AntiAliasing Bug 1.3 beta");
app.setSize(800, 600);
app.setVisible(true);
}
}