Skip to content
This repository has been archived by the owner on Mar 23, 2019. It is now read-only.

Commit

Permalink
convert mat4 exMatrix to a vec2 extrudeScale
Browse files Browse the repository at this point in the history
The matrix was only be used to scale vec2s. We don't need a mat4 to do
that. This should be slightly faster
  • Loading branch information
ansis committed Apr 26, 2016
1 parent 847b437 commit a8d549b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
6 changes: 3 additions & 3 deletions circle.vertex.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
precision highp float;

uniform mat4 u_matrix;
uniform mat4 u_exmatrix;
uniform vec2 u_extrude_scale;
uniform float u_devicepixelratio;

attribute vec2 a_pos;
Expand Down Expand Up @@ -64,14 +64,14 @@ void main(void) {
// unencode the extrusion vector that we snuck into the a_pos vector
v_extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0);

vec4 extrude = u_exmatrix * vec4(v_extrude * radius, 0, 0);
vec2 extrude = v_extrude * radius * u_extrude_scale;
// multiply a_pos by 0.5, since we had it * 2 in order to sneak
// in extrusion data
gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0, 1);

// gl_Position is divided by gl_Position.w after this shader runs.
// Multiply the extrude by it so that it isn't affected by it.
gl_Position += extrude * gl_Position.w;
gl_Position.xy += extrude * gl_Position.w;

#ifdef ATTRIBUTE_A_COLOR
v_color = a_color / 255.0;
Expand Down
12 changes: 5 additions & 7 deletions icon.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ attribute vec4 a_data2;
// matrix is for the vertex position, exmatrix is for rotating and projecting
// the extrusion vector.
uniform mat4 u_matrix;
uniform mat4 u_exmatrix;

uniform mediump float u_zoom;
uniform bool u_skewed;
uniform float u_extra;
uniform vec2 u_extrude_scale;

uniform vec2 u_texsize;

Expand All @@ -26,18 +27,15 @@ void main() {
mediump float a_minzoom = a_zoom[0];
mediump float a_maxzoom = a_zoom[1];

float a_fadedist = 10.0;

// u_zoom is the current zoom level adjusted for the change in font size
mediump float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom));

vec2 extrude = u_extrude_scale * (a_offset / 64.0);
if (u_skewed) {
vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, 0, 0);
gl_Position = u_matrix * vec4(a_pos + extrude.xy, 0, 1);
gl_Position = u_matrix * vec4(a_pos + extrude, 0, 1);
gl_Position.z += z * gl_Position.w;
} else {
vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, z, 0);
gl_Position = u_matrix * vec4(a_pos, 0, 1) + extrude;
gl_Position = u_matrix * vec4(a_pos, 0, 1) + vec4(extrude, 0, 0);
}

v_tex = a_tex / u_texsize;
Expand Down
9 changes: 4 additions & 5 deletions sdf.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ attribute vec4 a_data2;
// matrix is for the vertex position, exmatrix is for rotating and projecting
// the extrusion vector.
uniform mat4 u_matrix;
uniform mat4 u_exmatrix;

uniform mediump float u_zoom;
uniform bool u_skewed;
uniform float u_extra;
uniform vec2 u_extrude_scale;

uniform vec2 u_texsize;

Expand All @@ -31,13 +31,12 @@ void main() {
// u_zoom is the current zoom level adjusted for the change in font size
mediump float z = 2.0 - step(a_minzoom, u_zoom) - (1.0 - step(a_maxzoom, u_zoom));

vec2 extrude = u_extrude_scale * (a_offset / 64.0);
if (u_skewed) {
vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, 0, 0);
gl_Position = u_matrix * vec4(a_pos + extrude.xy, 0, 1);
gl_Position = u_matrix * vec4(a_pos + extrude, 0, 1);
gl_Position.z += z * gl_Position.w;
} else {
vec4 extrude = u_exmatrix * vec4(a_offset / 64.0, z, 0);
gl_Position = u_matrix * vec4(a_pos, 0, 1) + extrude;
gl_Position = u_matrix * vec4(a_pos, 0, 1) + vec4(extrude, 0, 0);
}

// position of y on the screen
Expand Down

0 comments on commit a8d549b

Please sign in to comment.