Set Hue for data stage (and for control stage; and saturation and value)

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 1974
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Set Hue for data stage (and for control stage; and saturation and value)

Post by darkfrei » Fri May 24, 2019 10:20 am

Hi devs!

Thank you again for the tinting support for almost all pictures.

Can you please add support for Hue?
Such thing makes very high flexibility by color changing.

Here was a request about icons recoloring, but it can be done just as vanilla graphics + some hue value
Last edited by darkfrei on Fri Jun 07, 2019 8:25 pm, edited 3 times in total.

User avatar
Deadlock989
Filter Inserter
Filter Inserter
Posts: 934
Joined: Fri Nov 06, 2015 7:41 pm
Contact:

Re: Set Hue for data stage

Post by Deadlock989 » Fri May 24, 2019 10:27 am

You can do this yourself. See https://www.niwa.nu/2013/05/math-behind ... s-rgb-hsl/

Edited to add: Just realised that's RGB to HSL. This StackOverflow post has it both ways: https://stackoverflow.com/questions/235 ... conversion

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 1974
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Set Hue for data stage

Post by darkfrei » Fri May 24, 2019 10:32 am

I can do it with the paint dot net or with ImageMagick
But why it cannot be done by the game starting?

User avatar
Deadlock989
Filter Inserter
Filter Inserter
Posts: 934
Joined: Fri Nov 06, 2015 7:41 pm
Contact:

Re: Set Hue for data stage

Post by Deadlock989 » Fri May 24, 2019 10:33 am

Because it's just maths and this is a game, not an image editor.

Someone else actually did it in Lua: https://github.com/EmmanuelOga/columns/ ... /color.lua

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3068
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Set Hue for data stage

Post by eradicator » Fri May 24, 2019 12:36 pm

Deadlock989 wrote:
Fri May 24, 2019 10:33 am
Because it's just maths and this is a game, not an image editor.
As a "math challenged" person i'd be very interested in how to change the hue of a picture via tinted layers. Can you please explain?
Also i certainly wouldn't mind if there were more image editor components to automate the creation of prototype pictures :D.

Edit: I.e. i'd like to do this simple hue adjustment without having to distribute a complete spritesheet.
gimp.png
gimp.png (84.72 KiB) Viewed 308 times
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
Deadlock989
Filter Inserter
Filter Inserter
Posts: 934
Joined: Fri Nov 06, 2015 7:41 pm
Contact:

Re: Set Hue for data stage

Post by Deadlock989 » Fri May 24, 2019 5:25 pm

Code: Select all

-- expects (hue, saturation, value, alpha) - all between 0-1 - as input
-- returns a Factorio colour table
function hsva2rgba(h, s, v, a)
  local r, g, b
  local i = math.floor(h * 6);
  local f = h * 6 - i;
  local p = v * (1 - s);
  local q = v * (1 - f * s);
  local t = v * (1 - (1 - f) * s);
  i = i % 6
  if i == 0 then r, g, b = v, t, p
  elseif i == 1 then r, g, b = q, v, p
  elseif i == 2 then r, g, b = p, v, t
  elseif i == 3 then r, g, b = p, q, v
  elseif i == 4 then r, g, b = t, p, v
  elseif i == 5 then r, g, b = v, p, q
  end
  return { r = r, g = g, b = b, a = a }
end

Code: Select all

icon = "whatever/kinda/pink-looking/icon.png"
tint = hsva2rgba(0.0, 0.25, 1.0, 1.0)
You're welcome.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3068
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Set Hue for data stage

Post by eradicator » Fri May 24, 2019 6:08 pm

Nope, that didn't work. The "inside" of the assembler is still being tinted.
didntwork.png
didntwork.png (30.2 KiB) Viewed 275 times
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 1974
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Set Hue for data stage

Post by darkfrei » Fri May 24, 2019 7:02 pm

This cod just adds:
2019-05-24T20_59_10-Window.png
2019-05-24T20_59_10-Window.png (1.07 KiB) Viewed 259 times
I've made this small mod:

Code: Select all

 -- (your function)
function deep_add_tint (tabl)
  for key, v in pairs (tabl) do
    if type (v) == 'table' then
      if v.filename or v.tint then
        v.tint = hsva2rgba(0.0, 0.25, 1.0, 1.0)
      else
        deep_add_tint (v)
      end
    end
  end
end

deep_add_tint (data.raw)
But the result was not too different:
2019-05-24T20_55_16-Window.png
2019-05-24T20_55_16-Window.png (63.09 KiB) Viewed 259 times
2019-05-24T20_57_51-Window.png
2019-05-24T20_57_51-Window.png (193.63 KiB) Viewed 259 times
Attachments
Magenta_0.0.1.zip
(1002 Bytes) Downloaded 1 time
Last edited by darkfrei on Fri May 24, 2019 7:26 pm, edited 1 time in total.

User avatar
Deadlock989
Filter Inserter
Filter Inserter
Posts: 934
Joined: Fri Nov 06, 2015 7:41 pm
Contact:

Re: Set Hue for data stage

Post by Deadlock989 » Fri May 24, 2019 7:24 pm

Woah.

What is it that you're trying to achieve? I thought you just wanted to be able to express a tint using HSV rather than RGB. Now I'm less sure what it is you're trying to do.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 1974
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Set Hue for data stage

Post by darkfrei » Fri May 24, 2019 10:38 pm

Deadlock989 wrote:
Fri May 24, 2019 7:24 pm
Woah.

What is it that you're trying to achieve? I thought you just wanted to be able to express a tint using HSV rather than RGB. Now I'm less sure what it is you're trying to do.
It would be good to achieve this way to make new tier graphics from old graphics:
F_05_01e.gif
F_05_01e.gif (1.95 MiB) Viewed 226 times

User avatar
Deadlock989
Filter Inserter
Filter Inserter
Posts: 934
Joined: Fri Nov 06, 2015 7:41 pm
Contact:

Re: Set Hue for data stage

Post by Deadlock989 » Fri May 24, 2019 10:52 pm

darkfrei wrote:
Fri May 24, 2019 10:38 pm
Deadlock989 wrote:
Fri May 24, 2019 7:24 pm
Woah.

What is it that you're trying to achieve? I thought you just wanted to be able to express a tint using HSV rather than RGB. Now I'm less sure what it is you're trying to do.
It would be good to achieve this way to make new tiers of old graphics:
F_05_01e.gif
You want runtime adjustable hue sliders?

You can currently have a runtime adjustable tint in just one way: the apply_runtime_tint parameter, but this can only apply the force's colour (in single player games, the colour you get from the /color command). You could give this a slider in a GUI and have all the rainbow cycling belts you wanted. But it would affect everything belonging to that force all at once - all entities with apply_runtime_tint, all tanks, all cars, all turrets, the player, any other players on the same force.

If you want a runtime adjustable tint per individual entity, you need to ask for that, not just "can we set hue at data stage", to which the answer is, yes, you already can, hue/saturation/lightness is just another way of expressing what RGB values express.

If you want the game engine to duplicate sprites but with a shifted hue, that is yet a third thing. But there are very few assets in the game that this would be much good for. The locomotive icon is one. I can't think of many others. Anything that is only composed of pure greyscale and then just one colour as well, it could look alright. Anything that has more than one hue/tone is going to look like crap in my view. Belts look grey in comparison to their arrow but they're not, they're slightly reddish. If you rotate the hue of the sprite to get a red arrow from a yellow arrow, you will also get a purplish tint to the belt.

Essentially it's probably a million times easier to make your own sprite and mask off areas you don't want affected by the colour change, etc. etc.

With belts specifically, I made some mask-separated belts for 0.16, inspired by your method if I recall correctly, so that you could generate as many colours of belt as you liked during the data stage. They were rendered obsolete/incompatible by 0.17 and I didn't have the patience to try and redo them all in the new scheme with the new "wheels". posila said they considered making mask-separated belts but with just 3 belts in vanilla, there was no real advantage to it.
Last edited by Deadlock989 on Fri May 24, 2019 11:00 pm, edited 2 times in total.

Qon
Smart Inserter
Smart Inserter
Posts: 1239
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Set Hue for data stage

Post by Qon » Fri May 24, 2019 11:00 pm

That GIF is perfect darkfrei.
Colour rotation! I also want that!

And would be nice if we could make images darker and lighter independently of color tinting. What I mean is tinting with {r = 0, g = 0, b = 0} gives same result as {r = 1, g = 1, b = 1} for some reason, but the first should be black since {r= 1, g = 0, b = 0} actually removes green and blue. Why can't I remove all channels? I messed up. But colour rotations aren't affected by that.

Anything that allows me to make graphics that are visibly different from vanilla without forcing me to open an image editor is nice. I should maybe learn image magick though to do proper code image manipulation. But not including any graphics files decreases mod file size and maybe also startup times some.
Last edited by Qon on Sat May 25, 2019 11:51 am, edited 1 time in total.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3068
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Set Hue for data stage

Post by eradicator » Sat May 25, 2019 9:40 am

Deadlock989 wrote:
Fri May 24, 2019 10:52 pm
You want runtime adjustable hue sliders?
To me it's pretty clear OP wants to adjust the hue of existing pictures in data stage, it's even in the title.
Most factorio buildings have ample grey components, and channel-seperate hue changing gives acceptable results. Not everyone has the graphic talent to do a proper recoloration.

Code: Select all

hue_shift = {y=-0.5,r=0.3}
This is basically another angle on: "I want an easy way to make color variant vanilla machines without distributing 20MB of sprite sheets for a 100kB mod.". I.e. we desire to reduce the "reinvent-the-wheel" factor of modding colored machines by including a function invent_new_wheel() in the engine, so that every modder can use it.

Earlier i requested that the game could simple include mod-friendly (read: tint-friendly) greyscale masks for some of the vanilla entities. Which would work without changing anything in the engine. But if what you say about masked belts is true, then that probably doesn't have too great chances of succeeding either.
adjust_hue.gif
adjust_hue.gif (2.6 MiB) Viewed 194 times
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 1974
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Set Hue for data stage

Post by darkfrei » Sat May 25, 2019 11:35 am

Deadlock989 wrote:
Fri May 24, 2019 10:52 pm
If you want the game engine to duplicate sprites but with a shifted hue, that is yet a third thing. But there are very few assets in the game that this would be much good for. The locomotive icon is one. I can't think of many others. Anything that is only composed of pure greyscale and then just one colour as well, it could look alright. Anything that has more than one hue/tone is going to look like crap in my view. Belts look grey in comparison to their arrow but they're not, they're slightly reddish. If you rotate the hue of the sprite to get a red arrow from a yellow arrow, you will also get a purplish tint to the belt.
Right now we have the tint, that works the same way, but you can apply it on gray pixels only, all colored pixels don't change their color. I don't know how it works internal, but here must be already some loading optimization.
I have asked another parameter, that applies to all colored pixels. Yes, only few of vanilla entities can be recolored nicely, but it's enough for mods.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3068
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Set Hue for data stage

Post by eradicator » Sat May 25, 2019 12:01 pm

darkfrei wrote:
Sat May 25, 2019 11:35 am
Right now we have the tint, that works the same way, but you can apply it on gray pixels only, all colored pixels don't change their color. I don't know how it works internal, but here must be already some loading optimization.
Tint works fine on all pixels, but it doesn't look good due to how it works. Which behaves something like this (assuming 0~1 float range of each color channel):

Code: Select all

for pixel in pairs(all_pixels_of_the_picture) do
  pixel.r = math.min(pixel.r, pixel.r * tint.r)
  pixel.g = math.min(pixel.g, pixel.g * tint.g)
  pixel.b = math.min(pixel.b, pixel.b * tint.b)
  pixel.a = math.min(pixel.a, pixel.a * tint.a)
  end
  
That means tint multiplies every channel, but only up to the original color value. If it was allowed to create the full 0~1 (1-255) range of values then maybe hue changes might be moddable with just that (not sure, not a graphics person...).

A slight change in behavior to this (where tint is now an 1-255 range multiplication factor):

Code: Select all

for pixel in pairs(all_pixels_of_the_picture) do
  pixel.r = math.min(1, pixel.r * tint.r)
  pixel.g = math.min(1, pixel.g * tint.g)
  pixel.b = math.min(1, pixel.b * tint.b)
  pixel.a = math.min(1, pixel.a * tint.a)
  end
  
would allow some more flexibility. But obviously they're not using a crude lua function like this, so it might be difficult to make that change even if they wanted to.
Last edited by eradicator on Sat May 25, 2019 12:07 pm, edited 1 time in total.
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
Deadlock989
Filter Inserter
Filter Inserter
Posts: 934
Joined: Fri Nov 06, 2015 7:41 pm
Contact:

Re: Set Hue for data stage

Post by Deadlock989 » Sat May 25, 2019 12:07 pm

darkfrei wrote:
Sat May 25, 2019 11:35 am
Right now we have the tint, that works the same way, but you can apply it on gray pixels only, all colored pixels don't change their color. I don't know how it works internal, but here must be already some loading optimization.
I have asked another parameter, that applies to all colored pixels. Yes, only few of vanilla entities can be recolored nicely, but it's enough for mods.
No, I don't think that's true. Tint applies to all the pixels. I'm guessing it's multiplicative. If you have a yellow-ish mask and apply a green tint, you get a greenish-yellowish mask. In this post the coloured entities have a mask which is mostly grey but also some "rusty" patches. The red depot ends up red with rusty-red patches, the yellow one with yellowish-rusty patches etc. OK, it's subtle, so maybe not the best example, but it works just fine. I've also tinted generic multicoloured icons with red and what you get is a red-tinted multicoloured icon, just like you'd expect.

It sounds like what you want is something else entirely. You want to be able to rotate a sprite's palette by specifying a hue offset. If that's what you want then you need to ask for that because "Set hue for data stage" is confusing. I don't know enough about rendering to say whether it'd be FPS-friendly or not.

Qon
Smart Inserter
Smart Inserter
Posts: 1239
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Set Hue for data stage

Post by Qon » Sat May 25, 2019 12:48 pm

Deadlock989 wrote:
Sat May 25, 2019 12:07 pm
I don't know enough about rendering to say whether it'd be FPS-friendly or not.
It can't affect FPS since it's done in the data stage.

And modern GPUs with GLSL fragment shaders can do pretty much any filter you can imagine "instantly".

It would be possible to add hue, saturation and lightness filters so that we only rotate hue (and do other manipulations in HSL space etc) of the parts we want and leave the others unchanged, effectively making masks on the fly through code. Also possible to rotate different parts of the image separately and combine the results. Or load several images and combine the results.

Personally, if I'm allowed to dream, I would like a full GLSL code field in the prototype and the ability to give it multiple images as input.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2074
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Set Hue for data stage

Post by Optera » Sat May 25, 2019 2:32 pm

Using lua to crop and tint sprite parts on the fly doesn't sound feasible.

What you actually ask for is adding color masks to entities. Locomotives, cargo wagon, cars have such and therefore can be properly tinted during runtime without looking like someone lazily dumped a paint bucket on top of them.
I've asked for assemblers and fluid wagons to have color masks before and got denied.

Qon
Smart Inserter
Smart Inserter
Posts: 1239
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Set Hue for data stage

Post by Qon » Sat May 25, 2019 2:46 pm

I meant "on the fly" as in while being loaded in prototype stage, not in Factorio runtime. Though that would be even cooler.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 3068
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Set Hue for data stage

Post by eradicator » Sat May 25, 2019 2:51 pm

@Qon:
Except full GLSL support would be instantly abused and impossible to make secure. It's a nice dream though.
I'll keep be dreams to .invert_colors=true and .blending_mode=average_of_colors and rotate=90.
It'd be really nice to hear from a dev if *any* changes to the pre-processing systems are feasible. Then we could determine the smallest set of features that gets us as close to full color control as possible. Layers= could be much more powerful with just a few minor additions.
_____
Optera wrote:
Sat May 25, 2019 2:32 pm
Using lua to crop and tint sprite parts on the fly doesn't sound feasible.
Cropping already exists, it's called {x=,y=,width=,heigt=}. You can even move stuff around with shift=, and tint= already works (ofc you know all this ;). Combined with layers= some magic is possible. The main crux is that tint has an unflexible limit like i described above.
Author of: Hand Crank Generator, Screenshot Hotkey 2.0
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding interface requests”

Who is online

Users browsing this forum: No registered users