• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Shaders [SOLVED] using a variable to only draw part of an image

A

Anthony Navarro

Guest
Hello, I am having some trouble using a shader in my game.
I am relatively new to GLSL, so any help would be appreciated.
My goal: I want a shader to draw the bottom portion of a sprite, and work its way up.
I want the colors to be inverted, so the end result (for a white block) would look like
a black block is moving up to cover the white block. Hopefully this all makes sense. I
was able to make the color inversion easily enough, but I havent been able to get the inversion to rise instead of being drawn all at once. I have tried things like:

Code:
if(1.0-v_vTexCoord.y<time)
{
 //invert
}else{
 //use regular color
}
This always draws the inversion over the entire image at once, even though the "time"
uniform is decremented slowly (starting at 1). It is my understanding that v_vTexCoord coordinates are non-linear (0-1)
Maybe im wrong. Im definitely screwing something up.
Thanks in advance for any suggestions!
 

jo-thijs

Member
The texture coordinates are coordinates inside a texture pages.
Multiple images are put together on a texture page.
This often causes texture coordinates to only take up a small part of the range (0-1).
You can get the range of the texture coordinates of an image by using the function sprite_get_uvs.
Texture coordinates are linear though in the sense that texels have a constant width and height in a single texture page (as far as I understand it).
 
A

Anthony Navarro

Guest
This often causes texture coordinates to only take up a small part of the range (0-1).
You can get the range of the texture coordinates of an image by using the function sprite_get_uvs.
Good to know, I will look into this and see what I come up with. Thanks!
 
Top