Code re-work and content update: lighting.

This commit is contained in:
Joey de Vries
2017-05-30 22:17:40 +02:00
parent 320db41e89
commit e2e36d6ff8
33 changed files with 182 additions and 38 deletions

View File

@@ -0,0 +1,7 @@
#version 330 core
out vec4 FragColor;
void main()
{
FragColor = vec4(1.0); // set alle 4 vector values to 1.0
}

View File

@@ -0,0 +1,11 @@
#version 330 core
layout (location = 0) in vec3 aPos;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
gl_Position = projection * view * model * vec4(aPos, 1.0);
}

View File

@@ -1,5 +1,5 @@
#version 330 core
out vec4 fragColor;
out vec4 FragColor;
struct Material {
sampler2D diffuse;
@@ -55,18 +55,18 @@ void main()
// attenuation
float distance = length(light.position - FragPos);
float attenuation = 1.0f / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
// ambient *= attenuation; // remove attenuation from ambient, as otherwise at large distances the light would be darker inside than outside the spotlight due the ambient term in the else branche
diffuse *= attenuation;
specular *= attenuation;
vec3 result = ambient + diffuse + specular;
fragColor = vec4(result, 1.0f);
FragColor = vec4(result, 1.0);
}
else
{
// else, use ambient light so scene isn't completely dark outside the spotlight.
fragColor = vec4(light.ambient * texture(material.diffuse, TexCoords).rgb, 1.0f);
FragColor = vec4(light.ambient * texture(material.diffuse, TexCoords).rgb, 1.0);
}
}

View File

@@ -13,9 +13,9 @@ uniform mat4 projection;
void main()
{
FragPos = vec3(model * vec4(aPos, 1.0f));
FragPos = vec3(model * vec4(aPos, 1.0));
Normal = mat3(transpose(inverse(model))) * aNormal;
TexCoords = aTexCoords;
gl_Position = projection * view * vec4(FragPos, 1.0f);
gl_Position = projection * view * vec4(FragPos, 1.0);
}