GLSL - Why are bitwise operators reserved? What is a good alternative to using bitwise ops (floating point ops that emulate bitwise)

StackOverflow https://stackoverflow.com/questions/3543273

  •  30-09-2019
  •  | 
  •  

문제

I'm running some experiments in WebGL, one of them being an XOR effect fragment shader. For some reason all the bitwise operators are reserved in GLSL and cause a compiler error when used. Why are these operators illegal? What can I use instead of | in this case?

도움이 되었습니까?

해결책

In the GLSL 1.0 spec, they were reserved "for future use", which was the 1.3 spec. It's allowed for unsigned and signed integers, both scalar and vector.

You should begin your shader by

#version 130

다른 팁

I ran into this problem too, e.g. trying to run Slisesix in Shader Toy using Chrome.

This question has two answers showing ways you could implement bitwise XOR without bitwise operators. They might be slow, but in some cases they'd be fast enough. Better than nothing.

You might also see whether + is a close enough approximation to bitwise XOR, depending on what your requirements are.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top