11 static constexpr
const char* vertex = R
"(uniform mat4 u_matrix;
12 uniform vec2 u_dimension;
14 layout (location = 0) in vec2 a_pos;
15 layout (location = 1) in vec2 a_texture_pos;
20 gl_Position = u_matrix * vec4(a_pos, 0, 1);
22 highp vec2 epsilon = 1.0 / u_dimension;
23 float scale = (u_dimension.x - 2.0) / u_dimension.x;
24 v_pos = (a_texture_pos / 8192.0) * scale + epsilon;
27 static constexpr
const char* fragment = R
"(#ifdef GL_ES
28 precision highp float;
31 uniform sampler2D u_image;
33 uniform vec2 u_dimension;
35 uniform float u_maxzoom;
36 uniform vec4 u_unpack;
38 float getElevation(vec2 coord, float bias) {
39 // Convert encoded elevation value to meters
40 vec4 data = texture(u_image, coord) * 255.0;
42 return dot(data, u_unpack) / 4.0;
46 vec2 epsilon = 1.0 / u_dimension;
63 float a = getElevation(v_pos + vec2(-epsilon.x, -epsilon.y), 0.0);
64 float b = getElevation(v_pos + vec2(0, -epsilon.y), 0.0);
65 float c = getElevation(v_pos + vec2(epsilon.x, -epsilon.y), 0.0);
66 float d = getElevation(v_pos + vec2(-epsilon.x, 0), 0.0);
67 float e = getElevation(v_pos, 0.0);
68 float f = getElevation(v_pos + vec2(epsilon.x, 0), 0.0);
69 float g = getElevation(v_pos + vec2(-epsilon.x, epsilon.y), 0.0);
70 float h = getElevation(v_pos + vec2(0, epsilon.y), 0.0);
71 float i = getElevation(v_pos + vec2(epsilon.x, epsilon.y), 0.0);
73 // here we divide the x and y slopes by 8 * pixel size
74 // where pixel size (aka meters/pixel) is:
75 // circumference of the world / (pixels per tile * number of tiles)
76 // which is equivalent to: 8 * 40075016.6855785 / (512 * pow(2, u_zoom))
77 // which can be reduced to: pow(2, 19.25619978527 - u_zoom)
78 // we want to vertically exaggerate the hillshading though, because otherwise
79 // it is barely noticeable at low zooms. to do this, we multiply this by some
80 // scale factor pow(2, (u_zoom - u_maxzoom) * a) where a is an arbitrary value
81 // Here we use a=0.3 which works out to the expression below. see
82 // nickidlugash's awesome breakdown for more info
83 // https://github.com/mapbox/mapbox-gl-js/pull/5286#discussion_r148419556
84 float exaggeration = u_zoom < 2.0 ? 0.4 : u_zoom < 4.5 ? 0.35 : 0.3;
87 (c + f + f + i) - (a + d + d + g),
88 (g + h + h + i) - (a + b + b + c)
89 ) / pow(2.0, (u_zoom - u_maxzoom) * exaggeration + 19.2562 - u_zoom);
91 fragColor = clamp(vec4(
97 #ifdef OVERDRAW_INSPECTOR
98 fragColor = vec4(1.0);
@ OpenGL
The OpenGL API backend.
BuiltIn
This enum is used with the ShaderSource template to select source code for the desired program and gr...
@ HillshadePrepareProgram
Select shader source based on a program type and a desired graphics API.