Feature Request: Change a surface's blend mode

Started by Satoh, July 06, 2016, 08:49:04 PM

Previous topic - Next topic
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.

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.

July 06, 2016, 10:53:05 PM #2 Last Edit: July 06, 2016, 10:57:29 PM by Satoh
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.
Patience is difficult and rarely thanked, but always appreciated, and sorely missed when absent.

July 07, 2016, 04:07:33 AM #3 Last Edit: July 07, 2016, 04:11:59 AM by wrightmat
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?


Haha, you're the best! It'll be really cool to see what we can do with it :)



Patience is difficult and rarely thanked, but always appreciated, and sorely missed when absent.


July 12, 2016, 01:45:38 PM #10 Last Edit: July 12, 2016, 02:13:34 PM by MetalZelda
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 ?


July 12, 2016, 04:53:29 PM #12 Last Edit: July 12, 2016, 05:26:13 PM by MetalZelda
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

Quote from: MetalZelda on July 12, 2016, 04:53:29 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?

July 12, 2016, 06:26:45 PM #14 Last Edit: July 12, 2016, 07:40:28 PM by MetalZelda
Quote from: YoshiMario2000 on July 12, 2016, 05:43:08 PM
Quote from: MetalZelda on July 12, 2016, 04:53:29 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 ...