multiple layers of sprites with some blending mode other than simply overlapping.

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
yagaodirac
Fast Inserter
Fast Inserter
Posts: 152
Joined: Sun Jun 16, 2019 4:04 pm
Contact:

multiple layers of sprites with some blending mode other than simply overlapping.

Post by yagaodirac »

I read this,
viewtopic.php?t=26105
But I didn't success trying this.

In my mod, I tried to modify the tint(or should I say color directly?) of offshore pump.
I tried deepcopy, and then new_pump.graphics_set.animation.north.layers[1].filename = something else.

I'm curious about that, is it possible to create something like modifying image layer and put it on the top.
layers[3] = layers[2]//this layer is shadow.
layers[2] = layers[1].deepcopy()//this layer is the main body, and the code is pseudo.
layers[1].filename = nil
layers[1].layer_mode = modifying-layer
layers[1].blend_mode = hue-sat-vol
layers[1].delta_hue = 120
layers[1].delta_saturation = 30
layers[1].delta_volume = -5
...
data:extend({this new offshore pump})

In this way, it's very easy to change prototypes' color.

For now, the easiest way I knew is that, copy the png of the mainbody, paste into the mod folder. Modify the png file. Specify the filename to the new png. But if the blending mode is not variable within the whole playing duration, it doesn't bring any perfomance overhead to the game. And I think modifying an loaded png is faster than loading another png.

Koub
Global Moderator
Global Moderator
Posts: 7203
Joined: Fri May 30, 2014 8:54 am
Contact:

Re: multiple layers of sprites with some blending mode other than simply overlapping.

Post by Koub »

[Koub] Moved to modding discussion.
Koub - Please consider English is not my native language.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: multiple layers of sprites with some blending mode other than simply overlapping.

Post by Deadlock989 »

yagaodirac wrote:
Tue Sep 29, 2020 5:10 am
layers[1].layer_mode = modifying-layer
layers[1].blend_mode = hue-sat-vol
layers[1].delta_hue = 120
layers[1].delta_saturation = 30
layers[1].delta_volume = -5
...
data:extend({this new offshore pump})
No, there is nothing like this. Factorio is not an image editor. The ability to process loaded sprites with things like hue rotation has been requested in the past but it hasn't been implemented (so far). What you are talking about is not a "blending mode".

You can give some sprites and animations one of the following blend modes, which control the way the sprite's pixels interact with the pixels in the "background", i.e. whatever was rendered previously: https://wiki.factorio.com/Types/BlendMode . Of these, additive and additive-soft are probably the most useful (e.g. glows, fires, lights, other kinds of brightening), although I have seen multiplicative mode used effectively as well.

You can tint (most) sprites with one multiplicative colour value, and that's it (https://wiki.factorio.com/Types/Sprite#tint). Anything else has to be done outside of Factorio and loaded into the sprite atlas in the usual way. If you need to do that programmatically or systematically then it's time to start investigating something like batch scripts in Photoshop, or ImageMagick (if you enjoy passing notes under a door to a creature from another dimension), or Python libraries like PIL.

Finally there are runtime colour masks (https://wiki.factorio.com/Types/Sprite# ... ntime_tint) which are the only kind of tint that can be modified by scripts during game runtime, but they are limited to the colour values associated with forces, e.g. the player force or the default biter force. So changing it will change the colour tint for every entity in that force. This is used by vanilla for the player animation, turret and vehicle mask colours etc.

There are also recipe-specific tints but those only work with entities that can have a recipe set (Prototype/CraftingMachine), and fuel glow tints (generators).
Image

yagaodirac
Fast Inserter
Fast Inserter
Posts: 152
Joined: Sun Jun 16, 2019 4:04 pm
Contact:

Re: multiple layers of sprites with some blending mode other than simply overlapping.

Post by yagaodirac »

Koub wrote:
Tue Sep 29, 2020 5:56 am
[Koub] Moved to modding discussion.
Thanks~

yagaodirac
Fast Inserter
Fast Inserter
Posts: 152
Joined: Sun Jun 16, 2019 4:04 pm
Contact:

Re: multiple layers of sprites with some blending mode other than simply overlapping.

Post by yagaodirac »

Deadlock989 wrote:
Tue Sep 29, 2020 11:51 am
yagaodirac wrote:
Tue Sep 29, 2020 5:10 am
layers[1].layer_mode = modifying-layer
layers[1].blend_mode = hue-sat-vol
layers[1].delta_hue = 120
layers[1].delta_saturation = 30
layers[1].delta_volume = -5
...
data:extend({this new offshore pump})
No, there is nothing like this. Factorio is not an image editor. The ability to process loaded sprites with things like hue rotation has been requested in the past but it hasn't been implemented (so far). What you are talking about is not a "blending mode".

You can give some sprites and animations one of the following blend modes, which control the way the sprite's pixels interact with the pixels in the "background", i.e. whatever was rendered previously: https://wiki.factorio.com/Types/BlendMode . Of these, additive and additive-soft are probably the most useful (e.g. glows, fires, lights, other kinds of brightening), although I have seen multiplicative mode used effectively as well.

You can tint (most) sprites with one multiplicative colour value, and that's it (https://wiki.factorio.com/Types/Sprite#tint). Anything else has to be done outside of Factorio and loaded into the sprite atlas in the usual way. If you need to do that programmatically or systematically then it's time to start investigating something like batch scripts in Photoshop, or ImageMagick (if you enjoy passing notes under a door to a creature from another dimension), or Python libraries like PIL.

Finally there are runtime colour masks (https://wiki.factorio.com/Types/Sprite# ... ntime_tint) which are the only kind of tint that can be modified by scripts during game runtime, but they are limited to the colour values associated with forces, e.g. the player force or the default biter force. So changing it will change the colour tint for every entity in that force. This is used by vanilla for the player animation, turret and vehicle mask colours etc.

There are also recipe-specific tints but those only work with entities that can have a recipe set (Prototype/CraftingMachine), and fuel glow tints (generators).
Thank you very much. I'm gonna check them out. But still, you know, the existing blending formula is too limited. I tried slightly modifying the png files in some software, and they simply look very good. With the formula provided by factorio, the images always get darker as I've seen in many mods. So, I really believe that factorio should have a set of blending mode as the image software do.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: multiple layers of sprites with some blending mode other than simply overlapping.

Post by Deadlock989 »

yagaodirac wrote:
Wed Sep 30, 2020 12:37 am
Thank you very much. I'm gonna check them out. But still, you know, the existing blending formula is too limited. I tried slightly modifying the png files in some software, and they simply look very good. With the formula provided by factorio, the images always get darker as I've seen in many mods. So, I really believe that factorio should have a set of blending mode as the image software do.
It's not a "blending mode". Factorio does have blending modes for rendering sprites. You are asking for something very different: sprite processing tools that work with the HSV colour space. People have asked for it before and the response from devs ranged from "no" to "maybe one day". But there is no use case for it in vanilla so I can see why it was never going to be a priority - especially when such thousands of such tools already exist outside of Factorio, many of them freeware.

The usual problem with tints making things too dark is usually that folks don't understand how multiplicative tints work in RGB. The values of each channel in each pixel are multiplied by the corresponding channel in the specified tint: red * red, blue * blue, green * green. For example if you want something to be very faintly tinted red without any great darkening then you multiply it with a very very light pink (r = 1, g = 0.95, b = 0.95). People go in full throttle with pure unadulterated red (r = 1, g = 0, b = 0) and then wonder why everything that wasn't red in the first place ends up black (anything * 0 = 0).

At the end of the day, tinting a whole coloured sprite nearly always looks bad - they are only really useful with monochromatic masks designed to be layered on top of other sprites, so you are likely better off with external tools in the first place. Same argument applies to wholesale colour wheel rotations in HSV - rotating the hues of a entire sprite that was designed to have realistic colours is nearly always going to suck in some way.
Image

yagaodirac
Fast Inserter
Fast Inserter
Posts: 152
Joined: Sun Jun 16, 2019 4:04 pm
Contact:

Re: multiple layers of sprites with some blending mode other than simply overlapping.

Post by yagaodirac »

Deadlock989 wrote:
Wed Sep 30, 2020 1:00 am
yagaodirac wrote:
Wed Sep 30, 2020 12:37 am
Thank you very much. I'm gonna check them out. But still, you know, the existing blending formula is too limited. I tried slightly modifying the png files in some software, and they simply look very good. With the formula provided by factorio, the images always get darker as I've seen in many mods. So, I really believe that factorio should have a set of blending mode as the image software do.
It's not a "blending mode". Factorio does have blending modes for rendering sprites. You are asking for something very different: sprite processing tools that work with the HSV colour space. People have asked for it before and the response from devs ranged from "no" to "maybe one day". But there is no use case for it in vanilla so I can see why it was never going to be a priority - especially when such thousands of such tools already exist outside of Factorio, many of them freeware.

The usual problem with tints making things too dark is usually that folks don't understand how multiplicative tints work in RGB. The values of each channel in each pixel are multiplied by the corresponding channel in the specified tint: red * red, blue * blue, green * green. For example if you want something to be very faintly tinted red without any great darkening then you multiply it with a very very light pink (r = 1, g = 0.95, b = 0.95). People go in full throttle with pure unadulterated red (r = 1, g = 0, b = 0) and then wonder why everything that wasn't red in the first place ends up black (anything * 0 = 0).

At the end of the day, tinting a whole coloured sprite nearly always looks bad - they are only really useful with monochromatic masks designed to be layered on top of other sprites, so you are likely better off with external tools in the first place. Same argument applies to wholesale colour wheel rotations in HSV - rotating the hues of a entire sprite that was designed to have realistic colours is nearly always going to suck in some way.
OK, thank you very much for the replying. The way of modifying image files out side the game seems to be the best way. And it's already good enough.

Post Reply

Return to “Modding discussion”