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:25:53 EDT (-0400)
  Re: Need help creating "flat" quadradural panels with smooth_triangle  
From: Mesh Mongrel
Date: 20 Oct 2005 23:55:01
Message: <web.43586550748e45a8cfcbd10@news.povray.org>
> smooth_triangle { P1, N, P2, N, P3, N + <0,0,.000001>}

Thanks for the suggestion.  But that didn't solve the shading problem
either.

Good news!  Through some trial and error I finally stumbled upon a solution.

I discovered that if I calculate the normals for all 6 of my verticies and
just average the 4 normals together that share a line between the two
triangles and then use the two remaining normals for the verticies they
were calculated from, it renders as a smooth surface.

The solution I stumbled across is below:

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 = (N2 + N3 + N4 + N5) / 4;
        smooth_triangle { P1, N1, P2, N, P3, N }
        smooth_triangle { P2, N, P3, N, P4, N6 }
}

I've read bits and pieces that suggested the above was possible but couldn't
find an example that showed it in practice.

I don't know if this is the simplest solution, but it worked for my problem.


Post a reply to this message

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