texture wrapping mode

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
drhenry
Posts: 16
Joined: Fri Mar 26, 2010 8:03 am

texture wrapping mode

Post by drhenry »

Hi,

I'm implementing a Screen Space Ambient Occlusion (SSAO) shader and have difficulties with texture wrapping. (For those who don't know SSAO: it's a technique, where you compute the amount of occlusion for each pixel by comparing its depth with surrounding sample pixels. If samples are closer to the camera than current pixel, current pixel gets occluded and becomes darker).
As you can see in the image below, there's a dark area at the left window border at the same height as the cube at the right window border. It seems to me, that the texture coordinates of the samples are wrapped around (texture repeat or whatever you call it in Irrlicht). But in the SSAO shader code I definitely clamp sample texture coordinates to the range [0..1].

Image

Has anyone an idea what's wrong?
How can I set texture wrapping mode to CLAMP for a (shader) material, or for the render target texture respectively?
drhenry
Posts: 16
Joined: Fri Mar 26, 2010 8:03 am

Post by drhenry »

Ok, I think, I've fixed it:

Code: Select all

ScreenQuad.getMaterial().TextureLayer[2].TextureWrapU = ETC_CLAMP_TO_EDGE;
ScreenQuad.getMaterial().TextureLayer[2].TextureWrapV = ETC_CLAMP_TO_EDGE;
did the trick. Although I still don't understand why (can anyone explain it to me?)... in the shader I clamped the texture coordinates to 0..1 so I don't understand why there was still a wraparound...
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

drhenry wrote:Although I still don't understand why (can anyone explain it to me?)... in the shader I clamped the texture coordinates to 0..1 so I don't understand why there was still a wraparound...
I can't 100% answer why but I think it's related to bilinear filtering. So even if you are accessing the very edge of the texture, it will take some filter value from the otherside (Because you are not directly centered on the texel).

I've actually usually used clamp(texcoord, 0.001, 0.999) to get around this but your approach seems much less hackish.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Post Reply