Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 glsl 中执行位操作?
使用常规 C 风格的位运算符|, &, ^, or!不起作用。
|
&
^
!
它们是在 GLSL 1.30 (OGL 3.0) 中引入的。
例如,根据您想要做什么,您最终可以使用浮点运算来模拟它们x & (2^n)-1 = frac(x/(2^n))*(2^n),但您必须处理浮点错误。
x & (2^n)-1 = frac(x/(2^n))*(2^n)
你需要把
#version 130
或者
#extension GL_EXT_gpu_shader4 : enable
在着色器顶部以访问位运算符