webgpu / webgpu-samples

WebGPU Samples
https://webgpu.github.io/webgpu-samples/
BSD 3-Clause "New" or "Revised" License
1.74k stars 297 forks source link

Add dual source blending sample #441

Open beaufortfrancois opened 3 weeks ago

beaufortfrancois commented 3 weeks ago

I think a WebGPU sample illustrating the dual source blending feature would be nice. @Jiawei-Shao Did you have something in mind already?

Jiawei-Shao commented 3 weeks ago

No I haven't. I just know it is useful in Skia. Maybe I can prepare and add one to this repository.

beaufortfrancois commented 3 weeks ago

Chatted with @Kangz, and we're not 100% sure a dual-source blend is the best way for you to spend your time. But hey, I'm still game for one if you are!

kainino0x commented 2 weeks ago

Comment or assign yourself if you plan to work on it, otherwise this one can be "contributions welcome"!

https://registry.khronos.org/OpenGL/extensions/ARB/ARB_blend_func_extended.txt says:

Example Use Cases

    There are several potential uses for this functionality. A first example
    is in the implementation of sub-pixel accurate font rendering algorithms.
    Given a known layout of pixel elements (red, green and blue components),
    coverage may be calculated independently for each element and passed
    to the blender in the second source color as a per-channel opacity. To use
    this mode, use the following blend functions:

        glBlendFunc(GL_SRC1_COLOR, GL_ONE_MINUS_SRC1_COLOR);

    As a second example, consider a partially reflective colored glass window.
    It will attenuate light passing through it, and reflect some of the light
    that strikes it. Using an appropriate combination of functions, this effect
    may be simulated in a single pass using only fixed-function blending
    hardware. In this case, the following blend functions may be used:

        glBlendFunc(GL_SRC_ALPHA, GL_SRC1_COLOR);