noName
noName

Reputation: 130

How fast is the GLSL "determinant()" function

I'm programming a raytracer in GLSL and there are multiple algorithms for calculating the ray-triangle-intersection. Some of these are using determinants some not, but the point is that calculating a determinant is slow. So my question is : Is the determinant() function optimized on GPUs and how fast is it in comparison with multiplications.

Upvotes: 1

Views: 1247

Answers (1)

Tamás Zahola
Tamás Zahola

Reputation: 9311

Because the GLSL determinant() function operates on at most 4x4 matrices, it won't do Gaussian elimination or anything like that. It's a few multiplications and additions/subtractions just as if you were to write the "unrolled" formula down by hand. For the 3x3 case it's about 12 multiplications and 5 addition/subtraction (using Cramer's rule) from which multiplications can be parallelized.

You can look at the determinant implementation in the GLM library, the GLSL one is probably implemented very similarly, but of course it can vary between vendors/drivers/GPUs.

Upvotes: 3

Related Questions