10-14-2024, 04:46 PM
First, I am sorry for the late reply. It seems that there are some problems with the emails from the forum - I get some of them, but not others.
After checking your demo app, I can say that the VertexColorMaterial is correctly rendered.
The problem is that the colors for the VertexColorMaterial should be alpha-premultiplied. This means that if you take a Color3 with red, green and blue and add an alpha value to create Color4, you need to multiply all the color components with alpha: Color4(red * alpha, green * alpha, blue * alpha, alpha).
I guess that in your sample you wanted to use red colors with increasing transparency. You should use the following:
vertColors[idx] = new Color4(thing, 0, 0, thing);
So, a red color (1,0,0) that is premultiplied by the alpha value (thing in your sample) = Color4(thing, 0, 0, thing)
Instead you used "new Color4(128, thing, thing, thing)".
Also note that the valid values for the color components in Color4 are in range from 0 to 1 and not from 0 to 255 (those are float values and not byte values; you can use FromByteRgba static method to create Color4 with byte values).
When such value (128,0.5,0.5,0.5) is alpha-blended with the exiting value, the alpha value is multiplied by 128 and added to the existing color multiplied by 1-alpha. This almost always gives the value of the red component bigger than 1 - so you alost always get fully red color. This is also seen in your demo.
I will improve the documentation and sample to provide information about using alpha pre-multiplied color values. I will also consider adding a property that will define if the colors are alpha pre-multiplied.
I am sorry that this was not more clear.
About your comment:
"Also in the screenshot you attached in your previous post, half of the circle is missing behind the rectangle."
If you look closely enough, you will see that everything is correctly rendered. When the colors of the box with vertex color material and the sphere are blended, the color is almost the same as the background color, but on the right side it is possible to see the edge of the sphere.
If you start the sample and rotate the camera, you easily get the proof that everything is correct:
PS: I have removed your attachment with the demo app because the source had your license key. Please send such code by email or remove the license.
After checking your demo app, I can say that the VertexColorMaterial is correctly rendered.
The problem is that the colors for the VertexColorMaterial should be alpha-premultiplied. This means that if you take a Color3 with red, green and blue and add an alpha value to create Color4, you need to multiply all the color components with alpha: Color4(red * alpha, green * alpha, blue * alpha, alpha).
I guess that in your sample you wanted to use red colors with increasing transparency. You should use the following:
vertColors[idx] = new Color4(thing, 0, 0, thing);
So, a red color (1,0,0) that is premultiplied by the alpha value (thing in your sample) = Color4(thing, 0, 0, thing)
Instead you used "new Color4(128, thing, thing, thing)".
Also note that the valid values for the color components in Color4 are in range from 0 to 1 and not from 0 to 255 (those are float values and not byte values; you can use FromByteRgba static method to create Color4 with byte values).
When such value (128,0.5,0.5,0.5) is alpha-blended with the exiting value, the alpha value is multiplied by 128 and added to the existing color multiplied by 1-alpha. This almost always gives the value of the red component bigger than 1 - so you alost always get fully red color. This is also seen in your demo.
I will improve the documentation and sample to provide information about using alpha pre-multiplied color values. I will also consider adding a property that will define if the colors are alpha pre-multiplied.
I am sorry that this was not more clear.
About your comment:
"Also in the screenshot you attached in your previous post, half of the circle is missing behind the rectangle."
If you look closely enough, you will see that everything is correctly rendered. When the colors of the box with vertex color material and the sphere are blended, the color is almost the same as the background color, but on the right side it is possible to see the edge of the sphere.
If you start the sample and rotate the camera, you easily get the proof that everything is correct:
PS: I have removed your attachment with the demo app because the source had your license key. Please send such code by email or remove the license.
Andrej Benedik