POV-Ray : Newsgroups : povray.programming : Height field bug found and fixed : Height field bug found and fixed Server Time
28 Jul 2024 06:22:02 EDT (-0400)
  Height field bug found and fixed  
From: Slime
Date: 8 Oct 2002 15:54:09
Message: <3da337e1$1@news.povray.org>
Have you ever created a smooth height field with some flat areas? Noticed
how the smoothing around the flat areas, although looking rounded, doesn't
quite look entirely *smooth*? See the image in p.b.i.

I've dealt with this artifact for a while now, so now that I'm looking at
and fiddling with the source code, I took some time to look at it. That was
two days ago. I spent two days searching through the height field normal
functions, trying to find the bug, and in the end concluded that they worked
as they were supposed to. But the artifacts still seemed strange.

Then I noticed something about the smooth triangle normal function: it
doesn't transform the normal after interpolating it. Makes sense, I thought,
since transforms on a simple shape like a triangle can be applied
immediately - no need to transform the ray.

Then I thought, maybe this no-transformation-after-interpolation is a
necessity? So I went into the height field code and transformed the normals
*before* interpolation, and not after. Voila. See the second image in the
thread in p.b.i.

The reason? Height fields are extremely tall objects (internally). They're
65535 units tall by (image width) units wide by (image height) units deep.
The normals are calculated and interpolated between while the height field
is tall like this.

Then the height field is scaled down drastically to fit the unit box. This
has the effect that the normals, after interpolation, are stretched
*vertically* by a whole lot, after which they are normalized. This causes
any vectors that were interpolated between (anything) and <0,1,0> to be
almost always vertical. As a result, triangles near flat areas (where the
normal is <0,1,0>) end up thinking that they're almost entirely flat.

If you don't understand that (it wasn't the best explanation), you should
just remember that transforming normals after interpolation is a bad idea.
It causes some of the normals that were interpolated between to have more
weight than others.

Note that this doesn't fix the grid-like appearance of the height field, but
that's a natural artifact caused by the fact that height fields are, in
fact, grids.

(Oh, by the way: there is also another bug. The normals for the right-most
and up-most rows of triangle vertices aren't calculated (and end up being
<-32767,-32767,-32767> as a result). This was fixed by changing two < signs
to <= to signs in the for loops in the normal calculation function. This bug
normally isn't visible because of the smooth-triangle normal flipping bug
(see the last entry in the FAQ in the documentation).)

Am I making sense? =) See the thread in p.b.i for a graphical display of the
differences.

 - Slime
[ http://www.slimeland.com/ ]


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.