Jump to content
  • Advertisement
Sign in to follow this  

Does ARB Fragment Program have a sqrt function?

This topic is 5219 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!