Yellow-Dog-Man / Resonite-Issues

Issue repository for Resonite.
https://resonite.com
139 stars 2 forks source link

Add an option to tint a StaticTexture2D in-game #2783

Open JackTheFoxOtter opened 2 months ago

JackTheFoxOtter commented 2 months ago

Is your feature request related to a problem? Please describe.

I very frequently use the icons from the press kit for my own creations (they are great!). Frequently I need the sprites in a different color than the one provided in the press kit. When that happens I need to take the white version of the icon, throw it into Gimp, change the color, then export it from Gimp and import it into Resonite again.

Describe the solution you'd like

I would like to be able to simply tint a StaticTexture2D with a specified color through one of the image operators on the component. This comes up quite frequently for me, and this would be a tremendous help.

Specifically I'd like two coloring operators, one that tints the image in the specified color in visually the same way as if adding a tint to the image through a UIX image component for example, and a second that takes the R, G and B values from the specified color and multiplies the alpha channel from the specified color with the alpha channel of the original texture. That way you could both tint and also fully replace the colors of a StaticTexture2D with a simple button press right in-game!

Edit: This only needs a multiplicative tint operation, as Froox has elaborated in the comments below.

Describe alternatives you've considered

Going the laborous manual route, or perhaps making a complex camera setup. Both aren't very fun.

Additional Context

No response

Requesters

No response

Frooxius commented 2 months ago

Why not just tint the material? That's usually how this is done, with the base being white, allowing you to make lots of tinted versions efficiently.

We could add this on principle, but it seems like a wrong solution for the problem you presented.

JackTheFoxOtter commented 2 months ago

Because sometimes I need the actual texture itself tinted. The most recent example was today when I needed a correctly colored texture for the icon URI of the RadiantDashScreen component.

Frooxius commented 2 months ago

But why do you need the actual texture itself tinted? Why doesn't tinting the material work?

JackTheFoxOtter commented 2 months ago

Because the component only exposes an icon URI, and doesn't expose the material? Or is there a way to use a custom material for that? It generates the RadiantDashButton, I don't think I can tell it to use a custom template. There are a couple of situations in which components ask for a direct texture URI. Additionally, sometimes I don't have a pure white version of the texture. This would allow me to make one.

JackTheFoxOtter commented 2 months ago

Just to be clear, in 99% of cases I do tint the icon differently. But sometimes that's not applicable, or I don't have a pure-white version of the texture to begin with.

Frooxius commented 2 months ago

I see. We could add this for that.

We can also separately add more options to control the tint too in some cases.

However this brings other question - how do you expect the tinting to actually work? There's a bunch of ways to do it, but you bring up not having a pure-white version of the texture. Are you expecting the tint option to change the color of existing image?

Typically tinting is just multiplicative operation, but you can't change one color to another that way. We could instead make it work in the hue space and just set the hue to a particular color and max out the saturation.

JackTheFoxOtter commented 2 months ago

In the original issue text I requested two options:

I think that should cover all common cases of recoloring needs I've ever encountered. Together with the already existing channel swap operators that would allow a whole bunch of image processing options that weren't possible before!

We can also separately add more options to control the tint too in some cases.

Yeah, that would be good as well. And there are already some issues for that, for example #993. The RadiantDashButton in particular is really nieche, I'm not sure that would necessarily be worth the development time. And for those kind of situations it's good to have other options available.

Frooxius commented 2 months ago

The problem with the second approach is that it will destroy any brightness information in the image. You're essentially just using original texture as "cutout" for the solid color, which to me doesn't seem that good for tinting - and it's something you can already do with existing operations.

If it works by setting the hue to specific color, I think that can achieve much better results, because it'll preserve whatever brightness information is there.

JackTheFoxOtter commented 2 months ago

In some cases that's desired. Sometimes you want textures to have a uniform color, and just keep the alpha channel. Is that actually possible already? I can create a mask from alpha, then turn black to alpha, and then I have a fully bright white texture I can't recolor, as hue-shifting a color with value 1 does nothing.

JackTheFoxOtter commented 2 months ago

Then again I with only the new tinting option I could achive the same effect!

Frooxius commented 2 months ago

Yeah. Do Alpha To Mask -> Alpha From Intensity and you get a cutout.

JackTheFoxOtter commented 2 months ago

Which I could then tint if required.

In that case I only need the multiplicative tint to achive everything I want!

Frooxius commented 2 months ago

Ok, I'll see what kind of options I can add!