Good alternative to bitwise operations

I’m trying to draw a simple 2D map using a shader like so

This was going really well until I tried to run an actual build. This is when I learned I can’t use bitwise operators in my shader code …

I’m currently using two bitmask parameters to determine where the walls should be drawn in. In this 3 x 5 grid map that I have there are 38 possible wall locations. I’d really prefer not to have wall1, wall2 … wall38 different parameters passed in.

What is a good alternative to this?

You can use bitwise operators, but only when using DX10 or better. I think you need to compiler your shaders for target 3.5 (or better).

#pragma target 3.5

Alternatively: Encoding boolean flags into a float in HLSL – The Instruction Limit

2 Likes