Skip to content

Commit 2a2c82e

Browse files
committed
Fixed the alpha blending (copied the approach from the TriangleStrip PIXI shader) for Tilemap layers. The "blank tilemap" example now works properly and blends the background layers when you use the number keys to switch primary layers.
1 parent 9e3a7ec commit 2a2c82e

4 files changed

Lines changed: 5 additions & 6 deletions

File tree

docs/_phaser_tilemap_GL_progress.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,5 @@ Need to talk with Rich about it before proceeding further.
190190

191191
Modified the batch creation code and the batch drawing code to only insert degenerate triangles at the end of rows or when a row is broken (e.g. by some empty tiles which we won't draw at all). This should speed things up by optimising the draw, and reducing the amount of data required to describe the batch.
192192

193+
Took a look at the PIXI triangle strip shader and noticed that the alpha is being used as a multiplier on the whole colour vector... I was applying it directly to the .a fourth vector value. Changed the tilemap shader to match and it's working great now!
193194

src/pixi/extras/Tilemap.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ PIXI.Tilemap = function(texture, mapwidth, mapheight, tilewidth, tileheight, lay
5656
this.dirty = true;
5757

5858
/**
59-
* The blend mode to be applied to the sprite. Set to PIXI.blendModes.NORMAL to remove any blend mode.
59+
* The blend mode to be applied to the tilemap. Set to PIXI.blendModes.NORMAL to remove any blend mode.
6060
*
6161
* @property blendMode
6262
* @type Number
@@ -91,8 +91,7 @@ PIXI.Tilemap.prototype._renderWebGL = function(renderSession)
9191

9292
renderSession.spriteBatch.stop();
9393

94-
// init! init!
95-
if(!this._vertexBuffer)
94+
if (!this._vertexBuffer)
9695
{
9796
this._initWebGL(renderSession);
9897
}

src/pixi/renderers/webgl/shaders/TilemapShader.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ PIXI.TilemapShader = function(gl)
3535
" uniform float uAlpha;",
3636
" varying vec2 vTexCoord;",
3737
" void main(void) {",
38-
" vec4 col = texture2D(uImageSampler, vTexCoord);",
39-
" col.a = uAlpha;",
40-
" gl_FragColor = col;",
38+
" gl_FragColor = texture2D(uImageSampler, vTexCoord) * uAlpha;",
4139
" }"
4240
];
4341

src/pixi/renderers/webgl/utils/WebGLShaderManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ PIXI.WebGLShaderManager.prototype.setContext = function(gl)
6767
// the next one is used for rendering triangle strips
6868
this.stripShader = new PIXI.StripShader(gl);
6969

70+
// shader for batch drawing tilemap tiles as a set of triangle strips with degenerate triangles between them
7071
this.tilemapShader = new PIXI.TilemapShader(gl);
7172

7273
this.setShader(this.defaultShader);

0 commit comments

Comments
 (0)