Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r362 - in branches/itanium2: Interface Model/Groups Model/Materials Model/Primitives scenes
- Date: Thu, 2 Jun 2005 18:22:17 -0600 (MDT)
Author: abe
Date: Thu Jun 2 18:22:10 2005
New Revision: 362
Modified:
branches/itanium2/Interface/Parameters.h
branches/itanium2/Model/Groups/kdtree.cc
branches/itanium2/Model/Groups/kdtree.h
branches/itanium2/Model/Materials/LambertianAlt.cc
branches/itanium2/Model/Primitives/Sphere.cc
branches/itanium2/scenes/boeing777.cc
Log:
Changes to kdtree code for shadows, also note sphere code wasn't self
shadowing
Modified: branches/itanium2/Interface/Parameters.h
==============================================================================
--- branches/itanium2/Interface/Parameters.h (original)
+++ branches/itanium2/Interface/Parameters.h Thu Jun 2 18:22:10 2005
@@ -3,6 +3,6 @@
#define Manta_Interface_Parameters_h
#define MAXCACHELINESIZE 128
-#define T_EPSILON 1.e-8
+#define T_EPSILON 1.e-4
#endif
Modified: branches/itanium2/Model/Groups/kdtree.cc
==============================================================================
--- branches/itanium2/Model/Groups/kdtree.cc (original)
+++ branches/itanium2/Model/Groups/kdtree.cc Thu Jun 2 18:22:10 2005
@@ -18,15 +18,15 @@
// From Tomas Akenine-Mˆller's code, included below in this file.
int intersect_triangle3(const float orig[3],
-
const float dir[3],
-
const float vert0[3], const float
vert1[3], const float vert2[3],
-
float *t, float *u, float *v );
+
const float dir[3],
+
const float vert0[3], const float vert1[3], const float
vert2[3],
+
float *t, float *u, float *v );
int intersect_triangle3_edge( const float orig[3],
-
const float dir[3],
-
const float vert0[3], const float
vert1[3], const float vert2[3],
-
float *t, float *u, float *v,
-
const float *edge1, const float *edge2);
+
const float dir[3],
+
const float
vert0[3], const float vert1[3], const float vert2[3],
+
float *t, float *u,
float *v,
+
const float *edge1,
const float *edge2);
inline int intersectTriangle3Edge(const Ray &ray, const Triangle &tri,
float &t, float &u,
float &v );
@@ -38,18 +38,18 @@
BBox &bounds )
{
FILE *f;
-
+
// perVertNormals = perVertNormals;
-
+
// Open the input file.
if ((f=fopen(filename, "r")) == NULL) {
fprintf(stderr, "Cannot open file: %s\n", filename);
return 0;
}
-
+
// Allocate store for the triangles.
*tris = new VArray<Triangle>;
-
+
int line = 0;
char line_buffer[128];
@@ -74,8 +74,8 @@
&tri.payload
);
if (num_parsed != 10) {
cerr << "Only parsed " << num_parsed << " components
for line "
- << line << " in file "
- << filename << endl;
+ << line << " in file "
+ << filename << endl;
break;
}
@@ -96,7 +96,7 @@
continue;
}
#endif
-
+
// Update the bounding box of the whole scene
bounds.extendByPoint( tri[0] );
bounds.extendByPoint( tri[1] );
@@ -125,7 +125,7 @@
(*perTriNormals)[i] = Cross(v01, v02 ).normal();
}
}
-
+
// Check to see if per vertex normals are needed.
if (perVertNormals) { // if per-vertex normals are required
*perVertNormals = new Vectorf[3*n];
@@ -133,7 +133,7 @@
Vectorf v01, v02;
v01 = (**tris)[i][1] - (**tris)[i][0];
v02 = (**tris)[i][2] - (**tris)[i][0];
-
+
int offset = i*3;
// Hansong: these aren't actually per vertex normals??
@@ -141,11 +141,11 @@
(*perVertNormals)[offset+1] =
(*perVertNormals)[offset+2] = (*perVertNormals)[offset];
}
}
-
+
// Close the file.
if (fclose(f))
fprintf(stderr, "Error closing %s\n", filename);
-
+
return 1;
}
@@ -156,7 +156,7 @@
fprintf(stderr, "Cannot open file: %s\n", filename);
return 0;
}
-
+
fseek(f, 0, SEEK_END);
long fileSize = ftell(f);
@@ -169,16 +169,16 @@
// touch data for good distribution
//
long i;
-
+
#pragma omp parallel for private (i)
for (i=0; i<nFloats; i+=1024*4) {
rawData[i] = 0;
}
fseek(f, 0, SEEK_SET);
-
+
double time_begin = Time::currentSeconds();
-
+
// Read in the data.
long trisRead = fread(rawData, 48, fileSize/48, f);
if (trisRead != nTris) {
@@ -189,14 +189,14 @@
std::cout << "Time to input triangles: " << (time_end-time_begin) <<
" seconds. "
<<
(double)nTris/(time_end-time_begin) << " faces/second." << std::endl;
-
+
time_begin = Time::currentSeconds();
-
+
// Allocate a new array for the triangles.
*tris = new VArray<Triangle> (nTris);
(*tris)->setLen(nTris);
*perVertNormals = new Vectorf [nTris*3];
-
+
float *_rawData;
#pragma omp parallel for private (_rawData, i)
for (i=0; i<nTris; i++) {
@@ -207,7 +207,7 @@
(*perVertNormals)[3*i+2] =
Vectorf(_rawData[0], _rawData[1], _rawData[2]);
*/
-
+
// Check to see if we are on a big endian system
// Data was generate on Altix (little endian)
if (is_big_endian()) {
@@ -225,7 +225,7 @@
_rawData += 3;
}
}
-
+
#if 0
(**tris)[i][0] = Pointf(_rawData[0], _rawData[1],
_rawData[2]);
_rawData += 3;
@@ -254,14 +254,14 @@
(**tris)[i].edge1 = (**tris)[i][1] - (**tris)[i][0];
(**tris)[i].edge2 = (**tris)[i][2] - (**tris)[i][0];
(**tris)[i].payload = ((r<<16)+(g<<8)+b);
-
+
Vectorf v01, v02;
v01 = (**tris)[i][1] - (**tris)[i][0];
v02 = (**tris)[i][2] - (**tris)[i][0];
(*perVertNormals)[3*i] = Cross(v01, v02).normal();
-
+
(*perVertNormals)[3*i+1] = (*perVertNormals)[3*i+2] =
(*perVertNormals)[3*i];
-
+
// Update the bounding box of the whole scene
for (long j=0; j<3; j++) {
Triangle &tri = (**tris)[i];
@@ -269,14 +269,14 @@
bounds.extendByPoint( tri[1] );
bounds.extendByPoint( tri[2] );
}
-
+
}
-
+
time_end = Time::currentSeconds();
std::cout << "Time to parse triangles: " << (time_end - time_begin)
<< " seconds."
<< (double)nTris/(time_end-time_begin) << " faces/second."
<< std::endl;
-
+
fprintf(stderr, "Triangles loaded: %d\n", nTris);
delete [] rawData;
return 1;
@@ -394,7 +394,7 @@
fprintf(stderr, "Unrecognized file type.\n");
return 0;
}
-
+
/////////////////////////////////////////////////////////////////////////////
// Load the kd tree.
char filename[512];
@@ -404,10 +404,10 @@
if (! f) {
fprintf(stderr, "Error: cannot open %s for loading\n",
filename);
}
-
+
fseek(f, 0, SEEK_END);
long long fileSize = ftell(f);
-
+
void *buffer = (void*)malloc(fileSize);
fseek(f, 0, SEEK_SET);
@@ -416,23 +416,23 @@
long long nread = fread(buffer, 1, fileSize, f);
if (nread != fileSize) {
fprintf(stderr, "error reading file %s (size: %lld read:
%lld)\n",
- filename, fileSize, nread);
+ filename, fileSize, nread);
}
fclose(f);
-
+
double time_end = Time::currentSeconds();
std::cout << "Time to read kdtree: " << (time_end-time_begin) << "
seconds." << std::endl;
// Specify the root node loaded from the file.
rootNode = (KDTreeNode*)buffer;
-
+
// Get the bounding box from the file.
AABox3f bboxf = *(AABox3f*)((char*)buffer + fileSize -
sizeof(AABox3f));
-
+
if (is_big_endian()) {
-
+
std::cout << "NOTE: This system is big endian and the boeing
kdtree files are little, swapping bytes." << std::endl;
-
+
rootNode->endian_swap();
bboxf.min[0] = endian_swap( bboxf.min[0] );
@@ -458,7 +458,7 @@
fprintf(stderr, "Error: cannot open %s for loading\n",
filename);
return 0;
}
-
+
fseek(f, 0, SEEK_END);
fileSize = ftell(f);
fseek(f, 0, SEEK_SET);
@@ -471,17 +471,17 @@
nread = fread(indices->getArray(), sizeof(int), nInt, f);
if (nread != nInt) {
fprintf(stderr, "error reading file %s (size: %lld read:
%lld)\n",
- filename, fileSize, nread);
+ filename, fileSize, nread);
return 0;
}
fclose(f);
-
+
time_end = Time::currentSeconds();
std::cout << "Total time to read in indices: " <<
(time_end-time_begin) << std::endl;
triIndices = indices;
-
+
// Swap the indicies.
if (is_big_endian()) {
for (int i=0;i<nInt;++i) {
@@ -491,7 +491,7 @@
// create material
lambMat = new LambertianAlt;
-
+
return 1;
}
@@ -501,7 +501,7 @@
RayTriIntersectUserData *ud = (RayTriIntersectUserData*)userData;
float nearest_u, nearest_v;
int nearest_tri=-1;
-
+
/* Intersect the ray with all the bounding boxes */
int listEnd = listBegin+listSize;
for (i = listBegin; i < listEnd; i++) {
@@ -510,16 +510,16 @@
float t, u, v;
// if (intersectTriangle3Edge( *ray, tri, t, u, v )) {
-
+
Vectorf direction = ray->direction();
Pointf origin = ray->origin();
if(intersect_triangle3(
- &origin, &direction,
- &tri[0], &tri[1], &tri[2],
- &t, &u, &v/*,
- &tri.edge1, &tri.edge2*/)) {
-
+
&origin, &direction,
+
&tri[0], &tri[1], &tri[2],
+
&t, &u, &v/*,
+
&tri.edge1, &tri.edge2*/)) {
+
if (t < maxDist) {
maxDist = t;
nearest_u= u;
@@ -527,8 +527,8 @@
nearest_tri = triIdx;
}
}
- }
-
+ }
+
if (nearest_tri >= 0) {
ud->rayHit.t = maxDist;
ud->rayHit.u = nearest_u;
@@ -537,13 +537,13 @@
return 1;
} else
return 0;
-}
+ }
// Traversal Stack Entry.
struct TravStackEntry {
KDTreeNode* node; //8 bytes
float t; // 4 bytes
- // float point[3]; // 4*3=12 bytes
+
// float point[3]; // 4*3=12 bytes
int prev; // 4 bytes
};
@@ -552,7 +552,9 @@
///////////////////////////////////////////////////////////////////////////////
void KDTree::intersect(const RenderContext& context, RayPacket& rays) const
{
-
+
+ // Normalize and compute inverse directions,
+ // As a side effect this also computes the sign mask for the box
intersection.
rays.normalizeDirections();
rays.computeInverseDirections();
@@ -565,16 +567,19 @@
// Intersect the ray with the bounding box for the group.
if (Intersection::intersectAaBox( bbox,
-
minDist,
maxDist,
+
minDist, maxDist,
e.ray,
-
e.signMask,
-
e.inverseDirection )) {
+
e.signMask,
+
e.inverseDirection )) {
+ // Determine the actual minimum distance.
+ minDist = SCIRun::Max( minDist, T_EPSILON );
+ maxDist = SCIRun::Min( maxDist, e.hitInfo.minT() );
// Send the ray to the _intersect function.
isectData.rayHitTriIndex = -1;
- _intersect( &e.ray, e, &isectData, (float)minDist,
(float)maxDist);
-
+ _intersect( &e.ray, e, isectData, (float)minDist,
(float)maxDist);
+#if 0
// Check to see if the ray hit any triangles.
if (isectData.rayHitTriIndex >= 0) {
@@ -586,9 +591,10 @@
e.hitInfo.scratchpad<ScratchPadInfo>().payload =
tris->get(isectData.rayHitTriIndex).payload;
}
}
+#endif
}
#if 0
-
+
// Send the ray to the _intersect function.
isectData.rayHitTriIndex = -1;
_intersect( &e.ray, e, &isectData, 0,
numeric_limits<float>::max());
@@ -612,7 +618,7 @@
// This function performs the KD-Tree Traversal.
///////////////////////////////////////////////////////////////////////////////
void KDTree::computeNormal(const RenderContext& context, RayPacket& rays)
const {
-
+
// Copy the normal out of the KDTree::ScratchPadInfo structure.
for (int i=0;i<rays.getSize();++i) {
rays.get(i).normal =
rays.get(i).hitInfo.scratchpad<ScratchPadInfo>().normal;
@@ -624,8 +630,8 @@
// This function performs the KD-Tree Traversal.
///////////////////////////////////////////////////////////////////////////////
void KDTree::_intersect(
- const Ray* ray, RayPacket::Element &e, void *userData,
- float minDist, float maxDist) const
+
const Ray* ray, RayPacket::Element &e,
RayTriIntersectUserData &isectData,
+
float minDist, float maxDist) const
{
TravStackEntry travStack[128];
@@ -634,29 +640,29 @@
int axis, entryPos, exitPos;
bool foundIntersection = false;
int tmp;
-
+
entryPos = 0;
nearNode = travStack[entryPos].node = rootNode;
travStack[entryPos].prev = 1;
travStack[entryPos].t = minDist < 0.0f ? 0 : minDist;
-
+
exitPos = 1;
travStack[exitPos].node = NULL;
travStack[exitPos].t = maxDist;
travStack[exitPos].prev = 0;
-
+
while (travStack[entryPos].prev) {
-
+
while (nearNode && nearNode->isInternal()) {
-
+
axis = nearNode->axis();
split = nearNode->split();
-
+
float entryPos_coord_on_axis = ray->origin()[axis] +
travStack[entryPos].t*ray->direction()[axis];
float exitPos_coord_on_axis = ray->origin()[axis] +
travStack[exitPos].t*ray->direction()[axis];
-
+
if (entryPos_coord_on_axis <= split) {
if (exitPos_coord_on_axis <= split) {
nearNode = nearNode->left();
@@ -673,35 +679,39 @@
farNode = nearNode->left();
nearNode = nearNode->right();
}
-
+
tmp = exitPos;
if (++exitPos == entryPos) ++exitPos;
-
+
travStack[exitPos].node = farNode;
-
+
travStack[exitPos].t = (split - ray->origin()[axis])*
e.inverseDirection[axis];
-
+
travStack[exitPos].prev = tmp;
}
-
+
if (nearNode) {
// Intersect the ray with a list of triangles.
- foundIntersection =
- intersectTriangles(ray,
- nearNode->listBegin(),
- nearNode->listSize(),
travStack[exitPos].t,
- userData);
+ if (intersectTriangles(ray, nearNode->listBegin(),
nearNode->listSize(), travStack[exitPos].t, &isectData) &&
+ (isectData.rayHitTriIndex >= 0)) {
+
+ e.normal =
normals[isectData.rayHitTriIndex*3]; // Is this safe??? What if the hit()
function fails?
+
+ // Check against the hit record, Note that
tex coord mapper is null.
+ if (e.hitInfo.hit(isectData.rayHit.t,
lambMat, this, 0 )) {
+
e.hitInfo.scratchpad<ScratchPadInfo>().normal =
normals[isectData.rayHitTriIndex*3];
+
e.hitInfo.scratchpad<ScratchPadInfo>().payload =
tris->get(isectData.rayHitTriIndex).payload;
+ break;
+ }
+ }
}
-
- if (foundIntersection) break;
-
+
entryPos = exitPos;
exitPos = travStack[exitPos].prev;
nearNode = travStack[entryPos].node;
}
-
}
///////////////////////////////////////////////////////////////////////////////
@@ -813,7 +823,7 @@
/* calculate U parameter and test bounds */
*u = DOT(tvec, pvec);
if (*u < 0.0f || *u > det)
- return 0;
+ return 0;
/* prepare to test V parameter */
CROSS(qvec, tvec, edge1);
@@ -821,7 +831,7 @@
/* calculate V parameter and test bounds */
*v = DOT(dir, qvec);
if (*v < 0.0f || *u + *v > det)
- return 0;
+ return 0;
}
else if(det < -EPSILON)
@@ -834,7 +844,7 @@
/* printf("*u=%f\n",(float)*u); */
/* printf("det=%f\n",det); */
if (*u > 0.0f || *u < det)
- return 0;
+ return 0;
/* prepare to test V parameter */
CROSS(qvec, tvec, edge1);
@@ -842,7 +852,7 @@
/* calculate V parameter and test bounds */
*v = DOT(dir, qvec) ;
if (*v > 0.0f || *u + *v < det)
- return 0;
+ return 0;
}
else return 0; /* ray is parallell to the plane of the triangle */
@@ -885,7 +895,7 @@
/* calculate U parameter and test bounds */
*u = DOT(tvec, pvec);
if (*u < 0.0f || *u > det)
- return 0;
+ return 0;
/* prepare to test V parameter */
CROSS(qvec, tvec, edge1);
@@ -893,7 +903,7 @@
/* calculate V parameter and test bounds */
*v = DOT(dir, qvec);
if (*v < 0.0f || *u + *v > det)
- return 0;
+ return 0;
}
else if(det < -EPSILON)
@@ -901,7 +911,7 @@
/* calculate U parameter and test bounds */
*u = DOT(tvec, pvec);
if (*u > 0.0f || *u < det)
- return 0;
+ return 0;
/* prepare to test V parameter */
CROSS(qvec, tvec, edge1);
@@ -909,7 +919,7 @@
/* calculate V parameter and test bounds */
*v = DOT(dir, qvec) ;
if (*v > 0.0f || *u + *v < det)
- return 0;
+ return 0;
}
else return 0; /* ray is parallell to the plane of the triangle */
@@ -957,23 +967,23 @@
if (det > EPSILON)
{
if (uu < 0.0f || uu > det)
- return 0;
+ return 0;
/* calculate V parameter and test bounds */
vv = DOT(dir, qvec);
if (vv < 0.0f || uu + vv > det)
- return 0;
+ return 0;
}
else if(det < -EPSILON)
{
if (uu > 0.0f || uu < det)
- return 0;
+ return 0;
/* calculate V parameter and test bounds */
vv = DOT(dir, qvec) ;
if (vv > 0.0f || uu + vv < det)
- return 0;
+ return 0;
}
else return 0; /* ray is parallell to the plane of the triangle */
@@ -1015,23 +1025,23 @@
if (det > EPSILON)
{
if (uu < 0.0f || uu > det)
- return 0;
+ return 0;
/* calculate V parameter and test bounds */
vv = DOT(dir, qvec);
if (vv < 0.0f || uu + vv > det)
- return 0;
+ return 0;
}
else if(det < -EPSILON)
{
if (uu > 0.0f || uu < det)
- return 0;
+ return 0;
/* calculate V parameter and test bounds */
vv = DOT(dir, qvec) ;
if (vv > 0.0f || uu + vv < det)
- return 0;
+ return 0;
}
else return 0; /* ray is parallell to the plane of the triangle */
@@ -1075,24 +1085,24 @@
if (det > 1e-5)
{
if (uu < 0.0 || uu > det)
- return 0;
+ return 0;
/* calculate V parameter and test bounds */
vv = Dot( ray.direction(), qvec );
if (vv < 0.0 || uu + vv > det)
- return 0;
+ return 0;
}
else if(det < -1e-5)
{
if (uu > 0.0 || uu < det)
- return 0;
+ return 0;
/* calculate V parameter and test bounds */
vv = Dot(ray.direction(), qvec) ;
if (vv > 0.0f || uu + vv < det)
- return 0;
+ return 0;
}
else return 0; /* ray is parallell to the plane of the triangle */
@@ -1138,34 +1148,34 @@
/* calculate U parameter and test bounds */
uu = DOT(tvec, pvec);
if (det > EPSILON) {
- if (uu < 0.0f || uu > det) {
- hits[i] = 0;
- continue;
- }
-
- /* calculate V parameter and test bounds */
- vv = DOT(dir, qvec);
- if (vv < 0.0f || uu + vv > det) {
- hits[i] = 0;
- continue;
- }
+ if (uu < 0.0f || uu > det) {
+ hits[i] = 0;
+ continue;
+ }
+
+ /* calculate V parameter and
test bounds */
+ vv = DOT(dir, qvec);
+ if (vv < 0.0f || uu + vv >
det) {
+ hits[i] = 0;
+ continue;
+ }
}
else if(det < -EPSILON)
{
- if (uu > 0.0f || uu < det) {
- hits[i] = 0;
- continue;
- }
-
- /* calculate V parameter and test bounds */
- vv = DOT(dir, qvec) ;
- if (vv > 0.0f || uu + vv < det) {
- hits[i] = 0;
- continue;
- }
+ if (uu > 0.0f || uu < det) {
+ hits[i] = 0;
+ continue;
+ }
+
+ /* calculate V parameter and
test bounds */
+ vv = DOT(dir, qvec) ;
+ if (vv > 0.0f || uu + vv <
det) {
+ hits[i] = 0;
+ continue;
+ }
} else {
- hits[i] = 0;
- continue;
+ hits[i] = 0;
+ continue;
}
t[i] = DOT(edge2, qvec) * inv_det;
Modified: branches/itanium2/Model/Groups/kdtree.h
==============================================================================
--- branches/itanium2/Model/Groups/kdtree.h (original)
+++ branches/itanium2/Model/Groups/kdtree.h Thu Jun 2 18:22:10 2005
@@ -227,7 +227,7 @@
int intersectTriangles(const Ray* ray, unsigned int
listBegin, int listSize, float maxDist, void *userData) const;
// This method is called by the above method with a
hansong ray.
- void _intersect(const Ray* ray, RayPacket::Element
&e, void *userData, float _minDist=-1, float _maxDist=-1) const;
+ void _intersect(const Ray* ray, RayPacket::Element
&e, RayTriIntersectUserData &isectData, float _minDist=-1, float _maxDist=-1)
const;
public:
// This structure is used to record info about the
hit.
Modified: branches/itanium2/Model/Materials/LambertianAlt.cc
==============================================================================
--- branches/itanium2/Model/Materials/LambertianAlt.cc (original)
+++ branches/itanium2/Model/Materials/LambertianAlt.cc Thu Jun 2 18:22:10
2005
@@ -14,21 +14,20 @@
using namespace Manta;
void LambertianAlt::shade(const RenderContext& context, RayPacket& rays)
const {
-
- // Copy colors from hit info.
- Color colors[RayPacket::MaxSize];
- Real inv255 = 1.0/255.0;
-
- for (int i=0;i<rays.getSize();i++) {
- RayPacket::Element& e = rays.get(i);
- unsigned int rgb =
e.hitInfo.scratchpad<Kdtree::KDTree::ScratchPadInfo>().payload;
-
- colors[i] = Color(RGBColor(((rgb & 0xFF0000) >> 16)*inv255,
- ((rgb & 0x00FF00) >> 8)*inv255,
- ((rgb & 0x0000FF) >>
0)*inv255));
- }
-
-#if 0
+
+ // Copy colors from hit info.
+ Color colors[RayPacket::MaxSize];
+ Real inv255 = 1.0/255.0;
+
+ for (int i=0;i<rays.getSize();i++) {
+ RayPacket::Element& e = rays.get(i);
+ unsigned int rgb =
e.hitInfo.scratchpad<Kdtree::KDTree::ScratchPadInfo>().payload;
+
+ colors[i] = Color(RGBColor(((rgb & 0xFF0000) >> 16)*inv255,
+ ((rgb &
0x00FF00) >> 8)*inv255,
+ ((rgb &
0x0000FF) >> 0)*inv255));
+ }
+#if 0
for(int i=0;i<rays.getSize();i++) {
RayPacket::Element& e = rays.get(i);
float z = SCIRun::Abs(e.normal[2]);
@@ -37,51 +36,65 @@
}
return;
#endif
-
- Scene *scene = (Scene*)context.scene;
-
+
+ Scene *scene = (Scene*)context.scene;
+
// Compute ambient contributions for all rays
- scene->getLights()->getAmbientLight()->computeAmbient(context, rays);
-
+ scene->getLights()->getAmbientLight()->computeAmbient(context, rays);
+
// Compute the normals.
rays.computeNormals( context );
-
- RayPacketData data;
- int start = 0;
-
- do {
- RayPacket shadowRays(data, 0, rays.getDepth(), 0);
+
+# if 0
+ for (int i=0;i<rays.getSize();++i) {
+
+ Vector n = rays.get(i).normal;
+ Color color(RGB( n[0]*0.5+0.5,
+ n[1]*0.5+0.5,
+ n[2]*0.5+0.5 ) );
+ rays.setResult(i,color);
+ }
+#endif
+
+ // #if 0
+ RayPacketData data;
+ int start = 0;
+
+ do {
+ RayPacket shadowRays(data, 0, rays.getDepth(), 0);
// Send the shadow ray.
- int end = context.shadowAlgorithm->computeShadows( context,
scene->getLights(), rays, start, shadowRays );
-
+ int end = context.shadowAlgorithm->computeShadows( context,
scene->getLights(), rays, start, shadowRays );
+
// Normalize the shadow ray directions.
shadowRays.normalizeDirections();
// Iterate over the ray packet.
- for(int i=start;i<end;i++){
+ for(int i=start;i<end;i++) {
+
RayPacket::Element& e = rays.get(i);
Color totalLight(e.ambientLight);
-
+
// Iterate over the shadow ray packet for this ray
(Is this usually one??)
for(int j=e.shadowBegin;j<e.shadowEnd;j++){
RayPacket::Element& s = shadowRays.get(j);
+ // Add a pseudo diffuse term.
+ double cos_theta = Dot( s.ray.direction(),
e.normal );
+ totalLight += s.light*cos_theta*0.5;
+
// Check to see if the shadow ray hit
something.
if(!s.hitInfo.wasHit()){
- double cos_theta =
Dot(s.ray.direction(), e.normal);
- totalLight += s.light*cos_theta;
- // totalLight += Color(RGB(1,1,1));
- }
-
+ totalLight += s.light*cos_theta*0.5;
+ }
}
// Set the result..
rays.setResult( i, colors[i]*totalLight );
}
- start = end;
- } while(start < rays.getSize());
-
+ start = end;
+ } while(start < rays.getSize());
+ // #endif
}
Modified: branches/itanium2/Model/Primitives/Sphere.cc
==============================================================================
--- branches/itanium2/Model/Primitives/Sphere.cc (original)
+++ branches/itanium2/Model/Primitives/Sphere.cc Thu Jun 2 18:22:10
2005
@@ -9,7 +9,7 @@
using SCIRun::Clamp;
Sphere::Sphere(Material* material, const Point& center, double radius)
- : PrimitiveCommon(material, this), center(center), radius(radius)
+: PrimitiveCommon(material, this), center(center), radius(radius)
{
inv_radius = 1./radius;
}
@@ -25,7 +25,7 @@
void Sphere::intersect(const RenderContext&, RayPacket& rays) const
{
-#if VERSION1
+ // #if VERSION1
rays.normalizeDirections();
for(int i = 0;i<rays.getSize();i++){
RayPacket::Element& e = rays.get(i);
@@ -38,121 +38,123 @@
double t2hc=rad2-l2oc+tca*tca;
double thc=sqrt(t2hc);
double t=tca+thc;
- e.hitInfo.hit(material, this, t);
+ e.hitInfo.hit(t, material, this, tex);
} else {
if(tca < 0.0){
- // Behind ray, no intersections...
+ // Behind ray, no intersections...
} else {
- double t2hc=rad2-l2oc+tca*tca;
- if(t2hc <= 0.0){
- // Ray misses, no intersections
- } else {
- double thc=sqrt(t2hc);
- e.hitInfo.hit(material, this, tca-thc);
- e.hitInfo.hit(material, this, tca+thc);
- }
+ double t2hc=rad2-l2oc+tca*tca;
+ if(t2hc <= 0.0){
+ // Ray misses, no intersections
+ } else {
+ double thc=sqrt(t2hc);
+ e.hitInfo.hit(tca-thc, material,
this, tex);
+ e.hitInfo.hit(tca+thc, material,
this, tex);
+ }
}
}
}
-#endif
+ // #endif
+#if 0
switch(rays.getFlags() &
(RayPacket::ConstantOrigin|RayPacket::NormalizedDirections)){
- case RayPacket::ConstantOrigin|RayPacket::NormalizedDirections:
+ case
RayPacket::ConstantOrigin|RayPacket::NormalizedDirections:
{
// Rays of constant origin and normalized directions
RayPacket::Element& e0 = rays.get(0);
Vector O(e0.ray.origin()-center);
double C = Dot(O, O) - radius*radius;
for(int i = 0;i<rays.getSize();i++){
- RayPacket::Element& e = rays.get(i);
- const Vector& D(e.ray.direction());
- double B = Dot(O, D);
- double disc = B*B-C;
- if(disc >= 0){
- double r = sqrt(disc);
- double t0 = -(r+B);
- if(t0 > 0){
- e.hitInfo.hit(t0, material, this, tex);
- } else {
- double t1 = r-B;
- e.hitInfo.hit(t1, material, this, tex);
- }
- }
+ RayPacket::Element& e = rays.get(i);
+ const Vector& D(e.ray.direction());
+ double B = Dot(O, D);
+ double disc = B*B-C;
+ if(disc >= 0){
+ double r = sqrt(disc);
+ double t0 = -(r+B);
+ if(t0 > 0){
+ e.hitInfo.hit(t0, material,
this, tex);
+ } else {
+ double t1 = r-B;
+ e.hitInfo.hit(t1, material,
this, tex);
+ }
+ }
}
}
- break;
- case RayPacket::ConstantOrigin:
+ break;
+ case RayPacket::ConstantOrigin:
{
// Rays of constant origin for not normalized directions
RayPacket::Element& e0 = rays.get(0);
Vector O(e0.ray.origin()-center);
double C = Dot(O, O) - radius*radius;
for(int i = 0;i<rays.getSize();i++){
- RayPacket::Element& e = rays.get(i);
- const Vector& D(e.ray.direction());
- double A = Dot(D, D);
- double B = Dot(O, D);
- double disc = B*B-A*C;
- if(disc >= 0){
- double r = sqrt(disc);
- double t0 = -(r+B)/A;
- if(t0 > 0){
- e.hitInfo.hit(t0, material, this, tex);
- } else {
- double t1 = (r-B)/A;
- e.hitInfo.hit(t1, material, this, tex);
- }
- }
+ RayPacket::Element& e = rays.get(i);
+ const Vector& D(e.ray.direction());
+ double A = Dot(D, D);
+ double B = Dot(O, D);
+ double disc = B*B-A*C;
+ if(disc >= 0){
+ double r = sqrt(disc);
+ double t0 = -(r+B)/A;
+ if(t0 > 0){
+ e.hitInfo.hit(t0, material,
this, tex);
+ } else {
+ double t1 = (r-B)/A;
+ e.hitInfo.hit(t1, material,
this, tex);
+ }
+ }
}
}
- break;
- case RayPacket::NormalizedDirections:
+ break;
+ case RayPacket::NormalizedDirections:
{
// Rays of non-constant origin and normalized directions
for(int i = 0;i<rays.getSize();i++){
- RayPacket::Element& e = rays.get(i);
- Vector O(e.ray.origin()-center);
- const Vector& D(e.ray.direction());
- double B = Dot(O, D);
- double C = Dot(O, O) - radius*radius;
- double disc = B*B-C;
- if(disc >= 0){
- double r = sqrt(disc);
- double t0 = -(r+B);
- if(t0 > 0){
- e.hitInfo.hit(t0, material, this, tex);
- } else {
- double t1 = r-B;
- e.hitInfo.hit(t1, material, this, tex);
- }
- }
+ RayPacket::Element& e = rays.get(i);
+ Vector O(e.ray.origin()-center);
+ const Vector& D(e.ray.direction());
+ double B = Dot(O, D);
+ double C = Dot(O, O) - radius*radius;
+ double disc = B*B-C;
+ if(disc >= 0){
+ double r = sqrt(disc);
+ double t0 = -(r+B);
+ if(t0 > 0){
+ e.hitInfo.hit(t0, material,
this, tex);
+ } else {
+ double t1 = r-B;
+ e.hitInfo.hit(t1, material,
this, tex);
+ }
+ }
}
}
- break;
- case 0:
+ break;
+ case 0:
{
// Rays of non-constant origin and non-normalized directions
for(int i = 0;i<rays.getSize();i++){
- RayPacket::Element& e = rays.get(i);
- Vector O(e.ray.origin()-center);
- const Vector& D(e.ray.direction());
- double A = Dot(D, D);
- double B = Dot(O, D);
- double C = Dot(O, O) - radius*radius;
- double disc = B*B-A*C;
- if(disc >= 0){
- double r = sqrt(disc);
- double t0 = -(r+B)/A;
- if(t0 > 0){
- e.hitInfo.hit(t0, material, this, tex);
- } else {
- double t1 = (r-B)/A;
- e.hitInfo.hit(t1, material, this, tex);
- }
- }
+ RayPacket::Element& e = rays.get(i);
+ Vector O(e.ray.origin()-center);
+ const Vector& D(e.ray.direction());
+ double A = Dot(D, D);
+ double B = Dot(O, D);
+ double C = Dot(O, O) - radius*radius;
+ double disc = B*B-A*C;
+ if(disc >= 0){
+ double r = sqrt(disc);
+ double t0 = -(r+B)/A;
+ if(t0 > 0){
+ e.hitInfo.hit(t0, material,
this, tex);
+ } else {
+ double t1 = (r-B)/A;
+ e.hitInfo.hit(t1, material,
this, tex);
+ }
+ }
}
}
- break;
+ break;
}
+#endif
}
void Sphere::computeNormal(const RenderContext&, RayPacket& rays) const
@@ -166,7 +168,7 @@
}
void Sphere::computeTexCoords2(const RenderContext&,
- RayPacket& rays) const
+
RayPacket& rays) const
{
rays.computeHitPositions();
for(int i = 0;i<rays.getSize();i++){
@@ -181,7 +183,7 @@
}
void Sphere::computeTexCoords3(const RenderContext&,
- RayPacket& rays) const
+
RayPacket& rays) const
{
rays.computeHitPositions();
for(int i = 0;i<rays.getSize();i++){
Modified: branches/itanium2/scenes/boeing777.cc
==============================================================================
--- branches/itanium2/scenes/boeing777.cc (original)
+++ branches/itanium2/scenes/boeing777.cc Thu Jun 2 18:22:10 2005
@@ -20,6 +20,7 @@
#include <Model/Lights/PointLight.h>
#include <Model/Materials/Lambertian.h>
#include <Model/Materials/MetalMaterial.h>
+#include <Model/Materials/NormalMaterial.h>
#include <Model/Primitives/Parallelogram.h>
#include <Model/Primitives/Sphere.h>
#include <Model/Textures/CheckerTexture.h>
@@ -28,37 +29,50 @@
#include <Core/Util/NotFinished.h>
#include <Model/AmbientLights/ConstantAmbient.h>
+#include <SCIRun/Core/Thread/Time.h>
using namespace Manta;
using namespace Manta::Kdtree;
+using namespace SCIRun;
///////////////////////////////////////////////////////////////////////////
// This function constructs the Boeing 777 Test Scene using a KdTree.
extern "C"
Scene* make_scene(const ReadContext& context, const vector<string>& args) {
-
- string file_name;
-
- // Parse args.
- for (int i=0;i<args.size();++i) {
- if (args[i] == "-file") {
- // Determine the index of the filename.
- if (!getStringArg(i, args, file_name))
- throw IllegalArgument("boeing777 -file <filename>", i, args);
- }
- else {
- cerr << "Valid options for boeing777:" << endl;
- cerr << "-file <filename>" << endl;
- throw IllegalArgument( "boeing777", i, args );
- }
- }
-
- // Create the scene.
- Scene *scene = new Scene();
-
- // Create a kd tree.
- KDTree *kdtree = new KDTree;
- kdtree->load( file_name.c_str() );
+
+ string file_name;
+
+ // Parse args.
+ for (int i=0;i<args.size();++i) {
+ if (args[i] == "-file") {
+ // Determine the index of the filename.
+ if (!getStringArg(i, args, file_name))
+ throw IllegalArgument("boeing777 -file
<filename>", i, args);
+ }
+ else {
+ cerr << "Valid options for boeing777:" << endl;
+ cerr << "-file <filename>" << endl;
+ throw IllegalArgument( "boeing777", i, args );
+ }
+ }
+
+ // Create the scene.
+ Scene *scene = new Scene();
+ Group *group = new Group();
+
+ // Create a kd tree.
+ KDTree *kdtree = new KDTree;
+
+ double start_time = Time::currentSeconds();
+
+ kdtree->load( file_name.c_str() );
+
+ double end_time = Time::currentSeconds();
+
+ std::cout << "Total load time: " << (end_time-start_time)/60.0 << "
minutes." << std::endl;
+
+ // Add the kdtree to the world group.
+ group->add( kdtree );
// min = (0, -1200 -7)
// max = (2606, 1200, 716)
@@ -67,29 +81,36 @@
BBox bounds;
kdtree->computeBounds( bounds );
- // Compute the height of a light above the scene.
- // Real light_height = bounds.diagonal().maxComponent();
- // Point light_position = Point((bounds[1]-bounds[0])*0.5) +
Vector(0,0,light_height);
- Point light_position = bounds[1];
+ LightSet *lights = new LightSet();
- std::cout << "Adding light to scene: position: " << light_position <<
std::endl;
+ // Add lights at each corner of the model.
+ // for (int i=0;i<8;i+=2) {
+ // lights->add( new PointLight( bounds.getCorner(i), Color(RGB(
0.15, 0.15, 0.15 )) ));
+ //}
+
+ lights->add( new PointLight( Point(5000,5000,5000),
Color(RGB(1.0,1.0,1.0)) ));
+
+ //lights->add( new PointLight( bounds.center() + Vector
+
+ // group->add( new Sphere( new LambertianAlt(), Point(0,0,-11), 0.5 )
);
+ // group->add( new Sphere( new LambertianAlt(), Point(0,0,-5 ), 0.25
) );
// Add a light.
- LightSet* lights = new LightSet();
- lights->add( new PointLight(light_position, Color(RGBColor(0.9,0.9,0.9)
)));
- lights->setAmbientLight( new ConstantAmbient( Color(RGBColor(0.3,0.3,0.3)
) ));
+ // LightSet* lights = new LightSet();
+ // lights->add( new PointLight(light_position,
Color(RGBColor(0.9,0.9,0.9) )));
+
+ lights->setAmbientLight( new ConstantAmbient(
Color(RGBColor(0.2,0.2,0.2) ) ));
scene->setLights(lights);
-
- // Add the tree to the scene.
- scene->setObject( kdtree );
-
- // Set other important scene properties.
- PinholeCamera *camera = new PinholeCamera( bounds[1], bounds[0],
Vector(0,1,0), 40.0 );
+ // Add the tree to the scene.
+ scene->setObject( group );
- // Background.
- scene->setBackground( new ConstantBackground(Color(RGB(0.8, 0.8, 0.8))) );
-
- return scene;
+ // Set other important scene properties.
+ PinholeCamera *camera = new PinholeCamera( bounds[1], bounds[0],
Vector(0,1,0), 40.0 );
+
+ // Background.
+ scene->setBackground( new ConstantBackground(Color(RGB(0.8, 0.8,
0.8))) );
+
+ return scene;
}
- [MANTA] r362 - in branches/itanium2: Interface Model/Groups Model/Materials Model/Primitives scenes, abe, 06/02/2005
Archive powered by MHonArc 2.6.16.