Match js shaders

The only non-incidental change is to revert portions
of d5b4c116 and 3a9a9043.

See d5b4c1162d (commitcomment-7668050)
This commit is contained in:
John Firebaugh
2014-09-05 11:52:23 -07:00
parent 7b9ad022a9
commit 9d5f02ccaa
14 changed files with 68 additions and 44 deletions

View File

@@ -12,7 +12,7 @@ public:
void bind(char *offset);
UniformMatrix<4> u_matrix = {"u_posmatrix", *this};
UniformMatrix<4> u_matrix = {"u_matrix", *this};
UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this};
Uniform<std::array<float, 2>> u_linewidth = {"u_linewidth", *this};
Uniform<std::array<float, 2>> u_pattern_size = {"u_pattern_size", *this};

View File

@@ -29,8 +29,13 @@ public:
private:
int32_t a_pos = -1;
int32_t a_offset = -1;
int32_t a_data1 = -1;
int32_t a_data2 = -1;
int32_t a_tex = -1;
int32_t a_angle = -1;
int32_t a_minzoom = -1;
int32_t a_maxzoom = -1;
int32_t a_rangeend = -1;
int32_t a_rangestart = -1;
int32_t a_labelminzoom = -1;
};
}

View File

@@ -19,15 +19,12 @@ size_t TextVertexBuffer::add(int16_t x, int16_t y, float ox, float oy, uint16_t
shorts[3] = std::round(oy * 64);
uint8_t *ubytes = static_cast<uint8_t *>(data);
// a_data1
ubytes[8] = tx / 4;
ubytes[9] = ty / 4;
ubytes[10] = labelminzoom * 10;
ubytes[11] = (int16_t)std::round(angle * angleFactor) % 256;
// a_data2
ubytes[12] = minzoom * 10; // 1/10 zoom levels: z16 == 160.
ubytes[13] = std::fmin(maxzoom, 25) * 10; // 1/10 zoom levels: z16 == 160.
ubytes[11] = minzoom * 10; // 1/10 zoom levels: z16 == 160.
ubytes[12] = fmin(maxzoom, 25) * 10; // 1/10 zoom levels: z16 == 160.
ubytes[13] = (int16_t)round(angle * angleFactor) % 256;
ubytes[14] = util::max((int16_t)std::round(range[0] * angleFactor), (int16_t)0) % 256;
ubytes[15] = util::min((int16_t)std::round(range[1] * angleFactor), (int16_t)255) % 256;

View File

@@ -2,8 +2,8 @@ uniform vec4 u_color;
uniform float u_blur;
void main() {
float dist = length(gl_PointCoord - 0.5);
float t = smoothstep(0.5, 0.5 - u_blur, dist);
float dist = length(gl_PointCoord - 0.5);
float t = smoothstep(0.5, 0.5 - u_blur, dist);
gl_FragColor = u_color * t;
}

View File

@@ -1,8 +1,8 @@
attribute vec2 a_pos;
uniform mat4 u_matrix;
uniform float u_size;
attribute vec2 a_pos;
void main(void) {
gl_Position = u_matrix * vec4(a_pos, 0, 1);
gl_PointSize = u_size;

View File

@@ -2,11 +2,10 @@ uniform sampler2D u_image;
varying vec2 v_coords[3];
void main()
{
void main() {
vec4 sum = vec4(0.0);
sum += texture2D(u_image, v_coords[0]) * 0.40261994689424746;
sum += texture2D(u_image, v_coords[1]) * 0.2986900265528763;
sum += texture2D(u_image, v_coords[2]) * 0.2986900265528763;
gl_FragColor = sum;
}
}

View File

@@ -8,7 +8,7 @@ varying vec2 v_coords[3];
void main() {
gl_Position = u_matrix * vec4(a_pos, 0, 1);
vec2 tex = (gl_Position.xy + 1.0) / 2.0;
vec2 tex = gl_Position.xy / 2.0 + 0.5;
v_coords[0] = tex;
v_coords[1] = tex + u_offset * 1.1824255238063563;
v_coords[2] = tex - u_offset * 1.1824255238063563;

View File

@@ -4,7 +4,5 @@ varying vec2 v_tex;
varying float v_alpha;
void main() {
// Note: We don't need to premultiply here as the image we use is already
// premultiplied in the sprite atlas.
gl_FragColor = texture2D(u_texture, v_tex) * v_alpha;
}

View File

@@ -9,7 +9,7 @@ attribute float a_rangestart;
attribute float a_labelminzoom;
// posmatrix is for the vertex position, exmatrix is for rotating and projecting
// matrix is for the vertex position, exmatrix is for rotating and projecting
// the extrusion vector.
uniform mat4 u_matrix;
uniform mat4 u_exmatrix;

View File

@@ -10,7 +10,7 @@ attribute vec2 a_pos;
attribute vec2 a_extrude;
attribute float a_linesofar;
// posmatrix is for the vertex position, exmatrix is for rotating and projecting
// matrix is for the vertex position, exmatrix is for rotating and projecting
// the extrusion vector.
uniform mat4 u_matrix;
uniform mat4 u_exmatrix;
@@ -42,4 +42,4 @@ void main() {
// tile's zoom level.
gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0.0, 1.0) + u_exmatrix * dist;
v_linesofar = a_linesofar * u_ratio;
}
}

View File

@@ -9,9 +9,9 @@ attribute vec2 a_pos;
attribute vec2 a_extrude;
attribute float a_linesofar;
// posmatrix is for the vertex position, exmatrix is for rotating and projecting
// matrix is for the vertex position, exmatrix is for rotating and projecting
// the extrusion vector.
uniform mat4 u_posmatrix;
uniform mat4 u_matrix;
uniform mat4 u_exmatrix;
// shared
@@ -49,7 +49,7 @@ void main() {
// model/view matrix. Add the extrusion vector *after* the model/view matrix
// because we're extruding the line in pixel space, regardless of the current
// tile's zoom level.
gl_Position = u_posmatrix * vec4(floor(a_pos / 2.0), 0.0, 1.0) + u_exmatrix * vec4(dist, z, 0.0);
gl_Position = u_matrix * vec4(floor(a_pos / 2.0), 0.0, 1.0) + u_exmatrix * vec4(dist, z, 0.0);
v_linesofar = a_linesofar;// * u_ratio;

View File

@@ -17,9 +17,9 @@ void main() {
// spin
rgb = vec3(
dot(rgb, u_spin_weights.xyz),
dot(rgb, u_spin_weights.zxy),
dot(rgb, u_spin_weights.yzx));
dot(rgb, u_spin_weights.xyz),
dot(rgb, u_spin_weights.zxy),
dot(rgb, u_spin_weights.yzx));
// saturation
float average = (color.r + color.g + color.b) / 3.0;

View File

@@ -1,10 +1,15 @@
attribute vec2 a_pos;
attribute vec2 a_offset;
attribute vec4 a_data1;
attribute vec4 a_data2;
attribute vec2 a_tex;
attribute float a_angle;
attribute float a_minzoom;
attribute float a_maxzoom;
attribute float a_rangeend;
attribute float a_rangestart;
attribute float a_labelminzoom;
// posmatrix is for the vertex position, exmatrix is for rotating and projecting
// matrix is for the vertex position, exmatrix is for rotating and projecting
// the extrusion vector.
uniform mat4 u_matrix;
uniform mat4 u_exmatrix;
@@ -22,11 +27,6 @@ varying vec2 v_tex;
varying float v_alpha;
void main() {
vec2 a_tex = a_data1.xy;
float a_labelminzoom = a_data1[2];
float a_angle = a_data1[3];
vec2 a_zoom = a_data2.st;
vec2 a_range = a_data2.pq;
float rev = 0.0;
@@ -40,7 +40,7 @@ void main() {
// of the view plane so that the triangle gets clipped. This makes it easier
// for us to create degenerate triangle strips.
// u_zoom is the current zoom level adjusted for the change in font size
float z = 2.0 - step(a_zoom[0], u_zoom) - (1.0 - step(a_zoom[1], u_zoom)) + rev;
float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom)) + rev;
// fade out labels
float alpha = clamp((u_fadezoom - a_labelminzoom) / u_fadedist, 0.0, 1.0);
@@ -62,7 +62,7 @@ void main() {
// all the angles are 0..256 representing 0..2PI
// hide if (angle >= a_rangeend && angle < rangestart)
z += step(a_range[0], u_angle) * (1.0 - step(a_range[1], u_angle));
z += step(a_rangeend, u_angle) * (1.0 - step(a_rangestart, u_angle));
gl_Position = u_matrix * vec4(a_pos, 0, 1) + u_exmatrix * vec4(a_offset / 64.0, z, 0);
v_tex = a_tex * 4.0 / u_texsize;

View File

@@ -19,8 +19,13 @@ SDFShader::SDFShader()
a_pos = glGetAttribLocation(program, "a_pos");
a_offset = glGetAttribLocation(program, "a_offset");
a_data1 = glGetAttribLocation(program, "a_data1");
a_data2 = glGetAttribLocation(program, "a_data2");
a_tex = glGetAttribLocation(program, "a_tex");
a_angle = glGetAttribLocation(program, "a_angle");
a_minzoom = glGetAttribLocation(program, "a_minzoom");
a_maxzoom = glGetAttribLocation(program, "a_maxzoom");
a_rangeend = glGetAttribLocation(program, "a_rangeend");
a_rangestart = glGetAttribLocation(program, "a_rangestart");
a_labelminzoom = glGetAttribLocation(program, "a_labelminzoom");
}
void SDFShader::bind(char *offset) {
@@ -30,9 +35,29 @@ void SDFShader::bind(char *offset) {
glEnableVertexAttribArray(a_offset);
glVertexAttribPointer(a_offset, 2, GL_SHORT, false, 16, offset + 4);
glEnableVertexAttribArray(a_data1);
glVertexAttribPointer(a_data1, 4, GL_UNSIGNED_BYTE, false, 16, offset + 8);
glEnableVertexAttribArray(a_tex);
glVertexAttribPointer(a_tex, 2, GL_UNSIGNED_BYTE, false, 16, offset + 8);
glEnableVertexAttribArray(a_data2);
glVertexAttribPointer(a_data2, 4, GL_UNSIGNED_BYTE, false, 16, offset + 12);
glEnableVertexAttribArray(a_labelminzoom);
glVertexAttribPointer(a_labelminzoom, 1, GL_UNSIGNED_BYTE, false, 16,
offset + 10);
glEnableVertexAttribArray(a_minzoom);
glVertexAttribPointer(a_minzoom, 1, GL_UNSIGNED_BYTE, false, 16,
offset + 11);
glEnableVertexAttribArray(a_maxzoom);
glVertexAttribPointer(a_maxzoom, 1, GL_UNSIGNED_BYTE, false, 16,
offset + 12);
glEnableVertexAttribArray(a_angle);
glVertexAttribPointer(a_angle, 1, GL_UNSIGNED_BYTE, false, 16, offset + 13);
glEnableVertexAttribArray(a_rangeend);
glVertexAttribPointer(a_rangeend, 1, GL_UNSIGNED_BYTE, false, 16,
offset + 14);
glEnableVertexAttribArray(a_rangestart);
glVertexAttribPointer(a_rangestart, 1, GL_UNSIGNED_BYTE, false, 16,
offset + 15);
}