Swap green for blue wisely


Here’s a puzzle …
Let’s say I want to swap the GREEN component of a color with BLUE.

Sounds prertty simple:

fn swap_gb c = color c.r c.b c.g

does not it?

But we know that the intensity of the GREEN component is different from the BLUE one. The RGB luminous value is known as: 0.229, 0.587, 0.114

The question is - how to swap G and B, but keep the color intensity?


what do you mean by color intensity?
i’m not sure but seems ok here to swap as you did in linear space

could it be a gamma related issue?

also saturation which is what i think you mean by intensity is the same



Look at this picture… GREEN and BLUE are both 100% but blue looks darker than green.

Here is how the illuminance of a color is usually calculated:
0.299 * R + 0.587 * G + 0.114 * B

sqrt(0.299 * R^2 + 0.587 * G^2 + 0.114 * B^2)

but the idea is the same - each color component has a different effect on color illuminance, which means that if we just simply change the green and blue, it will make the color visually lighter or darker.


ok that blows me away…
i understand now your point but numerically they are the same
changing the background will also affect your perception


doesn’t it?

btw tomorrow i will try your method to understands more

sure it’s intresting


Ok, i found this

Now i better understand your point…
And i’m going to shut up


…kind of…


No! I want the opposite … to get more people involved in the discussion. :slight_smile:


Here’s “practical” example of luminosity values with green/blue checker map in displacement mod. (and material color).
Green going to 58,7/100 (or 0,587/1 from @denisT values


You should composite original and swapped bitmap with swapped set to “color” blend mode
(or original set to luminosity over swapped one).
Max composite map not working with colored bitmaps (same value for pure green and blue,red)
Mix also.

Why green/blue? Not normal swapping for normal map. Or it’s just example?
BTW, for correcting/inverting blue channel in normals we can set normal map to negative value in material- map amount.


We don’t need color information in “original” bitmap, just luminosity/values/greyscale image.


this works ok with the displacement method

this will exceed the 0-1 space tough so i’m not sure it will be good for the purpose

nr =0.229
ng =0.587
nb =0.114


g1 = g*ng/nb
b1= b*nb/ng

lumCol = #(nr*R,ng*G,nb*B)
L = lumCol[1] + lumCol[2] + lumCol[3]
oldSwap = nr*R + ng*b + nb*g
swapL = nr*R + ng*b1 + nb*g1

oldcolor = color r g b

newcolor = color ((nr*R)/nr) ((ng*b1)/ng) ((nb*g1)/nb)

format "original luminance: % \nOldSwap luminance: % \nNew Luminance: %\n" L oldSwap swapL
format "original color: % \nnewcolor:% \n" oldcolor newcolor

it decomposes the luminosity values, divide them by they respective coefficient and then recompose
i maybe be totally off but at least it will extrude the faces as expected


so in the end the function would be

fn swap_gb c = (
	local nr =0.229
	local ng =0.587
	local nb =0.114

	color c.r (c.b*nb/ng) (c.g*ng/nb)


swap_gb (color 0.848 0.429 0.111)

swap_gb (color 0.848 0.429 0.111)
-- (color 0.848 0.0215571 2.20897)

it would be too easy… but (color 0.848 0.0215571 2.20897)


i know, i wrote it in post °10

since the blue channel maximum (or 1.0) is way less than the green i see no other options unless you want to normalize the first color to the blue maximum intensity.

you can see in the format of post °10 the luminancce values are the same but you cant create something out of nothing.

i see no other options. do you?