Text archives Help
- From: sparker@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [Manta] r1865 - trunk/Interface
- Date: Mon, 26 Nov 2007 07:33:21 -0700 (MST)
Author: sparker
Date: Mon Nov 26 07:33:04 2007
New Revision: 1865
Modified:
trunk/Interface/RayPacket.cc
trunk/Interface/RayPacket.h
Log:
Added a "safeComputeNormals", which can be called on an entire raypacket even
if not all of the rays hit an object
Modified: trunk/Interface/RayPacket.cc
==============================================================================
--- trunk/Interface/RayPacket.cc (original)
+++ trunk/Interface/RayPacket.cc Mon Nov 26 07:33:04 2007
@@ -178,6 +178,48 @@
flags |= HaveNormals | HaveUnitNormals;
}
+/*
+ * Compute normals, but watch for the hit information (currently flagged by
matl)
+ * This can be called on a packet where some of the rays may have hit the
background
+ */
+void RayPacket::safeComputeNormals(const RenderContext& context)
+{
+ if(flags & HaveNormals)
+ return;
+ // Compute normals
+ for(int i=rayBegin;i<rayEnd;){
+ while(!data->hitMatl[i]){
+ i++;
+ if(i >= rayEnd) {
+ flags |= HaveNormals | HaveUnitNormals;
+ return;
+ }
+ }
+
+ const Primitive* prim = data->hitPrim[i];
+ int tend = i+1;
+ while(tend < rayEnd && data->hitPrim[tend] == prim)
+ tend++;
+ RayPacket subPacket(*this, i, tend);
+ prim->computeNormal(context, subPacket);
+ // BTW, == has higher precedence than &, so mind the ()'s.
+ if ((subPacket.flags & HaveUnitNormals) == 0) {
+ // Normalize the normals if they haven't been.
+ for(int s=i;s<tend;++s){
+ Real sum = 0;
+ for(int j=0;j<3;++j)
+ sum += data->normal[j][s] * data->normal[j][s];
+ Real scale = 1/SCIRun::Sqrt(sum);
+ for(int j=0;j<3;++j)
+ data->normal[j][s] *= scale;
+ }
+ }
+ i=tend;
+ }
+
+ flags |= HaveNormals | HaveUnitNormals;
+}
+
void RayPacket::actualComputeFFNormals(const RenderContext& context)
{
// We need to have normals
Modified: trunk/Interface/RayPacket.h
==============================================================================
--- trunk/Interface/RayPacket.h (original)
+++ trunk/Interface/RayPacket.h Mon Nov 26 07:33:04 2007
@@ -851,6 +851,7 @@
}
}
+ void safeComputeNormals(const RenderContext& context);
private:
void actualNormalizeDirections();
void actualComputeInverseDirections();
- [Manta] r1865 - trunk/Interface, sparker, 11/26/2007
Archive powered by MHonArc 2.6.16.