Text archives Help
- From: cgribble@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1071 - in trunk: Engine/Control Interface scenes
- Date: Thu, 18 May 2006 10:35:31 -0600 (MDT)
Author: cgribble
Date: Thu May 18 10:35:31 2006
New Revision: 1071
Modified:
trunk/Engine/Control/DynPLTWorker.cc
trunk/Engine/Control/DynPLTWorker.h
trunk/Interface/RayPacket.h
trunk/scenes/dynplt.cc
Log:
scenes/dynplt.cc
Added some bookmarks, including a reasonable default view for debugging
Interface/RayPacket.h
Engine/Control/DynPLTWorker.cc
Engine/Control/DynPLTWorker.h
Continue to flesh out functionality; no longer crashes (heck, it might even
work soon)
Modified: trunk/Engine/Control/DynPLTWorker.cc
==============================================================================
--- trunk/Engine/Control/DynPLTWorker.cc (original)
+++ trunk/Engine/Control/DynPLTWorker.cc Thu May 18 10:35:31 2006
@@ -144,38 +144,41 @@
}
int depth=0;
- int flags=RayPacket::NormalizedDirections;
+ int dlFlags=RayPacket::HaveHitPositions | RayPacket::HaveNormals |
+ RayPacket::HaveUnitNormals;
RayPacketData raydata;
RayPacket rays(raydata, RayPacket::UnknownShape, 0, size, depth,
- flags);
+ dlFlags);
- // Fill in the ray origins, surface normals at sample points
+ // Fill in the hit positions and surface normals at sample points
for (int i=rays.begin(); i<rays.end(); ++i) {
// Project surface sample point onto particle's surface
- Vector2D surface=sample_groups[sidx][i];
+ Vector2D sample=sample_groups[sidx][i];
- // Range of 2*M_PI*(u + surface.x)/res --> [0, 2*Pi]
- // Range of M_PI*(v + surface.y)/res --> [0, Pi]
- Real phi=2*M_PI*((u + surface.x()))*inv_res;
- Real theta=M_PI*((v + surface.y()))*inv_res;
+ // Range of 2*M_PI*(u + sample.x)/res --> [0, 2*Pi]
+ // Range of M_PI*(v + sample.y)/res --> [0, Pi]
+ Real phi=2*M_PI*((u + sample.x()))*inv_res;
+ Real theta=M_PI*((v + sample.y()))*inv_res;
Real x=cos(phi)*sin(theta);
Real z=sin(phi)*sin(theta);
Real y=cos(theta);
- rays.setOrigin(i, center + radius*Vector(x, y, z));
- normals.set(i, Vector(x, y, z).normal());
+ Vector surface=center + radius*Vector(x, y, z);
+ Vector normal=Vector(x, y, z).normal();
+
+ rays.setHitPosition(i, surface);
+ rays.setNormal(i, normal);
}
// Iteratively trace the ray packet
GrayValue result;
for (unsigned int d=0; d<max_depth; ++d) {
- // Compute direct lighting at sample points
+ // Compute direct lighting at current hit positions
ShadowAlgorithm::StateBuffer stateBuffer;
bool firstTime=true;
bool done;
- int count=0;
do {
RayPacketData shadowData;
RayPacket shadowRays(shadowData, RayPacket::UnknownShape, 0, 0,
@@ -188,16 +191,10 @@
// anything in the state buffer. Most SAs will only need to
// store an int or two in the statebuffer.
const LightSet* activeLights=scene->getLights();
-#if 0
- // XXX: causes segfaults, undoubtedly related to the (nearly
- // empty) RenderContext
done=rctx.shadowAlgorithm->computeShadows(rctx, activeLights,
rays, shadowRays,
firstTime,
stateBuffer);
-#else
- done=true;
-#endif
// Normalize directions for proper dot product computation
shadowRays.normalizeDirections();
@@ -205,7 +202,7 @@
for (int i=shadowRays.begin(); i<shadowRays.end(); ++i) {
if (!shadowRays.wasHit(i)) {
// Not in shadow, so compute the diffuse contribution
- Vector normal=normals.get(i);
+ Vector normal=rays.getNormal(i);
Vector shadowdir=shadowRays.getDirection(i);
ColorComponent cos_theta=Dot(shadowdir, normal);
Color light=shadowRays.getColor(i);
@@ -216,10 +213,10 @@
firstTime=false;
} while(!done);
- // Fill in the ray directions by generating random directions on
the
- // hemisphere
+ // Fill in the ray origins (computed above) and directions (by
+ // generating random directions on the hemisphere)
for (int i=rays.begin(); i<rays.end(); ++i) {
- Vector normal=normals.get(i);
+ Vector normal=rays.getNormal(i);
Vector v0(Cross(normal, Vector(1,0,0)));
if (v0.length2()==0)
v0=Cross(normal, Vector(0,1,0));
@@ -237,52 +234,65 @@
Vector out=Vector(hx, hy, hz).normal();
Vector dir=v0*out.x() + v1*out.y() + normal*out.z();
dir.normalize();
-
+
+ // Set ray origin, direction
+ rays.setOrigin(i, rays.getHitPosition(i));
rays.setDirection(i, dir);
}
+ // Reset flags
+ rays.setAllFlags(0);
+ rays.setFlag(RayPacket::NormalizedDirections);
+
// Intersect rays with the geometry
rays.resetHits();
scene->getObject()->intersect(rctx, rays);
-
- // Compute hit positions and normals
- rays.computeHitPositions();
- // XXX: causes segfaults, undoubtedly related to the (nearly
- // empty) RenderContext
- // rays.computeNormals(rctx);
- // Fill in the ray origins, surface normals for next iteration
+ // Prep ray packet for next iteration
unsigned int validRays=0;
for (unsigned int i=rays.begin(); i<rays.end();) {
if (rays.wasHit(i)) {
- // Check for a valid hit
- Real dotprod=Dot(rays.getNormal(i), -rays.getDirection(i));
- if (dotprod>0) {
- normals.set(validRays, rays.getNormal(i));
- rays.setOrigin(validRays, rays.getHitPosition(i));
- ++validRays;
- } else {
- // An invalid hit, resulting from:
- //
- // 1. Intersecting spheres---Ray origin is inside of one
- // sphere and it hits the inside surface of the other
- //
- // 2. Ray origin is coincident with the surface of a
- // neighboring sphere---May result in some crazy
math,
- // and thus a negative dot product
- //
- // Either way, ignore the hit and mark the texel for
dilation
- // inside(u, v) += 1;
+ // Find a run of rays that hit an object
+ unsigned int end=i + 1;
+ while (end < rays.end() && rays.wasHit(end))
+ ++end;
+
+ // Compute hit positions and normals
+ RayPacket sub(rays, i, end);
+ sub.computeHitPositions();
+ sub.computeNormals(rctx);
+
+ // Store hit positions, normals for only valid hits
+ for (unsigned int j=sub.begin(); j<sub.end(); ++j) {
+ Real dotprod=Dot(sub.getNormal(j), -sub.getDirection(j));
+ if (dotprod>0) {
+ rays.setHitPosition(validRays, sub.getHitPosition(j));
+ rays.setNormal(validRays, sub.getNormal(j));
+ ++validRays;
+ } else {
+ // An invalid hit, resulting from:
+ //
+ // 1. Intersecting spheres---Ray origin is inside of
one
+ // sphere and it hits the inside surface of the
other
+ //
+ // 2. Ray origin is coincident with the surface of a
+ // neighboring sphere---May result in some crazy
+ // math, and thus a negative dot product
+ //
+ // Either way, ignore the hit and mark the texel for
+ // dilation
+ // inside(u, v) += 1;
+ }
}
- ++i;
+ i=end;
} else {
// Find a run of rays that didn't hit anything and shade them
unsigned int end=i + 1;
while (end < rays.end() && !rays.wasHit(end))
++end;
- RayPacket subPacket(rays, i, end);
- scene->getBackground()->shade(rctx, subPacket);
+ RayPacket sub(rays, i, end);
+ scene->getBackground()->shade(rctx, sub);
// Accumulate background color
for (unsigned int j=i; j<end; ++j)
@@ -293,12 +303,15 @@
}
}
- // Terminate ray tracing, if necessary
+ // Terminate at current depth, if necessary
if (validRays==0)
break;
- // Resize the ray packet, loop to next depth
+ // Update the ray packet configuration, loop to next depth
+ rays.setDepth(rays.getDepth() + 1);
rays.resize(validRays);
+ rays.setAllFlags(0);
+ rays.setFlag(dlFlags);
}
// Store the result
Modified: trunk/Engine/Control/DynPLTWorker.h
==============================================================================
--- trunk/Engine/Control/DynPLTWorker.h (original)
+++ trunk/Engine/Control/DynPLTWorker.h Thu May 18 10:35:31 2006
@@ -4,7 +4,6 @@
#include <Core/Math/MT_RNG.h>
#include <Core/Math/vector2d.h>
-#include <Interface/Packet.h>
#include <SCIRun/Core/Containers/Array1.h>
#include <SCIRun/Core/Containers/Array2.h>
#include <SCIRun/Core/Thread/Mailbox.h>
@@ -58,7 +57,6 @@
MT_RNG rng;
SCIRun::Array1<SCIRun::Array1<Vector2D> > sample_groups;
int* hidx;
- Packet<Vector> normals;
};
}
Modified: trunk/Interface/RayPacket.h
==============================================================================
--- trunk/Interface/RayPacket.h (original)
+++ trunk/Interface/RayPacket.h Thu May 18 10:35:31 2006
@@ -155,6 +155,9 @@
return depth;
}
+ void setDepth(int new_depth) {
+ depth=new_depth;
+ }
// Raypacket iteration
int begin() const {
Modified: trunk/scenes/dynplt.cc
==============================================================================
--- trunk/scenes/dynplt.cc (original)
+++ trunk/scenes/dynplt.cc Thu May 18 10:35:31 2006
@@ -122,5 +122,12 @@
lights->setAmbientLight(new ConstantAmbient(Color(RGB(0.4, 0.4, 0.4))));
scene->setLights(lights);
+ scene->addBookmark("default view", Vector(0.83, 0.85, 4.71),
+ Vector(0.02, 0.01, 0.29), Vector(-0.54, -0.58, 0.59),
+ 0.59);
+ scene->addBookmark("another view", Vector(-0.83, 0.85, 4.71),
+ Vector(0.02, 0.01, 0.29), Vector(-0.59, -0.59, 0.59),
+ 0.59);
+
return scene;
}
- [MANTA] r1071 - in trunk: Engine/Control Interface scenes, cgribble, 05/18/2006
Archive powered by MHonArc 2.6.16.