View Full Version : Bit operation in fragment program?
06-28-2005, 08:07 AM
I have to use 16 bits to my fragment program. Is there an elegant way to do that? It mean, I want to be then able to read each of this 16bits, easily (e.g: MUL myout, myin, bit)
06-28-2005, 10:26 AM
No shading languages have bitwise operations. Shader ops tend to be floating-point in nature.
06-29-2005, 01:22 AM
Ok. But if I have 16 bits to access, I can put them in a float. And if I was in C++, I could simply use modulo operation to find the desired bit. Can I do the same in fragment program?
An other solution would be to pass the 16 bit in a texture, but a texture lookup is too slow and I can't use it.
Thanks for your help
06-29-2005, 11:10 AM
I seriously doubt it. The mod operator is an integer operation (technically not true, but close enough), and I don't recall seeing any mention of such a function in the glslang spec. It certainly isn't in any fragment program specs.
06-30-2005, 07:25 AM
There is no mod operation in GLSL or in the asm languages, but integer operations are possible.
With a series of multiplication by 2 and division by 2, it's possible to extract bits.
Unfortunatly, the overflow behavior is not portable and also, implementation are free to choose the integer precision they want.
04-25-2006, 06:50 PM
Looking at the Orange book there is a mod() function. I was able to create a bit-wise testing function that returns the value of a desired bit. See the following:
float BitSelect(vec3 pixel, float bit)
float value = 0.0;
float bitlcl = bit;
if (bit < 8.0)
value = pixel.r;
else if (bit < 16.0)
value = pixel.g;
bitlcl = bit - 8.0;
value = pixel.b;
bitlcl = bit - 16.0;
float ison = floor(mod(floor(value*255.0)/pow(2.0,bitlcl), 2.0));
04-26-2006, 08:04 AM
Hmmm. perhaps I was wrong back then.
Also, this thread is 1 year old. You will be able to do bitwise operations on the next generation of hw.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.