|
|
On Tue, 23 Mar 1999 12:47:37 -0500, david sharp <dsh### [at] interportnet> wrote:
>Ron Parker wrote:
>[ ... ]
>> The problem is, those triangles cause division by zero errors
>> on Alpha processors. There is no way to have the normal go
>> from "positive" to "negative" without going through zero, so
>> there is always a curve on such a triangle where the normal
>> is undefined. Since POV always needs a valid normal to compute
>> shading, that's a bad thing.
>
>
>Hmmmm, I just assumed that POV was rotating the normals from one
>triangle corner to the next, in which case I don't see any 'zero'
>normal.
>Your comment makes me believe that what POV does is interpolate the
>vector coefficients independently.
It's good that that's what it makes you believe, for that is indeed what it
does. Below are the nice ASCII-art comments from the relevant spot in
triangle.c. The normalization step is what causes the division-by-zero error
in some cases. There may also be lighting code that is sensitive to normals
that are exactly perpendicular to the ray. The solution to the problem is to
specify your geometry more precisely by creating more triangles. The
difference between the normals at the corners of a smooth triangle shouldn't
be large, anyway, because the Phong approximation works best for smallish
angles. I will admit, though, that if the new code is based on my original
thoughts on this matter, it might be a bit more sensitive to this problem
than is strictly necessary.
If you're trying to create a twisted-ribbon type of thing, perhaps you
would find more success and realism with bicubic patches.
* Calculate the Phong-interpolated vector within the triangle
* at the given intersection point. The math for this is a bit
* bizarre:
*
* - P1
* | /|\ \
* | / |Perp\
* | / V \ \
* | / | \ \
* u | /____|_____PI___\
* | / | \ \
* - P2-----|--------|----P3
* Pbase PIntersect
* |-------------------|
* v
*
* Triangle->Perp is a unit vector from P1 to Pbase. We calculate
*
* u = (PI - P1) DOT Perp / ((P3 - P1) DOT Perp).
*
* We then calculate where the line from P1 to PI intersects the line P2 to P3:
* PIntersect = (PI - P1)/u.
*
* We really only need one coordinate of PIntersect. We then calculate v as:
*
* v = PIntersect[X] / (P3[X] - P2[X])
* or v = PIntersect[Y] / (P3[Y] - P2[Y])
* or v = PIntersect[Z] / (P3[Z] - P2[Z])
*
* depending on which calculation will give us the best answers.
*
* Once we have u and v, we can perform the normal interpolation as:
*
* NTemp1 = N1 + u(N2 - N1);
* NTemp2 = N1 + u(N3 - N1);
* Result = normalize (NTemp1 + v(NTemp2 - NTemp1))
*
* As always, any values which are constant for the triangle are cached
* in the triangle.
Post a reply to this message
|
|