Fix metal roughness texture on streaked metal material
[opengl.git] / texturevertex.glsl
index 684b9b94ed98c2117496381ea1071fc53236a39f..06535cfe7f8d2915bd1e7c3ba023ab1f5a522e41 100644 (file)
@@ -1,7 +1,7 @@
 #version 330
-in vec3 vPosition;
+in vec3 pos;
 in vec4 vColor;
-in vec3 vNormal;
+in vec3 unscaledNormal;
 in vec3 tangent;
 in vec3 bitangent;
 in vec2 vTexCoord;
@@ -10,31 +10,37 @@ uniform mat4 model;
 uniform mat4 view;
 uniform mat4 projection;
 
-out vec3 defNormal;
+out vec3 defNormal, worldNormal;
 out vec2 texCoord;
 
 uniform vec3 vLightPos;
 uniform vec3 vViewPos;
 
-out vec3 lightPos;
-out vec3 viewPos;
-out vec3 fragPos;
+out vec3 lightPos, viewPos, fragPos;
+out vec3 worldViewPos, worldFragPos;
 
 void main() {
-       vec4 pos = model * vec4(vPosition, 1.f);
+       vec4 worldPos = model * vec4(pos, 1.f);
        texCoord = vTexCoord;
 
        //tangent space stuff
        vec3 T = normalize(vec3(model * vec4(tangent,   0.0)));
        vec3 B = normalize(vec3(model * vec4(bitangent, 0.0)));
-       vec3 N = normalize(vec3(model * vec4(vNormal,    0.0)));
+       vec3 N = normalize(vec3(model * vec4(unscaledNormal,    0.0)));
        // convert TBN to world->tangent space
        mat3 TBN = transpose(mat3(T, B, N));
 
        lightPos = TBN * vLightPos;
        viewPos = TBN * vViewPos;
-       fragPos = TBN * vec3(pos);
-       defNormal = TBN * mat3(transpose(inverse(model))) * vNormal;
+       fragPos = TBN * vec3(worldPos);
 
-       gl_Position = projection * view * pos;
+       worldViewPos = vViewPos;
+       worldFragPos = vec3(worldPos);
+
+       vec3 normal = mat3(transpose(inverse(model))) * unscaledNormal;
+
+       defNormal = TBN * normal;
+       worldNormal = normal;
+       
+       gl_Position = projection * view * worldPos;
 }