🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Best-performing collision algorithm when only using AABBs?

Started by
10 comments, last by JoeJ 3 weeks, 6 days ago
	struct AABox 
	{
		vec minmax[2]; // minimum [0] and maximum [1] corners in an array
// ...
		void DistanceRayFrontAndBackface (float &ffd, float& bfd, const vec& rayOrigin, const vec& rayInvDirection) const
		{
			vec t0 = vec(minmax[0] - rayOrigin).MulPerElem (rayInvDirection); // MulPerElem does (x0*x1, y0*y1, z0*z1) in a single SIMD instruction
			vec t1 = vec(minmax[1] - rayOrigin).MulPerElem (rayInvDirection);
			vec tMin = t0.MinPerElem (t1); // gives new vector with minimum per dimension, also using just one SIMD instruction
			vec tMax = t0.MaxPerElem (t1);
			// MaxElem gives the largest dimension
			ffd = tMin.MaxElem(); // front face distance (behind origin if inside box) 
			bfd = tMax.MinElem(); // back face distance	
		}

Ray box test is a fast operation if we reduce all the branching with SIMD.
But similar optimizations could be done for any other methods as well.

Advertisement