PDA

View Full Version : How can I render only a portion of a texture in GLSL?



hashbrown
09-09-2016, 09:56 AM
Can I render a portion of a texture using only GLSL? I'd like to animate a sprite sheet on a quad, and I know how to render a portion of the tex when I'm initializing a mesh, but what about during the loop using GLSL? I'm pretty sure I'd have to pass in a uniform with "time passed" in order to animate, but how would I crop the texture in GLSL?

john_connor
09-09-2016, 01:41 PM
the only thing you have to submitt to the shader is (animated) texture coordinates (vec2)
if you want to calculate the animation on the gpu, you can pass the passed frame time as a uniform
but you can also do the animation offline and just send the resulting data (texture coords) to the shader

hashbrown
09-09-2016, 07:30 PM
the only thing you have to submitt to the shader is (animated) texture coordinates (vec2)
if you want to calculate the animation on the gpu, you can pass the passed frame time as a uniform
but you can also do the animation offline and just send the resulting data (texture coords) to the shader

Thanks again John!