Author Topic: Feature Request: Change a surface's blend mode  (Read 4671 times)

Satoh

  • Newbie
  • *
  • Posts: 47
    • View Profile
Feature Request: Change a surface's blend mode
« on: July 06, 2016, 08:49:04 pm »
SDL has four blend modes, SDL_BLENDMODE_NONE, SDL_BLENDMODE_BLEND, SDL_BLENDMODE_ADD, and SDL_BLENDMODE_MOD.
SDL_BLENDMODE_NONE isn't terribly useful for Solarus so we can ignore it.

Solarus source code appears to always use BLEND already, which makes sense.
My desire is to be able to have some surfaces specify the ADD and MOD modes.
ADD is useful for creating brightly shining effects which lighten and color things under them, without washing them out or making them look hazy. Using a semitransparent sprite or surface by itself would cause the sprite underneath to lose some of its clarity.
If you wanted a particularly bright special effect, it would destroy the clarity of the scene beneath it, whereas an ADD blended surface would allow more of the detail to show through.
It would look better particularly when a dark and light colored object are beneath it, as the dark object would would be lit proportional to its original color.
A simple BLEND effect would cause the darker object to seem to be lit more, due to the BLEND surface partly replacing the scene, rather than adding to it.

Similarly MOD can be used to darken a scene, and add really rich vibrant color to it, without degrading image quality. This is fairly easy to demonstrate, using a screenshot from another SNES game.


At the top we have a BLEND mode style layering, with a blue color, at 75% opacity. It... doesn't look so great, and I wasn't able to make it much darker than that without the image turning more black than blue. Below that is a MOD style layer, which darkens the image with a rich blue color, without making the scene hazy, and it looks like a nice nighttime effect.

With the MOD blendmode, one could make an active day and night cycle by rendering a surface with different colors for different times of day, or shadows which darken sprites under them, without making them look smoky (like what happens with a black or gray semitransparent BLEND shadow)

As far as I could locate, the git src only sets the blendmode twice, so it seems like adding a blendmode property to the solarus drawable class and passing that as an argument, should work... But that's only as far as I could find. I'm sure Christopho knows the source better than I.

Anyway, that's my argument for why it would be a decent feature to have.
Patience is difficult and rarely thanked, but always appreciated, and sorely missed when absent.

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1172
    • View Profile
Re: Feature Request: Change a surface's blend mode
« Reply #1 on: July 06, 2016, 09:04:36 pm »
I am not an expert with blend modes, but your example is very convincing.
From the Lua API point of view, maybe the blend mode could be an optional additional parameter to drawable:draw(), or maybe we could make drawable:get/set_blend_mode(). The second option has my preference because drawable:draw() already has optional parameters, let's don't mix everything.

Satoh

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: Feature Request: Change a surface's blend mode
« Reply #2 on: July 06, 2016, 10:53:05 pm »
I was indeed imagining something like a drawable:set_blend_mode(mode) myself.
Sprites inherit from drawable as I understand it, so it should in theory work on manually defined surfaces as well as sprites right?

EDIT:
Link to SDL documentation on what the blend modes do. Pretty sure only the function needs to be called.
There are some other SDL_Set____BlendMode type functions, but the one in the link is the only one I found directly when I looked in the git.
« Last Edit: July 06, 2016, 10:57:29 pm by Satoh »
Patience is difficult and rarely thanked, but always appreciated, and sorely missed when absent.

wrightmat

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: Feature Request: Change a surface's blend mode
« Reply #3 on: July 07, 2016, 04:07:33 am »
This would be amazing, and it sounds like it would be easy to implement! Maybe we could even have it (at least experimentally) for 1.5?
« Last Edit: July 07, 2016, 04:11:59 am by wrightmat »

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1172
    • View Profile
Re: Feature Request: Change a surface's blend mode
« Reply #4 on: July 07, 2016, 12:39:32 pm »
If you insist :)

wrightmat

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: Feature Request: Change a surface's blend mode
« Reply #5 on: July 08, 2016, 06:05:39 am »
Haha, you're the best! It'll be really cool to see what we can do with it :)

Neovyse

  • Administrator
  • Full Member
  • *****
  • Posts: 142
    • View Profile
Re: Feature Request: Change a surface's blend mode
« Reply #6 on: July 08, 2016, 09:20:50 am »
Nice idea !


Satoh

  • Newbie
  • *
  • Posts: 47
    • View Profile
Patience is difficult and rarely thanked, but always appreciated, and sorely missed when absent.

Zefk

  • Hero Member
  • *****
  • Posts: 536
  • Just helping Solarus
    • View Profile
    • Zelzec
Re: Feature Request: Change a surface's blend mode
« Reply #9 on: July 12, 2016, 12:35:01 am »
This is magnificent.  Does that mean the PDF version of the documentation will be updated?
http://www.solarus-games.org/doc/solarus-doc-v1.5.pdf

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: Feature Request: Change a surface's blend mode
« Reply #10 on: July 12, 2016, 01:45:38 pm »
I already have a fully functionnal Day/Night system for my Zelda project, I should give a look at blending modes.

Thus, if the result is correct, I'll maybe release it.

Is it available in a released screenshot ?
« Last Edit: July 12, 2016, 02:13:34 pm by MetalZelda »

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1172
    • View Profile

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: Feature Request: Change a surface's blend mode
« Reply #12 on: July 12, 2016, 04:53:29 pm »
I do have to guess that to be better, the day/night tone surface needs to be in "color_modulate" blending ?

But, strange thing is, if a surface's color is at 0, 0, 0, 0, it is really dark (while it's alpha is at 0), I don't understand much about surface blendings but if someone has any clues I'll gladly take it.

I'll let a video about the different blendings mode available, with target colors unchanged, and let the OP decide about what could be the best option for this kind of system, thus, I'll change tones

Edit: here

https://www.youtube.com/watch?v=tvZ0mJAmQy8&feature=youtu.be
« Last Edit: July 12, 2016, 05:26:13 pm by MetalZelda »

YoshiMario2000

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: Feature Request: Change a surface's blend mode
« Reply #13 on: July 12, 2016, 05:43:08 pm »
...if a surface's color is at 0, 0, 0, 0, it is really dark (while it's alpha is at 0)...
I think what is going on in the video is that there is no alpha, rather than there being alpha.
Try changing the alpha value around, That might fix the darkness you see in the video.
This signature was way too long before, but now it's short!
Also, I am Still Alive!
On ad Off I go!

Do you ever get the feeling that the fandom of a product(s) ruin the potential that you could have had to enjoy the product?

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: Feature Request: Change a surface's blend mode
« Reply #14 on: July 12, 2016, 06:26:45 pm »
...if a surface's color is at 0, 0, 0, 0, it is really dark (while it's alpha is at 0)...
I think what is going on in the video is that there is no alpha, rather than there being alpha.
Try changing the alpha value around, That might fix the darkness you see in the video.

It didn't

The surface at daytime is completely clear (0, 0, 0, 0), from 7AM to 4PM and it give a pitch black surface with color moduling blending.
There is not so much documentation about this blending, so I don't know how this works, but it is very dark afaik

Edit: putting everything at 255 makes everything normal
Oh, I see ...
« Last Edit: July 12, 2016, 07:40:28 pm by MetalZelda »