math & physics
starstutter at August 12th, 2009 20:02 — #1
I was wondering if there is a faster alternative or approximation to these functions in HLSL. I realize that they can be replaced with texture look-ups, but I've heard that these math operations have become faster than textue samples in recent years. I also understand that I can store a lighting model in a texture, but then I would still have to do at least 8 samples.
So, plain and simple, any other functions or tricks I could use?
thanks in advance
alphadog at August 12th, 2009 20:17 — #2
How accurate? For very, very fast, precompute some lookup tables. Of course, the more accurate, the bigger the table. Else, you want to look into Chebyshev. The book Numerical Recipes covers this pretty well.
starstutter at August 12th, 2009 20:23 — #3
Are you talking about an array of half or float values? I would have to interpolate between then right?
Btw, I guess on a scale of 1 to 10 in terms of speed (with 1 being the regular functions in HLSL), I guess maybe 5-7
alphadog at August 12th, 2009 20:26 — #4
Yeah, an array. And, yes, assuming you need to get values that lie between your pre-computed ones, then interpolation (simplest being linear, else you can get slightly fancy and get a little more accuracy) would be the way to go.
starstutter at August 12th, 2009 20:29 — #5
ok, I'll give it a shot and get back to you, thanks
alphadog at August 12th, 2009 20:31 — #6
alphadog at August 12th, 2009 20:32 — #7
alphadog at August 12th, 2009 20:36 — #8
starstutter at August 12th, 2009 20:43 — #9
The result is actually slower, but I might know why:
I generated a lookup table like you said:
const half aCosT =
1.49259,........... and so on...
then referenced it like this:
half theta_r = aCosT[(VdotN * 0.5) * 64]; \<- VdotN stays between 0.0f - 1.0f
I rember reading in an ATI paper that referencing (indexing) with a float value is costly. Any way to perform this lookup without using a float (or half)?
starstutter at August 12th, 2009 20:46 — #10
oh, well then I'll try nicks idea