Search Unity

Question Additional light - Cel Shading Graph

Discussion in 'Shader Graph' started by Icetru, Jan 26, 2021.

  1. Icetru

    Icetru

    Joined:
    Jan 8, 2021
    Posts:
    1
    Hi,
    I am trying to make cel-shading graph, but actually my shader graph didn't react to additional light. I know this is normal, but I can't seem to implement an additional light script in my shader graph.
    Unity version: 2019.4.17
    URP version: 7.3.1

    I found this script for additional light:
    Code (CSharp):
    1.  
    2.  
    3. void AdditionalLights_float(float3 SpecColor, float Smoothness, float3 WorldPosition, float3 WorldNormal, float3 WorldView, out float3 Diffuse, out float3 Specular) {
    4.     float3 diffuseColor = 0;
    5.     float3 specularColor = 0;
    6.  
    7. #ifndef SHADERGRAPH_PREVIEW
    8.     Smoothness = exp2(10 * Smoothness + 1);
    9.     WorldNormal = normalize(WorldNormal);
    10.     WorldView = SafeNormalize(WorldView);
    11.     int pixelLightCount = GetAdditionalLightsCount();
    12.     for (int i = 0; i < pixelLightCount; ++i) {
    13.         Light light = GetAdditionalLight(i, WorldPosition);
    14.         float3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
    15.         diffuseColor += LightingLambert(attenuatedLightColor, light.direction, WorldNormal);
    16.         specularColor += LightingSpecular(attenuatedLightColor, light.direction, WorldNormal, WorldView, float4(SpecColor, 0), Smoothness);
    17.     }
    18. #endif
    19.  
    20.     Diffuse = diffuseColor;
    21.     Specular = specularColor;
    22. }
    My Shader Graph:
    upload_2021-1-26_10-53-12.png

    Thank for advance for your help