Normal maps now work as expected
This commit is contained in:
1 parent
bf2c02e240
commit
037ad47468
7 files changed
+69
-23
No files matched your search
@@ -3,6 +3,7 @@
|
||||
in vec3 fragPos;
|
||||
in vec2 texCoord;
|
||||
in vec3 normal;
|
||||
in mat3 tbn;
|
||||
|
||||
struct Material {
|
||||
bool hasDiffuseTex;
|
||||
@@ -27,10 +28,12 @@ void main() {
|
||||
|
||||
if (material.hasNormTex) {
|
||||
normals = texture(material.normalTexture, texCoord).xyz;
|
||||
normals = normalize(normals * 2.0 - 1.0);
|
||||
normals = normals * 2.0 - 1.0;
|
||||
normals = normalize(tbn * normals);
|
||||
}
|
||||
else
|
||||
normals = normalize(normal);
|
||||
normals = normal;
|
||||
|
||||
|
||||
if (material.hasDiffuseTex)
|
||||
diffuse = texture(material.diffuseTexture, texCoord).rgb;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
layout(location = 0) in vec3 pos;
|
||||
layout(location = 1) in vec2 texCoords;
|
||||
layout(location = 2) in vec3 normals;
|
||||
layout(location = 3) in vec3 tangent;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
@@ -11,13 +12,19 @@ uniform mat4 proj;
|
||||
out vec3 fragPos;
|
||||
out vec2 texCoord;
|
||||
out vec3 normal;
|
||||
out vec3 tang;
|
||||
out mat3 tbn;
|
||||
|
||||
void main() {
|
||||
vec4 world = model * vec4(pos, 1.0);
|
||||
fragPos = world.xyz;
|
||||
texCoord = texCoords;
|
||||
mat3 normalMat = transpose(inverse(mat3(model)));
|
||||
normal = normalMat * normals;
|
||||
vec3 t = normalize(normalMat * tangent);
|
||||
vec3 n = normalize(normalMat * normals);
|
||||
normal = n;
|
||||
vec3 b = cross(n, t);
|
||||
tbn = mat3(t, b, n);
|
||||
|
||||
gl_Position = proj * view * world;
|
||||
}
|
||||
Reference in new issue
Block a user