feat: add ambient component to fragment shader for Phong shading start

This commit is contained in:
2025-10-02 13:21:22 +02:00
parent e6dcc428d4
commit 3a138ec59e

View File

@@ -6,7 +6,13 @@ in vec3 vNormal;
void main() {
vec3 lightDirection = normalize(vec3(0.8, -0.5, 0.6));
// ambient component
float ambientStrength = 0.1;
vec3 ambient = ambientStrength * vColor.rgb;
// diffuse component (Lambert)
float lambert = max(0.0, dot(normalize(vNormal), -lightDirection));
vec3 litColor = vColor.rgb * lambert;
color = vec4(litColor, vColor.a);
vec3 diffuse = vColor.rgb * lambert;
// combine ambient and diffuse
vec3 result = ambient + diffuse;
color = vec4(result, vColor.a);
}