Original Post
Evening all, As those of you follow my developer journal probably know, I'm currently writing part of a book on lighting techniques with Direct3D 10. One of the parts I'm covering that I haven't experimented with before is Relief Mapping / Parallax Occlusion Mapping (which as far as I can tell are two names for pretty much the same thing). Whilst I have some copy-n-paste reference code I'm implementing the whole algorithm myself so that I fully understand it and, for obvious reasons, I'm not going to steal/publish someone else's code [wink] Anyway, I've had a strange recurring bug with my implementation that I'm starting to think is a fundamental flaw with the whole RM/POM algorithm. The ATI sample in the DX-SDK can be pushed to generate the same error given appropriate height maps and constants. I don't have time to draw and upload a proper image, so bare with the ASCII art [cool]:
eye
/
1.0 +--------/-----------------+
| / |
| / |
0.0 +-----x--------------------+
pixel
So the basic idea is that for the currently rendered pixel we trace a ray and check for intersections. Easy. You can flip the various definitions around and get much the same results (e.g. defining the pixel as the bottom of the volume or the top of the volume), but in particular it's the wrapping issue that I'm seeing:
eye
_/
1.0 +---_x---------------------
| _/
|/
_/|
/ |
0.0 / +--------------------------
In the above (crap) diagram, if the target pixel is defined at the top of the volume then you get the situation where the ray "overshoots" and leaves the bounding volume. At the edge of a texture this tends to mean it wraps around and you pick up the pixels from the opposite edge of the height/normal map. If you define the pixel at the bottom of the volume then you can get the following case:
eye
_/
1.0 +-------------------------+ _/
| | _/
| |_/
| _/
| / |
0.0 +----------------------x--+
Which is slightly less obvious, but it means that whilst tracing the ray you end up taking samples from the opposite side of the height map. It seems to me that you can't really avoid this problem - the heightmap scale and the viewing angle are key factors in determining whether you go out-of-bounds and they're both key inputs into the algorithm. All the sample code I've played with - reference material from research papers, ATI's sample etc... can demonstrate the above effects in some form. Seems that they get away with it by clever texture mapping and/or heightmaps (e.g. having a "wall" around the edge of the texture). Having a relatively small height scale makes it relatively difficult to spot this problem unless you really look for it. So, I'm done explaining my observations now - anyone care to comment? Who else has implemented these algorithms and either seen, or even better - disproved/solved this problem... Cheers, Jack



