Cybolic

Godot Tile Repeat Shader

Jun 15th, 2015
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. uniform texture tilesheet;
  2. uniform float repeat=16;
  3. uniform float tileOffsetX=0;
  4. uniform float tileOffsetY=0;
  5. uniform float tileWidth=16;
  6. uniform float tileHeight=16;
  7. uniform float tilesheetWidth=101;
  8. uniform float tilesheetHeight=169;
  9.  
  10. vec2 inverseTextureSize = vec2(1/tilesheetWidth, 1/tilesheetHeight);
  11. vec2 tileSize           = vec2(tileWidth, tileHeight);
  12. vec2 pixelCoord         = UV.xy * 1/TEXTURE_PIXEL_SIZE * repeat;
  13.  
  14. vec2 spriteOffset = vec2(tileOffsetX, tileOffsetY);
  15. vec2 spriteCoord = mod(pixelCoord, tileSize);
  16. vec2 texCoord = (spriteOffset + spriteCoord) * inverseTextureSize;
  17.  
  18. COLOR.rgba = tex(tilesheet, texCoord);
  19. // Get rid of empty lines that are due to floating point errors
  20. if (COLOR.a == 0) {
  21.     COLOR.rgba = tex(tilesheet, texCoord-vec2(0.0, -inverseTextureSize.y));
  22. }
  23. COLOR.rgba = COLOR.rgba * SRC_COLOR;
Advertisement
Add Comment
Please, Sign In to add comment