Re: [Algorithms] approximation to pow(n,x)?
Brought to you by:
vexxed72
From: Jon W. <jw...@gm...> - 2009-11-04 18:06:53
|
Nathaniel Hoffman wrote: > lowly cosine power - it's not completely physically meaningless. If you > are using Blinn-Phong (N dot H, which is much to be preferred over > original Phong - R dot L), then using a cosine power is equivalent to > Except you already have the reflection vector for your environment mapping, so why not re-use it? As far as I can tell, cos(half-vector dot) behaves the same as cos(0.5 + reflection-vector dot), so you can make them equivalent by just adjusting the dot product value you put into the power function. Why do you think that the half vector is preferable? When it comes to approximating the power function for a specular highlight, you can go with a texture lookup -- 0 .. 1 on one axis, and 0 .. 200 on the other, for example. Or you can do the cheapest of the cheap: float cheap_pow(float x, float n) { x = saturate(1 - (1 - x ) * (n * 0.333)); return x * x; } Not very accurate, but very cheap, and still creates a soft-ish diffuse highlight shape, which tends to be slightly narrower towards the edges. It also gets worse below power 5 or so. Sincerely, jw -- Revenge is the most pointless and damaging of human desires. |