@@ -785,7 +785,7 @@ void Mesh::UpdateBVH()
785
785
if (!bvh)
786
786
{
787
787
bvh = new BVH ();
788
- bvh->Build ( vertices.data (), (uint )vertices.size () / 3 );
788
+ bvh->Build ( (tinybvh::bvhvec4*) vertices.data (), (uint )vertices.size () / 3 );
789
789
}
790
790
else
791
791
{
@@ -801,9 +801,12 @@ int Mesh::Intersect( Ray& ray )
801
801
{
802
802
// backup ray and transform original
803
803
Ray backupRay = ray;
804
- ray.O = TransformPosition ( ray.O , invTransform );
805
- ray.D = TransformVector ( ray.D , invTransform );
806
- ray.rD = float3 ( safercp ( ray.D .x ), safercp ( ray.D .y ), safercp ( ray.D .z ) );
804
+ float3* O = (float3*)&ray.O ;
805
+ float3* D = (float3*)&ray.D ;
806
+ float3* rD = (float3*)&ray.rD ;
807
+ *O = TransformPosition ( *O, invTransform );
808
+ *D = TransformVector ( *D, invTransform );
809
+ *rD = float3 ( safercp ( D->x ), safercp ( D->y ), safercp ( D->z ) );
807
810
// trace ray through BVH
808
811
uint steps = bvh->Intersect ( ray );
809
812
// restore ray origin and direction
@@ -819,7 +822,8 @@ int Mesh::Intersect( Ray& ray )
819
822
void Mesh::UpdateWorldBounds ()
820
823
{
821
824
worldBounds.Reset ();
822
- float3 bmin = bvh->bvhNode [0 ].aabbMin , bmax = bvh->bvhNode [0 ].aabbMax ;
825
+ float3 bmin = *(float3*)&bvh->bvhNode [0 ].aabbMin ;
826
+ float3 bmax = *(float3*)&bvh->bvhNode [0 ].aabbMax ;
823
827
for (int i = 0 ; i < 8 ; i++)
824
828
{
825
829
float3 corner ( i & 1 ? bmax.x : bmin.x , i & 2 ? bmax.y : bmin.y , i & 4 ? bmax.z : bmin.z );
@@ -2420,7 +2424,7 @@ void Scene::InitializeGPUData()
2420
2424
}
2421
2425
}
2422
2426
// allocate buffers for GPU data
2423
- bvhNodeData = new Buffer ( nodeCount * sizeof ( BVH::BVHNode ) );
2427
+ bvhNodeData = new Buffer ( nodeCount * sizeof ( tinybvh:: BVH::BVHNode ) );
2424
2428
triangleData = new Buffer ( primCount * 3 * sizeof ( float4 ) );
2425
2429
triangleIdxData = new Buffer ( idxCount * sizeof ( uint ) );
2426
2430
offsetData = new Buffer ( (int )meshPool.size () * 2 * sizeof ( uint4 ) );
@@ -2438,12 +2442,12 @@ void Scene::InitializeGPUData()
2438
2442
uint4* offset = (uint4*)offsetData->GetHostPtr ();
2439
2443
if (tlas)
2440
2444
{
2441
- memcpy ( bvhPtr, tlas->bvhNode , tlas->newNodePtr * sizeof ( BVH::BVHNode ) );
2445
+ memcpy ( bvhPtr, tlas->bvhNode , tlas->newNodePtr * sizeof ( tinybvh:: BVH::BVHNode ) );
2442
2446
memcpy ( idxPtr, tlas->triIdx , meshPool.size () * sizeof ( uint ) );
2443
2447
}
2444
2448
for (int s = sky->width * sky->height , i = 0 ; i < s; i++)
2445
2449
((float4*)skyData->GetHostPtr ())[i] = float4 ( sky->pixels [i], 0 );
2446
- bvhPtr += 2 * (int )meshPool.size () * sizeof ( BVH::BVHNode );
2450
+ bvhPtr += 2 * (int )meshPool.size () * sizeof ( tinybvh:: BVH::BVHNode );
2447
2451
idxPtr += (int )meshPool.size () * sizeof ( uint );
2448
2452
for (int s = (int )meshPool.size (), i = 0 ; i < s; i++)
2449
2453
{
@@ -2553,7 +2557,7 @@ int Scene::Intersect( Ray& ray )
2553
2557
else
2554
2558
{
2555
2559
// use a local stack instead of a recursive function
2556
- BVH::BVHNode* node = &tlas->bvhNode [0 ], * stack[128 ];
2560
+ tinybvh:: BVH::BVHNode* node = &tlas->bvhNode [0 ], * stack[128 ];
2557
2561
uint stackPtr = 0 , steps = 0 ;
2558
2562
// traversl loop; terminates when the stack is empty
2559
2563
while (1 )
@@ -2573,8 +2577,8 @@ int Scene::Intersect( Ray& ray )
2573
2577
continue ;
2574
2578
}
2575
2579
// current node is an interior node: visit child nodes, ordered
2576
- BVH::BVHNode* child1 = &tlas->bvhNode [node->leftFirst ];
2577
- BVH::BVHNode* child2 = &tlas->bvhNode [node->leftFirst + 1 ];
2580
+ tinybvh:: BVH::BVHNode* child1 = &tlas->bvhNode [node->leftFirst ];
2581
+ tinybvh:: BVH::BVHNode* child2 = &tlas->bvhNode [node->leftFirst + 1 ];
2578
2582
float dist1 = child1->Intersect ( ray ), dist2 = child2->Intersect ( ray );
2579
2583
if (dist1 > dist2) { swap ( dist1, dist2 ); swap ( child1, child2 ); }
2580
2584
if (dist1 == 1e30f)
0 commit comments