Diffuse lighting and sending the normals to shaders
This commit is contained in:
25
OpenGL/playground/resources/shaders/phong.frag
Normal file
25
OpenGL/playground/resources/shaders/phong.frag
Normal file
@@ -0,0 +1,25 @@
|
||||
#version 330
|
||||
|
||||
in vec3 Normal;
|
||||
in vec3 FragPos;
|
||||
|
||||
uniform vec3 lightPos;
|
||||
|
||||
out vec4 outColour;
|
||||
|
||||
vec3 objectColour = vec3(0.58, 0.61, 0.627);
|
||||
vec3 lightColour = vec3(0.0, 1.0, 1.0);
|
||||
|
||||
void main() {
|
||||
float ambientStrength = 0.5;
|
||||
vec3 ambient = ambientStrength * lightColour;
|
||||
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 lightDir = normalize(lightPos - FragPos);
|
||||
|
||||
float diff = max(dot(norm, lightDir), 0.0);
|
||||
vec3 diffuse = diff * lightColour;
|
||||
|
||||
vec3 result = (ambient + diffuse) * objectColour;
|
||||
outColour = vec4(result, 1.0);
|
||||
}
|
||||
17
OpenGL/playground/resources/shaders/phong.vert
Normal file
17
OpenGL/playground/resources/shaders/phong.vert
Normal file
@@ -0,0 +1,17 @@
|
||||
#version 330
|
||||
|
||||
in vec3 position;
|
||||
in vec3 normal;
|
||||
|
||||
out vec3 Normal;
|
||||
out vec3 FragPos;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 proj;
|
||||
|
||||
void main() {
|
||||
gl_Position = proj * view * model * vec4(position, 1.0);
|
||||
FragPos = vec3(model * vec4(position, 1.0));
|
||||
Normal = normal;
|
||||
}
|
||||
Reference in New Issue
Block a user