Search Unity

Resolved Problem with additional light node

Discussion in 'Shader Graph' started by NarberalTools, Mar 24, 2021.

  1. NarberalTools

    NarberalTools

    Joined:
    Jul 8, 2019
    Posts:
    63
    I have a problem with an additional light node. I need to read the directions of additional light sources, but the node makes priorities only one to the object. Because of this, I can not use several additional light sources on the object.

    Code (CSharp):
    1. void AdditionalLights_half(half3 WorldPos,half3 WorldNormal, out half3 Color,out half3 Diffuse, out half3 Direction,out half3 LightPos, out half3 DistanceAtten, out half3 ShadowAtten)
    2. {
    3.    
    4.    half3 diffuseColor = 0;
    5.    half3 specularColor = 0;
    6.    half3 shadowAtten = 0;
    7.    half3 distanceAtten = 0;
    8.    WorldNormal = normalize(WorldNormal);
    9.    Direction = 0;;
    10.    Color = 0;
    11.    LightPos =0;
    12.    
    13.    #ifndef SHADERGRAPH_PREVIEW
    14.       int pixelLightCount = GetAdditionalLightsCount();
    15.       for (int i = 0; i < pixelLightCount; ++i)
    16.       {
    17.          Light light = GetAdditionalLight(i, WorldPos);
    18.          Color = light.color;
    19.          distanceAtten = light.distanceAttenuation;
    20.          shadowAtten = light.shadowAttenuation;
    21.          Direction = light.direction;
    22.          LightPos = _WorldSpaceLightPos0;
    23.          float3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
    24.          diffuseColor += LightingLambert(attenuatedLightColor, light.direction, WorldNormal);
    25.       }
    26.       #endif
    27.      
    28.    ShadowAtten = shadowAtten;
    29.    DistanceAtten = distanceAtten;
    30.    Diffuse = diffuseColor;
    31. }