From 78d0b091eeef75d9263961658e54b9c00a6ba274 Mon Sep 17 00:00:00 2001 From: Adrian G L Date: Thu, 2 Oct 2025 13:27:09 +0200 Subject: [PATCH] feat: add bump mapping to terrain for rougher, less smooth shading --- shaders/simple.frag | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/shaders/simple.frag b/shaders/simple.frag index da4e918..b3ffc6a 100644 --- a/shaders/simple.frag +++ b/shaders/simple.frag @@ -9,15 +9,19 @@ void main() { // ambient component float ambientStrength = 0.1; vec3 ambient = ambientStrength * vColor.rgb; - // diffuse component (Lambert) - float lambert = max(0.0, dot(normalize(vNormal), -lightDirection)); + // bump mapping perturbation + float bumpStrength = 0.2; + float nVal = fract(sin(dot(vNormal.xy, vec2(12.9898, 78.233))) * 43758.5453); + vec3 bumpNormal = normalize(vNormal + bumpStrength * (nVal - 0.5)); + // diffuse component (Lambert) with bump + float lambert = max(0.0, dot(normalize(bumpNormal), -lightDirection)); vec3 diffuse = vColor.rgb * lambert; // combine ambient and diffuse vec3 result = ambient + diffuse; // specular component (Phong) float shininess = 32.0; vec3 viewDir = vec3(0.0, 0.0, 1.0); - vec3 reflectDir = reflect(-lightDirection, normalize(vNormal)); + vec3 reflectDir = reflect(-lightDirection, bumpNormal); float spec = pow(max(dot(reflectDir, viewDir), 0.0), shininess); float specStrength = 0.5; vec3 specular = specStrength * spec * vec3(1.0);