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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Bug HDRP shadows working properly in editor, but not in build

Discussion in 'High Definition Render Pipeline' started by samlaserbeam, Sep 28, 2022.

  1. samlaserbeam

    samlaserbeam

    Joined:
    Oct 2, 2019
    Posts:
    6
    I'm currently having an issue where in the editor, the lighting from my directional light works just fine. However, when I build the game, it's like the scene has a giant shadow casted over it. Here's an image of what I'm talking about (top picture is in the editor, bottom is in the build)

    lightingbug.jpg


    If I disable shadow mapping in the build on the directional light, the lighting seems to be accurate and comparable to the first editor screenshot (but with no shadows of course)

    editor_noshadow.PNG

    I'm not sure if this is useful at all, but here's the code I use at the start of my scene to initialize all of the props/post processing/lighting

    Code (CSharp):
    1. public void UpdateProps()
    2.         {
    3.             //if (currentSceneSettings == null)
    4.             //    return;
    5.  
    6.             currentShakeInstance?.Stop(0, true);
    7.             currentShakeInstance = cameraShaker.Shake(shakePreset);
    8.             postProcessVolume.sharedProfile.TryGet(out whiteBalance);
    9.             postProcessVolume.sharedProfile.TryGet(out colorAdjustments);
    10.             postProcessVolume.sharedProfile.TryGet(out hdriSky);
    11.             postProcessVolume.sharedProfile.TryGet(out fog);
    12.             postProcessVolume.sharedProfile.TryGet(out blur);
    13.             postProcessVolume.sharedProfile.TryGet(out depthOfField);
    14.             postProcessVolume.sharedProfile.TryGet(out visualEnvironment);
    15.             retroVolume.sharedProfile.TryGet(out vignette);
    16.  
    17.             //Debug.LogWarning("White Balance " + whiteBalance != null);
    18.             //Debug.LogWarning("Color adjustments " + colorAdjustments != null);
    19.             //Debug.LogWarning("HDRI Sky " + hdriSky != null);
    20.             //Debug.LogWarning("Fog " + fog != null);
    21.             //Debug.LogWarning("Blur " + blur != null);
    22.             //Debug.LogWarning("Depth of Field " + depthOfField != null);
    23.             //Debug.LogWarning("Visual Environment " + visualEnvironment != null);
    24.             //Debug.LogWarning("Vignette " + vignette != null);
    25.  
    26.             foreach (Material material in windMaterials1)
    27.             {
    28.                 material.SetFloat("WindSpeedFloat1", currentSceneSettings.windSpeed);
    29.                 material.SetFloat("_WindStrength", currentSceneSettings.windStrength);
    30.             }
    31.  
    32.             foreach (Material material in windMaterials2)
    33.             {
    34.                 material.SetFloat("_Frequency", currentSceneSettings.windSpeed);
    35.                 material.SetFloat("_Amplitude", currentSceneSettings.windStrength);
    36.             }
    37.  
    38.             foreach (VisualEffect vfx in leavesAndWindVFX)
    39.             {
    40.                 vfx.enabled = currentSceneSettings.leafParticles;
    41.             }
    42.  
    43.             foreach (VisualEffect vfx in fireflyVFX)
    44.             {
    45.                 vfx.enabled = currentSceneSettings.fireflyParticles;
    46.             }
    47.  
    48.             foreach (Light light in eiffelTowerLights)
    49.             {
    50.                 light.enabled = currentSceneSettings.eiffelTowerLights;
    51.             }
    52.  
    53.             rainVFX.enabled = currentSceneSettings.rainParticles;
    54.             rainVFX.SetFloat("Spawn Rate", currentSceneSettings.rainSpawnRate);
    55.             rainVFX.SetFloat("Brightness", currentSceneSettings.rainBrightness);
    56.  
    57.             if (lightningCoroutine != null)
    58.                 StopCoroutine(lightningCoroutine);
    59.             lightningFlashTween?.Stop();
    60.             lightningRenderer.forceRenderingOff = true;
    61.             lightningRenderer.enabled = false;
    62.             thunderSound.Stop();
    63.  
    64.             if (currentSceneSettings.lightning)
    65.             {
    66.                 lightningCoroutine = StartCoroutine(LightningCoroutine());
    67.             }
    68.  
    69.             puddles.transform.localPosition = new Vector3(puddles.transform.localPosition.x, Mathf.Lerp(2.38f, 2.52f, currentSceneSettings.puddleHeight), puddles.transform.localPosition.z);
    70.  
    71.             wallPieceMaterial.SetTexture("_Cubemap", currentSceneSettings.skybox);
    72.             wallPieceMaterial.SetFloat("_IntensityDripLine", currentSceneSettings.wallWetness);
    73.             wallPieceMaterial.SetFloat("_TrailDropSpeed", currentSceneSettings.wallWetnessSpeed);
    74.  
    75.  
    76.             directionalLight.colorTemperature = currentSceneSettings.directionalLightTemperature;
    77.             directionalLight.GetComponent<HDAdditionalLightData>().SetIntensity(currentSceneSettings.directionalLightIntensity, LightUnit.Lux);
    78.  
    79.             Debug.Log("Direction light intensity: " + directionalLight.GetComponent<HDAdditionalLightData>().intensity);
    80.  
    81.             whiteBalance.temperature.value = currentSceneSettings.postProcessTemperature;
    82.             colorAdjustments.saturation.value = currentSceneSettings.postProcessSaturation;
    83.             hdriSky.hdriSky.value = currentSceneSettings.skybox;
    84.             hdriSky.scrollSpeed.value = currentSceneSettings.scrollSpeed;
    85.             hdriSky.rotation.value = currentSceneSettings.rotation;
    86.             hdriSky.skyIntensityMode.value = SkyIntensityMode.Multiplier;
    87.             hdriSky.multiplier.value = currentSceneSettings.intensityMultiplier;
    88.             fog.enabled.value = currentSceneSettings.fog;
    89.             fog.baseHeight.value = currentSceneSettings.fogBaseHeight;
    90.             fog.maxFogDistance.value = currentSceneSettings.fogMaxDistance;
    91.             fog.maximumHeight.value = currentSceneSettings.fogMaxHeight;
    92.             fog.meanFreePath.value = currentSceneSettings.fogAttenuationDistance;
    93.  
    94.             Debug.Log("HDRISky: " + hdriSky.hdriSky.value.name);
    95.             Debug.Log("HDRISky Intensity Mode: " + hdriSky.skyIntensityMode.value);
    96.             Debug.Log("HDRISky multiplier: " + hdriSky.multiplier.value);
    97.  
    98.  
    99.             Debug.LogError("DIRECTION LIGHT ROTATION: " + directionalLight.transform.localEulerAngles);
    100.             probe.RequestRenderNextUpdate();
    101.             initialized = true;
    102.             //Debug.LogError("Finished updating props");
    103.         }

    I've tried making sure the rotation of the directional light is correct in the build, using deferred rendering instead of forward, changing the light layer of the light, changing all the light parameters, and increasing the max distance for shadows in the shadow post process component. Only changing the max distance for shadows has had any effect, though it's still quite broken. I'm kind of stuck now, so any help is greatly appreciated!
     
  2. samlaserbeam

    samlaserbeam

    Joined:
    Oct 2, 2019
    Posts:
    6
    Just solved it. For anyone struggling with this in the future, I had a terrain layer with a hole in it above the tracks in the scene, but the hole was still casting shadows. I turned off shadow casting in the terrain settings and everything is fine now.