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.
  2. Dismiss Notice

Disable shadows with using Lightweight Pipeline Render in runtime

Discussion in 'General Graphics' started by Xakkar, Jun 17, 2018.

  1. Xakkar

    Xakkar

    Joined:
    Apr 8, 2016
    Posts:
    16
    Hi!
    Unity 2018.1.1
    How can I disable shadows with using Lightweight Pipeline Render in runtime?
    QualitySettings.shadows = ShadowQuality.Disable dosnt work =(
     
  2. eugene4552

    eugene4552

    Joined:
    Jun 28, 2018
    Posts:
    4
    Hello!

    1. Select LightweightAsset file, click on little gear -> Edit script
    Step1.png

    2. Find ShadowSetting property declaration in LightweightPipelineAsset.cs file, remove private modifier near set and save your changes.
    Step2.png

    3. Create new script "RenderSettings.cs" and paste this code:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Experimental.Rendering.LightweightPipeline;
    3.  
    4. public class RenderSettings : MonoBehaviour {
    5.     public LightweightPipelineAsset lightweightPipeline;
    6.  
    7.     private void Start()
    8.     {
    9.         lightweightPipeline.ShadowSetting = ShadowType.NO_SHADOW;
    10.     }
    11. }
    12.  
    4. Create empty gameobject, add Render Settings component, assign LightweightAsset for Lightweight Pipeline public variable.
    Step4.png

    5. Press play and shadows will disappear :)

    Note that script changes graphics settings permamently, not just in Play mode.
     
  3. Xakkar

    Xakkar

    Joined:
    Apr 8, 2016
    Posts:
    16
    Hi all!
    Unity 2018.3.0 and Lightweight 4.6.0

    The method described above does not work. How can the new version of Unity enable / disable shadows in runtime?
     
  4. unity_yH1F_Las9eY_OQ

    unity_yH1F_Las9eY_OQ

    Joined:
    Jan 11, 2019
    Posts:
    1
    Only Work in Editor
    Not Work in Android
     
  5. FixItFelix

    FixItFelix

    Joined:
    Mar 27, 2017
    Posts:
    51
    You can. The difference is those shadow settings are controlled by the LWRP asset. So you have to access this.

    ((LightweightRenderPipelineAsset) GraphicsSettings.renderPipelineAsset).shadowDistance = distance;

    Here you can set the shadow distance. Not sure if you could deactivate shadow with a bool. But a distance of 0 should do the same.
     
  6. pravusjif

    pravusjif

    Joined:
    Jul 24, 2012
    Posts:
    18
    You can access those values using ugly reflection:

    Code (CSharp):
    1. private FieldInfo lwrpaShadowField = null;
    2. private FieldInfo lwrpaSoftShadowField = null;
    3. private FieldInfo lwrpaShadowResolutionField = null;
    4.  
    5. lwrpaShadowField = lightweightRenderPipelineAsset.GetType().GetField("m_MainLightShadowsSupported", BindingFlags.NonPublic | BindingFlags.Instance);
    6. lwrpaSoftShadowField = lightweightRenderPipelineAsset.GetType().GetField("m_SoftShadowsSupported", BindingFlags.NonPublic | BindingFlags.Instance);
    7. lwrpaShadowResolutionField = lightweightRenderPipelineAsset.GetType().GetField("m_MainLightShadowmapResolution", BindingFlags.NonPublic | BindingFlags.Instance);
    8.  
    9. lwrpaShadowField?.SetValue(lightweightRenderPipelineAsset, qualitySettings.shadows);
    10. lwrpaSoftShadowField?.SetValue(lightweightRenderPipelineAsset, qualitySettings.softShadows);
    11. lwrpaShadowResolutionField?.SetValue(lightweightRenderPipelineAsset, qualitySettings.shadowResolution);