In order to get the desired behavior for 2D, please try the following methods:
- Change the axes 'SortMethod' property to 'childorder'. If there is 3D content in the axes, this property is set to 'depth'.
- Another work around is simply to not place objects in the same space, if the blending is important. The separation distance is a little challenging to calculate but may be determined via experimentation.
MATLAB graphics detects if you are trying to draw transparency in 3D and draws in a different way than it normally draws by using the 'Depth Peeling' method.
Depth Peeling is a mechanism used to draw transparency in a physically based scene. It essentially sorts the objects in each pixel from back to front and applies the blending equation layer by layer. It has a limitation in that it relies on the graphics depth buffer to do the sorting and can't handle drawing coincident surfaces (which is not a problem in physical models).
The blending equation is C = Sa + (1-a) D, where S is the next color, a is its opacity, and D is the destination color.
If surfaces could be coincident in the 3D reality, the actual color would be ambiguous as it's not clear which object is the source, and which is the destination.
There will be a numerical difference when calculating transparency based on the resolution of the color values since the values in the blending equation mentioned are 8-bit precision. In MATLAB, the resolution of the color values cannot reach a limit, i.e. the color, because of the limitation of using 8-bit values.
Please note that this is an issue with the way graphics rendering is done at the hardware level and MATLAB does not currently support HDR rendering.
The graphics card stores each pixel's color in a 32-bit integer: 8 bits each for Red, Green, Blue, and Alpha.
This means that each channel can have a value of 0-255. Usually, one can't see more than 255 gradations of each color, but the issue arises when we start to accumulate float values in 8-bit storage, which results in truncation error.