1
$\begingroup$

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

But in second case it gives very dark color.

Case 2

My question is why and how this is happening?

$\endgroup$
0
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.