Search Unity

Resolved Light data

Discussion in 'Shaders' started by NarberalTools, Jun 7, 2021.

  1. NarberalTools

    NarberalTools

    Joined:
    Jul 8, 2019
    Posts:
    63
    The code takes into account only one additional light source. I need the code to take into account several sources of extra light. What's wrong here?
    Code (CSharp):
    1. void AdditionalLights_half(
    2. half3 WorldPos,
    3. out half3 Color,
    4. out half3 Direction,
    5. out half DistanceAtten,
    6. out half ShadowAtten)
    7. {
    8.    Direction = 0;
    9.    Color = 0;
    10.    ShadowAtten = 0;
    11.    DistanceAtten = 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.          Direction = light.direction;
    20.          ShadowAtten = light.shadowAttenuation;
    21.          DistanceAtten = light.distanceAttenuation;
    22.       }
    23.    #endif
    24. }