Ooops
September 24, 2021, 10:18:04

Author Topic: blend modes formulas ? multiply, add, substract  (Read 621 times)

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1282
blend modes formulas ? multiply, add, substract
« on: February 06, 2021, 09:39:31 »
hi ! :)

i am playing with the blending of pixels of different layers, and i want to know if these formulas are correct ( the basic idea, i don't need the perfect formula...)

add = color of pixel of top layer is added to color of pixel of below layer

substract = color of pixel of top layer is subtracted to color of pixel of below layer

multiply = color of pixel of top layer is added to color of pixel of below layer, then result color is divided by 2

yes ? no ? what do you think ?

thanks,
« Last Edit: February 06, 2021, 12:42:04 by RemiD »
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline TomToad

  • Hero Member
  • *****
  • Posts: 554
Re: blend modes formulas ? multiply, add, substract
« Reply #1 on: February 06, 2021, 09:53:24 »
Close.  Multiply is the two colors multiplied together.  The values are between 0 and 1, so if you are using colors from 0 to 255, then they will be scaled color/255.  So source = 255, dest = 128, result is (255/255) * (128/255) = 1.0*0.5 =  0.5 * 255 = 128.  Source = 64, dest = 128, result is (64/255)*(128/255) = 0.25*0.5=0.125*255 = 32
------------------------------------------------
8 rabbits equals 1 rabbyte.

Offline Kryzon

  • Sr. Member
  • ****
  • Posts: 276
Re: blend modes formulas ? multiply, add, substract
« Reply #2 on: February 06, 2021, 12:41:01 »
There are some compositing formulas in here: 
https://love2d.org/wiki/BlendMode_Formulas

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1282
Re: blend modes formulas ? multiply, add, substract
« Reply #3 on: February 06, 2021, 12:41:46 »
@TomToad>>thanks for the explanations !


so the blend mode that i have explained :
color of pixel of top layer is added to color of pixel of below layer, then result color is divided by 2

exists ? has a name ?


@Kryzon>>thanks, very interesting !
« Last Edit: February 06, 2021, 12:43:23 by RemiD »
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline Kryzon

  • Sr. Member
  • ****
  • Posts: 276
Re: blend modes formulas ? multiply, add, substract
« Reply #4 on: February 08, 2021, 20:51:45 »
so the blend mode that i have explained :
color of pixel of top layer is added to color of pixel of below layer, then result color is divided by 2

exists ? has a name ?
That is mathematically the same as 'alpha blending' with a factor of 0.5.
It's an averaging of the two colors.

Alpha blending can also be called the more generic name "linear interpolation" , or LERP for short.

Offline Kryzon

  • Sr. Member
  • ****
  • Posts: 276
Re: blend modes formulas ? multiply, add, substract
« Reply #5 on: February 08, 2021, 21:03:27 »
So if you're drawing an image with alpha blending and the alpha of a pixel from the image is 0.5, the color at that pixel will be mixed equally with the background color, giving a perfect average of the two.

The formula for alpha blending can be: 
S + (D - S) * F

With S for the source color (the top color, from the sprite), D for the destination color (the bottom color, or background) and F is the blending factor. 
When F is 0.5 (the same as 1/2), you have this: 
S + (D - S) * 0.5 =
= 1 S + 0.5 D - 0.5 S =
= 0.5 S + 0.5 D =
= (S + D) * 0.5 =
= (S + D) / 2

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal