Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I perform bit operations in glsl

How do I perform bit operations in glsl?

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

like image 300
GameFreak Avatar asked Nov 09 '09 13:11

GameFreak


2 Answers

You need to put either

#version 130

or

#extension GL_EXT_gpu_shader4 : enable

in the top of your shader to get access to the bit operators

like image 160
Chris Dodd Avatar answered Oct 07 '22 23:10

Chris Dodd


They have been introduced with GLSL 1.30 (OGL 3.0).

Depending on what you want to do, you could eventually emulate them with floating point operations, x & (2^n)-1 = frac(x/(2^n))*(2^n) for example, but you'll have to take care of floating point errors.

like image 33
Aszarsha Avatar answered Oct 07 '22 22:10

Aszarsha