@@ -50,10 +50,11 @@ PIXI.TilemapShader = function (gl) {
5050 'precision lowp float;' ,
5151 'uniform sampler2D uImageSampler;' ,
5252 'uniform float uAlpha;' ,
53- 'uniform vec2 uClipping;' ,
53+ 'uniform vec2 uClipLoc;' ,
54+ 'uniform vec2 uClipLimit;' ,
5455 'varying vec2 vTexCoord;' ,
5556 'void main(void) {' ,
56- ' if ( gl_FragCoord.x < uClipping .x && gl_FragCoord.y > uClipping.y )' ,
57+ ' if ( gl_FragCoord.x >= uClipLoc.x && gl_FragCoord.y >= uClipLoc.y && gl_FragCoord.x < uClipLimit .x && gl_FragCoord.y > uClipLimit.y )' ,
5758 ' gl_FragColor = texture2D(uImageSampler, vTexCoord) * uAlpha;' ,
5859 '}'
5960 ] ;
@@ -63,11 +64,12 @@ PIXI.TilemapShader = function (gl) {
6364 'uniform vec2 uOffset;' ,
6465 'uniform vec2 uCentreOffset;' ,
6566 'uniform vec2 uScale;' ,
67+ 'uniform vec2 uClipOffset;' ,
6668 'attribute vec4 aPosition;' ,
6769 'varying vec2 vTexCoord;' ,
6870 'void main(void) {' ,
6971 ' gl_Position.zw = vec2(1, 1);' ,
70- ' gl_Position.xy = (aPosition.xy + uOffset + uCentreOffset) * uScale - uCentreOffset;' ,
72+ ' gl_Position.xy = (aPosition.xy + uClipOffset + uOffset + uCentreOffset) * uScale - uCentreOffset;' ,
7173 ' vTexCoord = aPosition.zw;' ,
7274 '}'
7375 ] ;
@@ -100,14 +102,29 @@ PIXI.TilemapShader.prototype.init = function () {
100102 // get and store the attributes
101103 this . aPosition = gl . getAttribLocation ( program , 'aPosition' ) ;
102104 this . uSampler = gl . getUniformLocation ( program , 'uImageSampler' ) ;
103- this . uClipping = gl . getUniformLocation ( program , 'uClipping' ) ;
105+
106+ // clipping uniforms...
107+
108+ // clipping start location (pixels)
109+ this . uClipLoc = gl . getUniformLocation ( program , 'uClipLoc' ) ;
110+ // clipping width/height (pixels)
111+ this . uClipLimit = gl . getUniformLocation ( program , 'uClipLimit' ) ;
112+ // clipping start location in webGl coordinates (-1...+1)
113+ this . uClipOffset = gl . getUniformLocation ( program , 'uClipOffset' ) ;
114+
115+ // offset for screen shake effect etc
104116 this . uOffset = gl . getUniformLocation ( program , 'uOffset' ) ;
117+
118+ // centre of a tile for offset before scaling (so tiles scale from the centre out)
105119 this . uCentreOffset = gl . getUniformLocation ( program , 'uCentreOffset' ) ;
106- this . uAlpha = gl . getUniformLocation ( program , 'uAlpha' ) ;
120+ // scale factor for tiles
107121 this . uScale = gl . getUniformLocation ( program , 'uScale' ) ;
108122
123+ // alpha blending
124+ this . uAlpha = gl . getUniformLocation ( program , 'uAlpha' ) ;
125+
109126 this . attributes = [ this . aPosition ] ;
110- this . uniforms = [ this . uClipping , this . uOffset , this . uCentreOffset , this . uAlpha , this . uScale , this . uSampler ] ;
127+ this . uniforms = [ this . uClipOffset , this . uClipLoc , this . uClipLimit , this . uOffset , this . uCentreOffset , this . uAlpha , this . uScale , this . uSampler ] ;
111128
112129 this . program = program ;
113130
0 commit comments