Problem with overlapping transparent objects

I thought I had come up with a simple but brilliant idea when I needed to have high quality shadows on dynamic objects.



I’m making an architectural application where the user can load, position and rotate objects in realtime.



I thought it sufficient to have a shadow against the floor so I added the shadow in the form of a plane in floor height with an alpha enabled texture.



This worked well I thought, until I noticed that the alpha enabled planes misbehaved when overlapping as you can see in the third picture.





two objects with shadow planes.





The chair moved in under the desk look good when the the chair is the closest to the camera. I guess cause I put the chair shadow plane a tiny bit higher from the ground than the desk shadow plane.





Seen from the other side the chair shadow plane seems to loose its transparency capability or something.



Which is the correct way to set up objects with alphastate that need to overlap like this?

First of all you need to put all transparent objects in the transparent queue ( Spatial.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT) ).

Second, coplanar primitives may have Z fighting issues, in that case you should use the polygon offset feature (search on the forum on how to use).

looks very much like z fighting. try to set the z order and c what happens

Setting z order only works on ortho rendered spatials.

Momoko_Fan said:

Setting z order only works on ortho rendered spatials.


learning never stops  :D thx for pointing that out.

Thanks!


Momoko_Fan said:

First of all you need to put all transparent objects in the transparent queue ( Spatial.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT) ).

Yes, I had already done that.

Momoko_Fan said:

Second, coplanar primitives may have Z fighting issues, in that case you should use the polygon offset feature (search on the forum on how to use).

Ill look into it, but they aren't really fighting. The phenomena is very determined by which object is closest to the camera.
As I said the chair shadow plane is a tiny bit higher above the ground than the desk shadow plane.

It's seems to me that when one transparent object is shown infront of another, the one closest to the camera is blending with the one in the back. But if you would rotate the back object so that a small part of it would stick out in front of the front object that part is not blended. I imagine this has to do with the way the blending is calculated.
But I'm just guessing now. I'll go look the for polygon offset feature.

Try turning off zbuffer (zbuffer state) write for the shadow stuff and let them blend (alpha state).

Thanks. Not sure I understand though. Turn of z buffer state? How do I do that? I am using alphastate now but not zbufferstate.

Rik said:

Thanks. Not sure I understand though. Turn of z buffer state? How do I do that? I am using alphastate now but not zbufferstate.


if u r using simple game, the zbuffer writable is set to true by default.


((ZBufferState)this.rootNode.getRenderState(RS_ZBUFFER)).setWritable(false);

Thanks!

neakor said:


((ZBufferState)this.rootNode.getRenderState(RS_ZBUFFER)).setWritable(false);



whaa! don't do that, it turns off the zbuffer for your whole scene! Create a zbuffer state for your shadow nodes and set that to false instead.

Yes, I just did that. It works perfectly! Lucky for me I named all my shadow textures with the word "shadow" somewhere in the filename.


if(textureFileName.contains("shadow")){...


irrisor said:

neakor said:


((ZBufferState)this.rootNode.getRenderState(RS_ZBUFFER)).setWritable(false);



whaa! don't do that, it turns off the zbuffer for your whole scene! Create a zbuffer state for your shadow nodes and set that to false instead.


oh yeah, sry i missed that~i was just thinking about turning off the writable haha  XD