Page 1 of 1

Drawing to Zbuffer

Posted: Thu Mar 03, 2011 3:39 pm
by MrJones
For some specific effect, I wonder how I can, inside a custom scene node's render function, draw a polygon which is completely transparent (= not changing anything visibly when drawn) but updates the zbuffer as if solid/opaque.

I think of something like the reverse of a solid opaque object with zwrite off: an invisible object but rendering to the zbuffer like with zwrite even for transparent parts.

It would be sufficient for me to use this with a triangle list, not an actual complete scene node. Also I use OpenGL if that helps.

Is there a way to do this?

Posted: Fri Mar 04, 2011 12:40 am
by agamemnus
How about adding a transparent texture/color to all polys in the mesh?


Also, the last post of this thread might help -- not sure. (solid inside transparent pass or transparent inside solid pass?)

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=43178

Posted: Fri Mar 04, 2011 2:12 am
by sudi
just use a polylist with vertex color totally transparent and use ONE_TEXTUREBLEND as material type and as blending function use what ever suits you but use the vertex color as transparent.

Posted: Fri Mar 04, 2011 2:41 am
by Lonesome Ducky
Use the ColorMask attribute of the node's SMaterial to prevent it from drawing to the screen. (This is even the way it's recommended in the comment there)

Posted: Fri Mar 04, 2011 5:08 am
by Yarcies
While I don't know for sure, I am pretty certain that any sort of usual color masking or transparent texture will NOT cause the polygon to fill the zbuffer (since Irrlicht checks for a 0.5 alpha treshold to do that usually).

Therefore I don't think any of the usual "just make the polygon appear transparent" approaches work, since then that would also stop them from rendering to the zbuffer. If I'm wrong with that then I'll happily use that color mask approach (will test tomorrow).

I am not sure if the vertex color approach is also prone to that 'limitation' (actually it makes sense in any normal scenario that the zbuffer is left untouched for invisible parts), but I am pretty sure both color keying and simply using a transparent texture are.

Posted: Fri Mar 04, 2011 12:28 pm
by hybrid
Just render the node as usual (EMT_SOLID), except that you change the color mask to ECM_NONE. Just like Lonesome Ducky said, this is what the color mask is meant for. And it works correctly for the usual zbuffer fill / early z-out approaches.

Posted: Fri Mar 04, 2011 2:50 pm
by Lonesome Ducky
If you used the transparency approach, wouldn't the node be drawn in the transparent pass? This would draw it after the other nodes. If you try drawing the node in the solid pass before the others, I don't think it will render. Food for thought :)

Posted: Fri Mar 04, 2011 6:49 pm
by Yarcies
Just render the node as usual (EMT_SOLID), except that you change the color mask to ECM_NONE.
Nice, thanks :) I will go with this approach then
If you used the transparency approach, wouldn't the node be drawn in the transparent pass? This would draw it after the other nodes. If you try drawing the node in the solid pass before the others, I don't think it will render.
Well... I will have a custom scene node and then in the render method, I will manually render (using the draw triangle list) first some solid wall surface with zwrite disabled, then a semi-transparent decals thing also with zwrite disabled, and then that ECM_NONE polygon to fill out the z-depth space afterwards.

Basically I just want to draw a wall with decals on it without having any z-fight issues between the wall and the decals.

Posted: Fri Mar 04, 2011 9:52 pm
by Lonesome Ducky
A problem with that approach is that if a wall behind you has decals on it, the decals from the wall behind will be drawn ahead of the wall in front of you. Almost like xray vision :lol: . You may also end up finding that without z-write, parts of the walls will be drawn over each other when they shouldn't be.