src/kdtree.cc
branchpyrit
changeset 85 907a634e5c02
parent 84 6f7fe14782c2
child 86 ce6abe0aeeae
equal deleted inserted replaced
84:6f7fe14782c2 85:907a634e5c02
   448 			if ((!cond1 && !cond2) || (cond1 && cond2))
   448 			if ((!cond1 && !cond2) || (cond1 && cond2))
   449 			{
   449 			{
   450 				// fall back to single rays
   450 				// fall back to single rays
   451 				// FIXME: split rays and continue
   451 				// FIXME: split rays and continue
   452 				for (int i = 0; i < 4; i++)
   452 				for (int i = 0; i < 4; i++)
   453 					if(!nearest_shapes[i])
   453 					if (!nearest_shapes[i])
   454 						nearest_shapes[i] = nearest_intersection(origin_shapes[i],
   454 						nearest_shapes[i] = nearest_intersection(origin_shapes[i],
   455 							rays[i], nearest_distances[i]);
   455 							rays[i], nearest_distances[i]);
   456 				return;
   456 				return;
   457 			}
   457 			}
   458 
   458 
   491 		}
   491 		}
   492 
   492 
   493 		/* current node is the leaf . . . empty or full */
   493 		/* current node is the leaf . . . empty or full */
   494 		__m128 dists = stack[exit].t;
   494 		__m128 dists = stack[exit].t;
   495 		ShapeList::iterator shape;
   495 		ShapeList::iterator shape;
       
   496 		__m128 results;
   496 		for (shape = node->getShapes()->begin(); shape != node->getShapes()->end(); shape++)
   497 		for (shape = node->getShapes()->begin(); shape != node->getShapes()->end(); shape++)
   497 		{
   498 		{
       
   499 			results = (*shape)->intersect_packet(rays, dists);
       
   500 			int valid = _mm_movemask_ps(
       
   501 				_mm_and_ps(mask, _mm_and_ps(results, _mm_cmpge_ps(dists, _mm_sub_ps(stack[entry].t, mEps)))));
   498 			for (int i = 0; i < 4; i++)
   502 			for (int i = 0; i < 4; i++)
   499 				if ( ((_mm_movemask_ps(mask)>>(i))&1) &&
   503 			{
   500 				((float*)&stack[entry].t)[i] < ((float*)&stack[exit].t)[i] &&
   504 				if (*shape != origin_shapes[i] && ((valid>>i)&1))
   501 				*shape != origin_shapes[i] &&
       
   502 				(*shape)->intersect(rays[i], ((float*)&dists)[i])
       
   503 				&& ((float*)&dists)[i] >= ((float*)&stack[entry].t)[i] - Eps)
       
   504 				{
   505 				{
   505 					nearest_shapes[i] = *shape;
   506 					nearest_shapes[i] = *shape;
   506 					nearest_distances[i] = ((float*)&dists)[i];
   507 					nearest_distances[i] = ((float*)&dists)[i];
   507 				}
   508 				}
   508 
   509 			}
   509 			/*
       
   510 			bool results[4];
       
   511 			(*shape)->intersect_packet(rays, dists, results);
       
   512 			int greater_than_entry = _mm_movemask_ps(
       
   513 				_mm_and_ps(_mm_cmpge_ps(dists, _mm_sub_ps(stack[entry].t, mEps)), mask));
       
   514 			for (int i = 0; i < 4; i++)
       
   515 			{
       
   516 				if (results[i] //&& *shape != origin_shapes[i]
       
   517 				&& ((greater_than_entry>>(3-i))&1))
       
   518 				{
       
   519 					nearest_shapes[i] = *shape;
       
   520 					nearest_distances[i] = ((float*)&dists)[i];
       
   521 				}
       
   522 			}
       
   523 			*/
       
   524 		}
   510 		}
   525 
   511 
   526 		for (int i = 0; i < 4; i++)
   512 		for (int i = 0; i < 4; i++)
   527 			if (nearest_shapes[i])
   513 			if (nearest_shapes[i])
   528 				((int*)&mask)[i] = 0;
   514 				((int*)&mask)[i] = 0;