RGB to Hue in material

How could I convert a RGB input to a Hue value inside the material editor?

I found this formula but I have no clue how and if it is even possible in the material editor of UE4:

The required max and min are especially hard to wrap my head around.

It would be great if a full conversion from RGB to HSB would work but Hue alone would be already great.

It would be great to be able to get HSL off a color or texture the same way you can RGB (at least for colors since those should be low-overhead, I’d imagine textures might be a bit more costly.

Probably not what you’re looking for but I had a similar question a moment ago and this process might help with what you are trying to achieve.

The formula doesn’t seem possible in the material editor - the max/min stuff is easy (there’s a function for that in the editor) but the issue arises from the logical statements allowed in the material editor (the if statement specifically). You could build it with the logic in the editor but you’d end up with dozens of statements and the way it’s set up gives me the distinct impresion it’s meant to be compiled to a graphics processor so you would be killing performance doing HSL calculations per-pixel.

After lots of try and error I made it now work by using 7 If nodes to get the min and max values. After that replicating the formula was easy. Have not seen those max and min nodes before, not sure it using them will make it less costly. I still need the If nodes anyway I guess.

I’m using it for a post process material with the Base Color rendering pass to basically get color ids. The colors then use ramp lighting based on their id through a ramp texture which has the gradients in X and the colors in Y. With Light Vector not working with deferred rendering that is pretty much the only way to get ramp texture lighting. Hopefully the performance it uses is not too bad, still have to test that. One problem already is that Base Color nor Diffuse Color work with the Skybox and any other illuminated materials.

For others looking for a solution aswell I ended up having to dothe same thing and here is the network:

In 4.12 there is now a HSV to RGB material node, so you could just use the H part by putting a Mask R after it. I also made a working RGB to HSV node now by using the bugged parts someone of Epic left there, it anyone needs that just let me know.

need it! :smiley: