Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r2063 - in trunk/Model: Groups Primitives


Chronological Thread 
  • From: "Austin Robison" <arobison@rayscale.com>
  • To: manta@sci.utah.edu
  • Subject: [Manta] r2063 - in trunk/Model: Groups Primitives
  • Date: Wed, 13 Feb 2008 18:01:40 -0700 (MST)

Author: arobison
Date: Wed Feb 13 18:01:40 2008
New Revision: 2063

Modified:
   trunk/Model/Groups/Mesh.cc
   trunk/Model/Groups/Mesh.h
   trunk/Model/Primitives/KenslerShirleyTriangle.cc
   trunk/Model/Primitives/KenslerShirleyTriangle.h
Log:
Adding per vertex tangent and binormal vectors to Mesh.

KSTriangles now use these new vectors to compute its
surface derivatives.


Modified: trunk/Model/Groups/Mesh.cc
==============================================================================
--- trunk/Model/Groups/Mesh.cc  (original)
+++ trunk/Model/Groups/Mesh.cc  Wed Feb 13 18:01:40 2008
@@ -7,6 +7,8 @@
 using namespace Manta;
 
 const unsigned int Mesh::kNoTextureIndex = static_cast<unsigned int>(-1);
+const unsigned int Mesh::kNoBinormalIndex = static_cast<unsigned int>(-1);
+const unsigned int Mesh::kNoTangentIndex = static_cast<unsigned int>(-1);
 
 Mesh::Mesh()
 {
@@ -33,10 +35,14 @@
 
   copy->vertices = vertices;
   copy->vertexNormals = vertexNormals;
+  copy->vertexBinormals = vertexBinormals;
+  copy->vertexTangents = vertexTangents;
   copy->texCoords = texCoords;
   copy->materials = materials;
   copy->vertex_indices = vertex_indices;
   copy->normal_indices = normal_indices;
+  copy->binormal_indices = binormal_indices;
+  copy->tangent_indices = tangent_indices;
   copy->texture_indices = texture_indices;
   copy->face_material = face_material;
 
@@ -95,6 +101,28 @@
     vertexNormals[i] = Vector(0,0,0);
     for(unsigned int frame=0; frame < keyframes.size(); ++frame) {
       vertexNormals[i] += meshes[frame]->vertexNormals[i] * 
keyframes[frame].t;
+    }
+  }
+
+  //vertexBinormals
+  size = vertexBinormals.size();
+  start = proc*size/numProcs;
+  end = (proc+1)*size/numProcs;
+  for (unsigned int i=start; i < end; ++i) {
+    vertexBinormals[i] = Vector(0,0,0);
+    for(unsigned int frame=0; frame < keyframes.size(); ++frame) {
+      vertexBinormals[i] += meshes[frame]->vertexBinormals[i] * 
keyframes[frame].t;
+    }
+  }
+
+  //vertexTangents
+  size = vertexTangents.size();
+  start = proc*size/numProcs;
+  end = (proc+1)*size/numProcs;
+  for (unsigned int i=start; i < end; ++i) {
+    vertexTangents[i] = Vector(0,0,0);
+    for(unsigned int frame=0; frame < keyframes.size(); ++frame) {
+      vertexTangents[i] += meshes[frame]->vertexTangents[i] * 
keyframes[frame].t;
     }
   }
 

Modified: trunk/Model/Groups/Mesh.h
==============================================================================
--- trunk/Model/Groups/Mesh.h   (original)
+++ trunk/Model/Groups/Mesh.h   Wed Feb 13 18:01:40 2008
@@ -20,11 +20,16 @@
   public:
 
     // If a triangle has a vertex without texture coordinates, this
-    // will be its index into the texture_indices array.
+    // will be its index into the texture_indices array. Similarly
+    // for binormals and tangents.
     static const unsigned int kNoTextureIndex;
+    static const unsigned int kNoBinormalIndex;
+    static const unsigned int kNoTangentIndex;
 
     vector<Vector> vertices;
     vector<Vector> vertexNormals;
+    vector<Vector> vertexBinormals;
+    vector<Vector> vertexTangents;
     vector<Vector> texCoords;
 //     vector<Vector> faceNormals; //not handled for now
     vector<Material*> materials;
@@ -38,6 +43,8 @@
     // Per vertex data.  size() == 3*numTriangles;
     vector<unsigned int> vertex_indices;
     vector<unsigned int> normal_indices;
+    vector<unsigned int> binormal_indices;
+    vector<unsigned int> tangent_indices;
     vector<unsigned int> texture_indices;
 
     // Per face data.  size() == numTriangles;

Modified: trunk/Model/Primitives/KenslerShirleyTriangle.cc
==============================================================================
--- trunk/Model/Primitives/KenslerShirleyTriangle.cc    (original)
+++ trunk/Model/Primitives/KenslerShirleyTriangle.cc    Wed Feb 13 18:01:40 
2008
@@ -46,6 +46,49 @@
   context.done();
 }
 
+void KenslerShirleyTriangle::computeSurfaceDerivatives(const RenderContext& 
context, RayPacket& rays) const
+{
+  const int which = myID*3;
+  const unsigned int binormal0_idx = mesh->binormal_indices.size() ?
+    mesh->binormal_indices[which] : Mesh::kNoBinormalIndex;
+
+  // No binormals means use the default implementation
+  if (binormal0_idx == Mesh::kNoBinormalIndex) {
+    MeshTriangle::computeSurfaceDerivatives(context, rays);
+    return;
+  }
+
+  const unsigned int binormal1_idx = mesh->binormal_indices[which+1];
+  const unsigned int binormal2_idx = mesh->binormal_indices[which+2];
+  
+  const unsigned int tangent0_idx = mesh->tangent_indices[which+0];
+  const unsigned int tangent1_idx = mesh->tangent_indices[which+1];
+  const unsigned int tangent2_idx = mesh->tangent_indices[which+2];
+
+  const Vector binormal0 = mesh->vertexBinormals[binormal0_idx];
+  const Vector binormal1 = mesh->vertexBinormals[binormal1_idx];
+  const Vector binormal2 = mesh->vertexBinormals[binormal2_idx];
+
+  const Vector tangent0 = mesh->vertexTangents[tangent0_idx];
+  const Vector tangent1 = mesh->vertexTangents[tangent1_idx];
+  const Vector tangent2 = mesh->vertexTangents[tangent2_idx];
+
+  for(int i = rays.begin(); i != rays.end(); ++i) {
+
+    float a = rays.getScratchpad<float>(SCRATCH_U)[i];
+    float b = rays.getScratchpad<float>(SCRATCH_V)[i];
+    float c = (1 - a - b);
+
+    Vector dPdu = a * tangent1 + b * tangent2 + c * tangent0;
+    Vector dPdv = a * binormal1 + b * binormal2 + c * binormal0;
+
+    rays.setSurfaceDerivativeU(i, dPdu);
+    rays.setSurfaceDerivativeV(i, dPdv);
+  }
+
+  rays.setFlag(RayPacket::HaveSurfaceDerivatives);
+}
+
 void KenslerShirleyTriangle::computeTexCoords2(const RenderContext&, 
RayPacket& rays) const
 {
   const int which = myID*3;

Modified: trunk/Model/Primitives/KenslerShirleyTriangle.h
==============================================================================
--- trunk/Model/Primitives/KenslerShirleyTriangle.h     (original)
+++ trunk/Model/Primitives/KenslerShirleyTriangle.h     Wed Feb 13 18:01:40 
2008
@@ -38,6 +38,8 @@
       computeTexCoords2(context, rays);
     }
 
+    virtual void computeSurfaceDerivatives(const RenderContext&, RayPacket& 
rays) const;
+
     void intersect(const RenderContext& context, RayPacket& rays) const;
 
     void computeNormal(const RenderContext& context, RayPacket &rays) const;




  • [Manta] r2063 - in trunk/Model: Groups Primitives, Austin Robison, 02/13/2008

Archive powered by MHonArc 2.6.16.

Top of page