我想使用GLSL中计算的点光源。我工作正常,但如果我按像素计算它仍然看起来与基于顶点的计算相同。
我的顶点代码:
uniform vec3 LightPos;
varying vec2 UVCoord;
varying vec3 Normal;
varying vec3 posToLight;
void main()
{
UVCoord = gl_MultiTexCoord0.st;
gl_Position = ftransform();
Normal = normalize(gl_NormalMatrix * gl_Normal);
vec3 pos = vec3(gl_ModelViewMatrix * gl_Vertex);
posToLight = normalize(LightPos - pos);
}
我的片段代码:
uniform sampler2D tex1;
varying vec2 UVCoord;
varying vec3 Normal;
varying vec3 posToLight;
void main()
{
vec3 Color = vec3(texture2D(tex1, UVCoord));
float LightIntensity = pow(max(dot(posToLight, Normal), 0.0), 10.0);
gl_FragColor = vec4(Color * (LightIntensity), 1.0);
}
有人知道我做错了吗?