Download

Weird issue: blue appearing when working only with red and green channels... and a blueless texture!

Hello, fellow devs! My first post here. I decided to bring this issue to the forum because I didn’t manage to find any other thread discussing anything like this.

I have a problem regarding materials and colour masking.

Recently I came up with the idea of using non-basic colours to package masks within a texture (like yellow, cyan and magenta). I am working on a model which requires several of them and I didn’t want to have more than a single material applied to it. So I started wondering if I could package more than three masks —four if you consider alpha— inside one texture. The point is that I should use some channel overlapping trickery to differentiate all the colours.

Finally I ended up creating a very simple texture with three coloured dots on a black background, being these pure red, yellow and green:

Colour-masking.png

As you can see, we are only working with two basic colours now just for the sake of simplicity. If we took off the red and green channels, we would see:
-Firstly, two white dots at left and center, representing the red channel.
-Secondly, other two white dots at center and right, representing the green channel.

Both channels overlap at center, giving us yellow. So my idea was to convert the green channel to the red (or first) channel of a vector by appending it sequentially two zeros and then subtracting it to the “real” red channel in order to leave us only with the dot at the left. That, I thought, should cause the center dot to become black (one minus one, red “minus” red) and the right dot to become black too (technically its area would contain negative values, but since their colour representation is clamped in the range 0-1 they wouldn’t go beyond pure black).

The thing is… this didn’t work out as intended!

Do you see the preview of the Subtract node? Where the hell did that light blue come from?? And why does this method not work? I think the most confusing part of it is that it seems correct until that very Subtract node: both Append previews show the expected green-to-red dots. My only guess is that blue comes from how Unreal works with channels “under the hood”; maybe the colour conversion has more to it than I thought.

Some insight on this issue?

Thanks for reading!,

Álex.

Your math is slightly flawed. Applicable to the middle dot, You have a (1,1,1) vector. You are subtracting (1,0,0) from it . What remains is (0,1,1), which is cyan.

You use a float one minus float3, which middle color is float(1.)-float3(1.,.0,.0)=float3(.0,.1,.1),then use this multply float3(0.4,0.,0.325) just result in float3(.0,.0,0.325)

Agh! It seems so obvious now. Indeed, I didn’t realise that the Red channel would be converted into a vector.

It finally worked!

(EDIT: I have just seen that this screenshot didn’t show the final net yet. In a later version I masked the Subtract node to let only pass the Red channel and thus using this as the multiplier for the purple colour).

I have been extending the code and it works perfectly with the secondary colours implementation, but when trying to include tertiary colours I ran into this new issue:

It seems like the same problem arises with all the Multiply nodes. Here I am working with non-1-nor-0 channels (specifically with channels at 0, 0.5 and 1 values), so at that node I need no convert all non-0 values to 1 (which means, 0.5 to 1 and 1 unchanged). So I tried a simple remapping by multiplying by 2 and then clamping between 0 and 1, but… it seems like the Multiply node doesn’t change anything! I have been looking closely to the colours and yes, it seems like it is the Multiply node, and not the Clamp node, which doesn’t work as intended.

Just to further detail the setup, in each arc of dots all of them have a value of 1 except those at both ends, which have the value of 0.5. As far as I know, colour combinations are defined in the RGB colour space as the sum of both colours “at its sides” in the colour wheel, then reducing the new values to the range 0-1 preserving the channel proportions. This is obvious with secondary colours, but beyond them this becomes a little trickier (we cannot plug in ones here and there to get our colours). So orange, for instance, a tertiary colour composed of red (primary) and yellow (secondary) would be obtained by doing the following:

  1. We add both colours: Red (1,0,0) + Yellow (1,1,0) = Out-of-range orange (2,1,0)
  2. We remap the colour to the range 0-1, always preserving the proportions between the channels by dividing by the highest value: (2,1,0) / 2 = Orange (1,0.5,0) (Here is our 0.5!)

I hope this helps to clarify my nodes :).

I have been testing a few posible solutions and looking it up on the internet, but I had no luck. Any insights on this?

Álex.