mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-30 20:13:22 +08:00
Code re-work and content update: lighting.
This commit is contained in:
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);
|
||||
}
|
||||
Reference in New Issue
Block a user