# Manually calculate additive blendmode with pixels\[\]

**URL:** <https://discourse.processing.org/t/manually-calculate-additive-blendmode-with-pixels/28031>\
**Category:** Coding Questions\
**Created:** [February 23, 2021, 6:49pm UTC](https://discourse.processing.org/t/manually-calculate-additive-blendmode-with-pixels/28031 "2021-02-23T18:49:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lilzer7](https://avatars.discourse-cdn.com/v4/letter/l/9fc348/32.png) [@lilzer7](https://discourse.processing.org/u/lilzer7)\
**Post date:** [February 23, 2021, 6:49pm UTC](https://discourse.processing.org/t/manually-calculate-additive-blendmode-with-pixels/28031/1 "2021-02-23T18:49:05Z")

</div>

Hi,

I’m currently coding a program in which I draw some random generated patterns like this :

```auto
function setup() {
     colorMode(RGB, 255, 255, 255, 255);
     blendMode(ADD);
}

function draw() {
    for(var i = 0; i < 20000; i++)
    {
      x = generateCoordinatesX();
      y = generateCoordinateY();

      var pointColor = generateColor(); //rgba

      stroke(pointColor);
      point(x, y);
     }
}

```

When two ore more points get supperposed, they are displayed with additive BlendMode.  
As the number of point is quite big, it slows down the simulation a lot. I tried to adapt this code with the pixels method like bellow to speed up things :

```auto
function draw() {
    loadPixels();
    for(var i = 0; i < 20000; i++)
    {
      x = generateCoordinatesX();
      y = generateCoordinateY();
      var index = (x + y * width)*4;
      
      pixels[index+0] += ???;
      pixels[index+1] += ???;
      pixels[index+2] += ???;
      pixels[index+3] += ???;
     }
     updatePixels();
}

```

The issue is that i dont know how to generate the R,G,B,A value so that it behave with additive Blending like my first version.  
Is there a way to manually calculate this ? I tried with formulas i found but after some tests, the results are different.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [February 23, 2021, 8:34pm UTC](https://discourse.processing.org/t/manually-calculate-additive-blendmode-with-pixels/28031/2 "2021-02-23T20:34:09Z")

</div>

What did you try? Do you have sketches you made? It would be helpful to post complete sketches (not meaning functional but the whole sketch not a snippet) for others to debug!

Additive blending is literally adding r, g, b channels independently (assuming alpha is opaque).
