Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r2089 - in trunk: Interface Model/Primitives


Chronological Thread 
  • From: "Austin Robison" <arobison@rayscale.com>
  • To: manta@sci.utah.edu
  • Subject: [Manta] r2089 - in trunk: Interface Model/Primitives
  • Date: Tue, 19 Feb 2008 11:30:14 -0700 (MST)

Author: arobison
Date: Tue Feb 19 11:30:11 2008
New Revision: 2089

Modified:
   trunk/Interface/Primitive.cc
   trunk/Interface/Primitive.h
   trunk/Interface/RayPacket.cc
   trunk/Interface/RayPacket.h
   trunk/Model/Primitives/KenslerShirleyTriangle.cc
   trunk/Model/Primitives/KenslerShirleyTriangle.h
Log:
Adding geometric normals to Manta.  The default
behavior for primitives is to use the shading normal
computation for their geometric normals.  Primitives
that interpolate their normals, such as KS triangles,
return a geometric normal that is different from their
shading normal.



Modified: trunk/Interface/Primitive.cc
==============================================================================
--- trunk/Interface/Primitive.cc        (original)
+++ trunk/Interface/Primitive.cc        Tue Feb 19 11:30:11 2008
@@ -21,6 +21,18 @@
   throw InternalError("Unimplemented getRandomPoint for Primitive");
 }
 
+void Primitive::computeGeometricNormal(const RenderContext& context,
+                                        RayPacket& rays) const {
+  computeNormal(context, rays);
+
+  for(int i = rays.begin(); i != rays.end(); ++i)
+    rays.setGeometricNormal(i, rays.getNormal(i));
+
+  rays.setFlag( RayPacket::HaveGeometricNormals );
+  if( rays.getFlag( RayPacket::HaveUnitNormals ) )
+    rays.setFlag( RayPacket::HaveUnitGeometricNormals );
+}
+
 void Primitive::computeSurfaceDerivatives(const RenderContext& context,
                                           RayPacket& rays) const {
   rays.computeNormals(context);

Modified: trunk/Interface/Primitive.h
==============================================================================
--- trunk/Interface/Primitive.h (original)
+++ trunk/Interface/Primitive.h Tue Feb 19 11:30:11 2008
@@ -19,6 +19,8 @@
                            RayPacket& rays) const = 0;
     virtual void computeNormal(const RenderContext& context,
                                RayPacket& rays) const = 0;
+    virtual void computeGeometricNormal(const RenderContext& context,
+                                        RayPacket& rays) const;
 
     // Compute dPdu and dPdv (aka tangent vectors) - these are not
     // normalized. Cross(dPdu, dPdv) = k*N where k is some scale

Modified: trunk/Interface/RayPacket.cc
==============================================================================
--- trunk/Interface/RayPacket.cc        (original)
+++ trunk/Interface/RayPacket.cc        Tue Feb 19 11:30:11 2008
@@ -235,6 +235,31 @@
   flags |= HaveFFNormals;
 }
 
+void RayPacket::actualComputeGeometricNormals(const RenderContext& context)
+{
+  for(int i = rayBegin; i < rayEnd;) {
+    const Primitive* prim = data->hitPrim[i];
+    int tend = i+1;
+    while(tend < rayEnd && data->hitPrim[tend] == prim)
+      tend++;
+    RayPacket subPacket(*this, i, tend);
+    prim->computeGeometricNormal(context, subPacket);
+    if((subPacket.flags & HaveUnitGeometricNormals) == 0) {
+      for(int s=i;s<tend;++s) {
+        Real sum = 0;
+        for(int j=0;j<3;++j)
+          sum += data->geometricNormal[j][s] * data->geometricNormal[j][s];
+        Real scale = 1/Sqrt(sum);
+        for(int j=0;j<3;++j)
+          data->geometricNormal[j][s] *= scale;
+      }
+    }
+    i=tend;
+  }
+
+  flags |= HaveGeometricNormals | HaveUnitGeometricNormals;
+}
+
 void RayPacket::actualComputeSurfaceDerivatives(const RenderContext& 
context) {
   // Compute surface derivatives in runs over Primitive*
   for(int i=rayBegin;i<rayEnd;){

Modified: trunk/Interface/RayPacket.h
==============================================================================
--- trunk/Interface/RayPacket.h (original)
+++ trunk/Interface/RayPacket.h Tue Feb 19 11:30:11 2008
@@ -96,6 +96,7 @@
     MANTA_ALIGN(16) Real image[2][MaxSize];
     MANTA_ALIGN(16) Real normal[3][MaxSize];
     MANTA_ALIGN(16) Real ffnormal[3][MaxSize]; // Forward facing normals
+    MANTA_ALIGN(16) Real geometricNormal[3][MaxSize];
     MANTA_ALIGN(16) Real hitPosition[3][MaxSize];
     MANTA_ALIGN(16) Real texCoords[3][MaxSize];
     MANTA_ALIGN(16) Real dPdu[3][MaxSize];
@@ -138,30 +139,33 @@
 
     enum RayPacketFlags {
       // Flags. Please use 8 digits to represent new ones (i.e. 0x00010000)
-      ConstantOrigin         = 0x00000001,
-      ConstantEye            = 0x00000002,
-      HaveImageCoordinates   = 0x00000004,
-      NormalizedDirections   = 0x00000008,
-      HaveHitPositions       = 0x00000010,
-
-      HaveTexture3           = 0x00000040,
-      HaveTexture2           = 0x00000080,
-      HaveUnitNormals        = 0x00000100, // Used by prims that set
-                                       // whether the normals computed
-                                       // have been normalized.
-      HaveNormals            = 0x00000200,
-      HaveFFNormals          = 0x00000400,
-      HaveInverseDirections  = 0x00000800,
-      HaveSigns              = 0x00001000,
-      ConstantSigns          = 0x00002000,
-      HaveCornerRays         = 0x00004000,
+      ConstantOrigin           = 0x00000001,
+      ConstantEye              = 0x00000002,
+      HaveImageCoordinates     = 0x00000004,
+      NormalizedDirections     = 0x00000008,
+      HaveHitPositions         = 0x00000010,
+
+      HaveTexture3             = 0x00000040,
+      HaveTexture2             = 0x00000080,
+      HaveUnitNormals          = 0x00000100, // Used by prims that set
+                                             // whether the normals computed
+                                             // have been normalized.
+      HaveNormals              = 0x00000200,
+      HaveFFNormals            = 0x00000400,
+      HaveInverseDirections    = 0x00000800,
+      HaveSigns                = 0x00001000,
+      ConstantSigns            = 0x00002000,
+      HaveCornerRays           = 0x00004000,
+
+      HaveSurfaceDerivatives   = 0x00008000,
+      ConstantSampleRegion     = 0x00010000,
 
-      HaveSurfaceDerivatives = 0x00008000,
-      ConstantSampleRegion   = 0x00010000,
+      ConstantPixel            = 0x00020000,
 
-      ConstantPixel          = 0x00020000,
+      HaveGeometricNormals     = 0x00040000,
+      HaveUnitGeometricNormals = 0x00080000,
 
-      DebugPacket            = 0x80000000,
+      DebugPacket              = 0x80000000,
     };
 
     enum PacketShape {
@@ -776,6 +780,11 @@
       for(int i=0;i<3;i++)
         data->dPdv[i][which] = v[i];
     }
+    void setGeometricNormal(int which, const Vector& gnormal)
+    {
+      for(int i=0;i<3;i++)
+        data->geometricNormal[i][which] = gnormal[i];
+    }
     Vector getNormal(int which) const
     {
       return Vector(data->normal[0][which], data->normal[1][which], 
data->normal[2][which]);
@@ -784,6 +793,12 @@
     {
       return Vector(data->ffnormal[0][which], data->ffnormal[1][which], 
data->ffnormal[2][which]);
     }
+    Vector getGeometricNormal(int which) const
+    {
+      return Vector(data->geometricNormal[0][which],
+                    data->geometricNormal[1][which], 
+                    data->geometricNormal[2][which]);
+    }
     Vector getSurfaceDerivativeU(int which) const {
       return Vector(data->dPdu[0][which], data->dPdu[1][which], 
data->dPdu[2][which]);
     }
@@ -807,6 +822,14 @@
       actualComputeFFNormals(context);
     }
 
+    void computeGeometricNormals(const RenderContext& context)
+    {
+      if(flags & HaveGeometricNormals)
+        return;
+         
+      actualComputeGeometricNormals(context);
+    }
+
     // Compute the surface derivatives
     void computeSurfaceDerivatives(const RenderContext& context) {
       if(flags & HaveSurfaceDerivatives)
@@ -867,6 +890,7 @@
     void actualComputeHitPositions();
     void actualComputeNormals(const RenderContext& context);
     void actualComputeFFNormals(const RenderContext& context);
+    void actualComputeGeometricNormals(const RenderContext& context);
     void actualComputeSurfaceDerivatives(const RenderContext& context);
 
     void actualComputeTextureCoordinates2(const RenderContext& context);

Modified: trunk/Model/Primitives/KenslerShirleyTriangle.cc
==============================================================================
--- trunk/Model/Primitives/KenslerShirleyTriangle.cc    (original)
+++ trunk/Model/Primitives/KenslerShirleyTriangle.cc    Tue Feb 19 11:30:11 
2008
@@ -411,3 +411,17 @@
       rays.setNormal(ray, normal);
   }
 }
+
+void KenslerShirleyTriangle::computeGeometricNormal(const RenderContext& 
context, RayPacket& rays) const
+{
+  const unsigned int index = myID*3;
+  const Vector p0 = mesh->vertices[mesh->vertex_indices[index+0]];
+  const Vector p1 = mesh->vertices[mesh->vertex_indices[index+1]];
+  const Vector p2 = mesh->vertices[mesh->vertex_indices[index+2]];
+
+  const Vector edge0 = p1 - p0;
+  const Vector edge1 = p2 - p0;
+  const Vector normal = Cross(edge0, edge1);
+  for(int ray=rays.begin(); ray<rays.end(); ray++)
+    rays.setGeometricNormal(ray, normal);
+}

Modified: trunk/Model/Primitives/KenslerShirleyTriangle.h
==============================================================================
--- trunk/Model/Primitives/KenslerShirleyTriangle.h     (original)
+++ trunk/Model/Primitives/KenslerShirleyTriangle.h     Tue Feb 19 11:30:11 
2008
@@ -43,6 +43,7 @@
     void intersect(const RenderContext& context, RayPacket& rays) const;
 
     void computeNormal(const RenderContext& context, RayPacket &rays) const;
+    void computeGeometricNormal(const RenderContext& context, RayPacket& 
rays) const;
   };
 }
 




  • [Manta] r2089 - in trunk: Interface Model/Primitives, Austin Robison, 02/19/2008

Archive powered by MHonArc 2.6.16.

Top of page