Skip to content

Commit fdb80f1

Browse files
committed
Modify Tile Shader to produce scaled layers that look identical to the Canvas renderer scaling (add uCentreOffset, scale the drawing coordinates, subtract uCentreOffset).
1 parent 0b392e1 commit fdb80f1

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ PIXI.TilemapShader = function(gl)
4141

4242
this.vertexSrc = [
4343
" precision lowp float;",
44-
" uniform vec2 uScrollOffset;",
44+
" uniform vec2 uCentreOffset;",
45+
" uniform vec2 uScale;",
4546
" attribute vec4 aPosition;",
4647
" varying vec2 vTexCoord;",
4748
" void main(void) {",
4849
" gl_Position.zw = vec2(1, 1);",
49-
" gl_Position.xy = aPosition.xy - uScrollOffset;",
50+
" gl_Position.xy = (aPosition.xy + uCentreOffset) * uScale - uCentreOffset;",
5051
" vTexCoord = aPosition.zw;",
5152
" }"
5253
];
@@ -79,11 +80,12 @@ PIXI.TilemapShader.prototype.init = function()
7980
// get and store the attributes
8081
this.aPosition = gl.getAttribLocation(program, 'aPosition');
8182
this.uSampler = gl.getUniformLocation(program, 'uImageSampler');
82-
this.uScrollOffset = gl.getUniformLocation(program, 'uScrollOffset');
83+
this.uCentreOffset = gl.getUniformLocation(program, 'uCentreOffset');
8384
this.uAlpha = gl.getUniformLocation(program, 'uAlpha');
85+
this.uScale = gl.getUniformLocation(program, 'uScale');
8486

8587
this.attributes = [this.aPosition, this.uSampler];
86-
this.uniforms = [this.uScrollOffset, this.uAlpha];
88+
this.uniforms = [this.uCentreOffset, this.uAlpha, this.uScale];
8789

8890
this.program = program;
8991
};

0 commit comments

Comments
 (0)