Fix metal roughness texture on streaked metal material
[opengl.git] / texturevertex.glsl
index d8c97f4df3c9a73169770d7dcca7a512782a70fe..06535cfe7f8d2915bd1e7c3ba023ab1f5a522e41 100644 (file)
@@ -1,61 +1,46 @@
 #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;
+
 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;
-
-struct Material {
-       vec3 ambient;
-       vec3 diffuse;
-       sampler2D diffuseMap;
-       vec3 specular;
-       sampler2D specularMap;
-       float shininess;
-       
-       bool hasTexture;
-       bool hasSpecularMap;
-
-       sampler2D normalMap;
-       bool hasNormalMap;
-};
-
-uniform Material material;
-
+out vec3 lightPos, viewPos, fragPos;
+out vec3 worldViewPos, worldFragPos;
 
 void main() {
-       vec4 pos = model * vec4(vPosition, 1.f);
-       defNormal = mat3(transpose(inverse(model))) * vNormal;
+       vec4 worldPos = model * vec4(pos, 1.f);
        texCoord = vTexCoord;
 
        //tangent space stuff
-       if (material.hasNormalMap) {
        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);
-       } else {
-               lightPos = vLightPos;
-               viewPos = vViewPos;
-               fragPos = vec3(pos);
-       }
+       fragPos = TBN * vec3(worldPos);
+
+       worldViewPos = vViewPos;
+       worldFragPos = vec3(worldPos);
+
+       vec3 normal = mat3(transpose(inverse(model))) * unscaledNormal;
+
+       defNormal = TBN * normal;
+       worldNormal = normal;
        
-       gl_Position = projection * view * pos;
+       gl_Position = projection * view * worldPos;
 }