Search Unity

Question Applying custom Ambient Color in Surface Shader (legacy)

Discussion in 'Shaders' started by marchall_box, Dec 27, 2020.

  1. marchall_box

    marchall_box

    Joined:
    Mar 28, 2013
    Posts:
    139
    Hello,

    I have a shader that uses a custom lighting function with legacy surface shader format.

    I really hope to use a custom Ambient Color for this specific shader only.
    Is it possible to do that?

    I am on Legacy, Unity 2019.4.16f1


    Right now, as you know, this affects globally and that is okay but I want to set a specific color only for the shader separately.

    Thank you!
     

    Attached Files:

    Last edited: Dec 27, 2020
  2. marchall_box

    marchall_box

    Joined:
    Mar 28, 2013
    Posts:
    139
    Got an answer from bgolus:

    There’s a noambient directive you can add to the
    #pragma surface

    line, and then you can add your own ambient lighting however you want.
    A solid color ambient is really just ambientColor * albedo * ambientOcclusion (and you can skip the AO if you want).

    You can do this with or without a custom lighting function. Just do:
    Code (CSharp):
    1. o.Emission += _AmbientColor * o.Albedo;