Icon blend modes?

Place to get help with not working mods / modding interface.
Post Reply
User avatar
kirazy
Filter Inserter
Filter Inserter
Posts: 416
Joined: Tue Mar 06, 2018 12:18 am
Contact:

Icon blend modes?

Post by kirazy »

I have these five "tier" overlays to display over icons, conditional on a setting, and tinted according to other settings:

ImageImageImageImageImage

I use a tint with partial alpha blending to make the colors lighter, which is producing an interesting problem: the entities are coming through when I want the blend to be opaque.

Image

My solution was to do this, because trying to set a blend_mode didn't work (not supported by icon?):

Code: Select all

icon = 
{
	{
		icon = inputs.icon
	},
	{
		icon = inputs.directory.."/graphics/icons/tiers/"..inputs.icon_size.."/tier-"..tier..".png",
	},
	{
		icon = inputs.directory.."/graphics/icons/tiers/"..inputs.icon_size.."/tier-"..tier..".png",
		tint = reskins.lib.adjust_alpha(reskins.lib.tint_index["tier-"..tier], 0.75),
	}
}
Is there a better way to accomplish this? I'd prefer not to have a redundant layer.

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

Re: Icon blend modes?

Post by Deadlock989 »

That's what partial alpha means: semi-transparent.

If you want the tinted colour to be lighter - make the tinted colour a lighter colour? What you're doing works but it's extra complication.

Things will look worse if the entities ever have a red "can't craft" background because the current character GUI adds transparency to every layer in a layered icon, meaning they all show through each other. Ditto for when the icon is dimmed because you don't have the ingredients. This may not be the case in the upcoming character GUI refresh but we don't know yet.

Edited to add, in case it's not clear:

Tinting is multiplicative. That means the red, green and blue values of the target pixel are multiplied by the red, green and blue values of the tint.

If your pixel is white {1,1,1} and you tint it pure red {1,0,0} then you get pure red {1,0,0}. 1 x 1 = 1, 1 x 0 = 0, 1 x 0 = 0.

If your pixel is pure green {0,1,0} and you tint it pure blue {0,0,1} then you get black {0,0,0}. 0 x 0 = 0, 1 x 0 = 0, 0 x 1 = 0.

So if your pixel is close to white {1,1,1} and you want it to look very light green {0.95,1.0,0.95} then you tint it by very light green.

With item icons it is best to avoid having layers at all. It is not so bad for things you are unlikely to ship around in mass quantities on belts (e.g. boilers) but even so, it's a potential hit on rendering performance. Recipe icons are OK because they can only appear on the screen once per entity (alt-view). Items can number in the thousands.
Image

User avatar
kirazy
Filter Inserter
Filter Inserter
Posts: 416
Joined: Tue Mar 06, 2018 12:18 am
Contact:

Re: Icon blend modes?

Post by kirazy »

Deadlock989 wrote:
Thu Mar 12, 2020 8:56 am
With item icons it is best to avoid having layers at all. It is not so bad for things you are unlikely to ship around in mass quantities on belts (e.g. boilers) but even so
Ack, you opened a can of worms for me, lol.:

Image

I'm going to go out on a limb and assume there's no way to have my cake and eat it too in this case, i.e. tier dots in crafting grid, but not in-world. Bleh. (also, layers cast a shadow, what which I guess makes sense.)

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Icon blend modes?

Post by posila »

kirazy wrote:
Thu Mar 12, 2020 12:11 pm
I'm going to go out on a limb and assume there's no way to have my cake and eat it too in this case, i.e. tier dots in crafting grid, but not in-world. Bleh. (also, layers cast a shadow, what which I guess makes sense.)
In this case, there is a way. Look at how eg. iron-ore item is defined.

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

Re: Icon blend modes?

Post by Deadlock989 »

kirazy wrote:
Thu Mar 12, 2020 12:11 pm
Ack, you opened a can of worms for me, lol.:
I live to serve.

You have options:

1. Only show the tier-indicator overlays on the recipe icon, so that the crafting menu is clearer. The item icon goes without them and just has the tier colouring. For bonus points, you bake that colouring into the icon so it's a single layer.

2. You go full Python (or some other batch-processing method) and have an automated workflow for preparing individual icons for absolutely everything.
Image

User avatar
kirazy
Filter Inserter
Filter Inserter
Posts: 416
Joined: Tue Mar 06, 2018 12:18 am
Contact:

Re: Icon blend modes?

Post by kirazy »

posila wrote:
Thu Mar 12, 2020 12:17 pm
kirazy wrote:
Thu Mar 12, 2020 12:11 pm
I'm going to go out on a limb and assume there's no way to have my cake and eat it too in this case, i.e. tier dots in crafting grid, but not in-world. Bleh. (also, layers cast a shadow, what which I guess makes sense.)
In this case, there is a way. Look at how eg. iron-ore item is defined.
Oh cool.

Code: Select all

{
    type = "item",
    name = "iron-ore",
    icon = "__base__/graphics/icons/iron-ore.png",
    icon_size = 64,
    icon_mipmaps = 4,
    pictures =
    {
      { size = 64, filename = "__base__/graphics/icons/iron-ore.png",   scale = 0.25, mipmap_count = 4 },
      { size = 64, filename = "__base__/graphics/icons/iron-ore-1.png", scale = 0.25, mipmap_count = 4 },
      { size = 64, filename = "__base__/graphics/icons/iron-ore-2.png", scale = 0.25, mipmap_count = 4 },
      { size = 64, filename = "__base__/graphics/icons/iron-ore-3.png", scale = 0.25, mipmap_count = 4 }
    },
    subgroup = "raw-resource",
    order = "e[iron-ore]",
    stack_size = 50
  }
So if I'm understanding this right, defining pictures will cause those to be used in-world, and icon in inventory?

User avatar
kirazy
Filter Inserter
Filter Inserter
Posts: 416
Joined: Tue Mar 06, 2018 12:18 am
Contact:

Re: Icon blend modes?

Post by kirazy »

Deadlock989 wrote:
Thu Mar 12, 2020 12:18 pm
kirazy wrote:
Thu Mar 12, 2020 12:11 pm
Ack, you opened a can of worms for me, lol.:
I live to serve.

You have options:

1. Only show the tier-indicator overlays on the recipe icon, so that the crafting menu is clearer. The item icon goes without them and just has the tier colouring. For bonus points, you bake that colouring into the icon so it's a single layer.

2. You go full Python (or some other batch-processing method) and have an automated workflow for preparing individual icons for absolutely everything.
My issue is that I had just added the ability to customize tier colors, which needs everything to be masked, lol. I can strip it out if that proves unworkable.

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

Re: Icon blend modes?

Post by Deadlock989 »

... Actually that's a nice tip from posila. I use pictures for "belt variants" but it never occurred to me that they can also be used to make an item have a different single-layer appearance on belts to the icons used in inventory tabs.
Image

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

Re: Icon blend modes?

Post by Deadlock989 »

kirazy wrote:
Thu Mar 12, 2020 12:22 pm
My issue is that I had just added the ability to customize tier colors, which needs everything to be masked, lol. I can strip it out if that proves unworkable.
I did something similar for the beltboxes mod, which can produce beltboxes of any particular colour, and the items are layered. This goes back to what posila said in the other thread about not having to be exclusively focused on optimisation - in the case of beltboxes and boilers, players are never going to have a 16-lane megabus filled with them crossing a kilometre, so the minor loss of performance will always be "minor enough" to make it worth easing your work. There's "best" but also "good enough".

It would be a different story if we were talking about iron plates.
Last edited by Deadlock989 on Thu Mar 12, 2020 12:28 pm, edited 1 time in total.
Image

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Icon blend modes?

Post by posila »

kirazy wrote:
Thu Mar 12, 2020 12:20 pm
So if I'm understanding this right, defining pictures will cause those to be used in-world, and icon in inventory?
That's correct. Pictures are used on belts, in inserter hand and for item entities only.

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Icon blend modes?

Post by posila »

Deadlock989 wrote:
Thu Mar 12, 2020 12:22 pm
... Actually that's a nice tip from posila. I use pictures for "belt variants" but it never occurred to me that they can also be used to make an item have a different single-layer appearance on belts to the icons used in inventory tabs.
I almost made it so that icon definition is always variation 0 (and pictures add rest of the variations), so people don't have to repeat the definition, but then I thought maybe being able to use completely different icon in GUI than in world might be useful (and also it makes the pictures property cleaner, imho)

User avatar
kirazy
Filter Inserter
Filter Inserter
Posts: 416
Joined: Tue Mar 06, 2018 12:18 am
Contact:

Re: Icon blend modes?

Post by kirazy »

Deadlock989 wrote:
Thu Mar 12, 2020 12:25 pm
I did something similar for the beltboxes mod, which can produce beltboxes of any particular colour, and the items are layered. This goes back to what posila said in the other thread about not having to be exclusively focused on optimisation - in the case of beltboxes and boilers, players are never going to have a 16-lane megabus filled with them crossing a kilometre, so the minor loss of performance will always be "minor enough" to make it worth easing your work. There's "best" but also "good enough".

It would be a different story if we were talking about iron plates.
I don't anticipate skinning anything that a player is likely to have zillions of on belts, but we'll see. I'm just doing Bob's structures at the moment, with plans to do the rest at some point (though those won't need tier coloring and so masks).
posila wrote:
Thu Mar 12, 2020 12:25 pm
kirazy wrote:
Thu Mar 12, 2020 12:20 pm
So if I'm understanding this right, defining pictures will cause those to be used in-world, and icon in inventory?
That's correct. Pictures are used on belts, in inserter hand and for item entities only.
Awesome. This will make things even better. :D
posila wrote:
Thu Mar 12, 2020 12:31 pm
I almost made it so that icon definition is always variation 0 (and pictures add rest of the variations), so people don't have to repeat the definition, but then I thought maybe being able to use completely different icon in GUI than in world might be useful (and also it makes the pictures property cleaner, imho)
And thanks for that! :D

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

Re: Icon blend modes?

Post by Deadlock989 »

posila wrote:
Thu Mar 12, 2020 12:31 pm
I almost made it so that icon definition is always variation 0 (and pictures add rest of the variations), so people don't have to repeat the definition, but then I thought maybe being able to use completely different icon in GUI than in world might be useful (and also it makes the pictures property cleaner, imho)
Yeah, that would have tripped me up in other ways. I have Blender spitting out 4-6 variations of things, it doesn't matter to me what order they are defined in in the pictures definition (because it's random when on belts or spilled on the ground), but it is nice to have the control over which one is picked for the item icon without having to renumber the sprites for every material.
Image

Post Reply

Return to “Modding help”