Search Unity

HLSL/Custom Shader Light Distance Attenuation is 0 in Build

Discussion in 'Universal Render Pipeline' started by caladluin, Dec 30, 2020.

  1. caladluin

    caladluin

    Joined:
    Jan 29, 2014
    Posts:
    25
    Hello,

    I'm working on a custom URP shader that relies on the BRDFData &
    LightingPhysicallyBased function that the URP provides, but I'm running into a strange issue, and couldn't find the solution.
    In editor - it seems to work perfectly:
    upload_2020-12-30_8-17-6.png
    The green shapes are using my custom shader, the grey cube is using the URP's default lit shader, and was there for reference.
    In game however (in this case, built to Win64, IL2CPP - I'll try on other devices when I have a chance) - the shader doesn't take in light information at all:
    upload_2020-12-30_8-19-11.png

    I've done some tests - outputting some of the different values provided by the light, and found out that the distanceAttenuation is 0 - which is why these objects are dark.
    I'm getting my lights using:
    Code (csharp):
    1.  
    2. Light mainLight = GetMainLight();
    3. &
    4. Light additionalLight = GetAdditionalLight(i, surf.p);
    5.  
    though I also tried:
    Code (csharp):
    1.  
    2. Light mainLight = GetMainLight(float4(0,0,0,0), surf.p, half4(0,0,0,0));
    3.  
    but it still ends up in the same situation. Any ideas what the issue could be here? Why is it working in editor and not in build?
    Thanks!
    Just to clarify the attenuation thing - here the R channel is distance attenuation, and the G channel is shadow attenuation:
    In editor
    upload_2020-12-30_8-37-35.png
    In build
    upload_2020-12-30_8-37-57.png upload_2020-12-30_8-37-57.png upload_2020-12-30_8-37-35.png upload_2020-12-30_8-19-11.png upload_2020-12-30_8-17-6.png

    EDIT: I forgot to note - this shader is running as part of a scriptable render pass, not on a per object basis.
     
    Last edited: Dec 30, 2020
  2. clixmods

    clixmods

    Joined:
    Sep 21, 2021
    Posts:
    3
    Do you find a solution ? I have the same prob