1
\$\begingroup\$

I have a pixel that have a colour RGB. This color is calculated by the shader and can be anything.

How can I override this color by a colour I choose. If my pixel is white it's simple, I can do this:

half3 original = half3(1, 1, 1);
half3 mycolor = half3(1, 0, 0);
half3 result = original * mycolor;

But what can I do if:

half3 original = half3(0.36, 0.74, 0.18);
half3 mycolor = half3(1, 0, 0);
half3 result = ?;

What operation or function should I apply to my original pixel color to override it ?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I don't get the problem here. What is the problem with "result = mycolor;" \$\endgroup\$
    – Arne
    Jan 30 '14 at 23:09
5
\$\begingroup\$

Just

half3 result = (original + mycolor) / 2;

does what you'd expect because the arithmetic operators are overridden for the half3 type.

\$\endgroup\$
4
\$\begingroup\$

It was very easy finally. Here is the answer. I am using an external value.

half3 original = half3(0.36, 0.74, 0.18);
half3 mycolor = half3(1, 0, 0);
half value = 0.5;
half3 result = original * value + mycolor * (1 - value);

You could also use mix(); or lerp(); depending on your platform.

\$\endgroup\$
3
  • 6
    \$\begingroup\$ result = mix(mycolor, original, value); \$\endgroup\$
    – MickLH
    Jan 29 '14 at 15:14
  • \$\begingroup\$ The mix function doesn't appears in the NVidia developer zone... This function is only available in OpengGL, no ? \$\endgroup\$
    – MaT
    Jan 29 '14 at 15:21
  • 3
    \$\begingroup\$ GLSL is just my flavor of choice, in HLSL it's called lerp() \$\endgroup\$
    – MickLH
    Jan 29 '14 at 15:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .