3

Using spherical harmonics for lighting I faced a problem for a big enough bandwidths. The correctness of an approximation by first n^2 terms became worse and worse starting from n=7. I look into associated Legendre polynomials definition and found out, that there is a ratio of factorials (l - m)! / (l + m)! in normalization constant. For n = 7 (l + m)! can be up to 12!. I have to use float (IEEE-754 32-bit floating-point type), due to GPUs nature.

Now I think, that tgamma from C/C++ might be more appropriate, then naive calculation of factorial by definition. Even more: maybe there is a good (approximation) formula for ratio of gamma functions (of two big arguments).

Is there a good stable approach to calculate gamma function (for big positive integers) in shaders?

Surely I just can save a lookup table (matrix) for all the possible combinations of values in numerator and denominator, but I want to have alternative (space-efficient) approach.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Tomilov Anatoliy
  • 15,657
  • 10
  • 64
  • 169
  • 3
    Just for clarification, because this question touches graphics *and* calculus. OP is asking about availability of the generalized factorial function called "[Gamma](https://en.wikipedia.org/wiki/Gamma_function)". OP is not asking about colour space gamma factor correction. – datenwolf Feb 08 '17 at 09:31
  • @datenwolf Good point. It is sad, but most relevant search results touches upon gamma correction. – Tomilov Anatoliy Feb 08 '17 at 10:14
  • 1
    You don't need `(a+m)!` but `(a-m)!/(a+m)!`right? Then `(a-m)!/(a+m)!` = `1/(a+m)/(a+m-1)/(a+m-2).../(a-m+1)` – Ripi2 Feb 08 '17 at 23:13
  • where do I go if I am asking about the colour space gamma factor correction function definitions :)? – ThorSummoner Dec 20 '21 at 01:01

0 Answers0