How to use early_fragment_tests?

Hi, is there a way to use Early Depth Test on JME3?

The line:
layout(early_fragment_tests) in;
in fragment shader gives me an error:

com.jme3.renderer.RendererException: compile error in:ShaderSource[name=MatDefs/Shadow/PostShadow15.frag, defines, type=Fragment, language=GLSL150] error:0(13) : error C3008: unknown layout specifier 'early_fragment_tests'

Well, you are trying to compile a glsl 150 compatible shader with language features that got introduced in glsl 420

1 Like

Most drivers will already perform early depth testing, unless you have a “discard” or “gl_FragDepth = …” statement in the shader code.
Specifying the early_fragment_tests statement is needed for other reasons, see here:

So, the solution is to set “DepthWrite Off” in ForcedRenderState and to get rid of all discards?
The first shader I have paints ambient + first point light (without shadows), it have depth write enabled.
I want to have early depth tests in shaders that execute after it, those shaders don’t need to write into depth buffer anymore.

“DepthWrite” doesn’t influence the early fragment tests. However if you’re doing multipass rendering then disabling depth write for subsequent passes can save extra work for the GPU as the depth for those pixels is already written.