3D Object Intersections with jagged edges

11 replies [Last post]
sgano
Offline
Joined: 2007-01-14

I have a scene that has a sphere and a transparent cone (alpha about 0.75); when the two intersect it doesn't appear like a smooth intersection, but is rather ragged in spots and fine in others. I have posted two pictures of the situation at the following URLs:

I was wondering if anyone has had this problem and knows how to fix it or if anyone might have any suggestions?

Thanks!
- Shawn

fherinean
Offline
Joined: 2004-07-08

Now that I've seen your images I'm sure the problem lies within Z-buffer resolution. Those who have played for example WorldOfWarcraft will see *exactly* the same jagged edges if they were playing with 16 bit depth buffer. The problems goes away as soon as you choose from the game options a depth buffer of 24.

The solution proposed by 'aces' I think it's the best.

pepe
Offline
Joined: 2003-06-10

Sorry, i don't believe it is due to the zbuffer precision.
If it were so, the overlapping would be different on each image, and as you can see, it is exactly the same even if point of view is changed.
I think it is because the two objects intersect.
To avoid this, i see two solutions:

- make the cone large enough so that the edge of the polygons never enter the sphere. This can be mathematically avoided, based on cone edge count and radius. This formula ( http://upload.wikimedia.org/math/6/1/b/61b34064547b0021c31a0e850521724e.png ) will give you the radius of the internal of your cone. If it is greater than your sphere's, you will not see any intersection ( alpha and beta would be the same, that is (PI/edgeCount), and l is the length of the edge of the basis of your polygon )

- the other solution, if you really need your cone to be the same size would be to trick with zbuffer. This could be done with those steps:
- a clear of the zbuffer right before drawing the cone
- draw of a disc that would be positionned at the center of earth, directed to the camera, so that it makes a flat mask for earth. this mask would be drawn only in zbuffer.

Last solution is not free from side effects, and can only be used in very restricted conditions (cone would be the last to be drawn, or, other graphical elements would not need zbuffer...)

 corrected alpha

Message was edited by: pepe

Scott Vorthmann

In my application, this jagged-intersections effect has been a
problem for quite some time. I see this effect only when using
perspective... in orthographic/parallel projection it does not
occur. Perhaps someone can draw useful inferences from that fact.

Scott Vorthmann

On Feb 18, 2007, at 10:47 AM, java3d-interest@javadesktop.org wrote:

> Sorry, i don't believe it is due to the zbuffer precision.
> If it were so, the overlapping would be different on each image,
> and as you can see, it is exactly the same even if point of view is
> changed.
> I think it is because the two objects intersect.
> To avoid this, i see two solutions:
> - make the cone large enough so that the edge of the polygons never
> enter the sphere. This can be mathematically avoided, based on cone
> math/6/1/b/61b34064547b0021c31a0e850521724e.png ) will give you the
> radius of the internal of your cone. If it is greater than your
> sphere's, you will not see any intersection ( alpha and beta would
> be the same, that is (PI/edgeCount/2), and l is the length of the
> edge of the basis of your polygon )
> - the other solution, if you really need your cone to be the same
> size would be to trick with zbuffer. This could be done with those
> steps:
> - a clear of the zbuffer right before drawing the cone
> - draw of a disc that would be positionned at the center of earth,
> directed to the camera, so that it makes a flat mask for earth.
> this mask would be drawn only in zbuffer.
>
> Last solution is not free from side effects, and can only be used
> in very restricted conditions (cone would be the last to be drawn,
> or, other graphical elements would not need zbuffer...)
> [Message sent by forum member 'pepe' (pepe)]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
> For additional commands, e-mail: interest-help@java3d.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net

pepe
Offline
Joined: 2003-06-10

Please post images of both cases, maybe we can figure out something out of them.

Scott Vorthmann

I finally took some time to generate images to illustrate this
problem. The first image is a parallel projection, with normal
aliasing being the only effect. The 2nd and third images use
perspective, and you can see the artifacts at the intersection
points. Note that the artifact "scale" remains more or less fixed
with the display resolution, as the viewpoint is moved back from the
model.

Could this be some sort of Z-buffer roundoff error accumulation,
related to the scaling from world to view space? I think I did some
experimentation several years ago, adjusting scale factors, but to no
avail.

I'd really love to finally fix this!

Scott

[parallel.png]
[perspective1.png]
[perspective2.png]

On Feb 18, 2007, at 2:28 PM, java3d-interest@javadesktop.org wrote:

> Please post images of both cases, maybe we can figure out something
> out of them.
> [Message sent by forum member 'pepe' (pepe)]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
> For additional commands, e-mail: interest-help@java3d.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net

aces
Offline
Joined: 2003-07-17

I assume this is a Z-Buffer problem.
You can try fix this by reducing back/front clip distance ratio or by increasing Z-Buffer depth to 24 or 32bits (default is 16).

For the first option :
Reduce back clips distance and increase front clip. The best value is up with you and your application requeriments.
Ideal values for back/front ratio is < 3000, for a 16 bits Zbuffer.

For 2nd option
Z-Buffer can be 32, 24, 16, 8 and 0.
Create a GraphicsConfigTemplate3D (lets call it as gct3D) with setDepthSize(24) or setDepthSize(32) .

For safety, you can create a loop when you try to get a non-null GraphicsConfiguration using all possible Z-Buffer values, from highest to lowest using :

[code]

GraphicsConfiguration config = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice()
.getBestConfiguration(gct3D);
[/code]

Create you canvas3D with first non-null GraphicsConfiguration config from above.

Scott Vorthmann

Outstanding! The setDepthSize() did the trick. Thank you!

Scott

On Mar 15, 2007, at 7:27 AM, java3d-interest@javadesktop.org wrote:

> I assume this is a Z-Buffer problem.
> You can try fix this by reducing back/front clip distance ratio or
> by increasing Z-Buffer depth to 24 or 32bits (default is 16).
>
> For the first option :
> Reduce back clips distance and increase front clip. The best value
> is up with you and your application requeriments.
> Ideal values for back/front ratio is < 3000, for a 16 bits Zbuffer.
>
> For 2nd option
> Z-Buffer can be 32, 24, 16, 8 and 0.
> Create a GraphicsConfigTemplate3D (lets call it as gct3D) with
> setDepthSize(24) or setDepthSize(32) .
>
> For safety, you can create a loop when you try to get a non-null
> GraphicsConfiguration using all possible Z-Buffer values, from
> highest to lowest using :
>
> [code]
>
> GraphicsConfiguration config = GraphicsEnvironment
> .getLocalGraphicsEnviron
> ment()
> .getDefaultScreenDevice()
> .getBestConfiguration
> (gct3D);
> [/code]
>
> Create you canvas3D with first non-null GraphicsConfiguration
> config from above.
> [Message sent by forum member 'aces' (aces)]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
> For additional commands, e-mail: interest-help@java3d.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net

fherinean
Offline
Joined: 2004-07-08

the problem is that at the scale you're working, the graphic card z-buffer resolution cannot distinguish which element comes on top, the cone or the sphere. You have 2 posibilities here, increase the depth of the z-buffer (in case you were using 16 bit, go to 24 or 32 bit) or change the scale of the image so that you'll have a better depth resolution.

sgano
Offline
Joined: 2007-01-14

Thanks for your help. I first tried the clipping distance approach, with something like the following:

canvas3D.getView().setBackClipDistance(2);
canvas3D.getView().setFrontClipDistance(0.05);

[I am working in units of Earth Diameters - to help in scaling], but this didn't seem to help any. I also looked around but couldn't find a way to set the z-buffer resolution and I was getting the feeling that this would be hardware specific, so I didn't really want to go that route.

I ended up getting around the issue by making the cone slightly shorter so it wouldn't quite intersect with the Earth and this worked out quite well.

sgano
Offline
Joined: 2007-01-14

Oh, yeah, I did try changing the tessellation of the Earth and intersecting cone, this did help some, but required a lot of divisions in each of the objects and ultimately didn't completely clear up the problem.

Jeroen Lapre

Try making your camera clipping planes as tight on the subjects as possible.
Also try increasing the tesselation of your Earth and intersecting cone
geometry.
cheers
-jeroen

>I have a scene that has a sphere and a transparent cone (alpha about 0.75); when the two intersect it doesn't appear like a smooth intersection, but is rather ragged in spots and fine in others. I have posted two pictures of the situation at the following URLs:
>
>
>I was wondering if anyone has had this problem and knows how to fix it or if anyone might have any suggestions?
>
>Thanks!
>- Shawn
>[Message sent by forum member 'sgano' (sgano)]
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net