Skip to content

Commit a286459

Browse files
committed
add shear to render
1 parent 4ee2ae6 commit a286459

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/ShaderManager.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,19 @@ ShaderManager.EFFECT_INFO = {
181181
mask: 1 << 12,
182182
converter: x => x - 1,
183183
shapeChanges: false
184-
}
184+
},
185+
horizontalShear: {
186+
uniformName: 'u_horizontalShear',
187+
mask: 1 << 13,
188+
converter: x => x,
189+
shapeChanges: true
190+
},
191+
verticalShear: {
192+
uniformName: 'u_verticalShear',
193+
mask: 1 << 14,
194+
converter: x => x,
195+
shapeChanges: true
196+
},
185197
};
186198

187199
/**

src/shaders/sprite.vert.glsl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ const float epsilon = 1e-3;
2020
uniform mat4 u_projectionMatrix;
2121
uniform mat4 u_modelMatrix;
2222
attribute vec2 a_texCoord;
23+
#ifdef ENABLE_horizontalShear
24+
uniform float u_horizontalShear;
25+
#endif
26+
#ifdef ENABLE_verticalShear
27+
uniform float u_verticalShear;
28+
#endif
2329
#endif
2430

2531
attribute vec2 a_position;
@@ -76,7 +82,17 @@ void main() {
7682
#elif defined(DRAW_MODE_background)
7783
gl_Position = vec4(a_position * 2.0, 0, 1);
7884
#else
79-
gl_Position = u_projectionMatrix * u_modelMatrix * vec4(a_position, 0, 1);
85+
float x = a_position.x;
86+
float y = a_position.y;
87+
#ifdef ENABLE_horizontalShear
88+
if (y < 0.0)
89+
x += u_horizontalShear;
90+
#endif
91+
#ifdef ENABLE_verticalShear
92+
if (x < 0.0)
93+
y += u_verticalShear;
94+
#endif
95+
gl_Position = u_projectionMatrix * u_modelMatrix * vec4(x,y, 0, 1);
8096
v_texCoord = a_texCoord;
8197
#endif
8298
}

0 commit comments

Comments
 (0)