Quote:Original post by Promit
Ok, now it's my turn to help you [wink] I used quad cutting LoD instead of half cutting LoD, so I'm sort of thinking out "loud" here. Bear with me. (I'm also ignoring your implementation, as it looks like an MFH (Mess From Hell)).
you should see the function to create the index buffers with its tons of special cases and variations (the "direction" for even lods must alternate, odd lods are handles differently and depending on cutout combinations single corner triangles are needed)
Quote:
Let's look at the high detail sample.
| | xxxxxxxxx xx x xx x x x x x x xxx x--xxxxxxxxx-- x xxx x x x x x x xx x xx xxxxxxxxx | |
I've used lines to mark the 4 "critical" vertices. These are the vertices that are removed when shifting down to the next LoD.
xxxxxxxxx xx xxx x x xx x x xx x xx x x xx x x xxx xxxxxxxxxxx
for a moment i went "duh, of course, im forgetting these 4. but then i noticed these two are different step sizes.
in fact the above example would use a smaller step size, reducing one "segment" to case 1 (or just horz flipped to make it alternate).
so all segments are either looking like the lowest lod for a patch (two triangles) or the second lowest (adding one point in the center, four triangles). yet, it seems this center point isnt making a difference to the max error in most cases.
i think i should explain some of the terms im using (as they are all made up).
PS is the patchsize, here 33. inconsistent i notice, as patchsize is 32 and mapsize is 1025 instead of 1024.
step is the distance between two points for an even lod (or and odd one ignoring the one in the middle). a segment is a square with size step (ie the "quad" you get when ignoring all skipped points). seg_left, etc. are the global coordinates in the heightmap (ie seg_left is the global x coord for the left side).
relx is the relative distance into a segment (ie for x=4 with a step size of 8 it is .5).
when reaching the right or bottom side of the map i need to set it to 1 (1 is usually never reached as its treated as 0 for the next segment.. at these two edges they need to be set to 1 to prevent being out of bounds with the right or bottom side of a segment.. so its forcing the exception of using the left or top segment when reaching the edge).
tl=topleft, br=bottomright, etc. are the height values at the corners of a segment. mid is the height in the center.
the loop is only going over half the levels, starting with 1 (level 0 never has errors) and handles 2 consecutive levels at once (ie. 1 and 2 use the same step size, 1 simple adds the center point and needs to interpolate differently).
all the ugly if's..
for odd levels, its four triangles meeting in the center, so the left,top,right,bottom triangle are interpolated depending on where the real coordinate is. you get that by adding the patch internal ix, iz to the patch offset x,z.
bl2tr is just used to decide in which direction the quad is divided.
where you are is decided by the relative positions, as you can say if the diagonal is going from topleft to bottom right and relx<relz then youre in the bottom left triangle, else youre past the diagonal and in the top right.
the rest is just getting the difference between two corners and interpolating. height at corner you start + interpolated height difference in x direction + interpolated height difference in z direction.
hm, need to check that the start is consistent with the rest..
what i hate about error calculation is that its a pain to debug and always works great for the small test cases where you can afford to track each step.
errors for patch 512 end up like this:
0, 8, 8, 12, 12, (annoying but right order so far)
16, 14, 16, 15, (wtf?)
32, 32