POV-Ray : Newsgroups : povray.programming : Smooth mesh 'bug' inverted normals (+Patch) : Smooth mesh 'bug' inverted normals (+Patch) Server Time: 26 Sep 2017 21:49:23 GMT
  Smooth mesh 'bug' inverted normals (+Patch)  
From: Jurjen
Date: 10 Aug 2002 19:20:06
Here is some code that will change the behaviour of smooth-triangles:
- It will trim the triangles so the spots with inverted normals get
transparent.
- This also trims the triangles towards the light source so there will be
less shadow on triangles behind a smoothed triangle.

There is a mayor side effect:
The inside of the triangles of a mesh get transparent also...
This is no problem for 3d objects (like body-parts or a chair) but the mesh
will be more restricted in use. It could be handy to make a flag on the
mesh so that this 'feature' can be turned off for people that don't approve
on this restriction.

The calculations on a smoothed mesh will be somewhat slower but not much.
But at least by me there are not many 'side-effects' to a smoothed mesh
anymore (pun intended).

I used the Linux-standard patch tool to deliver this patch...

diff -U 3 -N -r povray-3.50a/src/mesh.cpp povray-3.50b/src/mesh.cpp
--- povray-3.50a/src/mesh.cpp   Thu Aug  1 04:30:14 2002
+++ povray-3.50b/src/mesh.cpp   Sat Aug 10 17:38:05 2002
@@ -1344,6 +1344,7 @@
 * CHANGES
 *
 *   Feb 1995 : Creation.
+*   Aug 2002 : Smooth outlines for smooth triangles
 *
 ******************************************************************************/

@@ -1367,8 +1368,41 @@

     push_entry_pointer_uv(world_dist, IPoint, uv, Object, Triangle,
Depth_Stack);
     */
-
-               push_entry_pointer(world_dist, IPoint, Object, Triangle,
Depth_Stack);
+/*
+
+   When the normal of a smooth triangle is pointing away from the current
ray
+   that point on the triangle gets invisible.
+
+*/
+
+    if (Triangle->Smooth)
+    {
+      VECTOR Normal;
+      VECTOR IMesh;
+      DBL NDot;
+
+      Assign_Vector(IMesh, IPoint);
+      if (Mesh->Trans != NULL)
+      {
+        MInvTransPoint(IMesh, IMesh, Mesh->Trans);
+      }
+
+      smooth_mesh_normal(Mesh, Normal, Triangle, IMesh);
+
+      if (Mesh->Trans != NULL)
+      {
+        MTransNormal(Normal, Normal, Mesh->Trans);
+      }
+
+      VDot(NDot, Normal, OrigRay->Direction);
+      if (NDot>0) {
+        return(false);
+      }
+    }
+/*
+*/
+
+    push_entry_pointer(world_dist, IPoint, Object, Triangle, Depth_Stack);
     return(true);
   }


Post a reply to this message

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