diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-08-10 11:47:31 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-08-10 11:47:31 -0700 |
commit | 1a3e0863ccf251dc76944f11aab5abf9205c6a0d (patch) | |
tree | 97a98fd9993eebba6e6e48939449dea50621699d /src/mbgl/shaders | |
parent | 5d641f4d6892ae22c9b96f77d92a5295f3ca28b3 (diff) | |
download | qtlocation-mapboxgl-1a3e0863ccf251dc76944f11aab5abf9205c6a0d.tar.gz |
[core] Use separate attribute component for line normalsupstream/cp-9676
Selective cherry pick of 822df3dd514ec3d05f876e6746cb8ba6348ac89d
Diffstat (limited to 'src/mbgl/shaders')
-rw-r--r-- | src/mbgl/shaders/line.cpp | 20 | ||||
-rw-r--r-- | src/mbgl/shaders/line_pattern.cpp | 19 | ||||
-rw-r--r-- | src/mbgl/shaders/line_sdf.cpp | 19 |
3 files changed, 27 insertions, 31 deletions
diff --git a/src/mbgl/shaders/line.cpp b/src/mbgl/shaders/line.cpp index dce6046257..ce62ecb3bd 100644 --- a/src/mbgl/shaders/line.cpp +++ b/src/mbgl/shaders/line.cpp @@ -21,7 +21,7 @@ const char* line::vertexSource = R"MBGL_SHADER( // #define scale 63.0 #define scale 0.015873016 -attribute vec2 a_pos; +attribute vec3 a_pos_normal; attribute vec4 a_data; uniform mat4 u_matrix; @@ -107,20 +107,21 @@ void main() { vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; - // We store the texture normals in the most insignificant bit - // transform y so that 0 => -1 and 1 => 1 + vec2 pos = a_pos_normal.xy; + + // transform y normal so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap // y is 1 if the normal points up, and -1 if it points down - mediump vec2 normal = mod(a_pos, 2.0); + mediump vec2 normal = unpack_float(a_pos_normal.z); normal.y = sign(normal.y - 0.5); - v_normal = normal; + v_normal = normal; - // these transformations used to be applied in the JS and native code bases. - // moved them into the shader for clarity and simplicity. + // these transformations used to be applied in the JS and native code bases. + // moved them into the shader for clarity and simplicity. gapwidth = gapwidth / 2.0; float width = u_width / 2.0; - offset = -1.0 * offset; + offset = -1.0 * offset; float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); float outset = gapwidth + width * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; @@ -137,9 +138,6 @@ void main() { mediump float t = 1.0 - abs(u); mediump vec2 offset2 = offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); - // Remove the texture normal bit to get the position - vec2 pos = floor(a_pos * 0.5); - vec4 projected_extrude = u_matrix * vec4(dist / u_ratio, 0.0, 0.0); gl_Position = u_matrix * vec4(pos + offset2 / u_ratio, 0.0, 1.0) + projected_extrude; diff --git a/src/mbgl/shaders/line_pattern.cpp b/src/mbgl/shaders/line_pattern.cpp index 1c07b4f515..f43b3a3cf7 100644 --- a/src/mbgl/shaders/line_pattern.cpp +++ b/src/mbgl/shaders/line_pattern.cpp @@ -23,7 +23,7 @@ const char* line_pattern::vertexSource = R"MBGL_SHADER( // Retina devices need a smaller distance to avoid aliasing. #define ANTIALIASING 1.0 / DEVICE_PIXEL_RATIO / 2.0 -attribute vec2 a_pos; +attribute vec3 a_pos_normal; attribute vec4 a_data; uniform mat4 u_matrix; @@ -97,19 +97,21 @@ void main() { float a_direction = mod(a_data.z, 4.0) - 1.0; float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE; - // We store the texture normals in the most insignificant bit - // transform y so that 0 => -1 and 1 => 1 + vec2 pos = a_pos_normal.xy; + + // transform y normal so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap // y is 1 if the normal points up, and -1 if it points down - mediump vec2 normal = mod(a_pos, 2.0); + mediump vec2 normal = unpack_float(a_pos_normal.z); normal.y = sign(normal.y - 0.5); + v_normal = normal; - // these transformations used to be applied in the JS and native code bases. - // moved them into the shader for clarity and simplicity. + // these transformations used to be applied in the JS and native code bases. + // moved them into the shader for clarity and simplicity. gapwidth = gapwidth / 2.0; float width = u_width / 2.0; - offset = -1.0 * offset; + offset = -1.0 * offset; float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); float outset = gapwidth + width * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; @@ -126,9 +128,6 @@ void main() { mediump float t = 1.0 - abs(u); mediump vec2 offset2 = offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); - // Remove the texture normal bit to get the position - vec2 pos = floor(a_pos * 0.5); - vec4 projected_extrude = u_matrix * vec4(dist / u_ratio, 0.0, 0.0); gl_Position = u_matrix * vec4(pos + offset2 / u_ratio, 0.0, 1.0) + projected_extrude; diff --git a/src/mbgl/shaders/line_sdf.cpp b/src/mbgl/shaders/line_sdf.cpp index b37bf688d4..24b7153c7f 100644 --- a/src/mbgl/shaders/line_sdf.cpp +++ b/src/mbgl/shaders/line_sdf.cpp @@ -23,7 +23,7 @@ const char* line_sdf::vertexSource = R"MBGL_SHADER( // Retina devices need a smaller distance to avoid aliasing. #define ANTIALIASING 1.0 / DEVICE_PIXEL_RATIO / 2.0 -attribute vec2 a_pos; +attribute vec3 a_pos_normal; attribute vec4 a_data; uniform mat4 u_matrix; @@ -116,20 +116,22 @@ void main() { float a_direction = mod(a_data.z, 4.0) - 1.0; float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE; - // We store the texture normals in the most insignificant bit - // transform y so that 0 => -1 and 1 => 1 + vec2 pos = a_pos_normal.xy; + + // transform y normal so that 0 => -1 and 1 => 1 // In the texture normal, x is 0 if the normal points straight up/down and 1 if it's a round cap // y is 1 if the normal points up, and -1 if it points down - mediump vec2 normal = mod(a_pos, 2.0); + mediump vec2 normal = unpack_float(a_pos_normal.z); normal.y = sign(normal.y - 0.5); + v_normal = normal; - // these transformations used to be applied in the JS and native code bases. - // moved them into the shader for clarity and simplicity. + // these transformations used to be applied in the JS and native code bases. + // moved them into the shader for clarity and simplicity. gapwidth = gapwidth / 2.0; float width = u_width / 2.0; offset = -1.0 * offset; - + float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); float outset = gapwidth + width * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; @@ -145,9 +147,6 @@ void main() { mediump float t = 1.0 - abs(u); mediump vec2 offset2 = offset * a_extrude * scale * normal.y * mat2(t, -u, u, t); - // Remove the texture normal bit to get the position - vec2 pos = floor(a_pos * 0.5); - vec4 projected_extrude = u_matrix * vec4(dist / u_ratio, 0.0, 0.0); gl_Position = u_matrix * vec4(pos + offset2 / u_ratio, 0.0, 1.0) + projected_extrude; |