3
3
4
4
// #define DBG
5
5
#include " utils/pspRT.h"
6
- #include " utils/pspDbg.h"
7
6
#include " utils/pspTimer.h"
8
7
9
8
using namespace std ;
@@ -47,13 +46,8 @@ rt::Ray::Ray(const V3f& orig, const V3f& dir) :
47
46
{
48
47
// blute: 2019-May-28 watertight fixes
49
48
50
- VAR3 ( o[0 ],o[1 ],o[2 ] );
51
- VAR3 ( d[0 ],d[1 ],d[2 ] );
52
-
53
49
V3f ad = ABS (d);
54
50
int md = MAX_DIM (ad);
55
- VAR ( ad );
56
- VAR ( md );
57
51
58
52
// calculate dimension where the raydirection is maximal
59
53
kz = MAX_DIM ( ABS (d) );
@@ -62,16 +56,10 @@ rt::Ray::Ray(const V3f& orig, const V3f& dir) :
62
56
// swap kx and ky dim to preserve winding dir of triangles
63
57
if ( d[kz] < 0 .f ) std::swap (kx,ky);
64
58
65
- VAR3 ( kx,ky,kz );
66
-
67
59
// calculate shear constants, to make ray unit length aligned with Z
68
60
Sx = d[kx] / d[kz];
69
61
Sy = d[ky] / d[kz];
70
62
Sz = 1 .f / d[kz];
71
- VAR ( d[kz] );
72
- VAR ( (1 .f /d[kz]) )
73
-
74
- VAR3 ( Sx,Sy,Sz );
75
63
76
64
// old
77
65
i[0 ] = 1 .0f / d[0 ];
@@ -117,31 +105,15 @@ rt::Triangle::bounds(void) const
117
105
return res;
118
106
}
119
107
120
- #if 1
121
-
122
108
bool
123
109
rt::Triangle::intersect (const Ray &ray, Hit *hit) const
124
110
{
125
- VAR ( ray.kx );
126
- VAR ( ray.ky );
127
- VAR ( ray.kz );
128
-
129
- VAR ( ray.Sx );
130
- VAR ( ray.Sy );
131
- VAR ( ray.Sz );
132
-
133
111
const Imath::V3f &origA = mesh->p [vi[0 ]];
134
112
const Imath::V3f &origB = mesh->p [vi[1 ]];
135
113
const Imath::V3f &origC = mesh->p [vi[2 ]];
136
- VAR ( origA );
137
- VAR ( origB );
138
- VAR ( origC );
139
114
const Imath::V3f A = origA - ray.o ;
140
115
const Imath::V3f B = origB - ray.o ;
141
116
const Imath::V3f C = origC - ray.o ;
142
- VAR ( A );
143
- VAR ( B );
144
- VAR ( C );
145
117
146
118
// shear/scale verts
147
119
const float Ax = A[ray.kx ] - ray.Sx * A[ray.kz ];
@@ -156,10 +128,6 @@ rt::Triangle::intersect(const Ray &ray, Hit *hit) const
156
128
float V = Ax*Cy - Ay*Cx;
157
129
float W = Bx*Ay - By*Ax;
158
130
159
- VAR ( U );
160
- VAR ( V );
161
- VAR ( W );
162
-
163
131
// fall back to dbl prec test for edges
164
132
if ( U==0 .f or V==0 .f or W==0 .f )
165
133
{
@@ -223,83 +191,6 @@ rt::Triangle::intersect(const Ray &ray, Hit *hit) const
223
191
return true ;
224
192
}
225
193
226
- #else
227
-
228
- bool
229
- rt::Triangle::intersect(const Ray &ray, Hit *hit) const
230
- {
231
- const Imath::V3f &v0 = mesh->p[vi[0]];
232
- const Imath::V3f &v1 = mesh->p[vi[1]];
233
- const Imath::V3f &v2 = mesh->p[vi[2]];
234
- const Imath::V3f edge1 = v1 - v0;
235
- const Imath::V3f edge2 = v2 - v0;
236
- const Imath::V3f pvec = ray.d.cross(edge2);
237
- const float det = edge1.dot(pvec);
238
- if (det == 0.f ) {
239
- MESG("rt::hitTri: missed 0");
240
- VAR( ray.o );
241
- VAR( ray.d );
242
- VAR( v0 );
243
- VAR( v1 );
244
- VAR( v2 );
245
- return false;
246
- }
247
- const float idet = 1.f/det;
248
- const Imath::V3f tvec = ray.o - v0;
249
- const float u = idet * tvec.dot(pvec);
250
- if (u < 0.0f || u > 1.0f) {
251
- MESG("rt::hitTri: missed 1");
252
- VAR( ray.o );
253
- VAR( ray.d );
254
- VAR( v0 );
255
- VAR( v1 );
256
- VAR( v2 );
257
- VAR( u );
258
- return false;
259
- }
260
- const Imath::V3f qvec = tvec.cross(edge1);
261
- const float v = idet * ray.d.dot(qvec);
262
- if (v < 0.0f || u + v > 1.0f) {
263
- MESG("rt::hitTri: missed 2");
264
- VAR( ray.o );
265
- VAR( ray.d );
266
- VAR( v0 );
267
- VAR( v1 );
268
- VAR( v2 );
269
- VAR( u );
270
- VAR( v );
271
- return false;
272
- }
273
- const float t = idet * edge2.dot(qvec);
274
- if( t < 0.f or t > ray.tmax ) {
275
- MESG("rt::hitTri: missed 3");
276
- VAR( ray.o );
277
- VAR( ray.d );
278
- VAR( ray.tmax );
279
- VAR( v0 );
280
- VAR( v1 );
281
- VAR( v2 );
282
- VAR( u );
283
- VAR( v );
284
- VAR( t );
285
-
286
- return false;
287
- }
288
-
289
- //std::cerr<<" === tri hit ===\n";
290
- hit->t = t;
291
- hit->pos = ray.o + t * ray.d;
292
- hit->nrm = edge1.cross(edge2);
293
- hit->u=u;
294
- hit->v=v;
295
- hit->w=1.f - (u + v);
296
- hit->primID = primID;
297
-
298
- if( hit->nrm.dot(ray.d) > 0.f ) hit->nrm = -hit->nrm;
299
- return true;
300
- }
301
- #endif
302
-
303
194
// //////////////////////////// TriangleMesh //////////////////////////////
304
195
305
196
rt::TriangleMesh::TriangleMesh (const std::vector<Imath::V3f>& t, const size_t stride) :
@@ -309,23 +200,18 @@ rt::TriangleMesh::TriangleMesh(const std::vector<Imath::V3f>& t, const size_t st
309
200
p = t;
310
201
for (int tidx=0 ;tidx<nVertices;++tidx)
311
202
vertexIndices.push_back (tidx);
312
- VAR ( nVertices );
313
- VAR ( nTriangles );
314
- VAR ( vertexIndices.size () );
315
203
}
316
204
317
205
std::vector<std::shared_ptr<rt::Primitive>>
318
206
rt::CreateTriangleMesh (const std::vector<float >& raw, size_t stride)
319
207
{
320
208
321
209
size_t nv = raw.size ()/stride;
322
- VAR ( nv );
323
210
std::vector<Imath::V3f> inTris ( nv );
324
211
for ( size_t vidx=0 ; vidx<nv ; ++vidx ){
325
212
const float * v = raw.data () + vidx*stride;
326
213
inTris[vidx] = Imath::V3f (v[0 ],v[1 ],v[2 ]);
327
214
}
328
- VAR ( inTris.size () );
329
215
std::shared_ptr<TriangleMesh> mesh = std::make_shared<TriangleMesh>(inTris, stride);
330
216
std::vector<std::shared_ptr<Primitive>> outTris;
331
217
outTris.reserve (mesh->nTriangles );
@@ -449,31 +335,11 @@ rt::BVH::BVH(const std::vector<std::shared_ptr<Primitive>> &p, int maxPrimsInNod
449
335
BuildNode *root = recursiveBuild (arena, primitiveInfo, 0 , primitives.size (), &totalNodes, orderedPrims);
450
336
primitives.swap (orderedPrims);
451
337
452
- // Box3f buildbox = checkbuild(root);
453
- // VAR( buildbox.min );
454
- // VAR( buildbox.max );
455
-
456
338
nodes = AllocAligned<LinearNode>(totalNodes);
457
339
458
340
int offset = 0 ;
459
341
flattenTree (root, &offset);
460
342
ASSERT (offset == totalNodes);
461
-
462
- // Box3f bvhbox = bounds();
463
- // VAR( bvhbox.min );
464
- // VAR( bvhbox.max );
465
- // for(int d=0;d<3;++d){ASSERT( bvhbox.min[d] <= buildbox.min[d] and buildbox.max[d] <= bvhbox.max[d] );}
466
-
467
- // auto aend = std::chrono::system_clock::now();
468
- // std::chrono::duration<double> atime = aend - abgn;
469
- // std::cout << "time to build BVH " << atime.count() << "s" << std::endl;
470
-
471
- /*
472
- std::cout << " total primitives "<<commas(totalPrimitives)<<"\n";
473
- std::cout << " leaf nodes "<<commas(leafNodes)<<"\n";
474
- std::cout << " interior nodes "<<commas(interiorNodes)<<"\n";
475
- std::cout << " total nodes "<<commas(totalNodes)<<"\n";
476
- */
477
343
}
478
344
479
345
rt::BVH::~BVH (void )
@@ -508,8 +374,6 @@ rt::BVH::intersect(const Ray &ray, Hit *isect) const
508
374
509
375
while (true ) {
510
376
511
- VAR ( currentNodeIndex );
512
-
513
377
const LinearNode *node = &nodes[currentNodeIndex];
514
378
515
379
// Check ray against BVH node
@@ -659,7 +523,6 @@ rt::BVH::recursiveBuild(MemoryArena &arena,
659
523
}
660
524
cost[i] = 1 .f + ((float )count0 * rt::SurfaceArea (b0) +
661
525
(float )count1 * rt::SurfaceArea (b1)) / rt::SurfaceArea (bounds);
662
- // VAR2( i, cost[i] );
663
526
} // for i
664
527
665
528
// Find bucket to split at that minimizes SAH metric
0 commit comments