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 :)
Please log in or register to post a reply.
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.
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
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.
ok, I’ll give it a shot and get back to you, thanks
Of course, wikipedia is your friend:
Duh, don’t forget our local heavy contributor:
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)?
oh, well then I’ll try nicks idea :)