这是我编写的关于normal mapping的代码,但是它现在的效果是全部黑色的,请问各位我哪个地方出现了问题TAT
这是我的效果图
这是原本的图
layout(location = 0) in vec3 vertexPos;
layout(location = 1) in vec3 vertexNormal;
layout(location = 2) in vec2 textureCoords;
layout(location = 3) in vec3 vertexTangent;
uniform mat4 transformationMatrix;
uniform mat4 rotationMatrix;
uniform mat4 translationMatrix;
uniform vec3 diffuseColor;
uniform float textureLevel;
out vec3 fragNormal;
out vec3 fragPos;
out vec3 fragTexCoords;
out mat3 TBN;
void main() {
gl_Position = transformationMatrix * vec4(vertexPos, 1);
fragPos = (translationMatrix * rotationMatrix * vec4(vertexPos, 1)).xyz;
fragNormal = (rotationMatrix * vec4(vertexNormal, 1)).xyz;
fragTexCoords = vec3(textureCoords, textureLevel);
vec3 T = normalize((rotationMatrix * vec4(vertexTangent, 0.0)).xyz);
vec3 N = normalize((rotationMatrix * vec4(vertexNormal, 0.0)).xyz);
vec3 B = cross(N, T);
TBN = mat3(T, B, N);
}
这是我的顶点着色器
in vec3 fragNormal;
in vec3 fragPos;
in vec3 fragTexCoords;
in mat3 TBN;
layout (binding = 2) uniform sampler2DArray diffuseTexture;
// 定义法线贴图
layout(binding = 3) uniform sampler2DArray normalMap;
vec3 calculateBlinnPhong(vec3 lightDir, vec3 lightColour){
vec3 normalMapColor = texture(normalMap, fragTexCoords).rgb;
vec3 normal = normalize(TBN * (normalMapColor * 2.0 - 1.0));
float diffuseMult = max(dot(normalize(normal), lightDir), 0.f);
vec3 diffuseContribution = diffuseMult * getDiffuseColour();
vec3 halfVector = normalize((-1 * viewDirection) + lightDir);
float specularMult = max(dot(halfVector, normal), 0.f);
specularMult = pow(specularMult, shininess);
vec3 specularContribuion = specularMult * specularColour;
float ambientLight = 0.05f;
vec3 ambientContribution = ambientLight * getAmbientColour();
vec3 lightContribution = (diffuseContribution + specularContribuion + ambientContribution) * lightColour;
return lightContribution;
}
这是我的片段着色器
请问大家我需要怎么修改