PDA

View Full Version : Bitwise operators in GLSL



JoshKlint
08-10-2013, 04:31 PM
I store terrain texture data in RGBA textures that define the alpha level of each layer, packing one texture layer into each channel. I've implemented a virtual texturing system that allows me any number of texture layers at good speed. With so many texture layers possible, the bottleneck becomes the memory usage of these alpha textures. If the terrain is 2048x2048 points, every four texture layers consumes 16 mb video memory.

If I could perform bitwise operations in GLSL and just store a boolean for each texture layer, I could pack 32 texture layers into a single RGBA texture, greatly reducing the memory requirements of large terrains with many layers.

Foobarbazqux
08-10-2013, 05:08 PM
> If I could perform bitwise operations in GLSL and just store a boolean for each texture layer,

GLSL has had bitwise operators since at least GLSL version 1.3, which released in 2008. Which operations do you need?

JoshKlint
08-11-2013, 07:33 PM
> If I could perform bitwise operations in GLSL and just store a boolean for each texture layer,

GLSL has had bitwise operators since at least GLSL version 1.3, which released in 2008. Which operations do you need?
Really? I just need OR to store some bitwise flags. I did a google search and everything said it wasn't supported. :)

GClements
08-11-2013, 08:01 PM
Really? I just need OR to store some bitwise flags. I did a google search and everything said it wasn't supported. :)
Since version 1.3, GLSL supports all of C's operators except address-of (unary-&), pointer dereference (unary-* and ->) and type casts (constructors are used instead).

The first programmable GPUs had weak support for integer types in general, which was reflected in the early versions of GLSL (prior to 1.3), which didn't support bitwise and (&), or (|), xor (^), ones-complement (~), and shifts (<<,>>), or modulo (%), or the corresponding modify-assign operators (&=,|=,^=,<<=,>>=,%=).

kRogue
08-19-2013, 02:14 AM
I think the issue is this: the bitwise operation works on integer types only. For the OP, the solution you are hunting for is to make an _integer_ texture (there is the whole matrix: {number_channels=1,2,3 or 4} X { size of each channel = 8, 16 or 32 bits} X {unsigned or signed}, which is comes to 24 different integer texture choices.