How to debug a GLSL shader?

后端 未结 11 1363
青春惊慌失措
青春惊慌失措 2020-11-28 17:38

I need to debug a GLSL program but I don\'t know how to output intermediate result. Is it possible to make some debug traces (like with printf) with GLSL ?

11条回答
  •  无人及你
    2020-11-28 18:23

    I am sharing a fragment shader example, how i actually debug.

    #version 410 core
    
    uniform sampler2D samp;
    in VS_OUT
    {
        vec4 color;
        vec2 texcoord;
    } fs_in;
    
    out vec4 color;
    
    void main(void)
    {
        vec4 sampColor;
        if( texture2D(samp, fs_in.texcoord).x > 0.8f)  //Check if Color contains red
            sampColor = vec4(1.0f, 1.0f, 1.0f, 1.0f);  //If yes, set it to white
        else
            sampColor = texture2D(samp, fs_in.texcoord); //else sample from original
        color = sampColor;
    
    }
    

    enter image description here

提交回复
热议问题