Search Unity

Why are there differences between SetVector("_Color") and SetColor("_Color")

Discussion in 'General Graphics' started by shapov1, Feb 14, 2019.

  1. shapov1

    shapov1

    Joined:
    Jun 16, 2017
    Posts:
    2
    Could someone help me understand the reason why the two behaviors differ?

    An example script that uses two cubes to demonstrate this:

    Code (CSharp):
    1.  
    2. MaterialPropertyBlock props1 = new MaterialPropertyBlock();
    3. props1.SetColor("_Color", new Color(0.25f, 0.1845f, 0.562f , 1f));
    4.  
    5. MaterialPropertyBlock props2 = new MaterialPropertyBlock();
    6. props2.SetVector("_Color", new Vector4(0.25f, 0.1845f, 0.562f, 1f));
    7.  
    8. cube1.GetComponent<Renderer>().SetPropertyBlock(props1);
    9. cube2.GetComponent<Renderer>().SetPropertyBlock(props2);
    10.  
    Which leads to the two cubes looking like this:



    Both cubes use the same exact material, and Unity's standard shader.
    One would think that since both color values end up as float4 in the shader, the two cubes would have the same color value, and look identical.
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,014
    karl_jones likes this.
  3. shapov1

    shapov1

    Joined:
    Jun 16, 2017
    Posts:
    2
    Thanks, for the response. Much appreciated. I feel silly for not actually checking the docs.