GLSL header to force Early-Z

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.

GLSL header to force Early-Z

Postby devsh » Sat May 27, 2017 8:05 am

You put this after your "#version 400" or other declaration at the very top of the fragment shader

cpp Code: Select all
 
#extension GL_ARB_conservative_depth: require
 
#if __VERSION__>=420
layout(early_fragment_tests) in;
#else
    #extension GL_ARB_shader_image_load_store: enable
 
    #ifdef GL_ARB_shader_image_load_store
        layout(early_fragment_tests) in;
    #else
        #extension GL_EXT_shader_image_load_store: enable
 
        #ifdef GL_EXT_shader_image_load_store
            layout(early_fragment_tests) in;
        #else
            layout (depth_unchanged) out float gl_FragDepth;
        #endif // GL_EXT_shader_image_load_store
    #endif // GL_ARB_shader_image_load_store
#endif // __VERSION__
 


if you're tagetting lower than GL 4.0, (same rule about positioning at the top of the file and just after version).

cpp Code: Select all
 
#if __VERSION__>=420
layout(early_fragment_tests) in;
#else
    #extension GL_ARB_shader_image_load_store: enable
 
    #ifdef GL_ARB_shader_image_load_store
        layout(early_fragment_tests) in;
    #else
        #extension GL_EXT_shader_image_load_store: enable
 
        #ifdef GL_EXT_shader_image_load_store
            layout(early_fragment_tests) in;
        #else
            #extension GL_ARB_conservative_depth: enable
           
            #ifdef GL_ARB_conservative_depth
                layout (depth_unchanged) out float gl_FragDepth;
            #endif // GL_ARB_conservative_depth
        #endif // GL_EXT_shader_image_load_store
    #endif // GL_ARB_shader_image_load_store
#endif // __VERSION__
 
User avatar
devsh
Competition winner
 
Posts: 1857
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK

Re: GLSL header to force Early-Z

Postby devsh » Mon Feb 05, 2018 6:50 pm

I wrote a compendium of corner-cases for Hi-Z and Early-Z covering almost all common combinations of Depth/Stencil Function/Mask settings which may fuck-up the performance of your displacement-mapping shaders.
https://github.com/buildaworldnet/IrrlichtBAW/wiki/Early-Fragment-Tests,-Hi-Z,-Depth,-Stencil-and-other-benchmarks
User avatar
devsh
Competition winner
 
Posts: 1857
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK


Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest