engine/test/res/shader.frag

38 lines
1.1 KiB
GLSL
Raw Normal View History

2022-11-07 20:15:26 +00:00
#version 450
layout(location = 0) in vec3 fragPos;
layout(location = 1) in vec3 fragNorm;
layout(location = 2) in vec2 fragUV;
layout(location = 3) in vec3 fragLightPos;
layout(location = 4) in vec3 fragColor;
layout(location = 0) out vec4 outColor;
2022-11-11 16:18:22 +00:00
layout(set = 1, binding = 0) uniform sampler2D texSampler;
2022-11-08 15:34:59 +00:00
2022-11-07 20:15:26 +00:00
void main() {
// constants
vec3 lightColor = vec3(1.0, 1.0, 1.0);
vec3 ambientColor = vec3(1.0, 1.0, 1.0);
float ambientStrength = 0.1;
2022-11-11 16:18:22 +00:00
vec3 baseColor = vec3(texture(texSampler, fragUV));
2022-11-07 20:15:26 +00:00
vec3 emission = vec3(0.0, 0.0, 0.0);
// code
vec3 norm = normalize(fragNorm);
vec3 lightDir = normalize(fragLightPos - fragPos);
vec3 diffuse = max(dot(norm, lightDir), 0.0) * lightColor;
vec3 ambient = ambientColor * ambientStrength;
vec3 viewDir = normalize(-fragPos);
vec3 reflectDir = reflect(-lightDir, norm);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
vec3 specular = 0.5 * spec * lightColor;
vec3 lighting = min(diffuse + ambient + specular, 1.0);
outColor = min( ( vec4(baseColor, 1.0) ) * vec4(lighting + emission, 1.0), vec4(1.0));
}