2

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

Mika
  • 21
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 09 '21 at 08:17
  • Indeed this is not clearly written. From the title I infer that you are thinking of something on the lines "find whether there is a sequence 10101 in 00100101000101011011". Your image, however, implies that you are only interested whether certain bits are set in a given binary sequence (for which you just need to do a binary "and" operation with a "mask" having only those bits set). Or - you may be thinking of something entirely different. Can you please edit your question to make it clearer? –  Sep 09 '21 at 08:23
  • Ill try to clarify my intention more, im not very good at math language – Mika Sep 09 '21 at 08:38
  • Can you make more sense of it now? – Mika Sep 09 '21 at 08:54

1 Answers1

0

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?

Trebor
  • 4,575
  • I have see if HLSL has a thing like that – Mika Sep 09 '21 at 09:21
  • The bit-wise AND operation is often denoted by the single symbol & (i.e. not && but &). To test if a particular bit is set, you would use an expression like (n&(1<<i)) != 0 or ((n>>i)&1) != 0. – Jaap Scherphuis Sep 09 '21 at 09:32