Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r1712 - trunk/Interface


Chronological Thread 
  • From: boulos@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [Manta] r1712 - trunk/Interface
  • Date: Wed, 5 Sep 2007 18:21:50 -0600 (MDT)

Author: boulos
Date: Wed Sep  5 18:21:50 2007
New Revision: 1712

Modified:
   trunk/Interface/Primitive.cc
   trunk/Interface/Primitive.h
   trunk/Interface/RayPacket.cc
   trunk/Interface/RayPacket.h
Log:
Interface/RayPacket.cc
Interface/RayPacket.h

  Adding support for surface derivatives (dPdu and dPdv).

Interface/Primitive.cc
Interface/Primitive.h

  Adding a computeSurfaceDerivatives to Primitive that defaults to
  constructing a valid coordinate frame.


Modified: trunk/Interface/Primitive.cc
==============================================================================
--- trunk/Interface/Primitive.cc        (original)
+++ trunk/Interface/Primitive.cc        Wed Sep  5 18:21:50 2007
@@ -1,5 +1,7 @@
 
 #include <Interface/Primitive.h>
+#include <Interface/Context.h>
+#include <Interface/RayPacket.h>
 #include <Core/Geometry/Vector.h>
 #include <Core/Exceptions/InternalError.h>
 
@@ -18,4 +20,15 @@
                                 RayPacket& rays) const {
   throw SCIRun::InternalError("Unimplemented getRandomPoint for Primitive",
                               __FILE__, __LINE__);
+}
+
+void Primitive::computeSurfaceDerivatives(const RenderContext& context,
+                                          RayPacket& rays) const {
+  rays.computeNormals(context);
+  for (int i = rays.begin(); i < rays.end(); i++) {
+    Vector U = rays.getNormal(i).findPerpendicular();
+    Vector V = Cross(rays.getNormal(i), U);
+    rays.setSurfaceDerivatives(i, U, V);
+  }
+  rays.setFlag(RayPacket::HaveSurfaceDerivatives);
 }

Modified: trunk/Interface/Primitive.h
==============================================================================
--- trunk/Interface/Primitive.h (original)
+++ trunk/Interface/Primitive.h Wed Sep  5 18:21:50 2007
@@ -19,6 +19,14 @@
                            RayPacket& rays) const = 0;
     virtual void computeNormal(const RenderContext& context,
                                RayPacket& rays) const = 0;
+
+    // Compute dPdu and dPdv (aka tangent vectors) - these are not
+    // normalized. Cross(dPdu, dPdv) = k*N where k is some scale
+    // factor. By default, we'll just construct a coordinate frame
+    // around the Normal so that the invariant is satisfied.
+    virtual void computeSurfaceDerivatives(const RenderContext& context,
+                                           RayPacket& rays) const;
+
     virtual void setTexCoordMapper(const TexCoordMapper* new_tex) = 0;
 
     virtual void getRandomPoints(Packet<Vector>& points,

Modified: trunk/Interface/RayPacket.cc
==============================================================================
--- trunk/Interface/RayPacket.cc        (original)
+++ trunk/Interface/RayPacket.cc        Wed Sep  5 18:21:50 2007
@@ -196,6 +196,21 @@
   flags |= HaveFFNormals;
 }
 
+void RayPacket::actualComputeSurfaceDerivatives(const RenderContext& 
context) {
+  // Compute surface derivatives in runs over Primitive*
+  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->computeSurfaceDerivatives(context, subPacket);
+    i=tend;
+  }
+
+  flags |= HaveSurfaceDerivatives;
+}
+
 void RayPacket::actualComputeTextureCoordinates2(const RenderContext& 
context)
 {
   // Compute texture coordinates

Modified: trunk/Interface/RayPacket.h
==============================================================================
--- trunk/Interface/RayPacket.h (original)
+++ trunk/Interface/RayPacket.h Wed Sep  5 18:21:50 2007
@@ -103,6 +103,8 @@
     MANTA_ALIGN(16) Real ffnormal[3][MaxSize]; // Forward facing normals
     MANTA_ALIGN(16) Real hitPosition[3][MaxSize];
     MANTA_ALIGN(16) Real texCoords[3][MaxSize];
+    MANTA_ALIGN(16) Real dPdu[3][MaxSize];
+    MANTA_ALIGN(16) Real dPdv[3][MaxSize];
 
 
     // Color-based arrays
@@ -132,28 +134,28 @@
     };
 
     enum RayPacketFlags {
-      // Flags.
-      ConstantOrigin        = 0x0001,
-      ConstantEye           = 0x0002,
-      HaveImageCoordinates  = 0x0004,
-      NormalizedDirections  = 0x0008,
-      HaveHitPositions      = 0x0010,
-      // HaveHitRecords        = 0x0020,  Don't use this flag anymore
-      HaveTexture3          = 0x0040,
-      HaveTexture2          = 0x0080,
-      HaveUnitNormals       = 0x0100, // Used by prims that set
-                                      // whether the normals computed
-                                      // have been normalized.
-      HaveNormals           = 0x0200,
-      HaveFFNormals         = 0x0400,
-      HaveInverseDirections = 0x0800,
-      HaveSigns             = 0x1000,
-      ConstantSigns         = 0x2000,
-      HaveCornerRays        = 0x4000,
+      // 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,
 
-      DebugPacket           = 0x8000
+      HaveSurfaceDerivatives = 0x00008000,
 
-      // Use 8 digits to represent new ones (i.e. 0x00010000)
+      DebugPacket            = 0x80000000,
     };
 
     enum PacketShape {
@@ -732,6 +734,13 @@
       for(int i=0;i<3;i++)
         data->ffnormal[i][which] = normal[i];
     }
+    void setSurfaceDerivatives(int which, const Vector& u, const Vector& v)
+    {
+      for(int i=0;i<3;i++)
+        data->dPdu[i][which] = u[i];
+      for(int i=0;i<3;i++)
+        data->dPdv[i][which] = v[i];
+    }
     Vector getNormal(int which) const
     {
       return Vector(data->normal[0][which], data->normal[1][which], 
data->normal[2][which]);
@@ -740,6 +749,10 @@
     {
       return Vector(data->ffnormal[0][which], data->ffnormal[1][which], 
data->ffnormal[2][which]);
     }
+    void getSurfaceDerivatives(int which, Vector& u, Vector& v) {
+      u = Vector(data->dPdu[0][which], data->dPdu[1][which], 
data->dPdu[2][which]);
+      v = Vector(data->dPdv[0][which], data->dPdv[1][which], 
data->dPdv[2][which]);
+    }
     void computeNormals(const RenderContext& context)
     {
       if(flags & HaveNormals)
@@ -757,6 +770,14 @@
       actualComputeFFNormals(context);
     }
 
+    // Compute the surface derivatives
+    void computeSurfaceDerivatives(const RenderContext& context) {
+      if(flags & HaveSurfaceDerivatives)
+        return;
+
+      actualComputeSurfaceDerivatives(context);
+    }
+
     // Hit positions
     Vector getHitPosition(int which) const
     {
@@ -808,6 +829,8 @@
     void actualComputeHitPositions();
     void actualComputeNormals(const RenderContext& context);
     void actualComputeFFNormals(const RenderContext& context);
+    void actualComputeSurfaceDerivatives(const RenderContext& context);
+
     void actualComputeTextureCoordinates2(const RenderContext& context);
     void actualComputeTextureCoordinates3(const RenderContext& context);
 





Archive powered by MHonArc 2.6.16.

Top of page