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;
@@ -41,5 +41,5 @@ void main()
vec3 specular = light.specular * (spec * material.specular);
vec3 result = ambient + diffuse + specular;
fragColor = vec4(result, 1.0f);
FragColor = vec4(result, 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);
}

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;
@@ -41,5 +41,5 @@ void main()
vec3 specular = light.specular * spec * texture(material.specular, TexCoords).rgb;
vec3 result = ambient + diffuse + specular;
fragColor = vec4(result, 1.0f);
FragColor = vec4(result, 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);
}

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;
@@ -45,5 +45,5 @@ void main()
vec3 emission = texture(material.emission, TexCoords).rgb;
vec3 result = ambient + diffuse + specular + emission;
fragColor = vec4(result, 1.0f);
FragColor = vec4(result, 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);
}

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;
@@ -43,5 +43,5 @@ void main()
vec3 specular = light.specular * spec * texture(material.specular, TexCoords).rgb;
vec3 result = ambient + diffuse + specular;
fragColor = vec4(result, 1.0f);
FragColor = vec4(result, 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);
}

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;
@@ -46,12 +46,12 @@ 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;
diffuse *= attenuation;
specular *= attenuation;
vec3 result = ambient + diffuse + specular;
fragColor = vec4(result, 1.0f);
FragColor = vec4(result, 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);
}

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);
}

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;
@@ -56,11 +56,11 @@ 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;
diffuse *= attenuation;
specular *= attenuation;
vec3 result = ambient + diffuse + specular;
fragColor = vec4(result, 1.0f);
FragColor = vec4(result, 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);
}

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;
@@ -79,7 +79,7 @@ void main()
// phase 3: spot light
result += CalcSpotLight(spotLight, norm, FragPos, viewDir);
fragColor = vec4(result, 1.0);
FragColor = vec4(result, 1.0);
}
// calculates the color when using a directional light.
@@ -109,7 +109,7 @@ vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
// 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));
// combine results
vec3 ambient = light.ambient * vec3(texture(material.diffuse, TexCoords));
vec3 diffuse = light.diffuse * diff * vec3(texture(material.diffuse, TexCoords));
@@ -131,7 +131,7 @@ vec3 CalcSpotLight(SpotLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
// 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));
// spotlight intensity
float theta = dot(lightDir, normalize(-light.direction));
float epsilon = light.cutOff - light.outerCutOff;

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);
}