|
![](/i/fill.gif) |
"Chris B" <c_b### [at] btconnect com nospam> wrote:
> "Mesh Mongrel" <cor### [at] users sourceforge net> wrote in message
> news:web.43586b5c748e45a8cfcbd10@news.povray.org...
> > ... snip ...
> > I get very strange results when I try this. I end up with shadows in
> > strange parts of my panels.
>
> Bands of shadows can occur in the middle of a panel if the normals at the
> vertices are pointing in opposite directions.
> When you do a cross product at the apex of a triangle that is facing towards
> you, you get two possible results.
> One is a normal facing towards you, the other is a normal facing away from
> you. This depends on the sequence and direction of the vectors you specify
> with vcross.
Ah. Now I get it. I need to make certain I order the verticies I put into
the cross product so I generate vectors that all point in generally the
same direction. Once all the normals are on the same side of the two
triangles then I can average the normals for the vertices shared on the
triangles and use those as normals for my smooth triangles and I get a
"flat" panel!
After doing some debug and working out the signs in my normal vectors I
ended up putting the below code in my panel macro:
#local N1 = vnormalize(vcross(P3 - P1, P2 - P1));
#local N2 = vnormalize(vcross(P1 - P2, P3 - P2));
#local N3 = vnormalize(vcross(P2 - P3, P1 - P3));
#local N4 = vnormalize(vcross(P4 - P3, P2 - P3));
#local N5 = vnormalize(vcross(P3 - P2, P4 - P2));
#local N6 = vnormalize(vcross(P2 - P4, P3 - P4));
#local Na = (N2 + N5) / 2;
#local Nb = (N3 + N4) / 2;
smooth_triangle { P1, N1, P2, Na, P3, Nb }
smooth_triangle { P2, Na, P3, Nb, P4, N6 }
I just so happened to luck out with my earlier approach of averaging 4
vectors together. I was lucky that it worked for the 6 panels I had the
problem with.
Uderstanding the correct approach will better serve me in the future.
Thanks Chris.
Post a reply to this message
|
![](/i/fill.gif) |