POV-Ray : Newsgroups : povray.advanced-users : Need help creating "flat" quadradural panels with smooth_triangle : Re: Need help creating "flat" quadradural panels with smooth_triangle Server Time
28 Jul 2024 12:23:24 EDT (-0400)
  Re: Need help creating "flat" quadradural panels with smooth_triangle  
From: Chris B
Date: 20 Oct 2005 21:38:58
Message: <435846b2$1@news.povray.org>
"Mesh Mongrel" <cor### [at] userssourceforgenet> wrote in message 
news:web.4357fbd1748e455f0b7e880@news.povray.org...
> Update:
>
> I think I figured out that the normal I was calculating was the normal for
> each vertex rather than the normal for the plane.  My misunderstanding. 
> If
> I understand that correctly than I should need to calculate 6 vectors and
> average them together rather than 2.
>
> So I have tried this:
>
> mesh {
>        #local P1 = <x1, y1, z1>;
>        #local P2 = <x2, y2, z2>;
>        #local P3 = <x3, y3, z3>;
>        #local P4 = <x4, y4, z4>;
>        #local N1 = vnormalize(vcross(P3 - P1, P2 - P1));
>        #local N2 = vnormalize(vcross(P1 - P2, P3 - P2));
>        #local N3 = vnormalize(vcross(P1 - P3, P2 - P3));
>        #local N4 = vnormalize(vcross(P4 - P3, P2 - P3));
>        #local N5 = vnormalize(vcross(P3 - P2, P4 - P2));
>        #local N6 = vnormalize(vcross(P3 - P4, P2 - P4));
>        #local N = (N1 + N2 + N3 + N4 + N5 + N6)/6;
>        smooth_triangle { P1, N, P2, N, P3, N }
>        smooth_triangle { P2, N, P3, N, P4, N }
> }
>
>
> I still end up with the same shading problem.
>
> I'd love to know what I'm missing.
>

I suspect you may be getting a couple of different explanations for 
different things mixed up.
In your example you work out a normal for each vertex of two triangles in 
isolation (as if the two triangles were not connected), then you 'average' 
all of the normals giving you a single surface normal that you apply to all 
points.
If you apply the same normal vector to all points in a triangle you are 
telling POV-Ray that the surface at all 3 points is pointing in the same 
direction.
If I've misunderstood your question and that is what you want to do, then I 
think Slime's suggestion should fix your problems.

If I understand correctly though, you just want a smooth surface made of 
multiple triangles.
For this, the normal at a vertex needs to be derived from the edges leading 
into the vertex. Each vertex will therefore have its own normal.
Where a vertex is only part of a single triangle you can simply use the 
cross product of the two edges leading into that vertex as the normal at 
that point.
Where a vertex is part of two triangles you could average the two cross 
products. Alternatively, you can imagine it as part of a single triangle 
made up using that vertex and the two points that are not on the joined edge 
of the two triangles. You can then still use a single cross product (as 
shown for P3 below).

When you have more than two triangles you need to start averaging your cross 
products. P2 in the example below is part of 4 triangles, so two cross 
products are calculated, one for each pair of triangles, then these vectors 
are added together and divided by two to give a surface normal N2 for the 
point P2. The same surface normal is then used for the point P2 in all 4 
triangles, but the other points in each of the triangles have their own 
normals.

I hope that the following example helps to clarify all this.
When you render it you can still make out some joins between the triangles, 
but that's because the points are a fair distance out of alignment and I've 
used a light at an extreme angle to the surface to emphasize the effect.
If your points are close to lying on a plane then it should look "flat".
The debug instructions write some values into the message stream to help 
show the workings for the calculation of N2.

light_source { < -150, 10  ,-80> color rgb 1}
camera {location <0.5,0.5,-2> look_at <0,0.5,0>}


#local P1  = < 0,0,0  >;
#local P2  = < 0,1,0.5>;
#local P3  = < 1,0,0  >;
#local P4  = < 1,1,0  >;
#local P5  = <-1,0,0.2>;
#local P6  = <-1,1,0  >;

#local N1a = vnormalize(vcross(P3 - P1, P2 - P1));
#local N2a = vnormalize(vcross(P4 - P2, P2 - P1));
#local N3  = vnormalize(vcross(P3 - P1, P4 - P3));
#local N4  = vnormalize(vcross(P4 - P2, P4 - P3));

#local N1b = vnormalize(vcross(P1 - P5, P2 - P1));
#local N2b = vnormalize(vcross(P2 - P6, P2 - P1));
#local N6  = vnormalize(vcross(P2 - P6, P6 - P5));
#local N5  = vnormalize(vcross(P1 - P5, P6 - P5));

#local N1 = (N1a+N1b)/2;
#local N2 = (N2a+N2b)/2;


#debug concat("N2a; ",vstr(3,N2a,",",3,3),"\n")
#debug concat("N2b: ",vstr(3,N2b,",",3,3),"\n")
#debug concat("N2 : ",vstr(3,N2,",",3,3),"\n")

mesh {
  smooth_triangle { P1, N1, P2, N2, P3, N3}
  smooth_triangle { P2, N2, P3, N3, P4, N4}
  smooth_triangle { P1, N1, P2, N2, P5, N5}
  smooth_triangle { P2, N2, P5, N5, P6, N6}
  pigment {color rgb 1}
}



Chris B.


Post a reply to this message

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