我有以下着色器
顶点着色器
#version 330
layout (location = 0) in vec3 inPosition;
layout (location = 1) in vec4 inColour;
layout (location = 2) in vec2 inTex;
layout (location = 3) in vec3 inNorm;
uniform mat4 transformationMatrix;
uniform mat4 projectionMatrix;
out vec4 ShadowCoord;
void main()
{
gl_Position = projectionMatrix * transformationMatrix * vec4(inPosition, 1.0);
ShadowCoord = gl_Position;
}
片段着色器
#version 330
in vec4 ShadowCoord;
out vec4 FragColor;
uniform sampler2D heightmapTexture;
void main()
{
FragColor = vec4(vec3(clamp(ShadowCoord.x/500,0.0,1.0),clamp(gl_FragCoord.y/500,0.0,1.0),0.0),1.0);
}
我希望这样做是绘制场景,左上角为绿色,右上角为黄色,右下角为红色,左下角为黑色。事实上,当我在片段着色器中ShadowCoord.x
替换为时,就会发生这种情况。gl_FragCoord.x
那么,为什么我只能得到垂直渐变的绿色呢?显然,我的 ShadowCoord 发生了一些奇怪的事情。有人知道这是什么吗?