I’m attempting to port a CG shader of mine to GLSL, and have hit a problem: I’m not sure of how to use the “texpad_x” variable in GLSL.
Specifically, I’m using FilterManager to set up some post-processing effects. Naturally, I want to adjust the texture coordinates to account for the (presumed) padding to a power-of-two texture, as indicated in the manual. In CG this is accomplished via the “texpad_x” variable (where “x” is the name of the texture involved, as given via “setShaderInput”), I believe–and indeed, in CG this seems to work. In GLSL, however, it seems that either I’m doing something incorrectly, or the variable doesn’t exist.
Where am I going wrong?
Here is the vertex shader in which I’m using “texpad”:
As far as I remember texpad is just “aspect ratio” of texture? How it can help in adjusting? If I understand texture should be itself power-of-two, i.e. it should have U2 x W2 resolution and it’s not related to the texcoords.
If you have a 800x600 window and you render that to a buffer with power-o-2 textures on you will get a 1024x1024 texture with a 800x600 image and some empty space. Texpad helps to crop this to only the used pixels. I think you should be able to supply a texpad value from python vec4(win_y/tex_y, win_x/tex_x, 1.0, 1.0)… or x and y the other way, and make sure you get floats not ints on python 2.x
Or You can assume that all gpu support non-power-of-two textures and don’t mess with texpad.
Aah, thank you both–that looks about right; I’ll hopefully try it out tomorrow.
It’s a pity that the automatic version doesn’t seem to work in GLSL as it does in CG, but as you’ve pointed out, it’s not too difficult to provide the value oneself.
Just FYI, there’s not a lot of merit to the texture padding system nowadays. It’s pretty safe to just set “textures-power-2 none” in Config.prc if you have a shader-based application.
(And it’s a mild relief to see that my own card does indeed seem to be on that list–it’s a little old these days, so I wasn’t entirely confident. ^^; )