<p>In a shader, colors in the viewable range are assumed to be in the range 0 to 1. If you take a value that's between 0 and 1 and add a positive value to it, it will get brighter. However, if you take a value between 0 and 1 and multiply it by a value between 0 and 1, it will get darker. To understand, think about multiplying 0.5 by 0.5. The result is 0.25.</p>

<p>More generally, any value between 0 and 1 can be thought of as a percentage. 0.05 = 5%. 0.25  = 25%. So multiply any value between 0 and 1 by a percentage between 0 and 1, and it will be less than the original value. (50% of 50% is 25% in the earlier example.)</p>

<p>If you have a photo editing application like Photoshop or GIMP, you can see the difference between the 2 by creating 2 layers with image data in them, and setting the blend mode of the top layer to either Add or Multiply. It's particularly revealing if you use a left-to-right gradient of black to white over the same gradient rotated 90°. You'll see how all the values react to the current blend mode.</p>

CC BY-SA 4.0
2018-09-04T03:11:59.103Z
2018-09-04T03:11:59.103Z
user1118321
<p>I have a two different codes with a little difference  </p>

<p>Case 1. I used a + operator before _myColor.</p>

<p><code>void surf(Input IN, inout SurfaceOutput o) {
       o.Albedo = (tex2D(_myTexture, IN.uv_myTexture) + _myColor).rgb;
    }</code></p>

<p>Case 2. I used a * operator before _myColor.</p>

<p><code>void surf(Input IN, inout SurfaceOutput o) {
       o.Albedo = (tex2D(_myTexture, IN.uv_myTexture) * _myColor).rgb;
    }</code></p>

<p>In first case It gives bright color.</p>

<p><a href="https://i.sstatic.net/QaAmi.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/QaAmi.png" alt="Case 1"></a></p>

<p>But in second case it gives very dark color. </p>

<p><a href="https://i.sstatic.net/VzObL.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/VzObL.png" alt="Case 2"></a></p>

<p>My question is why and how this is happening? </p>

<shader><unity>
Difference between using + and * operator after tex2D to add albedo color?
Abhinay Singh Negi
# Difference between using + and * operator after tex2D to add albedo color?

(Asked by: username_0 on 2018-09-04)

I have a two different codes with a little difference

Case 1. I used a + operator before \_myColor.

`void surf(Input IN, inout SurfaceOutput o) {
o.Albedo = (tex2D(_myTexture, IN.uv_myTexture) + _myColor).rgb;
}`

Case 2. I used a \* operator before \_myColor.

`void surf(Input IN, inout SurfaceOutput o) {
o.Albedo = (tex2D(_myTexture, IN.uv_myTexture) * _myColor).rgb;
}`

In first case It gives bright color.

[![Case 1](https://i.sstatic.net/QaAmi.png)](https://i.sstatic.net/QaAmi.png)

But in second case it gives very dark color.

[![Case 2](https://i.sstatic.net/VzObL.png)](https://i.sstatic.net/VzObL.png)

My question is why and how this is happening?

**Tags:** shader, unity


---

## 1 answers

### Answer by username_1 on 2018-09-04. Score: 1 | Accepted answer

In a shader, colors in the viewable range are assumed to be in the range 0 to 1. If you take a value that's between 0 and 1 and add a positive value to it, it will get brighter. However, if you take a value between 0 and 1 and multiply it by a value between 0 and 1, it will get darker. To understand, think about multiplying 0.5 by 0.5. The result is 0.25.

More generally, any value between 0 and 1 can be thought of as a percentage. 0.05 = 5%. 0.25 = 25%. So multiply any value between 0 and 1 by a percentage between 0 and 1, and it will be less than the original value. (50% of 50% is 25% in the earlier example.)

If you have a photo editing application like Photoshop or GIMP, you can see the difference between the 2 by creating 2 layers with image data in them, and setting the blend mode of the top layer to either Add or Multiply. It's particularly revealing if you use a left-to-right gradient of black to white over the same gradient rotated 90°. You'll see how all the values react to the current blend mode.


---

