Jump to content
  • Advertisement
Sign in to follow this  
dimensionX

OpenGL Bitwise operations on GPUs

This topic is 4909 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

Has anyone tried to emulate bitwise operation on the GPU ? I know that GLSL and Cg do not support bitwise operations. So how to get around this problem ? Can we use the preprocessor because the preprocessor expressions do allow bitwise operators ? Has anyone tired this ? The 'abs' & 'mod' functions in GLSL: 1) float abs(float x) --> Returns x if x >= 0; otherwise it returns x. "OpenGL Shading Language" - page 122. Ok. Is it not returning x with the same sign ? What is the use of this function ? Isn't it supposed to get rid of the -ve sign if x < 0 ? 2) float mod(float x, float y) --> Returns x - y * floor(x/y); Somebody please explain it to me what is this function doing ? Is there a builtin function for sgn(x) = 1 if x > 0; otherwise 0; Thanks! [Edited by - dimensionX on February 8, 2005 5:37:24 PM]

Share this post


Link to post
Share on other sites
Advertisement
1) of course the abs(x) function returns the negated value of x if negative. If you've read a spec that says something else, this is obviously a typo.

2) the mod function returns the remainder of the division, just like the Pascal's mod function or C's % function, except the fact that this version also works with floating-point numbers.
Examples :
mod(10,3) == 1
mod(10,5) == 0
mod(6.5, 3) == 0.5
This function ensures that for any x,y pair, the result of mod(x,y) is in the [0,y[ range : 0 <= mod(x,y) < y.
A typical example of this property is with y=2*PI : it transforms any angle value x from the ]-oo, +oo[ range to the [0,2*PI] range.

As for bitwise operations, you can actually use the logical operation functionality glLogicOp, available since OpenGL 1.0, but it's fairly limited and rarely accelerated in hardware for all operations.

Share this post


Link to post
Share on other sites
Quote:
Is there a builtin function for sgn(x) = 1 if x > 0; otherwise 0;


genType step (genType edge, genType x)
genType step (float edge, genType x)
Returns 0.0 if x < edge, otherwise it returns 1.0

Share this post


Link to post
Share on other sites
Vincoof,

I know what the spec says about 'abs(x)'. What is the use of this function if it returns the same (value and sign) as the input 'x' ?

Share this post


Link to post
Share on other sites
Quote:
Original post by dimensionX
I know what the spec says about 'abs(x)'. What is the use of this function if it returns the same (value and sign) as the input 'x' ?


That's not what it does. It returns the absolute value of x. And in case you don't know, that means if x is positive it returns x, if it is negative it returns -x. What vincoof was saying is that if you've read somewhere that it just returns x, then it's obviously a typo.

ie:
Quote:
1) float abs(float x) --> Returns x if x >= 0; otherwise it returns x. "OpenGL Shading Language" - page 122.


That is obviously a typo and should be "otherwise it returns -x."

Share this post


Link to post
Share on other sites
Usually you when you take the absolute value of something its called the magnitude of that something. The last time I used abs () in a program it was to take the sqrt() of negative numbers when I was rolling my complex number class.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!