Skip to content

Commit f37a61d

Browse files
committed
Shader now using viewLoad2D instead and accounting for origin
1 parent ba8d1ad commit f37a61d

2 files changed

Lines changed: 23 additions & 79 deletions

File tree

src/gameobjects/shader/Shader.js

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -186,21 +186,12 @@ var Shader = new Class({
186186
*/
187187
this._tempMatrix3 = new TransformMatrix();
188188

189-
/**
190-
* A temporary Transform Matrix, re-used internally during batching.
191-
*
192-
* @name Phaser.Renderer.WebGL.Pipelines.QuadShaderPipeline#_tempMatrix4
193-
* @private
194-
* @type {Phaser.GameObjects.Components.TransformMatrix}
195-
* @since 3.17.0
196-
*/
197-
this._tempMatrix4 = new TransformMatrix();
198-
199189
this.setPosition(x, y);
200190
this.setSize(width, height);
201191
this.setOrigin(0.5, 0.5);
202192

203193
this.mvpInit();
194+
204195
this.projOrtho(0, this.renderer.width, this.renderer.height, 0, -1000.0, 1000.0);
205196
},
206197

@@ -292,60 +283,31 @@ var Shader = new Class({
292283
gl.drawArrays(topology, 0, vertexCount);
293284
},
294285

295-
296-
297286
/**
298287
* Renders a single quad using the current shader and then flushes the batch.
299288
*
300289
* @method Phaser.Renderer.WebGL.Pipelines.QuadShaderPipeline#draw
301290
* @since 3.17.0
302-
*
303-
* @param {number} x - Horizontal top left coordinate of the rectangle.
304-
* @param {number} y - Vertical top left coordinate of the rectangle.
305-
* @param {number} width - Width of the rectangle.
306-
* @param {number} height - Height of the rectangle.
307-
* @param {Phaser.GameObjects.Components.TransformMatrix} currentMatrix - The current transform.
308-
* @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - The parent transform.
309291
*/
310-
draw: function (x, y, width, height, currentMatrix, parentMatrix)
292+
draw: function ()
311293
{
312-
var calcMatrix = this._tempMatrix3;
313-
314-
// Multiply and store result in calcMatrix, only if the parentMatrix is set, otherwise we'll use whatever values are already in the calcMatrix
315-
if (parentMatrix)
316-
{
317-
parentMatrix.multiply(currentMatrix, calcMatrix);
318-
}
319-
320-
var xw = x + width;
321-
var yh = y + height;
322-
323-
var x0 = calcMatrix.getX(x, y);
324-
var y0 = calcMatrix.getY(x, y);
325-
326-
var x1 = calcMatrix.getX(x, yh);
327-
var y1 = calcMatrix.getY(x, yh);
328-
329-
var x2 = calcMatrix.getX(xw, yh);
330-
var y2 = calcMatrix.getY(xw, yh);
331-
332-
var x3 = calcMatrix.getX(xw, y);
333-
var y3 = calcMatrix.getY(xw, y);
294+
var xw = this.width;
295+
var yh = this.height;
334296

335297
var vertexViewF32 = this.vertexViewF32;
336298

337-
vertexViewF32[0] = x0;
338-
vertexViewF32[1] = y0;
339-
vertexViewF32[2] = x1;
340-
vertexViewF32[3] = y1;
341-
vertexViewF32[4] = x2;
342-
vertexViewF32[5] = y2;
343-
vertexViewF32[6] = x0;
344-
vertexViewF32[7] = y0;
345-
vertexViewF32[8] = x2;
346-
vertexViewF32[9] = y2;
347-
vertexViewF32[10] = x3;
348-
vertexViewF32[11] = y3;
299+
vertexViewF32[0] = 0;
300+
vertexViewF32[1] = 0;
301+
vertexViewF32[2] = 0;
302+
vertexViewF32[3] = yh;
303+
vertexViewF32[4] = xw;
304+
vertexViewF32[5] = yh;
305+
vertexViewF32[6] = 0;
306+
vertexViewF32[7] = 0;
307+
vertexViewF32[8] = xw;
308+
vertexViewF32[9] = yh;
309+
vertexViewF32[10] = xw;
310+
vertexViewF32[11] = 0;
349311

350312
this.flush();
351313
},

src/gameobjects/shader/ShaderWebGLRenderer.js

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,6 @@ var ShaderWebGLRenderer = function (renderer, src, interpolationPercentage, came
2525

2626
renderer.clearPipeline();
2727

28-
// src.projOrtho(0, renderer.width, renderer.height, 0, -1000.0, 1000.0);
29-
30-
// src.viewLoad2D(src);
31-
32-
// ITRS
33-
34-
src.viewIdentity();
35-
src.viewTranslate(src.x, src.y, src.z);
36-
src.viewRotateZ(src.rotation);
37-
src.viewScale(src.scaleX, src.scaleY, 1.0);
38-
39-
src.mvpUpdate();
40-
41-
src.bind();
42-
43-
var dx = src._displayOriginX;
44-
var dy = src._displayOriginY;
45-
46-
src.draw(-dx, -dy, src.width, src.height);
47-
48-
/*
4928
var camMatrix = src._tempMatrix1;
5029
var shapeMatrix = src._tempMatrix2;
5130
var calcMatrix = src._tempMatrix3;
@@ -71,11 +50,14 @@ var ShaderWebGLRenderer = function (renderer, src, interpolationPercentage, came
7150

7251
camMatrix.multiply(shapeMatrix, calcMatrix);
7352

74-
var dx = src._displayOriginX;
75-
var dy = src._displayOriginY;
53+
src.viewLoad2D(calcMatrix.matrix);
54+
src.viewTranslate(-src._displayOriginX, -src._displayOriginX, 0);
55+
56+
src.mvpUpdate();
57+
58+
src.bind();
7659

77-
src.draw(-dx, -dy, src.width, src.height);
78-
*/
60+
src.draw();
7961

8062
renderer.rebindPipeline(pipeline);
8163
};

0 commit comments

Comments
 (0)