Changing out-of-range tex fetch behavior

Does anyone know an efficient way to make texture fetches return zero (or some other constant) when a fetch is performed on an out-of-range address?

I know I can do this with clamp mode if I pad the texture with a border of zeros, but in my application that’s a bit problematic. My other choice is to check the address before fetching, but that strikes me as highly inefficient.

Any good ideas?

Thanks,

Brian

You could initialize another texture, working as a mask. This texture would have the border pixels filled with the constant as you already mentioned, and all other pixels set to another value.

This way you would have to do two tex fetches to determine, if the coordinates are outside your desired area.

Calculating correct texture coordinates is a problem then. Different texture dimensions for example may cause problems.

I think you’re better off if you just check the coordinates. “Highly inefficient” is a bit overstated. :)