Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: New blend mode (Like Blend::Add but that uses source alpha)  (Read 9290 times)

0 Members and 1 Guest are viewing this topic.

tireswing

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • http://www.tireswinggames.com/
New blend mode (Like Blend::Add but that uses source alpha)
« on: February 27, 2009, 11:56:29 pm »
Blend::Add ignores the source image's alpha channel.
In my game, I am using some special effects where I want an additive blend mode, but I need it to use the source image's alpha channel as well.

The GL blend function I need is:
glBlendFunc(GL_SRC_ALPHA, GL_ONE)

It was really simple to change SFML to do this, but I'd like to stay standard to maintain a good upgrade path.  It would be helpful to add a new blend mode to handle this.

Thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
New blend mode (Like Blend::Add but that uses source alpha)
« Reply #1 on: February 28, 2009, 10:13:34 am »
Actually, I think there's no point ignoring the source alpha, so I could even use your solution as a replacement for Blend::Add instead of creating a new one.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
New blend mode (Like Blend::Add but that uses source alpha)
« Reply #2 on: February 28, 2009, 08:11:14 pm »
It's done.

Thanks for your feedback :)
Laurent Gomila - SFML developer

tireswing

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • http://www.tireswinggames.com/
New blend mode (Like Blend::Add but that uses source alpha)
« Reply #3 on: March 01, 2009, 03:16:37 am »
Sounds great! Thanks!!

UArchitect

  • Newbie
  • *
  • Posts: 5
    • View Profile
New blend mode (Like Blend::Add but that uses source alpha)
« Reply #4 on: March 02, 2009, 11:52:08 am »
rather than make a new thread i thought i would request some additional blending modes (also since you use glblendfunc for blending is there any chance in the future of being able to define the blending ourselves?)

anyway here are the blending modes i would like to request using the following two textures as an example:


Modulate
Modulate = src*dest+src*dest or (dest*src)*2 = glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);

useful for decal textures which can lighten and darken

Screen
Screen = src+(1-src)*dest = glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_COLOR);

same as "screen" blend mode in photoshop, its like add but doesnt overbrighten and doesnt look as harsh


thanks in advance if you consider any of these

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
New blend mode (Like Blend::Add but that uses source alpha)
« Reply #5 on: March 02, 2009, 12:57:42 pm »
Modulate --> it's like Blend::Multiply, except mine is not multiplied by 2. Does the *2 actually mean something ?

Screen --> is it really useful? If so, can you give me some examples?

My concern here is to keep a limited number of blend modes, so that the user is not confused with the tons of combinations usually available.
Laurent Gomila - SFML developer

UArchitect

  • Newbie
  • *
  • Posts: 5
    • View Profile
New blend mode (Like Blend::Add but that uses source alpha)
« Reply #6 on: March 02, 2009, 10:23:50 pm »
hello, are the pictures in my above post showing properly?

anyway modulate is a bit like multiply but it works similarly to the overlay mode in photoshop
lower than mid gray = darken
higher than mid gray = lighten
it just means i can have a "decal texture" which can darken and brighten rather than just darken (like the bullet holes above)

Quote from: "Laurent"
Modulate --> it's like Blend::Multiply, except mine is not multiplied by 2. Does the *2 actually mean something ?

rather than just src*dest (multiply)
its src*dest + src*dest, or to be put simpler (src*dest)*2
which means mid-gray will cause the underlying colors to be unaffected, higher than mid gray will lighten and lower than mid gray will darken

screen is like additive but its much softer, it preserves detail in lighter areas it wont bleach out and cause things to turn into white blobs which in certain situations it looks alot nicer (partivcularly when you have many overlapping translucent objects)

heres an example:
many sprites overlayed using screen blending:


the same image but using additive blending:



anyway, im not demanding or anything i imagine i could add custom blending modes myself but i wanted to throw the idea out there for consideration :>

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
New blend mode (Like Blend::Add but that uses source alpha)
« Reply #7 on: March 02, 2009, 11:12:37 pm »
Ok I see. It's interesting :)

I'll think about it, thanks for your feedback.
Laurent Gomila - SFML developer

UArchitect

  • Newbie
  • *
  • Posts: 5
    • View Profile
New blend mode (Like Blend::Add but that uses source alpha)
« Reply #8 on: March 03, 2009, 03:51:15 am »
np, thanks for responding