uniform vec4 g_AmbientLightColor; uniform vec3 m_SunDir; // Richtung von der Fläche zur Sonne (world-space, normiert) uniform vec4 m_SunColor; // Sonnenfarbe RGB uniform float m_Wetness; in vec4 varColor; in vec3 varNormal; out vec4 outFragColor; void main() { // Normale für Rück- und Vorderseite korrekt ausrichten vec3 n = normalize(varNormal); if (!gl_FrontFacing) n = -n; vec3 L = normalize(m_SunDir); // Diffuses Licht float nDotL = max(dot(n, L), 0.0); // Subsurface-Scatter-Approximation: etwas Licht scheint durch den Halm float sss = max(dot(-n, L), 0.0) * 0.25; float light = nDotL + sss; vec3 col = varColor.rgb * (1.0 - 0.18 * m_Wetness); vec3 ambient = g_AmbientLightColor.rgb * col; vec3 diffuse = m_SunColor.rgb * col * light; // Farbe nicht über die Vertex-Color-Helligkeit hinaus aufhellen vec3 result = ambient + diffuse; result = min(result, col * 1.5); float shine = pow(max(nDotL, 0.0), 12.0) * m_Wetness * 0.25; outFragColor = vec4(result + vec3(shine), 1.0); }