How to perform bit operations in glsl

How to perform bit operations in glsl?

Using regular C-style bitwise operators | , & , ^ or ! does not work.

+7
bitwise-operators glsl
source share
2 answers

They were introduced with GLSL 1.30 (OGL 3.0).

Depending on what you want to do, you may end up simulating them using floating point operations, e.g. x & (2^n)-1 = frac(x/(2^n))*(2^n) , but you have to take care of floating point errors.

+6
source share

You need to put

 #version 130 

or

 #extension GL_EXT_gpu_shader4 : enable 

at the top of your shader to access the bit operator

+5
source share

All Articles