1

所以我试图制作一个着色器,随着时间的推移稍微改变我的水晶的颜色,一切都很顺利,直到我注意到它离光源越远它并没有变暗(默认的 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 语句!)

4

0 回答 0