-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MultiMesh custom data bits are not accurate #93875
Comments
The colors are compressed internally to have 16 bit components (Line 1723): godot/drivers/gles3/storage/mesh_storage.cpp Lines 1710 to 1728 in f0d15bb
So some precision is lost: var mm: MultiMesh = MultiMesh.new()
mm.use_colors = true
mm.instance_count = 1
var color_in: Color = Color(0.3, 0.3, 0.3, 0.3)
mm.set_instance_color(0, color_in)
print(color_in == mm.get_instance_color(0)) # false;
print(mm.get_instance_color(0)) # (0.2998, 0.2998, 0.2998, 0.2998) This isn't well documented and has also been a problem for me before when I tried to use the custom data (which is compressed the same way). I think having the option to set the raw data would be ideal, at least for the custom data. |
ah, this makes sense. It really feels essential that there exists a way to pass in raw data into the custom data in some form. I can easily pack data into a 64-bit structure if the channels are only 16 bits. But due to the data compression, it doesn't seem like there is actually a way to achieve this at all even if I create my structure beforehand, since no matter what the data is going to get messed up even if the values put inside the color are a half_float |
Closed by #94942. |
Tested versions
4.3 beta2, 4.1.1 stable
System information
Godot v4.3.beta2 - Windows 10.0.19045 - GLES3 (Compatibility) - NVIDIA GeForce RTX 4050 Laptop GPU (NVIDIA; 31.0.15.5186) - 13th Gen Intel(R) Core(TM) i5-13500HX (20 Threads)
Issue description
Godot docs describe the Color variant as being composed of 4 32-bit values, one float for each value.
The custom data property of Multimesh allows us to use a single Color variant as multimesh custom data.
Theoretically, this allows us to pack up to 128 bits of custom data inside if we use bitwise operations and bit copying without conversions.
However, when done in practice, it doesn't actually work because the bits seem to not be preserved.
Steps to reproduce
I've set up an example project that is supposed to achieve the following task:
Since the custom data of multimesh instances accepts 1 Color value, and the docs state that a Color variant is composed of 4 32-bit values, in theory we could pack 4 different colors into 1 singular color by storing each color channel as a uint8 in a 32-bit integer.
It lines up perfectly, with each color being able to be represented as a 32-bit integer.
The following line creates the byte array of colors:
which can then be turned into a color as following by extracting 4 floats:
and then passed into the multimesh:
Then the shader splits each color up, and sets the vertex colors:
But then, when actually put to use, the values do not behave as expected - the colors are totally wrong.
Minimal reproduction project (MRP)
MultimeshBits.zip
The text was updated successfully, but these errors were encountered: