Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <a href="https://developer.mozilla.org/samples/canvas-tutorial/6_1_canvas_composite.html" rel="nofollow noreferrer">composite modes</a> are as you find them. You can't composite any better than this as far as I am aware, without manually <a href="https://stackoverflow.com/questions/4899799/whats-the-best-way-to-set-a-single-pixel-in-an-html5-canvas">setting pixels</a>. If you update your question with an explicit description of how you want to blend the pixels, I will update my answer accordingly.</p> <p>So what's are the per-pixel solutions?</p> <p>There are 2 main pixel-based approaches I can see that would begin to solve this problem</p> <ol> <li><p>Draw onto a hidden context and blend with a manual function</p></li> <li><p>Write a function that calculates the gradient manually and applies a custom blending function.</p></li> </ol> <p>Your first option is more versatile than the second in the sense that you can draw whatever you like using the normal canvas methods, and then blend this canvas onto your visible canvas. See @Phrogz <a href="https://github.com/Phrogz/context-blender" rel="nofollow noreferrer">context-blender</a> project for a good idea of how to blend one context onto another</p> <p>The second option is necessary when you need to draw in a way that the canvas doesn't facilitate by default.</p> <p>The largest difficulty to contend with is the alpha transparency due to the fact you could have contents behind the radial gradient. Once you have drawn on top of a background image, it's near impossible to see what that was before you drew over the top of it, unless you keep a copy of that background. Even on a per-pixel basis you have the difficulty: <strong>blending an image over the top of another image would not work</strong>.</p> <p>Essentially that means that compositing your image of multiple translucent gradients on top of your visible canvas, regardless of your choice of generic compositing function, isn't going to work unless that canvas has a transparent background to begin with. </p> <p>In the spirit of option 1, you could create a blank context and render multiple gradients onto it. Then render this on top.</p> <p>And in the spirit of option 2, if you are able to define <strong>all</strong> of the points before rendering, you could calculate the image and blending from those points in a single pass.</p> <p>Combining the one-pass rendering technique with a background context will allow you to draw the contour on top of the visible canvas without making a single manual pixel read, only pixel writes.</p> <p>Nowhere near as elegant I know, but it may be the only real way to achieve what I would call an alpha blended contour effect on the 2D canvas.</p> <hr> <p>I think the per pixel blend function you need would choose the pixel from the source and destination with the largest alpha value.</p> <pre><code>if (src.a &lt;= dst.a) { result = dst; } else { result = src; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload