+
Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RuiwenTang
Copy link
Collaborator

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

@github-actions github-actions bot added the cpu Software render backend label Dec 27, 2024
@hermet hermet added the enhancement Improve features label Dec 27, 2024
@RuiwenTang RuiwenTang force-pushed the ruiwen/composite_blending branch 2 times, most recently from 2c438bf to a7e2b61 Compare January 3, 2025 08:11
@hermet
Copy link
Member

hermet commented Jan 7, 2025

@RuiwenTang Please check this:

image

@hermet
Copy link
Member

hermet commented Jan 7, 2025

image

@hermet
Copy link
Member

hermet commented Jan 9, 2025

@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.

sw:
image

gl:
image

@RuiwenTang
Copy link
Collaborator Author

@hermet
image
This is what I have been saying. I think this PR fixes all the problems of GLEngine in Blending, and I think that all of the result is correct.

@hermet
Copy link
Member

hermet commented Jan 9, 2025

@hermet image This is what I have been saying. I think this PR fixes all the problems of GLEngine in Blending, and I think that all of the result is correct.

@RuiwenTang

  1. Separating commits per problems. That is our basic policy.
  2. You know, I didn't say that is the wrong result. I requested you to see me further the layer level scene blending first to put them together fix. If it's not harder for you, Please humor me.

@hermet hermet force-pushed the ruiwen/composite_blending branch 3 times, most recently from d07b491 to 4a7ce3a Compare January 14, 2025 03:20
@hermet hermet force-pushed the ruiwen/composite_blending branch from 4a7ce3a to f30a2a9 Compare February 7, 2025 04:24
@github-actions github-actions bot added the raster label Feb 7, 2025
@hermet hermet removed the raster label Feb 20, 2025
@hermet hermet force-pushed the main branch 2 times, most recently from b234c07 to f1e9ce0 Compare March 17, 2025 06:28
@hermet hermet force-pushed the main branch 2 times, most recently from 964770d to dadd7a9 Compare March 31, 2025 14:34
@hermet hermet force-pushed the ruiwen/composite_blending branch from f30a2a9 to 71434d6 Compare May 9, 2025 15:59
@github-actions github-actions bot added gl OpenGL/WebGL render backend and removed cpu Software render backend labels May 9, 2025
@hermet hermet requested a review from Copilot May 9, 2025 15:59
Copy link

@Copilot Copilot AI left a 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);

Copy link
Preview

Copilot AI May 9, 2025

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.

Suggested change
// 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();
}

Copy link
Preview

Copilot AI May 9, 2025

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.

Suggested change
/**
* 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);
}

Copy link
Preview

Copilot AI May 9, 2025

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.

Suggested change
/**
* 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];
Copy link
Preview

Copilot AI May 9, 2025

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.

Suggested change
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.

@hermet hermet force-pushed the main branch 5 times, most recently from 9b6c8bc to a6ffb7a Compare June 23, 2025 07:12
@hermet hermet force-pushed the main branch 5 times, most recently from 7ceb794 to 43923a5 Compare June 25, 2025 15:59
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
@hermet hermet force-pushed the ruiwen/composite_blending branch from 3c88423 to bfe7071 Compare June 30, 2025 03:09
@hermet
Copy link
Member

hermet commented Jul 3, 2025

@SergeyLebedkin Please review this,

  • Animation looks leaking gpu resources after this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve features gl OpenGL/WebGL render backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载