Created
May 5, 2015 18:11
-
-
Save radiodario/f74c335800c4de373ff9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script id="vertexShader" type="x-shader/x-vertex"> | |
attribute vec3 color; | |
attribute float texIndex; | |
const float SpriteTextureSize = 64.0; | |
const float SpritesPerRow = 32.0; | |
varying vec2 TextureSize; | |
varying vec2 TextureCoord; | |
void main() { | |
vec4 mvPosition = modelViewMatrix * vec4(position, 1.0); | |
// calculate texturecoordinate | |
float col = mod(texIndex, SpritesPerRow); | |
float row = floor(texIndex / SpritesPerRow); | |
// where in the texture to start () | |
TextureCoord = vec2(col*SpriteTextureSize, row*SpriteTextureSize); | |
TextureSize = vec2(SpriteTextureSize, SpriteTextureSize); | |
gl_Position = projectionMatrix * mvPosition; | |
gl_PointSize = 20.; | |
} | |
</script> | |
<script id="fragmentShader" type="x-shader/x-fragment"> | |
uniform sampler2D texture; | |
varying vec2 TextureCoord; | |
varying vec2 TextureSize; | |
void main() { | |
vec2 realTexCoord = TextureCoord + (TextureSize * gl_PointCoord); | |
vec4 fragColor = texture2D(texture, realTexCoord); | |
gl_FragColor = fragColor; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment