Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Generate shaders from mapbox/mapbox-gl-js#9694
Browse files Browse the repository at this point in the history
  • Loading branch information
karimnaaji committed Jun 2, 2020
1 parent d4af66e commit 6bd46c1
Show file tree
Hide file tree
Showing 10 changed files with 509 additions and 484 deletions.
36 changes: 26 additions & 10 deletions src/mbgl/programs/gl/line_gradient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ struct ShaderSource;
template <>
struct ShaderSource<LineGradientProgram> {
static constexpr const char* name = "line_gradient";
static constexpr const uint8_t hash[8] = {0x3f, 0xba, 0xc6, 0x33, 0xcd, 0x86, 0xa2, 0xe8};
static constexpr const uint8_t hash[8] = {0x48, 0x6d, 0xde, 0x29, 0x5e, 0xfd, 0xe4, 0x01};
static constexpr const auto vertexOffset = 34444;
static constexpr const auto fragmentOffset = 37236;
static constexpr const auto fragmentOffset = 37367;
};

constexpr const char* ShaderSource<LineGradientProgram>::name;
Expand All @@ -39,10 +39,6 @@ Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programPara

// Uncompressed source of line_gradient.vertex.glsl:
/*
// the attribute conveying progress along a line is scaled to [0, 2^15)
#define MAX_LINE_DISTANCE 32767.0
// floor(127 / 2) == 63.0
// the maximum allowed miter limit is 2.0 at the moment. the extrude normal is
// stored in a byte (-128..127). we scale regular normals up to length 63, but
Expand All @@ -53,6 +49,9 @@ Backend::Create<gfx::Backend::Type::OpenGL>(const ProgramParameters& programPara
attribute vec2 a_pos_normal;
attribute vec4 a_data;
attribute float a_line_progress;
attribute float a_line_clip;
attribute float a_split_index;
uniform mat4 u_matrix;
uniform mediump float u_ratio;
Expand All @@ -63,6 +62,8 @@ varying vec2 v_normal;
varying vec2 v_width2;
varying float v_gamma_scale;
varying highp float v_lineprogress;
varying highp float v_line_clip;
varying lowp float v_split_index;
#ifndef HAS_UNIFORM_u_blur
Expand Down Expand Up @@ -151,7 +152,9 @@ void main() {
vec2 a_extrude = a_data.xy - 128.0;
float a_direction = mod(a_data.z, 4.0) - 1.0;
v_lineprogress = (floor(a_data.z / 4.0) + a_data.w * 64.0) * 2.0 / MAX_LINE_DISTANCE;
v_lineprogress = a_line_progress;
v_line_clip = a_line_clip;
v_split_index = a_split_index;
vec2 pos = floor(a_pos_normal * 0.5);
Expand Down Expand Up @@ -200,11 +203,14 @@ void main() {
/*
uniform lowp float u_device_pixel_ratio;
uniform sampler2D u_image;
uniform float u_image_height;
varying vec2 v_width2;
varying vec2 v_normal;
varying float v_gamma_scale;
varying highp float v_lineprogress;
varying highp float v_line_clip;
varying lowp float v_split_index;
#ifndef HAS_UNIFORM_u_blur
Expand All @@ -221,6 +227,10 @@ uniform lowp float u_opacity;
#endif
highp float map(highp float value, highp float start, highp float end, highp float new_start, highp float new_end) {
return ((value - start) * (new_end - new_start)) / (end - start) + new_start;
}
void main() {
#ifdef HAS_UNIFORM_u_blur
Expand All @@ -242,9 +252,15 @@ void main() {
float blur2 = (blur + 1.0 / u_device_pixel_ratio) * v_gamma_scale;
float alpha = clamp(min(dist - (v_width2.t - blur2), v_width2.s - dist) / blur2, 0.0, 1.0);
// For gradient lines, v_lineprogress is the ratio along the entire line,
// scaled to [0, 2^15), and the gradient ramp is stored in a texture.
vec4 color = texture2D(u_image, vec2(v_lineprogress, 0.5));
highp float texel_height = 1.0 / u_image_height;
highp float half_texel_height = 0.5 * texel_height;
highp vec2 uv = vec2(
map(v_lineprogress, 0.0, v_line_clip, 0.0, 1.0),
v_split_index * texel_height - half_texel_height);
// For gradient lines, v_lineprogress is the ratio along the
// entire line, the gradient ramp is stored in a texture.
vec4 color = texture2D(u_image, uv);
gl_FragColor = color * (alpha * opacity);
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/programs/gl/line_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ template <>
struct ShaderSource<LinePatternProgram> {
static constexpr const char* name = "line_pattern";
static constexpr const uint8_t hash[8] = {0x38, 0x9c, 0x3d, 0xde, 0xb4, 0xe0, 0xd1, 0x61};
static constexpr const auto vertexOffset = 38066;
static constexpr const auto fragmentOffset = 41460;
static constexpr const auto vertexOffset = 38647;
static constexpr const auto fragmentOffset = 42041;
};

constexpr const char* ShaderSource<LinePatternProgram>::name;
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/programs/gl/line_sdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ template <>
struct ShaderSource<LineSDFProgram> {
static constexpr const char* name = "line_sdf";
static constexpr const uint8_t hash[8] = {0x25, 0x94, 0x7f, 0xad, 0x84, 0xfe, 0x96, 0xad};
static constexpr const auto vertexOffset = 43815;
static constexpr const auto fragmentOffset = 47502;
static constexpr const auto vertexOffset = 44396;
static constexpr const auto fragmentOffset = 48083;
};

constexpr const char* ShaderSource<LineSDFProgram>::name;
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/programs/gl/raster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ template <>
struct ShaderSource<RasterProgram> {
static constexpr const char* name = "raster";
static constexpr const uint8_t hash[8] = {0x40, 0x3d, 0x6c, 0xf4, 0xd0, 0x41, 0x51, 0x0e};
static constexpr const auto vertexOffset = 49047;
static constexpr const auto fragmentOffset = 49396;
static constexpr const auto vertexOffset = 49628;
static constexpr const auto fragmentOffset = 49977;
};

constexpr const char* ShaderSource<RasterProgram>::name;
Expand Down
Loading

0 comments on commit 6bd46c1

Please sign in to comment.