Sign in to follow this  
MARS_999

Does ARB Fragment Program have a sqrt function?

Recommended Posts

I don't see anything on a sqrt() in the arg fragment program? Is this correct? I also don't see anything for division? I am assuming this because divison is slower than multiplying? So what do you suggest I use in place of the divison? Basically this is what I am trying to do in my fragment program....
nx = 2*r-1;
ny = 2*g-1;
nz = 2*b-1

d = sqrt(nx*nx + ny*ny + nz*nz);

nx /=d;
ny /=d;
nz /=d;

r = (nx + 1)/2;
g = (ny + 1)/2;
b = (nz + 1)/2;


I am having to do a lot of explicit calls in my fragment program which seems stupid? In GLSlang the above code would be close to what I would do or not? due to its like C syntax? This what I am doing currently in my fragment program and seems like there is a more effecient way to do it...
MUL nx, two, normalmap.r;
MUL ny, two, normalmap.g;
MUL nz, two, normalmap.b;
SUB nx, nx, 1;
SUB ny, ny, 1;
SUB nz, nz, 1;

#sqrt here?

Share this post


Link to post
Share on other sites
It has both a square root and a division opcode: RSQ (reciprocal sqrt) and RCP. RSQ is usually used to normalize vectors, but if you really need a standalone sqrt(), you could RCP it back. You divide by multiplying with the reciprocal.

Share this post


Link to post
Share on other sites
Huh, interesting.... would RSQ + RCP actually be faster than POW? (I'd benchmark it myself, but I get the feeling you already know [wink])

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this