Search code examples
unity-game-engineshadercg

Why the final color value is the product of two other color values in shader program?


in the diffuse lighting model or other models,the final color value of a pixel should be a product of other two light color value,and i don't quite understand. like this:

float4 c;
c.rgb = (s.Albedo * _LightColor0.rgb*diff);

Solution

  • It is because you also need to consider the colour of the lights and those reflected from the surrounding.

    In the code you have submitted s.Albedo is the colour of the object itself and _LightColor0.rgb provides the colour of your main light (that is the directional Light in your scene). as an experiment first try changing the colour of your main light from white to red to blue and you will notice what happens.

    Also without the _LightColor0.rgb * diff multiplied the object will give flat colours and look more like a 2D object.