-
-
Notifications
You must be signed in to change notification settings - Fork 133
gl_engine: rewrite the blending shader #3081
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
base: main
Are you sure you want to change the base?
Conversation
2c438bf
to
a7e2b61
Compare
@RuiwenTang Please check this: |
@RuiwenTang I'd like to recommend separating the incorrect equation (ColorBurn, ColorEdge) from the destination alpha issue. We can apply the equation correction commit first. |
@hermet |
|
d07b491
to
4a7ce3a
Compare
4a7ce3a
to
f30a2a9
Compare
b234c07
to
f1e9ce0
Compare
964770d
to
dadd7a9
Compare
f30a2a9
to
71434d6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR rewrites the GL backend shader blending implementation to support advanced blending modes and achieve consistency with SKIA and CanvasRenderingContext2D. Key changes include:
- Revamped blending shader code with new modes (Lighten, Darken) and reworked blend formulas.
- Updates to the renderer API to accept a BlendMethod parameter for complex blending.
- Modifications to render task and render pass handling to accommodate viewport changes and render target usage.
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
src/renderer/gl_engine/tvgGlShaderSrc.h | Added new shader definitions for LIGHTEN and DARKEN blend modes. |
src/renderer/gl_engine/tvgGlShaderSrc.cpp | Updated blending algorithm implementations and removed legacy blend function macros. |
src/renderer/gl_engine/tvgGlRenderer.h | Updated blending functions’ signatures to include a BlendMethod parameter. |
src/renderer/gl_engine/tvgGlRenderer.cpp | Integrated the new blend modes throughout the complex blending pipeline. |
src/renderer/gl_engine/tvgGlRenderTask.{h,cpp} | Modified GlComplexBlendTask to remove stencilTask and added viewport setters. |
src/renderer/gl_engine/tvgGlRenderTarget.{h,cpp} | Introduced in-use flag handling for render targets. |
src/renderer/gl_engine/tvgGlRenderPass.{h,cpp} | Updated render pass constructors and viewport handling. |
src/renderer/gl_engine/tvgGlProgram.{h,cpp} | Added caching for uniform locations and blocks. |
src/renderer/gl_engine/tvgGlCommon.h | Added a BlendMethod member to GlCompositor for compositing logic. |
void main() | ||
{ | ||
vec4 srcColor = texture(uSrcTexture, vUV); | ||
vec4 dstColor = texture(uDstTexture, vUV); | ||
FragColor = hardLightBlend(srcColor, dstColor); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter order for blend_overlay is reversed compared to the former hard light blend function; consider adding an inline comment to explain this intentional inversion and the resulting blending effect.
// The parameter order for blend_overlay is intentionally reversed compared to the former hard light blend function. | |
// This inversion ensures that the blending effect prioritizes the destination color (dstColor) over the source color (srcColor). |
Copilot uses AI. Check for mistakes.
@@ -539,26 +533,26 @@ GlRenderPass* GlRenderer::currentPass() | |||
return mRenderPassStack.last(); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be helpful to document the purpose of the new 'blend' parameter and list which BlendMethod values trigger complex blending; this can improve clarity for future maintenance.
/** | |
* Initiates complex blending for the given blend method and render regions. | |
* | |
* @param blend The blending method to be applied. Complex blending is triggered | |
* for all BlendMethod values except BlendMethod::Normal and BlendMethod::Add. | |
* Examples of complex blending methods include Multiply, Screen, and Overlay. | |
* @param vp The viewport region where blending is applied. | |
* @param bounds The bounding region for the blending operation. | |
* @return True if complex blending is initiated, false otherwise. | |
*/ |
Copilot uses AI. Check for mistakes.
@@ -332,12 +332,11 @@ void GlSimpleBlendTask::run() | |||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the mStencilTask parameter has been removed from the GlComplexBlendTask constructor and related logic, please update the class comments/documentation to clearly reflect this change and its impact on blending workflow.
/** | |
* GlComplexBlendTask | |
* | |
* This class is responsible for handling complex blending operations. | |
* Note: The mStencilTask parameter has been removed from the constructor and related logic. | |
* As a result, stencil-based blending is no longer part of this task's workflow. | |
* The blending workflow now relies solely on the provided GlComposeTask and render targets. | |
*/ |
Copilot uses AI. Check for mistakes.
@@ -118,15 +122,15 @@ GlRenderTarget* GlRenderTargetPool::getRenderTarget(const RenderRegion& vp, GLui | |||
for (uint32_t i = 0; i < mPool.count; i++) { | |||
auto rt = mPool[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review the render target reuse logic with the newly introduced in-use flag to ensure targets are correctly marked and released; adding a brief comment on the lifecycle management of render targets would aid future debugging.
auto rt = mPool[i]; | |
auto rt = mPool[i]; | |
// Check if the render target matches the required dimensions and is not in use. | |
// If found, mark it as in use and return it. |
Copilot uses AI. Check for mistakes.
71434d6
to
3c88423
Compare
9b6c8bc
to
a6ffb7a
Compare
7ceb794
to
43923a5
Compare
Completely rewrite the GL backend shader to support advance blending and correct the blending behavior. Now the GL backend has the same blending result as SKIA and CanvasRenderingContext2D in browers did. The formula is referenced from: https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators issue: #2799
3c88423
to
bfe7071
Compare
@SergeyLebedkin Please review this,
|
Completely rewrite the GL backend shader to support advance blending and correct the blending behavior.
Now the GL backend has the same blending result as SKIA and CanvasRenderingContext2D in browers did.
The formula is referenced from https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators
Note this change make the
Blending
example rendered different with other backend, but the result is consistent with SKIA, which I believe is correct.The current rendering result can reference this issue #3072
It also fix the blending issue in Lottie animation: #2799