OpenGL: Mesh shaders in the current year

supergoodcode.com

169 points by pjmlp 3 days ago


m-schuetz - 3 days ago

AMD, do support for NV_shader_buffer_load next! Shader Buffer Load brought "Buffer Device Address" / pointers to OpenGL/glsl, long before Vulkan was even a thing. It's the best thing since sliced bread, and easily lets you access all your vertex data with pointers, i.e., you don't need to bind any vertex buffers anymore. Also easily lets you draw the entire scene in a single draw call since vertex shaders can just load data from wherever the pointers lead them, e.g., it makes GLSL vertex shaders look like this:

    uniform Node* u_nodes;
    
    void main(){
    
        Node node = u_nodes[gl_DrawID];
        
        vec3 pos = node.position[gl_VertexID];
        vec2 uv  = node.uv[gl_VertexID];
    
        ...
    }
zackmorris - 3 days ago

A little bit off topic but: GL_LINES doesn't have a performant analog on lots of other platforms, even Unity. Drawing a line properly requires turning the two endpoint vertices into a quad and optionally adding endcaps which are at least triangular but can be polygons. From my understanding, that requires a geometry shader since we're adding virtual/implicit vertices. Does anyone know if mesh shaders could accomplish the same thing?

Also I wish that GL_LINES was open-sourced for other platforms. Maybe it is in the OpenGL spec and I just haven't looked. I've attempted some other techniques like having the fragment shader draw a border around each triangle, but they all have their drawbacks.

prideout - 3 days ago

Why is Minecraft mentioned several times in the post?