Horde3D
http://horde3d.org/forums/

ZFunc=Always != glDisable(GL_DEPTH_TEST)
http://horde3d.org/forums/viewtopic.php?f=2&t=1165
Page 1 of 1

Author:  AlexL [ 20.05.2010, 12:57 ]
Post subject:  ZFunc=Always != glDisable(GL_DEPTH_TEST)

I just noticed (reading the GL Spec), that the current way Horde handles the Shader's ZFunc is causing issues for us.
In a shader I set states to:
Code:
ZWriteEnable = true;
ZFunc = Always;
Maybe not a common use-case but this should be valid, I think.
Unfortunately Horde does a short cut and when seeing ZFunc=Always, it disables the depth test, and this disables updates to the depth buffer.
According to the spec:
Quote:
4.1.6 Depth Buffer Test
The depth buffer test discards the incoming fragment if a depth comparison fails. The comparison is enabled or disabled with the generic Enable and Disable commands using the symbolic constant DEPTH TEST. When disabled, the depth comparison and subsequent possible updates to the depth buffer value are bypassed and the fragment is passed to the next operation
Of course disabling the depth test and hence not writing to the depth buffer is an optimization, so maybe we a ZFunc=None could replace the current Always and disable the test, while "ZFunc=Always" uses glDepthFunc(GL_ALWAYS).
Any suggestions?

Author:  marciano [ 22.05.2010, 10:28 ]
Post subject:  Re: ZFunc=Always != glDisable(GL_DEPTH_TEST)

Thanks Alex, the current behavior of ZFunc=Always is clearly wrong in combination with depth writes, so we need to fix it. Yeah, we could either introduce ZFunc=None (not to confuse with ZFunc=Never) or do it as in CgFX by introducing a ZEnable state. The latter would probably be less confusing.

Author:  AlexL [ 31.05.2010, 09:57 ]
Post subject:  Re: ZFunc=Always != glDisable(GL_DEPTH_TEST)

Hi marciano.
Thanks for submitting the change to the SVN, works perfectly.
BTW: do you have a good advice for color buffer write selection, FX-like ColorWriteEnable = Red|Green|Blue or separate booleans like ColorRedWriteEnable = false;
Thanks again!
Alex

Author:  marciano [ 03.06.2010, 18:34 ]
Post subject:  Re: ZFunc=Always != glDisable(GL_DEPTH_TEST)

I think it makes sense to add a single ColorWriteEnable or ColorWriteMask. To simplify the parsing, I would suggest to specify the bit mask as a single "word", like RGBA or RGB or RGA etc.

Author:  AlexL [ 03.06.2010, 22:19 ]
Post subject:  Re: ZFunc=Always != glDisable(GL_DEPTH_TEST)

Yep, sounds fine. having to check only for the presence of a char like 'A' is indeed quite simple and easy to add to the existent parser (ignoring error checking for things like "AAA" or whatever)
BTW: In our code base we also added a BlendMode "BlendPMA" to enable premultiplied alpha blend state (GL_ONE, GL_ONE_MINUS_SRC_ALPHA), because we didn't come up with a better name and writing PremultipliedAlpha in all shader contexts was too error-prone :D

Author:  Fidora [ 17.06.2010, 09:43 ]
Post subject:  Re: ZFunc=Always != glDisable(GL_DEPTH_TEST)

AlexL wrote:
BTW: In our code base we also added a BlendMode "BlendPMA" to enable premultiplied alpha blend state (GL_ONE, GL_ONE_MINUS_SRC_ALPHA), because we didn't come up with a better name and writing PremultipliedAlpha in all shader contexts was too error-prone :D

That would be a very useful feature, though I would probably call it PremultipliedAlpha rather than PMA.
For anyone not familiar with premultiplied alpha you can read an article about it here.

Author:  DarkAngel [ 17.06.2010, 11:50 ]
Post subject:  Re: ZFunc=Always != glDisable(GL_DEPTH_TEST)

Would it be possible to be able to manually configure blend modes for materials? BlendMode=Custom could be used to enable this so the current convenience of the "popular" modes isn't lost.

It would be very useful to manually configure the Blend Coefficients for SrcRGB, DstRGB, SrcAlpha, DstAlpha and the blend Operation.

For example, if you're doing multi-layerd compositing with PMA (e.g. rendering particles to a seperate buffer), you'll want to use a different blend mode for RGB than you will for Alpha.
Other less-common modes like "Subtractive" also come in handy occasionally, and it would be nice to be able to use them without modifying Horde's source code.

Author:  marciano [ 26.06.2010, 18:12 ]
Post subject:  Re: ZFunc=Always != glDisable(GL_DEPTH_TEST)

DarkAngel wrote:
Would it be possible to be able to manually configure blend modes for materials? BlendMode=Custom could be used to enable this so the current convenience of the "popular" modes isn't lost.

It would be very useful to manually configure the Blend Coefficients for SrcRGB, DstRGB, SrcAlpha, DstAlpha and the blend Operation.

This is a good point. As the public API does not expose any internal render states, it makes sense to make as many of them as possible available via the FX files. This also fits Horde's data-driven approach nicely.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/