How to check between integers a & b, if inside the binary representation of a, you can find binary of b?

51 Views Asked by At

I'm using this to read a two dimensional texture that has a binary mapping of colors, to represent the hidden z dimension. This is used for a shadowmap im trying to create. I use the red channel to represent the z dimension, and if there is light, it gets colored with 0.01, 0.02, 0.04, 0.08, etc.

I then query from withing a point in world space, and I try to deduct that if in indeed, there is light in this particular position. Each color value represents a z point in world space as so; 0.01 = 0, 0.02 = 1, 0.04 = 2, 0.08 = 3,

I query the said texture and end up with the red color value of 0.06 (so 0.02+ 0.04). In the context of my game world, this means that the light voxels at the z positions of 1 and 2, are supposed to be lit.

Problem

Is there some cool property to binaries that would allow this?

I was somewhat able to do a naive implementation of this, using the textures RGBA as the keys to Z, but it only allows for max 4 world layers.

Naive thing

1

There are 1 best solutions below

2
On

In most programming languages, if you have an integer n, the expression n && (1<<i) picks out the i-th binary digit. (You may need to look up the specific symbol used for the binary operations.) Is that relevant to your question?