projects
/
opengl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Load lights from model
[opengl.git]
/
texturevertex.glsl
diff --git
a/texturevertex.glsl
b/texturevertex.glsl
index d8c97f4df3c9a73169770d7dcca7a512782a70fe..06535cfe7f8d2915bd1e7c3ba023ab1f5a522e41 100644
(file)
--- a/
texturevertex.glsl
+++ b/
texturevertex.glsl
@@
-1,61
+1,46
@@
#version 330
#version 330
-in vec3
vPosition
;
+in vec3
pos
;
in vec4 vColor;
in vec4 vColor;
-in vec3
v
Normal;
+in vec3
unscaled
Normal;
in vec3 tangent;
in vec3 bitangent;
in vec2 vTexCoord;
in vec3 tangent;
in vec3 bitangent;
in vec2 vTexCoord;
+
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
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 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() {
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
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 T = normalize(vec3(model * vec4(tangent, 0.0)));
vec3 B = normalize(vec3(model * vec4(bitangent, 0.0)));
-
vec3 N = normalize(vec3(model * vec4(v
Normal, 0.0)));
+
vec3 N = normalize(vec3(model * vec4(unscaled
Normal, 0.0)));
// convert TBN to world->tangent space
mat3 TBN = transpose(mat3(T, B, N));
// convert TBN to world->tangent space
mat3 TBN = transpose(mat3(T, B, N));
+
lightPos = TBN * vLightPos;
viewPos = TBN * vViewPos;
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 *
p
os;
+ gl_Position = projection * view *
worldP
os;
}
}