Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

[SOLVED] Change shadow intensity with code?

Discussion in 'High Definition Render Pipeline' started by Inferi, Apr 26, 2020.

  1. Inferi


    Sep 28, 2015
    Im trying to change the shadows intensity by code and I cant seem to get it to work. The old way wont work with HDRP.
    The old way:
    Code (CSharp):
    1. GetComponent<Light>().shadowStrength = [shadowIntensity];
    I have tried to change:
    Code (CSharp):
    1. HDAdditionalLightData.shadowDimmer
    but that makes the whole scene go darker and darker the more I lower it. So shadows dont just go dimmer.

    Is there anything I am missing here!?

    According to documentation that I have found , shadowDimmer is about fading the shadows. Is this correct?

    Any help appreciated.
  2. Olmi


    Nov 29, 2012

    These two should work, I don't know the difference as the manual is very brief about everything:
    (My version is HDRP 7.3 on Unity 2019.3.7.)

    Code (CSharp):
    1. hDAdditionalLightData.SetShadowDimmer(value, value);
    2. hDAdditionalLightData.shadowDimmer = value;
    That SetDimmer allows you also to set the dimming for volumetrics (2nd parameter.)

    You need to of course also include the correct namespaces (UnityEngine and UnityEngine.Rendering.HighDefinition.)

    P.S. I don't know how literal you were with your code example, but that second one wouldn't do anything anyway as there's no assignment of any sort.
  3. Inferi


    Sep 28, 2015

    I tried:

    Code (CSharp):
    1. SetShadowDimmer(shadowDimmer, volumetricShadowDimmer)
    yesterday but nothing changed.

    Today it worked just fine. I need to remember to restart Unity if something is not working correctly next time :)

    Thank you for taking time to help :)

    Here is my code, if it helps anyone:
    Code (CSharp):
    3. // Setting the shadows intensity according to sun location
    4.         if(GlobalMethods.floatBetween(currentSunRotation, 190f, 210f)) {
    5.             shadowIntensity = Mathf.Lerp(0.0f, shadowMaxIntensity, ((currentSunRotation - 190) / 20));
    6.             HDALD.SetShadowDimmer(shadowIntensity, 1f);
    7.         } else if(GlobalMethods.floatBetween(currentSunRotation, 330f, 350f)) {
    8.             shadowIntensity = Mathf.Lerp(shadowMaxIntensity, 0.0f, ((currentSunRotation - 330) / 20f));
    9.             HDALD.SetShadowDimmer(shadowIntensity, 1f);
    10.         } else if(GlobalMethods.floatBetween(currentSunRotation, 210f, 330f)) {
    11.             HDALD.SetShadowDimmer(shadowMaxIntensity, 1f);
    12.         } else {
    13.             HDALD.SetShadowDimmer(0f, 1f);
    14.         }
    Olmi likes this.