From 6781af306edc8f6b0928013ed9ec2fa87d63da81 Mon Sep 17 00:00:00 2001 From: jvech Date: Mon, 12 Sep 2022 10:18:08 -0500 Subject: learn: 15. lightning maps --- shaders/color.fsh | 12 ++++++------ shaders/color.vsh | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'shaders') diff --git a/shaders/color.fsh b/shaders/color.fsh index 4989d73..c2a8dc7 100644 --- a/shaders/color.fsh +++ b/shaders/color.fsh @@ -1,9 +1,8 @@ # version 330 core struct Material { - vec3 ambient; - vec3 diffuse; - vec3 specular; + sampler2D diffuse; + sampler2D specular; float shininess; }; @@ -16,6 +15,7 @@ struct Light { in vec3 Normal; in vec3 FragPos; +in vec2 TexCoords; out vec4 FragColor; @@ -26,19 +26,19 @@ uniform Light light; void main() { // ambient - vec3 ambient = material.ambient * light.ambient; + vec3 ambient = light.ambient * texture(material.diffuse, TexCoords).rgb; // diffuse vec3 norm = normalize(Normal); vec3 lightDir = normalize(light.position - FragPos); float diff = max(dot(norm, lightDir), 0.0); - vec3 diffuse = light.diffuse * diff * material.diffuse; + vec3 diffuse = light.diffuse * diff * texture(material.diffuse, TexCoords).rgb; // specular vec3 viewDir = normalize(viewPos - FragPos); vec3 reflectDir = reflect(-lightDir, norm); float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess); - vec3 specular = light.specular * spec * material.specular; + vec3 specular = light.specular * spec * texture(material.specular, TexCoords).rgb; FragColor = vec4((specular + ambient + diffuse), 1.0f); } diff --git a/shaders/color.vsh b/shaders/color.vsh index ff878be..d3a2082 100644 --- a/shaders/color.vsh +++ b/shaders/color.vsh @@ -2,16 +2,19 @@ layout (location = 0) in vec3 aPos; layout (location = 1) in vec3 aNormal; +layout (location = 2) in vec2 aTexCoords; uniform mat4 model, view, proj; uniform mat4 rotNormals; out vec3 FragPos; out vec3 Normal; +out vec2 TexCoords; void main() { gl_Position = proj * view * model * vec4(aPos, 1.0f); FragPos = vec3(model * vec4(aPos, 1.0)); Normal = vec3(rotNormals * vec4(aNormal, 1.0)); + TexCoords = aTexCoords; } -- cgit v1.2.3-70-g09d2