summaryrefslogtreecommitdiff
path: root/src/mbgl/shaders/hillshade.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/shaders/hillshade.cpp')
-rw-r--r--src/mbgl/shaders/hillshade.cpp251
1 files changed, 182 insertions, 69 deletions
diff --git a/src/mbgl/shaders/hillshade.cpp b/src/mbgl/shaders/hillshade.cpp
index 4083faa4b4..1238cf812d 100644
--- a/src/mbgl/shaders/hillshade.cpp
+++ b/src/mbgl/shaders/hillshade.cpp
@@ -1,80 +1,193 @@
// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.
#include <mbgl/shaders/hillshade.hpp>
+#include <mbgl/util/compression.hpp>
+
+#include <cstdint>
namespace mbgl {
namespace shaders {
const char* hillshade::name = "hillshade";
-const char* hillshade::vertexSource = R"MBGL_SHADER(
-uniform mat4 u_matrix;
-
-attribute vec2 a_pos;
-attribute vec2 a_texture_pos;
-
-varying vec2 v_pos;
-
-void main() {
- gl_Position = u_matrix * vec4(a_pos, 0, 1);
- v_pos = a_texture_pos / 8192.0;
-}
-
-)MBGL_SHADER";
-const char* hillshade::fragmentSource = R"MBGL_SHADER(
-uniform sampler2D u_image;
-varying vec2 v_pos;
-
-uniform vec2 u_latrange;
-uniform vec2 u_light;
-uniform vec4 u_shadow;
-uniform vec4 u_highlight;
-uniform vec4 u_accent;
-
-#define PI 3.141592653589793
-
-void main() {
- vec4 pixel = texture2D(u_image, v_pos);
-
- vec2 deriv = ((pixel.rg * 2.0) - 1.0);
-
- // We divide the slope by a scale factor based on the cosin of the pixel's approximate latitude
- // to account for mercator projection distortion. see #4807 for details
- float scaleFactor = cos(radians((u_latrange[0] - u_latrange[1]) * (1.0 - v_pos.y) + u_latrange[1]));
- // We also multiply the slope by an arbitrary z-factor of 1.25
- float slope = atan(1.25 * length(deriv) / scaleFactor);
- float aspect = deriv.x != 0.0 ? atan(deriv.y, -deriv.x) : PI / 2.0 * (deriv.y > 0.0 ? 1.0 : -1.0);
-
- float intensity = u_light.x;
- // We add PI to make this property match the global light object, which adds PI/2 to the light's azimuthal
- // position property to account for 0deg corresponding to north/the top of the viewport in the style spec
- // and the original shader was written to accept (-illuminationDirection - 90) as the azimuthal.
- float azimuth = u_light.y + PI;
-
- // We scale the slope exponentially based on intensity, using a calculation similar to
- // the exponential interpolation function in the style spec:
- // https://github.com/mapbox/mapbox-gl-js/blob/master/src/style-spec/expression/definitions/interpolate.js#L217-L228
- // so that higher intensity values create more opaque hillshading.
- float base = 1.875 - intensity * 1.75;
- float maxValue = 0.5 * PI;
- float scaledSlope = intensity != 0.5 ? ((pow(base, slope) - 1.0) / (pow(base, maxValue) - 1.0)) * maxValue : slope;
-
- // The accent color is calculated with the cosine of the slope while the shade color is calculated with the sine
- // so that the accent color's rate of change eases in while the shade color's eases out.
- float accent = cos(scaledSlope);
- // We multiply both the accent and shade color by a clamped intensity value
- // so that intensities >= 0.5 do not additionally affect the color values
- // while intensity values < 0.5 make the overall color more transparent.
- vec4 accent_color = (1.0 - accent) * u_accent * clamp(intensity * 2.0, 0.0, 1.0);
- float shade = abs(mod((aspect + azimuth) / PI + 0.5, 2.0) - 1.0);
- vec4 shade_color = mix(u_shadow, u_highlight, shade) * sin(scaledSlope) * clamp(intensity * 2.0, 0.0, 1.0);
- gl_FragColor = accent_color * (1.0 - shade_color.a) + shade_color;
-
-#ifdef OVERDRAW_INSPECTOR
- gl_FragColor = vec4(1.0);
-#endif
-}
-
-)MBGL_SHADER";
+const char* hillshade::vertexSource = [] () {
+ static const uint8_t compressed[] = {
+ 0x78, 0xda, 0x65, 0x8d, 0xc1, 0x0a, 0xc2, 0x30,
+ 0x10, 0x44, 0xef, 0xfb, 0x15, 0x73, 0x6c, 0xa5,
+ 0x68, 0x5b, 0x7a, 0x50, 0x82, 0xff, 0xe0, 0x1f,
+ 0x94, 0xa8, 0xb1, 0x2c, 0xd8, 0x44, 0xd2, 0x4d,
+ 0xa8, 0x88, 0xff, 0x6e, 0x4c, 0x51, 0x10, 0xf7,
+ 0xb2, 0xcb, 0xcc, 0xec, 0xbc, 0x60, 0xf9, 0xe2,
+ 0xfc, 0x88, 0x51, 0x4b, 0x87, 0xd0, 0xa7, 0xe5,
+ 0x79, 0x56, 0x44, 0x5a, 0xd2, 0x71, 0x0c, 0x62,
+ 0x10, 0xcd, 0xa9, 0x85, 0xee, 0x6f, 0x6e, 0x52,
+ 0xff, 0xaa, 0x98, 0x59, 0x82, 0x37, 0x8b, 0x4b,
+ 0x51, 0xfb, 0x3b, 0xdb, 0x61, 0x31, 0xe3, 0x47,
+ 0x74, 0x7c, 0x4e, 0xf5, 0x6c, 0x8b, 0x12, 0x0f,
+ 0x42, 0x9a, 0xe1, 0xda, 0x1f, 0xdc, 0xc4, 0xc2,
+ 0xce, 0x62, 0xff, 0x85, 0x62, 0xf5, 0xfe, 0xeb,
+ 0x8a, 0x8c, 0xaa, 0x50, 0x57, 0x68, 0x4a, 0x95,
+ 0xf3, 0xb9, 0x29, 0x25, 0x7f, 0x70, 0xd8, 0x60,
+ 0xdb, 0xec, 0xda, 0x75, 0xad, 0xe8, 0x49, 0x2f,
+ 0x97, 0x4d, 0x40, 0xaf
+ };
+ static std::string decompressed = util::decompress(std::string(reinterpret_cast<const char*>(compressed), sizeof(compressed)));
+ return decompressed.c_str();
+}();
+const char* hillshade::fragmentSource = [] () {
+ static const uint8_t compressed[] = {
+ 0x78, 0xda, 0x8d, 0x56, 0xdb, 0x6e, 0xdb, 0x38,
+ 0x10, 0x7d, 0xf7, 0x57, 0x4c, 0x91, 0x87, 0x95,
+ 0x1b, 0x5b, 0x8a, 0x95, 0x78, 0x9d, 0xa4, 0x9b,
+ 0x16, 0x8b, 0xa6, 0x05, 0x02, 0x14, 0x6d, 0x90,
+ 0x16, 0xed, 0xc3, 0xa2, 0x30, 0x68, 0x89, 0x96,
+ 0x98, 0xa5, 0x44, 0x95, 0xa4, 0x7c, 0xe9, 0x62,
+ 0xff, 0xbd, 0x33, 0x24, 0x65, 0xcb, 0x4e, 0x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 0x87, 0x5f, 0x09, 0xbb, 0xdc, 0x1c,
+ 0xc8, 0x2e, 0xb5, 0x4a, 0x6c, 0xa2, 0xee, 0x03,
+ 0x68, 0xd4, 0xff, 0xe6, 0x19, 0x79, 0x43, 0xca,
+ 0x16, 0x85, 0x74, 0xc0, 0xe9, 0xff, 0xce, 0xba,
+ 0x90, 0xf3, 0xf7, 0x9a, 0x15, 0x6f, 0x43, 0xac,
+ 0x83, 0xae, 0xec, 0x1e, 0xf0, 0x5e, 0x3e, 0x31,
+ 0xa3, 0x67, 0xbc, 0x77, 0x40, 0x5f, 0x58, 0x62,
+ 0x89, 0x7b, 0x06, 0x3e, 0x7d, 0x7d, 0xf7, 0x70,
+ 0xfb, 0xf0, 0xe7, 0xb7, 0xf9, 0xdd, 0xc7, 0xcf,
+ 0xf7, 0xef, 0xde, 0x7e, 0xf9, 0xf4, 0xf0, 0x5c,
+ 0x04, 0x2a, 0x30, 0xf2, 0xf1, 0x4f, 0x38, 0xbe,
+ 0x28, 0xcb, 0xc1, 0xbf, 0x83, 0x5f, 0x25, 0x18,
+ 0x54, 0xec
+ };
+ static std::string decompressed = util::decompress(std::string(reinterpret_cast<const char*>(compressed), sizeof(compressed)));
+ return decompressed.c_str();
+}();
} // namespace shaders
} // namespace mbgl