<p>(XYZ) can be the RGB colour you want to tint your scene by. For the above scene it can be a red colour (1.0, 0.0, 0.0) or something similar with a strong red component. </p>

<p>Bear in mind that since you are applying the colour in a multiplicative way it will act as a filter suppressing original colour components. So if your scene is mostly green but you apply (i.e. multiply it with) a red filter (1,0,0) the resulting scene will be very dark.</p>

<p>A trick you could potentially do in such cases is to desaturate the original scene and then multiply it by the tint colour. That way you will keep the overall image intensity and achieve the colour tint you require.</p>

<p>For example, here is the image multiplied by (1, 0, 0), (1, 0.2, 0.2), and (1, 0.5, 0.5) from left to right:</p>

<p><a href="https://i.sstatic.net/N4YCV.png" rel="noreferrer"><img src="https://i.sstatic.net/N4YCV.png" alt="enter image description here"></a> <a href="https://i.sstatic.net/95LBW.png" rel="noreferrer"><img src="https://i.sstatic.net/95LBW.png" alt="enter image description here"></a> <a href="https://i.sstatic.net/mkIgR.png" rel="noreferrer"><img src="https://i.sstatic.net/mkIgR.png" alt="enter image description here"></a></p>

CC BY-SA 3.0
2015-09-02T19:14:16.117Z
Also you might want to tint something other than 100% pure one channel color.
joojaa
CC BY-SA 3.0
2015-09-03T05:29:52.243Z
I went ahead and added some example images to the post - hope you don't mind!
Nathan Reed
CC BY-SA 3.0
2015-09-03T16:17:26.723Z
That is exactly what I meant. Thanks for effort and examples :)
bartosz.baczek
CC BY-SA 3.0
2015-09-02T13:47:43.743Z
2015-09-03T05:29:26.583Z
2015-09-03T05:29:26.583Z
Kostas Anagnostou
<p>Choose the color RGB of your colorful glasses and choose how transparent they are by choosing an alpha value A. Then <a href="https://en.wikipedia.org/wiki/Alpha_compositing" rel="nofollow">alpha composite</a> the glasses on top of the input image:</p>

<pre><code>OutputR = R * A + InputR * (1-A)
OutputG = G * A + InputG * (1-A)
OutputB = B * A + InputB * (1-A)
</code></pre>

CC BY-SA 3.0
2015-09-02T12:00:33.587Z
What do you mean by "composite"? Is there some mathematical operation  that lets me to composite two colours?
bartosz.baczek
CC BY-SA 3.0
2015-09-02T12:51:13.703Z
That's what the example equations in his post do.
yuriks
CC BY-SA 3.0
2015-09-02T14:58:30.927Z
I don't think this is what he wants. If you wear red-tinted glasses, you see red wavelengths at basically full strength, and very little from other wavelengths. That's not a great match for alpha compositing.
John Calsbeek
CC BY-SA 3.0
2015-09-02T11:58:46.027Z
2015-09-02T12:01:17.487Z
2015-09-02T12:01:17.487Z
lhf
<p>Extending Kostas Anagnostou's answer, a commonly used formula for desaturation is</p>

<pre><code>float value = 0.3 * InputR + 0.59 * InputG + 0.11 * InputB;
</code></pre>

<p>This accomodates the fact that different color hues are perceived with a different intensity by a human observer.</p>

<p>Further following the example, you would then define some tint color that is multiplied with the desaturated value. Also you could mix the tinted image with your original to get a less drastic effect. In this case, we're mixing 80% of the desaturated image tinted with (1.0, 0.2, 0.2) with 20% of the original:</p>

<pre><code>float3 tint = float3(1.0, 0.2, 0.2);
float tintMix = 0.8;
OutputR = tintMix * value * tint.r + (1.0 - tintMix) * InputR;
OutputG = tintMix * value * tint.g + (1.0 - tintMix) * InputG;
OutputB = tintMix * value * tint.b + (1.0 - tintMix) * InputB;
</code></pre>

CC BY-SA 3.0
2017-05-19T02:45:55.393Z
Note that (0.3, 0.59, 0.11) are the [luma coefficients](https://en.wikipedia.org/wiki/Luma_(video)) for Rec. 601 (aka Standard Def. NTSC), whereas Rec. 709 (aka High Def. ATSC) would be (0.2126, 0.7152, 0.0722). And sRGB images (which is likely what you're dealing with) are closer to Rec. 709 than Rec. 601.
user1118321
CC BY-SA 3.0
2015-09-03T13:53:39.800Z
2015-09-07T07:59:28.727Z
2015-09-07T07:59:28.727Z
David Kuri
<p>I am currently working on some simple pixel shader in HLSL. I send to shader texture and I want to make it more colorful (something like in the picture below). </p>

<p><a href="https://i.sstatic.net/AvcUu.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/AvcUu.jpg" alt="enter image description here"></a></p>

<p>In the picture 1 there is original texture. Picture 2 shows an effect that I want to achieve. Is there some mathematical formula to do that? My input is the RGBA value of each pixel.</p>

<p>EDIT:
I'll try to write more concrete. </p>

<p>Let's say I want to make that garden texture more red. I suppose that what I need to do is:</p>

<pre><code>OutputR = InputR * X,

OuputG = InputG * Y,

OutputB = InpputB * Z
</code></pre>

<p>But how do I find X, Y and Z?</p>

CC BY-SA 3.0
2015-09-02T11:48:29.010Z
When you say "more colorful" do you mean specifically as if looking through tinted glass?
trichoplax is on Codidact now
CC BY-SA 3.0
2015-09-02T11:50:53.190Z
Yes, that's what i mean
bartosz.baczek
CC BY-SA 3.0
2015-09-02T11:51:10.013Z
Do you also want to take the tint colour as a separate input, or do you just want an arbitrary tint colour that happens to be cheap to implement?
trichoplax is on Codidact now
CC BY-SA 3.0
2015-09-02T11:53:58.373Z
Sorry, I think I don't understand your question. Could you explain that more?
bartosz.baczek
CC BY-SA 3.0
2015-09-02T15:32:20.770Z
If [Kostas Anagnostou's answer](http://computergraphics.stackexchange.com/a/410/231) is what you want then ignore my comments. I was just asking whether you wanted that or a hardcoded colour.
trichoplax is on Codidact now
CC BY-SA 3.0
2015-09-03T09:06:49.237Z
For more realistic results, you might find this answer interesting: http://photo.stackexchange.com/a/49267/23075
wip
<texture><algorithm><image-processing><hlsl><pixel-shader>
Changing image so it would look like through colorful glasses
bartosz.baczek
# Changing image so it would look like through colorful glasses

(Asked by: username_0 on 2015-09-02)

I am currently working on some simple pixel shader in HLSL. I send to shader texture and I want to make it more colorful (something like in the picture below).

[![enter image description here](https://i.sstatic.net/AvcUu.jpg)](https://i.sstatic.net/AvcUu.jpg)

In the picture 1 there is original texture. Picture 2 shows an effect that I want to achieve. Is there some mathematical formula to do that? My input is the RGBA value of each pixel.

EDIT:
I'll try to write more concrete.

Let's say I want to make that garden texture more red. I suppose that what I need to do is:

```
OutputR = InputR * X,

OuputG = InputG * Y,

OutputB = InpputB * Z

```

But how do I find X, Y and Z?

**Tags:** texture, algorithm, image-processing, hlsl, pixel-shader

> **Comments:**
> **username_1**: When you say "more colorful" do you mean specifically as if looking through tinted glass?  
> **username_0**: Yes, that's what i mean  
> **username_1**: Do you also want to take the tint colour as a separate input, or do you just want an arbitrary tint colour that happens to be cheap to implement?  
> **username_0**: Sorry, I think I don't understand your question. Could you explain that more?  
> **username_1**: If [username_3 username_3's answer](http://computergraphics.stackexchange.com/a/410/231) is what you want then ignore my comments. I was just asking whether you wanted that or a hardcoded colour.  
> **username_2**: For more realistic results, you might find this answer interesting: http://photo.stackexchange.com/a/49267/23075  

---

## 3 answers

### Answer by username_9 on 2015-09-03. Score: 6 | Accepted answer

Extending username_3 username_3's answer, a commonly used formula for desaturation is

```
float value = 0.3 * InputR + 0.59 * InputG + 0.11 * InputB;

```

This accomodates the fact that different color hues are perceived with a different intensity by a human observer.

Further following the example, you would then define some tint color that is multiplied with the desaturated value. Also you could mix the tinted image with your original to get a less drastic effect. In this case, we're mixing 80% of the desaturated image tinted with (1.0, 0.2, 0.2) with 20% of the original:

```
float3 tint = float3(1.0, 0.2, 0.2);
float tintMix = 0.8;
OutputR = tintMix * value * tint.r + (1.0 - tintMix) * InputR;
OutputG = tintMix * value * tint.g + (1.0 - tintMix) * InputG;
OutputB = tintMix * value * tint.b + (1.0 - tintMix) * InputB;

```

> **Comments:**
> **username_10**: Note that (0.3, 0.59, 0.11) are the [luma coefficients](https://en.wikipedia.org/wiki/Luma_(video)) for Rec. 601 (aka Standard Def. NTSC), whereas Rec. 709 (aka High Def. ATSC) would be (0.2126, 0.7152, 0.0722). And sRGB images (which is likely what you're dealing with) are closer to Rec. 709 than Rec. 601.  

---

### Answer by username_3 on 2015-09-02. Score: 13

(XYZ) can be the RGB colour you want to tint your scene by. For the above scene it can be a red colour (1.0, 0.0, 0.0) or something similar with a strong red component.

Bear in mind that since you are applying the colour in a multiplicative way it will act as a filter suppressing original colour components. So if your scene is mostly green but you apply (i.e. multiply it with) a red filter (1,0,0) the resulting scene will be very dark.

A trick you could potentially do in such cases is to desaturate the original scene and then multiply it by the tint colour. That way you will keep the overall image intensity and achieve the colour tint you require.

For example, here is the image multiplied by (1, 0, 0), (1, 0.2, 0.2), and (1, 0.5, 0.5) from left to right:

[![enter image description here](https://i.sstatic.net/N4YCV.png)](https://i.sstatic.net/N4YCV.png) [![enter image description here](https://i.sstatic.net/95LBW.png)](https://i.sstatic.net/95LBW.png) [![enter image description here](https://i.sstatic.net/mkIgR.png)](https://i.sstatic.net/mkIgR.png)

> **Comments:**
> **username_4**: Also you might want to tint something other than 100% pure one channel color.  
> **username_5**: I went ahead and added some example images to the post - hope you don't mind!  
> **username_0**: That is exactly what I meant. Thanks for effort and examples :)  

---

### Answer by username_6 on 2015-09-02. Score: 3

Choose the color RGB of your colorful glasses and choose how transparent they are by choosing an alpha value A. Then [alpha composite](https://en.wikipedia.org/wiki/Alpha_compositing) the glasses on top of the input image:

```
OutputR = R * A + InputR * (1-A)
OutputG = G * A + InputG * (1-A)
OutputB = B * A + InputB * (1-A)

```

> **Comments:**
> **username_0**: What do you mean by "composite"? Is there some mathematical operation  that lets me to composite two colours?  
> **username_7**: That's what the example equations in his post do.  
> **username_8**: I don't think this is what he wants. If you wear red-tinted glasses, you see red wavelengths at basically full strength, and very little from other wavelengths. That's not a great match for alpha compositing.  

---

