How do I perform bit operations in glsl

北战南征 提交于 2020-01-12 05:28:05

问题


How do I perform bit operations in glsl?

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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/1700871/how-do-i-perform-bit-operations-in-glsl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!