sydnal
sydnal

Reputation: 317

OpenGL Post Processing using Power of Two Textures

I am trying to do some post processing in OpenGL ES, so I decided to use power of two texture sizes just to be safe. However, the source image is rectangular and does not exactly fit in a PoT texture, so I downscale and draw it into a Frame Buffer (without stretching, I will get to it later) like in this picture: enter image description here

So there is a gap/empty area in the texture which is black or whatever color I clear it to. This then becomes the source texture I use, and I ping pong it numerous times to apply an effect. I tried to outline the problem which I think I will face in the picture. Basically the pixels on the edge will sample from the empty area when I use a shader like blur or bloom that samples from neighboring pixels. If I used a npot texture or stretched it, CLAMP_TO_EDGE would save me from this, but I can't wrap my head around how to do it in my case. Here are some ideas I've come up with:

So, is there any way I can do this efficiently, like setting a texture coord as the edge or something? I know NPoT textures would make this a whole lot easier but I want to explore my options with PoT first. And since even Desktop GPUs were not NPoT friendly in the beginning, I feel like this has to be an already solved problem and there must exist some best practices for this.

Upvotes: 1

Views: 484

Answers (1)

solidpixel
solidpixel

Reputation: 12229

You can emulate clamp to edge when generating the POT version of the texture.

When generating the POT framebuffer rather than just rendering the part of the framebuffer which matches the original texture, render something slightly oversized (e.g. enough additional pixels to cover your filter kernel width). If you render this using CLAMP_TO_EDGE on the original NPOT texture read you make you'll simply extend the edge of the original texture into your kernel's overspill region.

You can then read this as normal with the coordinate range you were planning and it should just work as if you were reading the original texture with CLAMP_TO_EDGE applied. Even though clamp is cheap, I would expect this to be cheaper ...

Upvotes: 1

Related Questions