Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Issue with Shadows in URP

Discussion in 'Universal Render Pipeline' started by Elledy_19, Jan 8, 2022.

  1. Elledy_19

    Elledy_19

    Joined:
    Jan 7, 2022
    Posts:
    2
    Hello!:)

    I am trying to sample the additional-light shadowmap in a custom post processing effect in URP. The problem which arises is, that it all gets very.... jittery, if more than one point/spot light are active at once. Meaning that sometimes neither shadow nor any light will be visible (when it should be).
    Here is how I am trying to sample the shadowmap :

    #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
    //...
    float LocalShadowMap(float3 worldPos){
    int lightAmount = GetAdditionalLightsCount();
    float shadow = 0, product = 0;

    for(int i = 0; i < lightAmount; i++){
    Light light = GetAdditionalLight(i, worldPos);
    shadow = AdditionalLightRealtimeShadow(i, worldPos, light.direction) * light.distanceAttenuation;

    if(shadow > 0){ //Lit
    product += 1;
    }
    }
    return product;
    }

    I also attached the whole shader in use.

    I am using URP 12.1.2 in Unity Version 2021.2.7f1. The renderer is set to deferred, although it does not change if I switch it to forward. The RenderEvent of the Blit-Feature is set to BeforeRenderingPostProcessing.

    Am I missing something? Thanks in advance!:)
     

    Attached Files:

    Last edited: Jan 8, 2022
    onlyashley04 likes this.
  2. Luke-kaser

    Luke-kaser

    Joined:
    Apr 2, 2018
    Posts:
    19
    Hi.
    According to Unity Tech team's reply. GetAdditionalLightsCount() will return ”These lights are culled per-object in the forward renderer”.
    So if you using this Api In deferred mode it were not retrun the right lights counts

    // Returns the amount of lights affecting the object being renderer.
    // These lights are culled per-object in the forward renderer
    int additionalLightsCount = GetAdditionalLightsCount();
     
    Elledy_19 likes this.
  3. Elledy_19

    Elledy_19

    Joined:
    Jan 7, 2022
    Posts:
    2
    Thanks!^^

    For anyone stumbling across this thread - this worked for me:
    In the custom renderer Feature the LightsCount is exposed as a uniform to the shader through the usage of:

    (RenderingData variable).lightData.additionalLightsCount;


    In the post processing Shader, I will loop through all the lights - getting the Light-struct through the following Method:

    Light GetAdditionalLightPostProcess(uint i, float3 positionWS)
    {
    return GetAdditionalPerObjectLight(i, positionWS);
    }


    - Which worked for me :)
     
    Luke-kaser likes this.