X-Git-Url: http://git.lukelau.me/?p=opengl.git;a=blobdiff_plain;f=texturevertex.glsl;fp=texturevertex.glsl;h=d8c97f4df3c9a73169770d7dcca7a512782a70fe;hp=0000000000000000000000000000000000000000;hb=ba9c738e8660304aa0341eb44118e63502a4a009;hpb=37cba564a96018a5500e942498d4e48c0ebe73ed diff --git a/texturevertex.glsl b/texturevertex.glsl new file mode 100644 index 0000000..d8c97f4 --- /dev/null +++ b/texturevertex.glsl @@ -0,0 +1,61 @@ +#version 330 +in vec3 vPosition; +in vec4 vColor; +in vec3 vNormal; +in vec3 tangent; +in vec3 bitangent; +in vec2 vTexCoord; +uniform mat4 model; +uniform mat4 view; +uniform mat4 projection; +out vec3 defNormal; +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; + + +void main() { + vec4 pos = model * vec4(vPosition, 1.f); + defNormal = mat3(transpose(inverse(model))) * vNormal; + 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))); + // 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); + } + + gl_Position = projection * view * pos; +}