Text archives Help
- From: hansong@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r438 - branches/itanium2/Model/Groups
- Date: Fri, 22 Jul 2005 16:30:10 -0600 (MDT)
Author: hansong
Date: Fri Jul 22 16:30:09 2005
New Revision: 438
Modified:
branches/itanium2/Model/Groups/kdtree.cc
branches/itanium2/Model/Groups/kdtree.h
Log:
add intersectTrianglesTransparent(). Instead of keeping the nearest
intersection, collect all of them and sort, then composite.
Modified: branches/itanium2/Model/Groups/kdtree.cc
==============================================================================
--- branches/itanium2/Model/Groups/kdtree.cc (original)
+++ branches/itanium2/Model/Groups/kdtree.cc Fri Jul 22 16:30:09 2005
@@ -36,6 +36,7 @@
#include "kdtree.h"
#include <Model/Intersections/AxisAlignedBox.h>
+#include <Interface/Context.h>
#include <SCIRun/Core/Thread/Time.h>
#include <SCIRun/Core/Thread/Thread.h>
@@ -609,7 +610,7 @@
// INTERSECT TRIANGLES INTERSECT TRIANGLES INTERSECT TRIANGLES INTERSECT
TRI
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
-int KDTree::intersectTriangles(const Ray* ray, unsigned int listBegin, int
listSize, float maxDist, void *userData) const
+int KDTree::intersectTriangles(const Ray* ray, unsigned int listBegin, int
listSize, float maxDist, void *userData, const RenderContext &context) const
{
int i;
RayTriIntersectUserData *ud = (RayTriIntersectUserData*)userData;
@@ -653,6 +654,80 @@
}
}
+
+VArray<VArray<KDTree::Isect> *> KDTree::isectBuffers(1024, 0);
+
+int KDTree::intersectTrianglesTransparent(const Ray* ray, unsigned int
listBegin, int listSize, float maxDist, void *userData, const RenderContext
&context) const
+{
+ int i;
+ RayTriIntersectUserData *ud = (RayTriIntersectUserData*)userData;
+ float nearest_u, nearest_v;
+ int nearest_tri = -1;
+
+ Vectorf direction = ray->direction();
+ Pointf origin = ray->origin();
+
+ int threadId = context.proc;
+ VArray<KDTree::Isect> *isectbuf = isectBuffers.get(threadId);
+ if (! isectbuf) {
+ isectbuf = new VArray<KDTree::Isect>(8);
+ isectBuffers.set(threadId, isectbuf);
+ }
+ isectbuf->setLen(0);
+
+ // Intersect the ray with all the triangles.
+ int listEnd = listBegin+listSize;
+
+ #pragma swp
+ for (i = listBegin; i < listEnd; i++) {
+ int triIdx = triIndices->get(i);
+ Triangle &tri = tris->get(triIdx);
+ float t, u, v;
+
+ // if (intersectTriangle3Edge( direction, origin, tri.edge1,
tri.edge2, tri[0], t, u, v )) {
+ if(intersect_triangle3_edge( &origin, &direction, &tri[0],
&t, &u, &v, &tri.edge1, &tri.edge2 )) {
+
+ // Check to see if the t value is closer.
+ /*
+ if (t < maxDist) {
+ maxDist = t;
+ nearest_u = u;
+ nearest_v = v;
+ nearest_tri = triIdx;
+ }
+ */
+ Isect &isect = isectbuf->append();
+ isect.t = t;
+ isect.u = u;
+ isect.v = v;
+ isect.triIdx = triIdx;
+ }
+ }
+
+ if (isectbuf->getLen()) {
+ // sort the intersections
+ Isect *array = isectbuf->getArray();
+ std::sort(array, array+isectbuf->getLen());
+ // combine color and opacity
+ for (int i=0; i<isectbuf->getLen(); i++) {
+ }
+
+ return 1;
+ }
+
+ /*
+ if (nearest_tri >= 0) {
+ ud->rayHit.t = maxDist;
+ ud->rayHit.u = nearest_u;
+ ud->rayHit.v = nearest_v;
+ ud->rayHitTriIndex = nearest_tri;
+ return 1;
+
+ }*/ else {
+ return 0;
+ }
+}
+
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// This is the Manta interface method.
@@ -686,7 +761,7 @@
// Send the ray to the _intersect function.
isectData.rayHitTriIndex = -1;
- _intersect( &e.ray, e, isectData, (float)minDist,
(float)maxDist);
+ _intersect( &e.ray, e, isectData, context,
(float)minDist, (float)maxDist);
}
}
@@ -717,7 +792,7 @@
int prev; // 4 bytes
};
-void KDTree::_intersect(const Ray* ray, RayPacket::Element &e,
RayTriIntersectUserData &isectData,
+void KDTree::_intersect(const Ray* ray, RayPacket::Element &e,
RayTriIntersectUserData &isectData, const RenderContext &context,
float minDist, float maxDist) const
{
@@ -800,7 +875,7 @@
if (nearNode) {
// Intersect the ray with a list of triangles.
- if (intersectTriangles(ray, nearNode->listBegin(),
nearNode->listSize(), travStack[exitPos].t, &isectData) &&
+ if (intersectTriangles(ray, nearNode->listBegin(),
nearNode->listSize(), travStack[exitPos].t, &isectData, context) &&
(isectData.rayHitTriIndex >= 0)) {
e.normal =
normals[isectData.rayHitTriIndex*3];
Modified: branches/itanium2/Model/Groups/kdtree.h
==============================================================================
--- branches/itanium2/Model/Groups/kdtree.h (original)
+++ branches/itanium2/Model/Groups/kdtree.h Fri Jul 22 16:30:09 2005
@@ -252,10 +252,20 @@
LambertianAlt *lambMat;
// This method intersects a list of triangles with
the ray.
- int intersectTriangles(const Ray* ray, unsigned int
listBegin, int listSize, float maxDist, void *userData) const;
+ int intersectTriangles(const Ray* ray, unsigned int
listBegin, int listSize, float maxDist, void *userData, const RenderContext
&context) const;
+ int intersectTrianglesTransparent(const Ray* ray,
unsigned int listBegin, int listSize, float maxDist, void *userData, const
RenderContext &context) const;
// This method is called by the above method with a
hansong ray.
- void _intersect(const Ray* ray, RayPacket::Element
&e, RayTriIntersectUserData &isectData, float _minDist=-1, float _maxDist=-1)
const;
+ void _intersect(const Ray* ray, RayPacket::Element
&e, RayTriIntersectUserData &isectData, const RenderContext &context, float
_minDist=-1, float _maxDist=-1) const;
+ public:
+ struct Isect {
+ float t, u, v;
+ int triIdx;
+ bool operator<(const Isect &b) const {
+ return t < b.t;
+ }
+ };
+ static VArray<VArray<Isect> *> isectBuffers;
public:
// This structure is used to record info about the
hit.
@@ -279,6 +289,7 @@
};
}
+
}
- [MANTA] r438 - branches/itanium2/Model/Groups, hansong, 07/22/2005
Archive powered by MHonArc 2.6.16.