Correct for non uniform scale in lighting
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#version 330 core
|
||||
|
||||
noperspective in vec2 UV;
|
||||
in vec3 NORMAL;
|
||||
|
||||
in vec3 AMBIENT;
|
||||
in vec3 DIFFUSE;
|
||||
|
||||
@@ -7,9 +7,9 @@ layout (location = 2) in vec2 uv;
|
||||
uniform mat4 MODEL;
|
||||
uniform mat4 VIEW;
|
||||
uniform mat4 PROJECTION;
|
||||
uniform mat3 NORMAL;
|
||||
|
||||
noperspective out vec2 UV; // PSX use affine texture mapping
|
||||
out vec3 NORMAL;
|
||||
|
||||
out vec3 AMBIENT;
|
||||
out vec3 DIFFUSE;
|
||||
@@ -46,18 +46,19 @@ void main() {
|
||||
|
||||
UV = uv;
|
||||
|
||||
NORMAL = (VIEW * MODEL * vec4(normal, 0.0)).xyz;
|
||||
vec3 my_normal = (VIEW * MODEL * vec4(normal, 0.0)).xyz;
|
||||
my_normal *= NORMAL;
|
||||
|
||||
// Flat shading, we compute light per vertex
|
||||
AMBIENT = directionalLight.ambient * directionalLight.color * material.ambient;
|
||||
|
||||
vec3 direction = -(VIEW * vec4(directionalLight.direction, 0.0)).xyz;
|
||||
float diff = dot(normalize(direction), normalize(NORMAL));
|
||||
float diff = dot(normalize(direction), normalize(my_normal));
|
||||
diff = max(diff, 0.0);
|
||||
DIFFUSE = directionalLight.diffuse * diff * directionalLight.color * material.diffuse;
|
||||
|
||||
vec3 viewDir = normalize((VIEW * MODEL * vec4(pos, 1.0)).xyz);
|
||||
vec3 reflectionDir = reflect(normalize(direction), normalize(NORMAL));
|
||||
vec3 reflectionDir = reflect(normalize(direction), normalize(my_normal));
|
||||
float spec = dot(viewDir, reflectionDir);
|
||||
spec = max(spec, 0.0);
|
||||
spec = pow(spec, material.shininess);
|
||||
|
||||
Reference in New Issue
Block a user