When I tried to assign a value to an in value like this:
const char* fragmentShaderSource = "#version 330 core\n"
"out vec4 FragColor;\n"
"in vec2 TexCoord;\n"
"in vec3 Normal;\n" // <------here is the value I want to assign
"in vec3 Tangent;\n"
"in vec3 biTangent;\n"
"uniform sampler2D ourTexture;\n"
"uniform sampler2D norTexture;\n"
"uniform vec3 lightDir;\n"
"uniform vec3 viewDir;\n"
"void main()\n"
"{\n"
" mat3 accNormalTrans = mat3(Tangent, biTangent, Normal);\n"
" Normal = texture(norTexture, TexCoord).xyz;\n"// in 变量不可随意更改
" Normal = normalize(texNormal*2.0-1.0);\n"
" Normal = normalize(accNormalTrans*texNormal);\n"
" vec4 ambient = texture(ourTexture, TexCoord)*0.5;\n"//norTexture error //vec4(texNormal, 1.0f)
" vec4 diffuse = ambient*max(0,-dot(lightDir,Normal));\n"
" vec4 specular = ambient*pow(max(0,-dot(normalize(lightDir+viewDir),Normal)),32);\n"
" FragColor = ambient+diffuse+specular;\n"
"}\n\0";
the previous Normal is a normal vector of model plain, and I want to assign it a normal vector calculated with normal map. But I got my model transparent and the model will always follow my camera. Then I tried to build a new value for that normal vector, and the model is rendered correctly.
I want to know why this situation happens.
I have searched this question on google, but no specific explanation. I will appreciate if you could explain it or list a LINK for that.
The language does not allow it.
The OpenGL Shading Language specification, Version 4.40:
It is a compile-time error to write to a variable declared as an input.
This is probably to ease and/or optimize the implementation on the hardware level, because such variables are typically implemented using fixed locations.