Texture3D Value rounding

Hello,
I try to manage a Texture3D update problem I’m facing since a longer time. By that chance I found some weired behavior. for the texture generation process, I create a color-?array? and set its RGB values equals a variable stored in a List. I have the following example List:

[0.5156, 0.9883, 0.9844, 0.5703, 0.0547] and [0.4922, 0.9883, 0.9648, 0.6875, 0.0352]
(values rounded by hand to 4 digits so I don’t have to type all digits)

after having this written into the color-array and then used to generate the texture3D, the corresponding values looks in the Debug.Log(texture.GetPixels()[index]) like this:

[0.514, 0.988, 0.984, 0.569, 0.055] and [0.494, 0.988, 0.965, 0.686, 0.035]

Whats the reason for this strange rounding behavior marked in red?

What’s the texture format? RGBA32 has only 8 bits per channel, so 256 different values between 0 and 1.

Yes it is RGBA32

Okay I see:
a 0.5156 becomes rounded into 0.514 because of:
0.5156/(1/255) = 131.478 → rounded into 131 and then 131 * (1/255) = 0.5137 => 0.514 right?

thx for that hint

1 Like