Added offset vector back in.

This commit is contained in:
photonstorm 2016-10-20 15:01:22 +01:00
parent ef5e23abad
commit 4af0fb3247
2 changed files with 14 additions and 29 deletions

View file

@ -65,31 +65,7 @@ Phaser.Renderer.WebGL.BatchManager = function (renderer)
* *
* @property defaultVertexSrc * @property defaultVertexSrc
* @type String * @type String
this.multivertexSrc = [
'attribute vec2 aVertexPosition;',
'attribute vec2 aTextureCoord;',
'attribute vec4 aColor;',
'attribute float aTextureIndex;',
'uniform vec2 projectionVector;',
'uniform vec2 offsetVector;',
'varying vec2 vTextureCoord;',
'varying vec4 vColor;',
'varying float vTextureIndex;',
'const vec2 center = vec2(-1.0, 1.0);',
'void main(void) {',
' if (aTextureIndex > 0.0) gl_Position = vec4(0.0);',
' gl_Position = vec4( ((aVertexPosition + offsetVector) / projectionVector) + center, 0.0, 1.0);',
' vTextureCoord = aTextureCoord;',
' vColor = vec4(aColor.rgb * aColor.a, aColor.a);',
' vTextureIndex = aTextureIndex;',
'}'
];
*/ */
this.vertexSrc = [ this.vertexSrc = [
'attribute vec2 aVertexPosition;', 'attribute vec2 aVertexPosition;',
'attribute vec2 aTextureCoord;', 'attribute vec2 aTextureCoord;',
@ -98,6 +74,7 @@ Phaser.Renderer.WebGL.BatchManager = function (renderer)
'attribute vec4 aBgColor;', 'attribute vec4 aBgColor;',
'uniform vec2 projectionVector;', 'uniform vec2 projectionVector;',
'uniform vec2 offsetVector;',
'varying vec2 vTextureCoord;', 'varying vec2 vTextureCoord;',
'varying vec4 vTintColor;', 'varying vec4 vTintColor;',
@ -107,7 +84,9 @@ Phaser.Renderer.WebGL.BatchManager = function (renderer)
'const vec2 center = vec2(-1.0, 1.0);', 'const vec2 center = vec2(-1.0, 1.0);',
'void main(void) {', 'void main(void) {',
' gl_Position = vec4((aVertexPosition / projectionVector) + center, 0.0, 1.0);', ' if (aTextureIndex > 0.0) gl_Position = vec4(0.0);',
// ' gl_Position = vec4((aVertexPosition / projectionVector) + center, 0.0, 1.0);',
' gl_Position = vec4(((aVertexPosition + offsetVector) / projectionVector) + center, 0.0, 1.0);',
' vTextureCoord = aTextureCoord;', // pass the texture coordinate to the fragment shader, the GPU will interpolate the points ' vTextureCoord = aTextureCoord;', // pass the texture coordinate to the fragment shader, the GPU will interpolate the points
' vTintColor = vec4(aTintColor.rgb * aTintColor.a, aTintColor.a);', ' vTintColor = vec4(aTintColor.rgb * aTintColor.a, aTintColor.a);',
' vBgColor = aBgColor;', ' vBgColor = aBgColor;',
@ -140,9 +119,6 @@ Phaser.Renderer.WebGL.BatchManager = function (renderer)
'}' '}'
]; ];
// @type {WebGLUniformLocation }
// this.offsetVector;
// @type {GLint} // @type {GLint}
this.aVertexPosition; this.aVertexPosition;
@ -163,6 +139,9 @@ Phaser.Renderer.WebGL.BatchManager = function (renderer)
// @type {WebGLUniformLocation } // @type {WebGLUniformLocation }
this.projectionVector; this.projectionVector;
// @type {WebGLUniformLocation }
this.offsetVector;
}; };
Phaser.Renderer.WebGL.BatchManager.prototype.constructor = Phaser.Renderer.WebGL.BatchManager; Phaser.Renderer.WebGL.BatchManager.prototype.constructor = Phaser.Renderer.WebGL.BatchManager;
@ -272,7 +251,8 @@ Phaser.Renderer.WebGL.BatchManager.prototype = {
// The projection vector (middle of the game world) // The projection vector (middle of the game world)
this.projectionVector = gl.getUniformLocation(program, 'projectionVector'); this.projectionVector = gl.getUniformLocation(program, 'projectionVector');
// this.offsetVector = gl.getUniformLocation(program, 'offsetVector'); // The offset vector
this.offsetVector = gl.getUniformLocation(program, 'offsetVector');
this.program = program; this.program = program;
}, },
@ -467,6 +447,9 @@ Phaser.Renderer.WebGL.BatchManager.prototype = {
// I.e. if the world is 800x600 then the projection vector is 400 x -300 // I.e. if the world is 800x600 then the projection vector is 400 x -300
gl.uniform2f(this.projectionVector, this.renderer.projection.x, this.renderer.projection.y); gl.uniform2f(this.projectionVector, this.renderer.projection.x, this.renderer.projection.y);
// Set the offset vector.
gl.uniform2f(this.offsetVector, this.renderer.offset.x, this.renderer.offset.y);
// The Vertex Position (x/y) // The Vertex Position (x/y)
// 2 FLOATS, 2 * 4 = 8 bytes. Index pos: 0 to 7 // 2 FLOATS, 2 * 4 = 8 bytes. Index pos: 0 to 7
// final argument = the offset within the vertex input // final argument = the offset within the vertex input

View file

@ -428,6 +428,8 @@ Phaser.Renderer.WebGL.prototype = {
this.setBlendMode(this.blendModes.NORMAL); this.setBlendMode(this.blendModes.NORMAL);
*/ */
// this.offset.x = this.game.camera._shake.x;
// this.offset.y = this.game.camera._shake.y;
this.offset.x = 0; this.offset.x = 0;
this.offset.y = 0; this.offset.y = 0;