diff --git a/src/core/sprites/webgl/SpriteBatchRenderer.js b/src/core/sprites/webgl/SpriteBatchRenderer.js index 82a2318..ceb41f5 100644 --- a/src/core/sprites/webgl/SpriteBatchRenderer.js +++ b/src/core/sprites/webgl/SpriteBatchRenderer.js @@ -28,7 +28,7 @@ * * @member {number} */ - this.vertSize = 10; + this.vertSize = 12; /** * @@ -277,15 +277,21 @@ vertices[index++] = sprite.scale.x; vertices[index++] = sprite.scale.y; + //skew + vertices[index++] = sprite.skew.x; + vertices[index++] = sprite.skew.y; + //rotation vertices[index++] = sprite.rotation; // uv vertices[index++] = uvs.x0; vertices[index++] = uvs.y1; + // color vertices[index++] = sprite.alpha; + // ---- // xy vertices[index++] = w0; @@ -298,15 +304,21 @@ vertices[index++] = sprite.scale.x; vertices[index++] = sprite.scale.y; + //skew + vertices[index++] = sprite.skew.x; + vertices[index++] = sprite.skew.y; + //rotation vertices[index++] = sprite.rotation; // uv vertices[index++] = uvs.x1; vertices[index++] = uvs.y1; + // color vertices[index++] = sprite.alpha; + // ---- // xy vertices[index++] = w0; @@ -319,17 +331,21 @@ vertices[index++] = sprite.scale.x; vertices[index++] = sprite.scale.y; + //skew + vertices[index++] = sprite.skew.x; + vertices[index++] = sprite.skew.y; + //rotation vertices[index++] = sprite.rotation; // uv vertices[index++] = uvs.x2; vertices[index++] = uvs.y2; + // color vertices[index++] = sprite.alpha; - - + // ---- // xy vertices[index++] = w1; @@ -342,12 +358,17 @@ vertices[index++] = sprite.scale.x; vertices[index++] = sprite.scale.y; + //skew + vertices[index++] = sprite.skew.x; + vertices[index++] = sprite.skew.y; + //rotation vertices[index++] = sprite.rotation; // uv vertices[index++] = uvs.x3; vertices[index++] = uvs.y3; + // color vertices[index++] = sprite.alpha; @@ -438,7 +459,8 @@ gl.vertexAttribPointer(this.shader.attributes.aPositionCoord, 2, gl.FLOAT, false, stride, 5 * 4); gl.vertexAttribPointer(this.shader.attributes.aScale, 2, gl.FLOAT, false, stride, 7 * 4); - gl.vertexAttribPointer(this.shader.attributes.aRotation, 1, gl.FLOAT, false, stride, 9 * 4); + gl.vertexAttribPointer(this.shader.attributes.aSkew, 2, gl.FLOAT, false, stride, 9 * 4); + gl.vertexAttribPointer(this.shader.attributes.aRotation, 1, gl.FLOAT, false, stride, 11 * 4); }; /** diff --git a/src/core/sprites/webgl/SpriteBatchRenderer.js b/src/core/sprites/webgl/SpriteBatchRenderer.js index 82a2318..ceb41f5 100644 --- a/src/core/sprites/webgl/SpriteBatchRenderer.js +++ b/src/core/sprites/webgl/SpriteBatchRenderer.js @@ -28,7 +28,7 @@ * * @member {number} */ - this.vertSize = 10; + this.vertSize = 12; /** * @@ -277,15 +277,21 @@ vertices[index++] = sprite.scale.x; vertices[index++] = sprite.scale.y; + //skew + vertices[index++] = sprite.skew.x; + vertices[index++] = sprite.skew.y; + //rotation vertices[index++] = sprite.rotation; // uv vertices[index++] = uvs.x0; vertices[index++] = uvs.y1; + // color vertices[index++] = sprite.alpha; + // ---- // xy vertices[index++] = w0; @@ -298,15 +304,21 @@ vertices[index++] = sprite.scale.x; vertices[index++] = sprite.scale.y; + //skew + vertices[index++] = sprite.skew.x; + vertices[index++] = sprite.skew.y; + //rotation vertices[index++] = sprite.rotation; // uv vertices[index++] = uvs.x1; vertices[index++] = uvs.y1; + // color vertices[index++] = sprite.alpha; + // ---- // xy vertices[index++] = w0; @@ -319,17 +331,21 @@ vertices[index++] = sprite.scale.x; vertices[index++] = sprite.scale.y; + //skew + vertices[index++] = sprite.skew.x; + vertices[index++] = sprite.skew.y; + //rotation vertices[index++] = sprite.rotation; // uv vertices[index++] = uvs.x2; vertices[index++] = uvs.y2; + // color vertices[index++] = sprite.alpha; - - + // ---- // xy vertices[index++] = w1; @@ -342,12 +358,17 @@ vertices[index++] = sprite.scale.x; vertices[index++] = sprite.scale.y; + //skew + vertices[index++] = sprite.skew.x; + vertices[index++] = sprite.skew.y; + //rotation vertices[index++] = sprite.rotation; // uv vertices[index++] = uvs.x3; vertices[index++] = uvs.y3; + // color vertices[index++] = sprite.alpha; @@ -438,7 +459,8 @@ gl.vertexAttribPointer(this.shader.attributes.aPositionCoord, 2, gl.FLOAT, false, stride, 5 * 4); gl.vertexAttribPointer(this.shader.attributes.aScale, 2, gl.FLOAT, false, stride, 7 * 4); - gl.vertexAttribPointer(this.shader.attributes.aRotation, 1, gl.FLOAT, false, stride, 9 * 4); + gl.vertexAttribPointer(this.shader.attributes.aSkew, 2, gl.FLOAT, false, stride, 9 * 4); + gl.vertexAttribPointer(this.shader.attributes.aRotation, 1, gl.FLOAT, false, stride, 11 * 4); }; /** diff --git a/src/core/sprites/webgl/SpriteBatchShader.js b/src/core/sprites/webgl/SpriteBatchShader.js index 1f53252..f689d1c 100644 --- a/src/core/sprites/webgl/SpriteBatchShader.js +++ b/src/core/sprites/webgl/SpriteBatchShader.js @@ -18,6 +18,7 @@ 'attribute vec2 aPositionCoord;', 'attribute vec2 aScale;', + 'attribute vec2 aSkew;', 'attribute float aRotation;', 'uniform mat3 projectionMatrix;', @@ -33,8 +34,8 @@ 'void main(void){', ' vec2 v;', ' vec2 sv = aVertexPosition * aScale;', - ' v.x = (sv.x) * cos(aRotation) - (sv.y) * sin(aRotation);', - ' v.y = (sv.x) * sin(aRotation) + (sv.y) * cos(aRotation);', + ' v.x = (sv.x) * cos(aRotation + aSkew.y) - (sv.y) * sin(aRotation + aSkew.x);', + ' v.y = (sv.x) * sin(aRotation + aSkew.y) + (sv.y) * cos(aRotation + aSkew.x);', ' v = ( uMatrix * vec3(v + aPositionCoord , 1.0) ).xy ;', @@ -68,6 +69,7 @@ { aPositionCoord: 0, aScale: 0, + aSkew: 0, aRotation: 0 } );