Skip to content

Commit d43f29d

Browse files
committed
Use the tilemap layer alpha value when batch rendering tiles.
1 parent 61635c9 commit d43f29d

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/pixi/extras/Tilemap.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ PIXI.Tilemap.prototype._renderWholeTilemap = function(renderSession)
284284
// set the base offset (in screen units) (it's zero, scrolling is now handled by the batch buffer values)
285285
gl.uniform2f( shader.uScrollOffset, 0, 0 );
286286
//gl.uniform2f( shader.uScrollOffset, this.scrollX * iWide, -this.scrollY * iHigh );
287+
gl.uniform1f( shader.uAlpha, this.alpha );
287288

288289

289290
// check if a texture is dirty..

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ PIXI.TilemapShader = function(gl)
3232
this.fragmentSrc = [
3333
" precision lowp float;",
3434
" uniform sampler2D uImageSampler;",
35+
" uniform float uAlpha;",
3536
" varying vec2 vTexCoord;",
3637
" void main(void) {",
37-
" gl_FragColor = texture2D(uImageSampler, vTexCoord);",
38+
" vec4 col = texture2D(uImageSampler, vTexCoord);",
39+
" col.a = uAlpha;",
40+
" gl_FragColor = col;",
3841
" }"
3942
];
4043

@@ -79,9 +82,10 @@ PIXI.TilemapShader.prototype.init = function()
7982
this.aPosition = gl.getAttribLocation(program, 'aPosition');
8083
this.uSampler = gl.getUniformLocation(program, 'uImageSampler');
8184
this.uScrollOffset = gl.getUniformLocation(program, 'uScrollOffset');
85+
this.uAlpha = gl.getUniformLocation(program, 'uAlpha');
8286

8387
this.attributes = [this.aPosition, this.uSampler];
84-
this.uniforms = [this.uScrollOffset];
88+
this.uniforms = [this.uScrollOffset, this.uAlpha];
8589

8690
this.program = program;
8791
};

0 commit comments

Comments
 (0)