Added diffuse lighting

This commit is contained in:
Warwick 2022-06-13 14:07:55 +01:00
parent 16dd10f252
commit a91fc3d57d
2 changed files with 22 additions and 2 deletions

View file

@ -2,6 +2,8 @@
out vec4 FragColor;
in vec2 ourTexCoord;
in vec3 ourNormCoord;
in vec3 FragPos;
// Handle multiple textures from the Mesh Object (Might not even be used)
uniform sampler2D texture_diffuse1;
@ -14,7 +16,19 @@ uniform sampler2D ourTexture;
void main()
{
FragColor = texture(texture_diffuse1, ourTexCoord);
// Establish ambient lighting
float ambientStrength = 0.1;
// Establish a temporary hard coded light position
vec3 lightPosition = vec3(1.0, 1.0, 1.0);
// Normal light maths
vec3 norm = normalize(ourNormCoord);
vec3 lightDir = normalize(lightPosition - FragPos);
// Calculate diffuse
float diff = max(dot(norm, lightDir), 0.0);
FragColor = texture(texture_diffuse1, ourTexCoord) * (ambientStrength + diff);
//FragColor = texture(ourTexture, ourTexCoord);
//FragColor = vec4(ourTexCoord.y,ourTexCoord.x,0,0);
}

View file

@ -1,15 +1,21 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal; // Currently Unused
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTexCoord;
uniform mat4 MVP;
uniform mat4 Model;
out vec2 ourTexCoord;
out vec3 ourNormCoord;
out vec3 FragPos;
void main()
{
gl_Position = MVP * Model * vec4(aPos, 1.0);
ourNormCoord = aNormal;
ourTexCoord = aTexCoord;
// Calculate position of fragment
FragPos = vec3(Model * vec4(aPos, 1.0));
};