From 4db360df39ea295174480ebec1c35c17067a7cf3 Mon Sep 17 00:00:00 2001 From: Adrian G L Date: Thu, 2 Oct 2025 13:29:30 +0200 Subject: [PATCH] feat: add contour-based multi-octave bump mapping for rougher terrain --- shaders/simple.frag | 10 ++++++---- shaders/simple.vert | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/shaders/simple.frag b/shaders/simple.frag index b3ffc6a..6b6291f 100644 --- a/shaders/simple.frag +++ b/shaders/simple.frag @@ -9,10 +9,12 @@ void main() { // ambient component float ambientStrength = 0.1; vec3 ambient = ambientStrength * vColor.rgb; - // 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)); + // terrain bump mapping with multi‐octave noise based on world position + float bumpStrength = 0.4; + float n1 = fract(sin(dot(vPosition.xz, vec2(12.9898, 78.233))) * 43758.5453); + float n2 = fract(sin(dot(vPosition.xz * 0.5, vec2(93.9898, 67.345))) * 24634.6345); + float noiseVal = mix(n1, n2, 0.5); + vec3 bumpNormal = normalize(vNormal + bumpStrength * (noiseVal - 0.5) * vec3(1.0)); // diffuse component (Lambert) with bump float lambert = max(0.0, dot(normalize(bumpNormal), -lightDirection)); vec3 diffuse = vColor.rgb * lambert; diff --git a/shaders/simple.vert b/shaders/simple.vert index 27f00a3..9019264 100644 --- a/shaders/simple.vert +++ b/shaders/simple.vert @@ -5,11 +5,13 @@ layout(location = 1) in vec4 aColor; layout(location = 2) in vec3 aNormal; out vec4 vColor; out vec3 vNormal; +out vec3 vPosition; layout(location = 0) uniform mat4 transform; layout(location = 1) uniform mat3 normalMatrix; void main() { gl_Position = transform * vec4(position, 1.0); vColor = aColor; + vPosition = position; vNormal = normalize(normalMatrix * aNormal); }