PVR_PSP2 icon indicating copy to clipboard operation
PVR_PSP2 copied to clipboard

Assignment of gl_Position in different places leads to different results.

Open ZeroNinx opened this issue 4 years ago • 2 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);
}

ZeroNinx avatar Sep 09 '21 14:09 ZeroNinx

This is probably some internal GLSL compiler bug. Unlikely to be fixed, but I'll look into it more when I have time.

GrapheneCt avatar Sep 19 '21 16:09 GrapheneCt

Thanks you!

ZeroNinx avatar Sep 20 '21 16:09 ZeroNinx