Created
August 15, 2023 05:44
-
-
Save thatcosmonaut/17d615a4ff6242dec02772b8121c1d85 to your computer and use it in GitHub Desktop.
Specular Lighting Shader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 450 | |
layout(location = 0) in vec3 InNormal; | |
layout(location = 1) in vec3 InFragPos; | |
layout(location = 0) out vec4 FragColor; | |
layout(binding = 0, set = 3) uniform UBO | |
{ | |
vec3 ViewPos; | |
float Strength; | |
vec3 LightColor; | |
float Shininess; | |
} ubo; | |
void main() | |
{ | |
vec3 norm = normalize(InNormal); | |
vec3 viewDir = normalize(ubo.ViewPos - InFragPos); | |
vec3 lightDir = normalize(ubo.LightPos - InFragPos); | |
vec3 reflectDir = reflect(-lightDir, norm); | |
float spec = pow(max(dot(viewDir, reflectDir), 0.0), ubo.Shininess); | |
vec3 specular = ubo.Strength * spec * ubo.LightColor; | |
FragColor = vec4(specular, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment