Search Unity

Stuck on custom GI for Surface Shader

Discussion in 'Shaders' started by BPR, Apr 5, 2021.

  1. BPR

    BPR

    Joined:
    Jan 4, 2013
    Posts:
    56
    Hi,

    I would like to gain some fine control over reflection probe strength, lightprobe and lightmap intensity in one of my existing shaders.
    I started adapting form this custom GI example here.

    However I soon hit some walls:
    - I cant use a void Lighting<Name>_GI function like in the example or Unity will complain (and have no clue what to actually return there):
    Shader error in 'Skin/MinExample': Surface shader lighting model 'Skin' is missing a forward or deferred function (Skin) at line 22
    - As soon as I add the UnityGI gi parameter to my Lighting<Name> function the output color will be black
    - I am general confused how the Lighting<Name> and Lighting<Name>_GI function will interact:
    • Do I need the UnityGI gi parameter in Lighting<Name>? Do I have to add it manually to the resulting color like
      c.rgb += gi.indirect.specular;
    • Do I need to call Lighting<Name>_GI somewhere in my code? At the moment it seems like it does nothing.
    I broke my shader down to an simple minimal example, any help is greatly appreciated.

    Kind regards!
     

    Attached Files:

    Last edited: Apr 5, 2021
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
  3. BPR

    BPR

    Joined:
    Jan 4, 2013
    Posts:
    56
    Okay I found the issue by transforming step by step between the example and my MinExample:
    inline float4 LightingSkin(SurfaceOutputSkin s, fixed3 lightDir, float3 viewDir, fixed atten , UnityGI gi)
    Is not recognized by Unity because of the extra paramters.
    It has to be:
    inline float4 LightingSkin(SurfaceOutputSkin s, float3 viewDir, UnityGI gi)
    • lightDir can be accessed via gi.light.dir
    • and attenuation seems to be already included in gi.light.color
    Thanks for your time guys!