Skip to content

Instantly share code, notes, and snippets.

@thatcosmonaut
Created August 15, 2023 05:44
Show Gist options
  • Save thatcosmonaut/17d615a4ff6242dec02772b8121c1d85 to your computer and use it in GitHub Desktop.
Save thatcosmonaut/17d615a4ff6242dec02772b8121c1d85 to your computer and use it in GitHub Desktop.
Specular Lighting Shader
#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