Ligthing working
This commit is contained in:
37
shaders/lighting/Frag.glsl
Normal file
37
shaders/lighting/Frag.glsl
Normal file
@@ -0,0 +1,37 @@
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec3 FragPos;
|
||||
in vec3 Normal;
|
||||
|
||||
uniform vec3 ourColor;
|
||||
uniform vec3 lightColor;
|
||||
uniform vec3 lightPos;
|
||||
uniform vec3 viewPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
float ambientStrength = 0.15;
|
||||
float specularStrength = 0.5;
|
||||
|
||||
//msc
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 lightDir = normalize(lightPos - FragPos);
|
||||
|
||||
// ambient
|
||||
vec3 ambient = ambientStrength * lightColor;
|
||||
|
||||
// diffuse
|
||||
float diff = max(dot(norm, lightDir), 0.0);
|
||||
vec3 diffuse = diff * lightColor;
|
||||
|
||||
// specular
|
||||
vec3 viewDir = normalize(viewPos - FragPos);
|
||||
vec3 reflectDir = reflect(-lightDir, norm);
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 150);
|
||||
vec3 specular = specularStrength * spec * lightColor;
|
||||
|
||||
// out
|
||||
vec3 result = (ambient + diffuse+specular) * ourColor;
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
||||
9
shaders/lighting/LightFrag.glsl
Normal file
9
shaders/lighting/LightFrag.glsl
Normal file
@@ -0,0 +1,9 @@
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec3 ourColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(ourColor, 1.0);
|
||||
}
|
||||
18
shaders/lighting/Vert.glsl
Normal file
18
shaders/lighting/Vert.glsl
Normal file
@@ -0,0 +1,18 @@
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
|
||||
out vec3 FragPos;
|
||||
out vec3 Normal;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||
FragPos = vec3(model * vec4(aPos, 1.0));
|
||||
Normal = aNormal;
|
||||
//Normal = mat3(transpose(inverse(model))) * aNormal;//if non unifrom scale
|
||||
}
|
||||
Reference in New Issue
Block a user