• 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 Translating UV into Pixel coordinates

A

AlexM

Guest
Hi developer fellows!

I am looking for a way to get Texture Coordinates in the frag shader that are based on Pixels and not on 0..1 values.

For the Scenario:
I am using the vertex shader to create two triangles and then draw a sprite in the frag shader. I now simply want the first 10 Pixels along the x-axis to be treated in another way then the rest.

It is easily done with UV Coordinates ranging from 0..1, but my problem is that I need the exact pixel number starting from the beginning of the sprite.

something like:

Code:
        if (v_vPixelCoord.x >=   10.0)
        {
            // do shader stuff
        }
My next idea was to calculate it using: length * v_vTexcoord.x = Pixel Number. But when the UV Coord are not 0..1 as it is mostly the case, this also fails.

I tried gl_FragCoord but that seems to related to viewport size and not to the texture.

Is there maybe and hidden gl_ variable the would give the pixel coords instead of UV coords?

Or is it maybe possible to get the min and max UV value of the texture coords into the frag shader?

Thank you!

Best Regards
Alex
 
You might want to look into these functions:
texture_get_uvs(texid)
texture_get_texel_width(tex)

uv left + 10 * texelwidth should be what you wanted.

And you might need to uncheck sprite cropping in the texture page settings if your sprites have transparent pixel rows or columns.

Or
Get the sprites left coordinate in the view, add 10 pixels and pass that into the shader. Then you can use gl_Fragcoord.
 
Last edited:
Top