To my understanding, input attributes of vertex computed in vertex will be interpolated according to barycentric coordinate of current pixel. And being able to interpolate attributes
or to compute barycentric coordinate of current pixel is becuase the vertex stream is transited to triangle stream after vertex shader. The barycentric coordinate of current pixel can be derived by the screen positions of triangle vertices provided by gl_Position
and the pixel position.
But I'm confused how to interpolate in
variables in fragment shader. Here is an exampler of shader:
- vertex shader
layout(binding = 0) uniform WorldMVP {
mat4 worldMvp;
};
layout(binding = 0) uniform LightMVP{
mat4 lightMvp;
};
layout(location = 0) in vec3 aVertexPosition;
layout(location = 1) in vec3 aVertexNormal;
layout(location = 2) in vec2 aTextureCoord;
layout(location = 0) out vec4 vPositionFromLight;
layout(location = 1) out vec2 vTextureCoord;
layout(location = 2) out vec3 vNormal;
void mian()
{
gl_Position = worldMvp * vec4(aVertexPosition, 1.0);
vPositionFromLight = lightMvp * vec4(aVertexPosition, 1.0);
vTextureCoord = aTextureCoord;
vNormal = aVertexNormal;
}
- fragment shader
layout(location = 0) in vec4 vPositionFromLight;
layout(location = 1) in vec2 vTextureCoord;
layout(location = 2) in vec3 vNormal;
layout(location = 0) out vec4 outColor;
void main()
{
outColor = vec4(1.0, 1.0, 1.0, 1.0);
}
If the barycentric coordinate used in interpolating vPositionFromLight
is same as the one used in interpolating attributes like vTextureCoord
and vNormal
, it seems abnormal. Because vPositionFromLight
and gl_Position
are transformed into different clip spaces by different MVP.
How does the vPositionFromLight
is interpolated? What is the barycentric coordinate used in interpolating vPositionFromLight
.