Skip to content

Commit

Permalink
Merge pull request #177 from tangrams/simplify-spheremap
Browse files Browse the repository at this point in the history
Simplify spheremap shaders
  • Loading branch information
nvkelso authored May 10, 2017
2 parents 21923e8 + 7b598ac commit d134958
Showing 1 changed file with 13 additions and 48 deletions.
61 changes: 13 additions & 48 deletions walkabout-style.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -922,75 +922,40 @@ 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);
float scale1 = 20./(u_map_position.z) + 1.5;
float m = u_zoom_scale * (u_map_position.z - 0.8) * exp(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:
Expand Down

0 comments on commit d134958

Please sign in to comment.