Archived

This topic is now archived and is closed to further replies.

Pike65

Distorting a Projective Texture Map

Recommended Posts

I''ve been working on getting a reflective water surface into my terrain renderer for a few weeks (in between coursework deadlines) - and I was doing pretty well up until recently. The technique I''m using is pretty much a direct rip from YannL''s system that crops up in various threads (like this one). It basically describes how to flip the scene, render to a texture and then use projective texture mapping to get it back onto the water surface. So far so good. The problem arrises when I try to distort the surface of the water per-vertex using a normal map (as covered here). Unfortunately when I distort the surface I get pretty nasty effects around the edge of the screen as the normal map means the texture lookup goes outside the area of the texture (not sure if I described that too well - I''ll post a screen if people want). No one else seems to have mentioned this in any of the previous threads though, which makes me wonder if I screwed up the implementation somewhere . . . Anyone else come across this, and if so how did people deal with it?

Share this post


Link to post
Share on other sites
Yeah, I know the situation. You basicly have 2 options how to deal with it. First one is trivial. Just clamp the texture coordinates (after disortion) to 0,1 range. This will give you good results in most cases. The second one is a bit trickier to implement. The idea si to render to texture with a bit biger FOV (or moving camera back a little). Then disorted texture coordinats will still be in 0,1 range (if they are not you can still combine it with option 1)

You should never let your fears become the boundaries of your dreams.

Share this post


Link to post
Share on other sites
I'd suggest clamping them. That's the easiest option, and will generally give good results. Note that the edge behaviour will be a bit "weird" under some extreme conditions, eg. large waves at the corners. But it typically looks OK.

Rendering with a larger FOV works, but modifies the reflection over the entire surface. That's not visible if you have a lot of distortion, but you will notice it on a calm water surface, near local object reflections (the real and reflected object outlines won't match, it will seem like the reflection is floating above or below the surface).

A third option is to use a border map. That's an additional map that samples texels around edges, but outside the normally visible field. A small cubemap is well suited for that. Per pixel/vertex, you detect if the texcoords fall outside the projective map range. If they do, then you trace a reflection ray from the offending position into the cubemap, and sample from here. This technique can be applied per vertex or per pixel, depending on target hardware.


[edited by - Yann L on May 20, 2004 12:35:15 PM]

Share this post


Link to post
Share on other sites
K - thanks a lot guys.

Guess that means I''ll have to take my texture projection code out off the texture matrix stack and do it myself though. Ah well, it was high time I profiled my maths code anyway : )

(BTW - Good to see you back Yann)

Share this post


Link to post
Share on other sites