Parallax Occlusion Mapping Line Intersection

Started by
0 comments, last by Jason Z 12 years, 3 months ago
I am looking at the parallax occlusion mapping code in the DetailTessellation DX Sample.

I understand how they find the line segment on the heightmap where the view ray pierces the heightfield, but I do not understand how they perform the ray/line intersection test. It seems they were able to do
some optimization trick so it doesn't look like a normal intersection test.

Once they find the line segment, they save the heightmap heights fCurrHeight and fPrevHeight, and also the ray heights fCurrentBound and fCurrentBound + fStepSize.

Then somehow they determine the parallax amount from these height values only. When I do a 2D line/line intersection, I need to also take into considerating the horizontal coordinate values (not just the vertical coordinate values). How do they do it so that the horizontal coordinate values simplify out?



pt1 = float2( fCurrentBound, fCurrHeight );
pt2 = float2( fCurrentBound + fStepSize, fPrevHeight );

float fDelta2 = pt2.x - pt2.y;

float fDelta1 = pt1.x - pt1.y;

float fDenominator = fDelta2 - fDelta1;

fParallaxAmount = ( pt1.x * fDelta2 - pt2.x * fDelta1 ) / fDenominator;

-----Quat
Advertisement
I worked this out a long time ago, so please forgive the foggy answer. You are basically doing a two line intersection solution. This portion of the code is called when you get an intersection with the surface, so you can draw two vertical parallel lines to indicate the two locations that you are dealing with. On the right will be your previous sample location and on the left will be your ending sample location. The viewing line should start on the previous sample at a greater height than it ends with on the ending sample - so draw a line from the top of the right sample location to somewhere down low on the left sample location.

You will do the opposite for the current and previous heights, since you know that on the previous test you didn't intersect, and in this test you did intersect. So you can draw the line from the top of the left sampling location to somewhere lower down on the right sampling location.

At this point you have two lines crossing. If you work out the geometry of the situation given the heights that we just mentioned, then it simplifies out to what they have written there... Sorry, but I don't recall the exact solution - but after getting the diagram set up I think it will not be too difficult to follow (at least that is how I remember it...).

I hope that helps (and was clear enough to understand!).

This topic is closed to new replies.

Advertisement