mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-02 04:37:54 +08:00
Code re-work and content update: lighting.
This commit is contained in:
7
src/2.lighting/4.1.lighting_maps_diffuse_map/4.1.lamp.fs
Normal file
7
src/2.lighting/4.1.lighting_maps_diffuse_map/4.1.lamp.fs
Normal 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
|
||||
}
|
||||
11
src/2.lighting/4.1.lighting_maps_diffuse_map/4.1.lamp.vs
Normal file
11
src/2.lighting/4.1.lighting_maps_diffuse_map/4.1.lamp.vs
Normal 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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(1.0); // set alle 4 vector values to 1.0
|
||||
}
|
||||
11
src/2.lighting/4.2.lighting_maps_specular_map/4.2.lamp.vs
Normal file
11
src/2.lighting/4.2.lighting_maps_specular_map/4.2.lamp.vs
Normal 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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
7
src/2.lighting/4.3.lighting_maps_exercise4/4.3.lamp.fs
Normal file
7
src/2.lighting/4.3.lighting_maps_exercise4/4.3.lamp.fs
Normal 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
|
||||
}
|
||||
11
src/2.lighting/4.3.lighting_maps_exercise4/4.3.lamp.vs
Normal file
11
src/2.lighting/4.3.lighting_maps_exercise4/4.3.lamp.vs
Normal 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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
7
src/2.lighting/5.1.light_casters_directional/5.1.lamp.fs
Normal file
7
src/2.lighting/5.1.light_casters_directional/5.1.lamp.fs
Normal 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
|
||||
}
|
||||
11
src/2.lighting/5.1.light_casters_directional/5.1.lamp.vs
Normal file
11
src/2.lighting/5.1.light_casters_directional/5.1.lamp.vs
Normal 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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
7
src/2.lighting/5.2.light_casters_point/5.2.lamp.fs
Normal file
7
src/2.lighting/5.2.light_casters_point/5.2.lamp.fs
Normal 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
|
||||
}
|
||||
11
src/2.lighting/5.2.light_casters_point/5.2.lamp.vs
Normal file
11
src/2.lighting/5.2.light_casters_point/5.2.lamp.vs
Normal 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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
7
src/2.lighting/5.3.light_casters_spot/5.3.lamp.fs
Normal file
7
src/2.lighting/5.3.light_casters_spot/5.3.lamp.fs
Normal 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
|
||||
}
|
||||
11
src/2.lighting/5.3.light_casters_spot/5.3.lamp.vs
Normal file
11
src/2.lighting/5.3.light_casters_spot/5.3.lamp.vs
Normal 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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
7
src/2.lighting/5.4.light_casters_spot_soft/5.4.lamp.fs
Normal file
7
src/2.lighting/5.4.light_casters_spot_soft/5.4.lamp.fs
Normal 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
|
||||
}
|
||||
11
src/2.lighting/5.4.light_casters_spot_soft/5.4.lamp.vs
Normal file
11
src/2.lighting/5.4.light_casters_spot_soft/5.4.lamp.vs
Normal 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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
7
src/2.lighting/6.multiple_lights/6.lamp.fs
Normal file
7
src/2.lighting/6.multiple_lights/6.lamp.fs
Normal 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
|
||||
}
|
||||
11
src/2.lighting/6.multiple_lights/6.lamp.vs
Normal file
11
src/2.lighting/6.multiple_lights/6.lamp.vs
Normal 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);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user