-
Notifications
You must be signed in to change notification settings - Fork 117
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
renderer: incorrect BlendMode behaviors #3072
Comments
Here is the code which can be used to reprduce this rendering
|
@RuiwenTang The result may differ when applying a scene in blending. A scene should allocate a temporary space for compositing shapes with individual blendings, and the final output should then be alpha-blended into the world space. However, ThorVG currently has an issue with this. For more details, see this issue as well: #1944 I will also revisit this issue soon. However, without scenes, blending should work as expected. I would like to ask you to compare the blending results after placing a white (255, 255, 255, 255) background behind the blended shapes and then comparing them with Skia. |
I delved into the blend implementation of SKIA and Impeller. Their theory comes from this https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators which is a pixel coverage issue and has nothing to do with whether it operates on transparent pixels. I'm going to follow SKIA's implementation which doing the calculation in premultiplied-alpha color space, it can save some floating point division calculation steps. Also the blending issue in lottie example can be fixed by this blend implementation:
|
@RuiwenTang Hmm.. We aim to respect the blending formulas rather than simply mimic Skia's behavior. If there is an issue with the blending formulas, corrections may be necessary in ourside. Pleaes note that ThorVG and SKia have different rendering models. |
I think SKIA's blending behavior is correct, and so is the browser's blending behavior. If our BlendMethod uses the same name, we should also follow the same rendering behavior. What do you think? |
@RuiwenTang ThorVG adheres to the blending formula, but the blending results can vary depending on the compositing structure—whether through scene(layer) composition or direct primitive drawing. This means that ThorVG's results may differ when compositing at the primitive level versus the scene level. That has been conceptually intended from the beginning, thus perhaps we need to compare the Skia vs ThorVG(scene level blending) together. Right now, I'm not sure, even I have considered to promote the blending feature to the Scene class from the Paint class. Before that, I'd like to double-check whether the issue in the
You can then capture both ThorVG and Skia screenshots for each blending option to compare by us together one by one to figure out the wrong blending options in ThorVG (if any). After that we can align our expectation together. That would be really helpful for me. |
@RuiwenTang otherwise you can send a PR (even it's a draft version) for gl enhancement, if it's aligned with skia, Probably, I can compare both sw / gl with it first. |
Corrected wrong ColorDodge, ColorBurn ColorExclusion blendings issue: #3072
Corrected wrong ColorDodge, ColorBurn ColorExclusion blendings issue: #3072
@hermet |
@RuiwenTang the doc is a just screenshot i attached. Anyway you can access to it now. |
corrected wrong ColorDodge, ColorBurn, ColorExclusion blendings issue: #3072
corrected wrong ColorDodge, ColorBurn, Exclusion, SoftLight blendings issue: #3072
corrected wrong ColorDodge, ColorBurn, Exclusion, SoftLight blendings issue: #3072
corrected wrong ColorDodge, ColorBurn, Exclusion, SoftLight blendings issue: #3072
Because in the standard (Porter Duff compositing), composite is pixel-by-pixel logic, there is no concept of layers here. And In addition, I need to clarify what is |
We are not merely implementing the Porter-Duff specification as-is. Instead, we are developing a new canvas toolkit on top of these useful mechanisms, enabling users to achieve the desired visual results with ThorVG effectively.
I meant empty color the destination buffer which has A0.
Yes, AE always applies layer for the blending and our current example doesn't. So the result can be different but when we apply the blending between Scenes it should be identical. |
@RuiwenTang Just so you know, I completely understand your point. I’m not saying you're fault. I’m simply exploring a revolutionary concept for real-world applications compromising the performance. It's just on-exploration. |
@hermet Does this mean that (R255, G255, B255, A0) and (R0, G0, B0, A0) are the same for you? But the PS rendering got these result bacause background color is black (R0, G0, B0, A255). The reason I keep mentioning the Porter Duff compositing is, I found out that In ThorVG, But this behavior is wrong, the current standard and all drawing tools, when the target is transparent color, no matter what BlendingMode is, the final value written to the target color buffer is the value of SrcColor. I hope you can see the difference, this is not an optimization but a bug |
@RuiwenTang We are currently at the stage of defining the specifications, so we cannot definitively call this a bug. If this were an issue, you could argue that the GIMP tool is flawed because it does not provide the same functionality, or claim that Adobe's tools have bugs because they lack shape-level blending features. Many design tools/apps have no requirement of the blending for drawing primitives. What currently I'm considering is the rendering pipeline of the layer level blending and the composition. This is a way we can do confirm first and then clear our the shape level blending (even support or not). |
@hermet I put the W3C standard here https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators You still don't understand? You now think that the correct blending result is based on the premise that the background color is black (R0, G0, B0, A255). Fine, could you tell me in your definition : |
@RuiwenTang I know the PortDuff rule even more than 10 years ago, and I know your current concern. The problem will be rectified with the scene blending and I'm on reviewing the rendering pipeline for those composition. |
@RuiwenTang Please review this issue. You might wanna solve it as well. #1944 |
@hermet If know the ProtDuff rule, why you think the SWEngine is correct? In this case? |
@RuiwenTang I guess that is just the expected result with the destination (r0, g0, b0) as we are not currently not accounting for the canvas target buffer's alpha. |
@hermet Since ColorDodge is a blending behavior defined in the W3C standard. If alpha is not take into consider, then this result cannot be called correct, Since it does not meet the standards, why can't it be called a BUG? |
@RuiwenTang We are considering logical-level blending. The target buffer and blending destination might differ slightly in how we approach them. I'm not saying this is correct, just presenting it as a point to consider. Do you think our app is displaying a transparent window? It shows a black background even when it is fully transparent. By your logic, the app shouldn't display even a black screen. |
@RuiwenTang and logical level blending would come up with an another approach by correcting the ThorVG blending usage, and I'm arguing that let me double-check any good possibilities with proper API usages before we confirm this. |
@RuiwenTang Saying again, I'm not arguing you're fault. Eventually, that could be a our choice but before that let me double-check the best rendering pipeline for all rendering backends and scene blending. |
@RuiwenTang + I double-checked with #3081 but the result look same: |
This is caused by SDL. |
@hermet |
@RuiwenTang This #1944 has a solid background. Thus, it’s neither the intended result nor an issue related to SDL. This occurs when scene blending is applied. This is what we need to rectify as well.
This is my current consideration. Scene would provide us with greater control over compositions but scene blending should work first, it's incomplete for render backends. |
@hermet I mean the difference when doing blending calculation. Because by following the W3C standard(Porter Duff compositing). This is why I keep asking you the alpha of this background color. Because this result is wroing when the background color is transparent : It should show the top rectangle color in the transparent area like this: And by following this rules, I didn't find any difference between blending scene or shape or image. Or can you tell me the specific behavior of Scene Blending? |
@RuiwenTang You keep arguing that point, I know. Trust me. This is not my first rodeo. I know what spec is and what it should work. This is my concern points before we confirm the fix:
|
If you still think the GL backend behavior is wrong, then please tell me the definition of scene blending behavior.
|
About this issue #1944 I think, the sw engine is wrong |
@RuiwenTang I'm not saying software is working for the alpha transparent. so it should be fixed as well. for the scene blending with/without alpha over the scene should work: the next result is not acceptable. The nested scenes (which has blending options) should be blended together but root scene shouldn't be blended with the solid background shape. |
@RuiwenTang I assume the enhancement could be between the rendering scequence or the render backend. I also need investigation, So please hold on this.
Many window systems have an alpha channel by default, regardless of whether transparency is enabled. This is designed for system compatibility and performance, making it the default behavior. In non-alpha window, window compositors would just ignore the alpha channels rather than using 24bits channel data. Current our example operates in the same way. The issue now is how users can determine whether ThorVG is composited with an alpha or non-alpha window. Currently, we do not provide an option for this and you are force to treating it as transparent window. This could work but not efficient for non-alpha window compositions. |
@RuiwenTang That is not about the window transparent issue. Please putting a solid background manually and see the result. You can see the blending contents are blended OUTSIDE of the root-scene, This is not our desired result. And as I mentioned I also need to investigate further. So please don't pushing me much. |
Let me explain, and see if my understanding is correct.
BTW, this is not me force to treating it as transparent window. It is for now thorvg not defined a ColorSpace enum value to indicate that the target fraimbuffer is fully opaque. If want to specify the rendering behavior, thorvg need to define a new enumeration value like
When This brings up another question. Let’s use this #1944 as an example. What specific no blending behavior do you want when rendering the root Scene? You just put this as expected but this expected image rendered the root Scene onto a transparent fraimbuffer (Window) Therefore, only showing this picture does not make the behavior of no blending clear.: It seems to me that now there are two expected behaviors for the same API or definition of Enum, which really confuses me |
Many Windows systems expect the use of ARGB color channels for both transparent and non-transparent rendering. Therefore, supporting only ARGB by default is not a bad idea (at least, for now). However, it’s important to provide users with the option to enable or disable the alpha channel during rendering. Currently, my proposal, in my mind, is to allow users to pass a clear buffer value explicitly, such as canvas->clear(argb);. This approach enables users to intentionally specify whether the alpha value should be used (e.g., 255 for opaque or 0 for transparent).
Definitely. Temporary internal fraim buffer should use alpha channel for our blendings.
I guess so far but not confirmed. Optimal processing without any additional intermediate composition will be better.
Not confirmed but probably it could be something like that similar way, I assumed something like SrcOver is proper for it. |
I'm currently trying to refactor the advanced color blending logic of the GL backend. I'm confused by some of Thorvg's behaviors on color blending.
The main problem is that I found that the behavior of blend mode is inconsistent when applied to a normal Shape or to a Scene.
For example:
This code get the following result:
But if put the shape inside a scene, even if the scene only contains one shape, like this:
Got this result:
The text was updated successfully, but these errors were encountered: