Can someone helps me with blend mode?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
utunnels
Citizen
Posts: 75
Joined: Fri Jan 06, 2012 5:20 pm

Can someone helps me with blend mode?

Post by utunnels »

I need some special blend effects, but I'm not sure how to write.

1. Additive with alpha

It works like this:

R = MIN(dR + sR*A, 255)
G = MIN(dG + sG*A, 255)
B = MIN(dB + sB*A, 255)

In which A is a custom alpha factor.

2. Color additive

I don't know how to call this. Basically it uses additive blend to source image with a color before using normal alpha blend with destination image.
Maybe it can be divided into 2 steps, but I don't know how to blend a color instead of an image.

3. ...

Again I don't know how to call this. It is similar to 1.

R = MIN(dR + sR*sR, 255)
G = MIN(dG + sG*sG, 255)
B = MIN(dB + sB*sB, 255)

4. Can I use an external alpha mask?
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Can someone helps me with blend mode?

Post by vrld »

MarekkPie wrote:[links to the wiki without any explanation]
This is not helping much.
utunnels wrote:1. Additive with alpha
With A = 1 - sA, this is equivalent to the "premultiplied" blend mode coming in LÖVE 0.8. The premultiplied blend equation is:

Code: Select all

R = srcR + (1 - srcA) * dstR
There is no (easy) other way to set A to a custom value.[1]
utunnels wrote:2. Color additive
Use love.graphics.setColor(r,g,b,a) before drawing the image. This will tint the image in the defined color. Be sure to reset it to white afterwards.
utunnels wrote:Again I don't know how to call this. It is similar to 1.
This is not possible without pixel effects (coming in 0.8).
utunnels wrote:4. Can I use an external alpha mask?
Not with blend modes, but it is possible with pixel effects. 0.8 will also introduce stencils, which are sort of an alpha map (but then again, they aren't). With stencils, you can set some regions to be fully opaque, whereas others will be fully transparent.

[1] In theory this should be possible and there was some discussion about allowing the user to define new blend modes by exposing the underlying blend equations quite a while ago, but as it stands, this will not happen.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
utunnels
Citizen
Posts: 75
Joined: Fri Jan 06, 2012 5:20 pm

Re: Can someone helps me with blend mode?

Post by utunnels »

vrld wrote:With A = 1 - sA, this is equivalent to the "premultiplied" blend mode coming in LÖVE 0.8. The premultiplied blend equation is:

Code: Select all

R = srcR + (1 - srcA) * dstR
There is no (easy) other way to set A to a custom value.
Not exactly, the original equation (you may notice, I'm trying to port something) is based on additive, except a custom alpha is applied to the source image.
However, I just tested setColor works perfectly for adding custom A, so this is solved.

Code: Select all

  love.graphics.setColor(255,255,255,128)
  love.graphics.setBlendMode("additive")
  love.graphics.draw(sprite, 200, 200)
Use love.graphics.setColor(r,g,b,a) before drawing the image. This will tint the image in the defined color. Be sure to reset it to white afterwards.
But setColor doesn't make the image brighter, if I recall correctly?
For example, a pixel is (128,128,128), after using setColor(128, 0 0) it becomes (64, 0, 0) instead of (255, 128, 128)
This is not possible without pixel effects (coming in 0.8).
I see.
0.8 will also introduce stencils, which are sort of an alpha map (but then again, they aren't). With stencils, you can set some regions to be fully opaque, whereas others will be fully transparent.
Maybe that is what I want.
I want to make some sort of window shutter effect like those transitions in PowerPoint.
Post Reply

Who is online

Users browsing this forum: No registered users and 80 guests