There are two examples. One does not work correctly - “back_color”, the other as it should - “fill_color”. Also, everything is fine with white color in both examples.
You can also change the width and height of the buffer to see it in higher resolution. 512 pixels maximum.
Maybe I need to consider something when I use blending?
What this looks like to me is that the red and the blue are being added together instead of being “normal” as in Photoshop layer. I assume you may not be multiplying the alpha onto the red layer when setting it? So at full alpha 1 of blue the red bg should be multiplied by 0. It should be something like this I think https://github.com/subsoap/defblend/blob/master/defblend/materials/sprite/blend_normal.fp I have not looked at the drawpixels source though.
I’ll try to describe the problem again, in the example it’s easier to understand.
For the first image, where everything is fine:
I am creating a sprite that uses material with standard shaders.
In the code, I create a buffer (in the example 64x64).
I fill the pixels in the buffer in red.
I draw an object with alpha. I added normal blending to the library. And everything works well.
For second:
Creating a sprite that uses material with standard shaders.
Create a buffer.
fill the pixels in the buffer with (0, 0, 0, 0). As you can see alpha at 0, i.e. when drawing, I don’t have to mix pixels with anything.
I draw an object with alpha. For example, a pixel may be (255, 255, 255, 100).
I make the game background red.
Pixels in which alpha is not 0 or 255 behave strangely. More precisely, they behave as if they are mixed with white color.
How can I record pixels so that they behave as translucent and render normally?
This can be done?
Maybe something needs to be considered when recording pixels?
If the pixel in which the color will be written is empty (alpha is 0), then the pixel is just written.
For example, if you need to write red with alpha, it simply writes 4 numbers to the buffer (255, 0, 0, 130).
For such cases, I do not use normal blending, because I just do not know what to mix with the pixel.
I don’t know how can I find out the pixels of the background or sprite that are behind the sprite into which we draw from the buffer.
The problem is that sprite blending works strangely, you can see the topmost post.
The problem can really be in premultiplied alpha. Is it possible to somehow set up my own blending to sprite, except for standard ones?
This is how alpha behaves when another sprite is behind: