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__
 
We chose to stream mesh data from Multiple OpenGL Contexts in many threads and do the other things, not because they are easy, but because they are hard! - JFK
User avatar
devsh
Competition winner
 
Posts: 1741
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