Assignment of gl_Position in different places leads to different results.
ZeroNinx opened this issue · comments
Hi. When I try to use glsl to write a vertex shader. Everything runs well when I put the assignment of gl_Position in the first line of the main() function. But when I move it to the last line of the main() function, an error occurred in the vertex coordinates.
This is my repository: https://github.com/ZeroNinx/VitaTest
If you want to get a wrong result, just move the assignment of gl_Position to the last line of the main() function in data/Shader/VertexShader.glsl.
like this:
#version 100
attribute vec3 aPos; //顶点位置
attribute vec2 aTexCoord; //纹理坐标
attribute vec3 aNormal; //法向量
uniform mat4 ModelMat; //模型矩阵
uniform mat4 ViewMat; //相机矩阵
uniform mat4 ProjMat; //投影矩阵
uniform mat4 TranspostInverseModelMat; //模型矩阵左上角的逆矩阵的转矩阵(用于计算法向量)
varying vec3 FragPos; //片段位置
varying vec2 TexCoord; //纹理坐标
varying vec3 Normal; //法向量
void main()
{
//Place it here is right
// gl_Position = ProjMat * ViewMat * ModelMat * vec4(aPos, 1.0);
TexCoord = aTexCoord;
FragPos = vec3(ModelMat * vec4(aPos, 1.0));
Normal = mat3(TranspostInverseModelMat) * aNormal;
//Place here cause vertex coordinates error
gl_Position = ProjMat * ViewMat * ModelMat * vec4(aPos, 1.0);
}
This is probably some internal GLSL compiler bug. Unlikely to be fixed, but I'll look into it more when I have time.
Thanks you!