简体   繁体   English

奇怪的GLSL片段着色器颜色不起作用

[英]Strange GLSL Fragment Shader color not working

Somehow, modifying gl_FragColor does not change the final color of my 3D objects. 不知何故,修改gl_FragColor不会更改3D对象的最终颜色。 How can this be possible? 这怎么可能? This has only happened suddenly ... as the EXACT SAME CODE was working before ... 这只是突然发生的...由于之前完全相同的代码正在工作...

Fragment Shader: 片段着色器:

#version 120

uniform vec4 ambient;
uniform vec4 diffuse;
uniform vec4 specular;
uniform vec4 objColor;
uniform float shininess;
uniform bool shade;
uniform sampler2D texMap;

varying vec2 st;
varying vec3 N;
varying vec3 L;
varying vec3 E;

void main(void) {

    vec3 NN = normalize(N);
    vec3 EE = normalize(E);
    vec3 LL = normalize(L);
    vec3 H = normalize(LL+EE);  //Half vector
    float Kd = dot(LL, NN);
    float Ks = pow(max(dot(NN, H), 0.0), shininess);
    vec4 amb, diff, spec;
    amb = ambient;
    diff = Kd*diffuse;
    if(Kd <= 0.0) spec = vec4(0.0, 0.0, 0.0, 1.0);
    else spec = specular * Ks;

    if(shade) gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); <----------------- THIS LINE
    else gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); <---------------------- THIS LINE

}

Vertext Shader: 文字着色器:

#version 120

uniform mat4 projection_matrix;
uniform mat4 modelview_matrix;
uniform mat4 transform_matrix;
uniform vec4 light_position;

attribute vec2 a_Textcoord;
attribute vec4 a_Vertex;
attribute vec4 a_Normal;

varying vec2 st;
varying vec3 N;
varying vec3 L;
varying vec3 E;

void main(void) {

        vec4 clip_position = transform_matrix * a_Vertex;
        gl_Position = projection_matrix * modelview_matrix * clip_position;

        vec4 nn = transform_matrix * a_Normal;
        N = normalize(nn.xyz);
        L = light_position.xyz - clip_position.xyz;
        if(light_position.w == 0.0) L = light_position.xyz;
        E = clip_position.xyz;
        st = a_Textcoord;

}

As indicated in the Fragment Shader, "<----- THIS LINE", any object I shader, is BLACK instead of Red. 如片段着色器所示,我着色器中的任何对象“ <----- THIS LINE”都是黑色而不是红色。 I have checked all variable values sending into the shader, they match what's expected and ModelView Matrix and Projection Matrix works fine. 我检查了所有发送到着色器中的变量值,它们与期望值匹配,并且ModelView Matrix和Projection Matrix可以正常工作。 Anyone got any ideas why this is the case? 任何人都知道为什么会这样吗?

Magically, it worked again ... I did not do anything but restart the computer (Shut-down and wait 15s, turn on). 神奇的是,它又可以工作了……我什么也没做,只是重新启动了计算机(关机并等待15秒钟,然后再打开)。 Does it have to do with OpenGL settings? 它与OpenGL设置有关吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM