Thanks to visit codestin.com
Credit goes to github.com

Skip to content

renderer: incorrect BlendMode behaviors  #3072

@RuiwenTang

Description

@RuiwenTang

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:


//Normal
auto shape1 = tvg::Shape::gen();
shape1->appendRect(0, 0, 400, 400, 50, 50);
shape1->fill(0, 255, 255);
shape1->blend(tvg::BlendMethod::Normal);
canvas->push(shape1);

// direct draw shape with blend mode
auto shape = tvg::Shape::gen();
shape->appendRect(0, 0, 200, 200, 50, 50);
shape->fill(255, 255, 255, 250);
shape->blend(tvg::BlendMethod::ColorDodge);
canvas->push(shape);

This code get the following result:
截屏2024-12-23 下午5 53 22


But if put the shape inside a scene, even if the scene only contains one shape, like this:

//Normal
auto shape1 = tvg::Shape::gen();
shape1->appendRect(0, 0, 400, 400, 50, 50);
shape1->fill(0, 255, 255);
shape1->blend(tvg::BlendMethod::Normal);
canvas->push(shape1);


//ColorDodge On the scene
auto scene = tvg::Scene::gen();
scene->blend(tvg::BlendMethod::ColorDodge);

auto shape = tvg::Shape::gen();
shape->appendRect(0, 0, 200, 200, 50, 50);
shape->fill(255, 255, 255, 250);
scene->push(shape);

canvas->push(scene);

Got this result:
截屏2024-12-23 下午5 57 10

Some blend modes seem to draw nothing when DstColor is all zeros, and this behavior is different from skia or impeller or html & css.
I'm going to align SKIA's Blend behavior in the GL backend by following this reference : https://github.com/google/skia/blob/main/include/core/SkBlendMode.h

Metadata

Metadata

Labels

cpuSoftware render backendenhancementImprove featuresglOpenGL/WebGL render backendwebgpuWebGPU render backend

Type

No type

Projects

Status

Done 1.0

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions