My question is how can I emulate a bitwise & operator in a shader? I have a line of code that is basically:
int a = i & 255;
(where i can become a relatively large number) in a C# script and I need it to work identically in a shader. How can I emulate this operator in a shader?
The last time I checked, bitwise operators aren’t available in CG. See the description of table 3-2 on this page:
Table 3-2 presents the complete list of operators, along with their precedence, associativity, and usage. Operators marked with a reverse highlight are currently reserved. However, no existing Cg profiles support these reserved operators because current graphics hardware does not support bitwise integer operations.
The bitwise and (&) with 255 is equivalent to modding (%) with 256 though, so you can use that instead.