Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity 5 - Surface shader and Custom lighting functions

Discussion in 'Shaders' started by MaT227, Mar 6, 2015.

  1. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    Hey everyone,

    I am writing some custom surface shaders and it seems that the documentation is not right anymore. Here are all the custom lighting functions available depending for your configuration.
    Code (CSharp):
    1. half4 Lighting<Name>(SurfaceOutput s, half3 lightDir, half atten);
    2. half4 Lighting<Name>(SurfaceOutput s, half3 lightDir, half3 viewDir, half atten);
    3. half4 Lighting<Name>_PrePass(SurfaceOutput s, half4 light);
    4. half4 Lighting<Name>_SingleLightmap(SurfaceOutput s, fixed4 color);
    5. half4 Lighting<Name>_SingleLightmap(SurfaceOutput s, fixed4 color, half3 viewDir);
    6. half4 Lighting<Name>_DualLightmap(SurfaceOutput s, fixed4 totalColor, fixed4 indirectOnlyColor, half indirectFade);
    7. half4 Lighting<Name>_DualLightmap(SurfaceOutput s, fixed4 totalColor, fixed4 indirectOnlyColor, half indirectFade, half3 viewDir);
    8. half4 Lighting<Name>_DirLightmap(SurfaceOutput s, fixed4 color, fixed4 scale, bool surfFuncWritesNormal);
    9. half4 Lighting<Name>_DirLightmap(SurfaceOutput s, fixed4 color, fixed4 scale, half3 viewDir, bool surfFuncWritesNormal, out half3 specColor);
    It seems that those function are not working anymore because I tried to write a simple Lambert lighting function (using the Surface Shader Lighting Examples) and the light direction was always wrong but the shaders created with an old version of Unity are always working... This is a bit strange.
    I've made a new test while writing this post and it's working now, this is a bit strange...

    But here are the functions you can use now and it always include UnityGI informations and there are no more custom function for lightmapping.
    Code (CSharp):
    1. fixed4 Lighting<Name>(SurfaceOutput s, half3 viewDir, UnityGI gi)
    2. fixed4 Lighting<Name>(SurfaceOutput s, UnityGI gi)
    3. half4 Lighting<Name>_Deferred (SurfaceOutput s, half3 viewDir, UnityGI gi, out half4 outDiffuseOcclusion, out half4 outSpecSmoothness, out half4 outNormal)
    4. half4 Lighting<Name>_Deferred (SurfaceOutput s, UnityGI gi, out half4 outDiffuseOcclusion, out half4 outSpecSmoothness, out half4 outNormal)
    5. fixed4 Lighting<Name>(_PrePass (SurfaceOutput s, half4 light)
    6. void Lighting<Name>_GI(SurfaceOutput s, UnityGIInput data, inout UnityGI gi)
    But you need to use gi.light, gi.light2 (lightmap), gi.light3 (dynamic lightmap), gi.indirect.diffuse (indirect lighting).

    Could someone give some precisions about this ? What can we use (old functions or new) ?
    Thanks a lot !
     
  2. zRedCode

    zRedCode

    Joined:
    Nov 11, 2013
    Posts:
    131
    in theory new function works only in ...PBR shaders, old shader can use old functions.
     
  3. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    I am not sure because the built-in Lambert and Blinn-Phong lighting functions use the new lighting functions and on the shader sources old lightmapping functions are commented as deprecated.
     
  4. zRedCode

    zRedCode

    Joined:
    Nov 11, 2013
    Posts:
    131
    i think you have to look in the cginc files that comes with unity built in shaders zip file.
     
  5. MaT227

    MaT227

    Joined:
    Jul 3, 2012
    Posts:
    628
    Yes, that's what I did and that's why I say that they are using the new functions :)