Why is the default diffuse shader 2x brighter then expected?

The setup(the image bellow should make things clear):

  • one directional light pointing pointing perpendicular to one of the faces of two cubes.
  • both cubes are set to have the color white
  • ambient light set to black (has no effect)
  • the directional light color is set to 0.25 (i.e. ~64 gray in the byte range)

So one would expect that when a white light with the value 0.25 hits perpendicularly a white surface(1.0) the result would be 0.25 * 1.00 * cos(0 deg) = 0.25 (or 64,64,64 in the R8G8B8 format) but we get twice that.

[21183-diffuse+vs+simple+shader.png|21183]

If I use this simple shader the result is as expected:

Shader "Custom/Simple Shader" {
    Properties {
        _Color ("Main Color", Color) = (1,1,1,1)
    }
    SubShader {
        Pass {
            Material {
                Diffuse [_Color]
            }
            Lighting On
        }
    }
} 

Knowing that the diffuse shader does only the following (you can see it from the unity built in shaders “Normal-diffuse.shader”):

...
    void surf (Input IN, inout SurfaceOutput o) {
    	fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    	o.Albedo = c.rgb;
    	o.Alpha = c.a;
    }
...

and there is no texture set and the default is white (so it’s neutral to the multiplication)
where does the 2x factor come from?

Basically if the directional light has an intensity of 0.5 or above, the face of the cube is saturated in if it has a diffuse shader;

Ok there are two issues here.

  1. Not sure why yet but Diffuse shader is falling back to VertexLit in the example above.

  2. Diffuse/VertexLit shader have a texture attached which yours does not. If the texture is not set it assumes white. So a diffuse shader with no texture sets it color to white * white which explains your white doubled.

Hope this helps.