From 07825118534631aee8c0e4d0b5d6fb338813fcba Mon Sep 17 00:00:00 2001 From: Brett Camper Date: Tue, 9 May 2017 12:29:01 -0400 Subject: [PATCH 1/2] simplify spheremap shader and consolidate variants --- walkabout-style.yaml | 62 ++++++++++---------------------------------- 1 file changed, 14 insertions(+), 48 deletions(-) diff --git a/walkabout-style.yaml b/walkabout-style.yaml index fc7eb92..e21ff62 100644 --- a/walkabout-style.yaml +++ b/walkabout-style.yaml @@ -913,75 +913,41 @@ styles: raster: normal shaders: uniforms: - # u_envmap: images/relief-shading-environment-map.jpg u_envmap: images/draw-test10.jpg - # u_envmap: https://raw.githubusercontent.com/tangrams/walkabout-style/gh-pages/images/draw-test10.jpg u_contrast: 1. u_brightness: 1. + u_zoom_scale: 3.5 blocks: global: | // Simplified view-independent environment map - vec4 terrainEnvmap (in sampler2D _tex, in vec3 _normal) { - const vec3 eye = vec3(0.,0.,-1.); - vec3 r = reflect(eye, _normal); - r.z += 1.; - float m = 2. * length(r); - vec2 uv = r.xy / m + .5; - return texture2D(_tex, uv); + vec4 applyEnvmap (in sampler2D _tex, in vec3 _normal, in float scale) { + _normal.z *= scale; + return texture2D(_tex, .5*(normalize(_normal).xy + 1.)); } - const float e = 2.71828; color: | - // scale up normals with a function - // https://www.desmos.com/calculator/bv4mzh8erz - //float scale = 10./(u_map_position.z-.7) + 1.8; - float scale1 = 20./(u_map_position.z) + 1.5; - normal.z /= scale1; // turn terrain exaggeration up/down + // turn terrain exaggeration up/down // fade out spheremap normals with a function - // https://www.desmos.com/calculator/ptgkzcnfyc - float m = 3.5 * (u_map_position.z - 0.8) * pow(e, u_map_position.z * -.29); + const float e = 2.71828; + float scale1 = 20./(u_map_position.z) + 1.5; + float m = u_zoom_scale * (u_map_position.z - 0.8) * pow(e, u_map_position.z * -.29); m = clamp(m, 0., 1.5); - color = terrainEnvmap(u_envmap, normal); + color = applyEnvmap(u_envmap, normal, 1./scale1); - // Apply contrast + // apply contrast and brightness float contrast = m; color.rgb = ((color.rgb - 0.5) * max(contrast, 0.)) + 0.5; - // Apply brightness float brightness = .5 - m * .5; color.rgb += brightness; - color *= v_color; // apply layer color + // apply layer color + color *= v_color; terrain-park: - base: polygons - lighting: false - raster: normal + mix: terrain shaders: uniforms: u_envmap: images/walkabout-green1.jpg - blocks: - global: | - vec4 terrainEnvmap (in sampler2D _tex, in vec3 _normal) { - const vec3 eye = vec3(0.,0.,-1.); - vec3 r = reflect(eye, _normal); - r.z += 1.; - float m = 2. * length(r); - vec2 uv = r.xy / m + .5; - return texture2D(_tex, uv); - } - const float e = 2.71828; - color: | - float scale1 = 20./(u_map_position.z) + 1.5; - normal.z /= scale1; - float m = 3.95 * (u_map_position.z - 0.8) * pow(e, u_map_position.z * -.29); - m = clamp(m, 0., 1.5); - color = terrainEnvmap(u_envmap, normal); - - float contrast = m; - color.rgb = ((color.rgb - 0.5) * max(contrast, 0.)) + 0.5; - float brightness = .5 - m * .5; - color.rgb += brightness; - - color *= v_color; + u_zoom_scale: 3.95 # HSV/RGB functions hsv: From 23b0109de9a1bf5b51c366c3d39c3c7b9d24ed9c Mon Sep 17 00:00:00 2001 From: Brett Camper Date: Tue, 9 May 2017 12:38:37 -0400 Subject: [PATCH 2/2] use GLSL exp() --- walkabout-style.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/walkabout-style.yaml b/walkabout-style.yaml index e21ff62..a08c864 100644 --- a/walkabout-style.yaml +++ b/walkabout-style.yaml @@ -927,9 +927,8 @@ styles: color: | // turn terrain exaggeration up/down // fade out spheremap normals with a function - const float e = 2.71828; float scale1 = 20./(u_map_position.z) + 1.5; - float m = u_zoom_scale * (u_map_position.z - 0.8) * pow(e, u_map_position.z * -.29); + float m = u_zoom_scale * (u_map_position.z - 0.8) * exp(u_map_position.z * -.29); m = clamp(m, 0., 1.5); color = applyEnvmap(u_envmap, normal, 1./scale1);