Skip to content

Instantly share code, notes, and snippets.

@Shaptic
Created February 10, 2013 22:14
Show Gist options
  • Save Shaptic/4751274 to your computer and use it in GitHub Desktop.
Save Shaptic/4751274 to your computer and use it in GitHub Desktop.
Animation fragment shader
#version 330 core
uniform sampler2D texture;
// Individual sprite dimensions expressed in the proper texcoord range.
// For example, a 32x32 sprite would be <0.03125, 0.03125>
// This would then be interpolated from [0, 0.03125], properly rendering
// all of the texels in the desired sprite.
uniform vec2 tc_offset;
// Starting offset within the sprite sheet. For example, if you wanted the
// 2nd sprite of the 3rd row of a sprite sheet with 16x16 sprites, you'd
// pass <2 * 1/16, 3 * 1/16>
uniform vec2 tc_start;
smooth in vec2 fs_texc;
smooth in vec4 fs_color;
out vec4 out_color;
void main()
{
out_color = texture2D(texture, tc_start + (fs_texc * tc_offset)) * fs_color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment