How do I perform bit operations in glsl

前端 未结 2 2081
滥情空心
滥情空心 2021-02-06 01:14

How do I perform bit operations in glsl?

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

相关标签:
2条回答
  • 2021-02-06 01:24

    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.

    0 讨论(0)
  • 2021-02-06 01:37

    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

    0 讨论(0)
提交回复
热议问题