GLSL着色器,gl_ModelViewMatrix不正确?

时间:2013-10-06 16:27:55

标签: java opengl glsl shader lwjgl

所以我试图制作一个着色器,随着时间的推移改变了我的水晶的颜色,一切都很好,直到我注意到它离光源越远越暗(默认值) opengl现在亮了!)。因此,我尝试将颜色值调低距离光线的距离,但这不起作用。后来我发现(如果世界坐标中顶点的x位置大于某个值,则将颜色设置为红色),即vertex.x值大约为0.即使它应该是大约87.0。

void main()
{
    vec3 vertexPosition = vec3(gl_ModelViewMatrix * vertexPos);
    vec3 surfaceNormal = (gl_NormalMatrix * normals).xyz;
    vec3 lightDirection = normalize(gl_LightSource[0].position.xyz - vertexPosition);
    float diffuseLI = max(0.0, dot(surfaceNormal, lightDirection));

    vec4 texture = texture2D(textureSample, gl_TexCoord[0]);
    if(vertexPosition.x > 0)gl_FragColor.rgba = vec4(1, 0, 0, 1);
    /*And so on....*/
}

据我所知gl_ModelViewMatrix * gl_Vertex应该给出顶点的世界坐标。我只是愚蠢还是什么? (我也尝试使用光线位置正确的if语句!)

0 个答案:

没有答案
相关问题