Skip to content

Instantly share code, notes, and snippets.

@mikolalysenko
Last active December 21, 2015 09:49
Show Gist options
  • Save mikolalysenko/6287996 to your computer and use it in GitHub Desktop.
Save mikolalysenko/6287996 to your computer and use it in GitHub Desktop.
uniform vec2 worldSize;
uniform vec2 tileScale;
uniform sampler2D tileIds; //This is the map you update every frame
uniform sampler2D tileSheet; //This has the texture data
varying vec3 worldCoord;
void main() {
vec2 worldUV = worldCoord.xy / worldCoord.z;
vec2 tileCoord = tileScale * (floor(255.0 * texture2D(tileIds, floor(worldUV) / worldSize).ra) + fract(worldUV));
gl_FragColor = texture2D(tileSheet, tileCoord);
}
attribute vec2 position;
uniform mat3 viewMatrix;
varying vec3 worldCoord;
void main() {
vec3 worldCoord = viewMatrix * vec3(pixelCoordinate, 1.0);
gl_Position = position;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment