Wrap texels between desired values I'm using a basic pixel shader here uniform sampler2D texture uniform float pixel threshold void main() float factor 1.0 (pixel threshold 0.001) vec2 pos floor(gl TexCoord 0 .xy factor 0.5) factor gl FragColor texture2D(texture, pos) gl Color It works great in my game. But on a new enemy it doesn't. This enemy is different because it uses a texture atlas one big texture holding more frames than just the character. The sampling gets messed up because factorapproaches 0 so does the xy coord therefore sampling some pixels outside of the character's sheet. Likewise when pixel threshold gets small, the xy coord goes outside of the character's spot in the texture. Clamping is not the solution because we want it to wrap around. I've tried many ways of wrapping but not seem to offer the desired effect of the original. I tried using 4 uniforms left,top,width,height and passing in the masking values used when drawing the sprite from the spritesheet. vector2 size mySprite.getSize() float left mySprite.getTextureRect().left size.x float top mySprite.getTextureRect().top size.y float width mySprite.getTextureRect().width size.x float height mySprite.getTextureRect().height size.y myShader.setUniformf("left", left) ... myShader.setUniformf("height", height) How can I have the pixel blur shader stay within the texel ranges provided by the uniform? Thanks.