Hi guys, I’m new to HDRP and I’m trying to learn how to properly use lights in this new rendering pipeline. I’m trying to manually update shadowmaps due to performance issues, but if I use the Every Frame setting, everything works fine. Instead, using On Enable and On Demand settings results in no shadows at all. I made a simple script calling HDAdditionalLightData’s function to update shadow maps (RequestShadowMapRendering), but with no success. The script itself is fine: I tried to use it on the sample HDRP scene and seems to properly work, but on my scene, as I previously said, no luck at all. Here’s my really simple script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
public class ShadowUpdate : MonoBehaviour
{
private HDAdditionalLightData hdLightData;
// Start is called before the first frame update
void Start()
{
hdLightData = GetComponent<HDAdditionalLightData>();
}
private void OnEnable() {
hdLightData.RequestShadowMapRendering();
}
private void OnDisable() {
hdLightData.RequestShadowMapRendering();
}
}
The point of this script is to update shadows once only when toggled on or off. Can someone help me to understand this weird behaviour? I’m attaching a couple of screenshots to let you understand what my problem is.
It is likely that your shadow won’t fit in the atlas and therefore not rendering, can you try decreasing the shadow resolution or increasing the atlas size?
First of all, thank you for your reply, and now I’m going to answer your questions:
I’m on HDRP 10.4.0, so the latest available
Nope, I have no errors in the console
I tried to reduce shadows settings and worked, so I went to check, as you suggested, tha cached atlas size and set it to 16.384 for now, just to have no more issues.
Now I’d like to better understand this thing: assuming every light generates a 2048 shadow map, does this mean I can only have (16384/2048)^2 lights? So I can “only” use 64 lights in ALL my scene?
You can phase things in and out if you want to manage that (more info in the doc I linked above) so you can decide. There is API to know if a light is in the Atlas or not.
But generally yes, if the atlas is full you cannot have more shadows than what would fit in the atlas for cached shadows. This is because if we did dynamic rescaling we’d need to re-render the shadows defeating their purpose.
I need the Shadow Update Mode set to On Demand because of the frame rate, but when I call RequestShadowMapRendering for every HDAdditionalLightData in the scene (there are 8 spot lights) the shadows are wrong. Instead, if I set the mode to Every Frame then shadows are correct.
This is not a problem of atlas size, right? If it was, then shadows would be wrong also in real-time, no?
It is not possible to update shadows and reflection probes during the same frame properly.
So I have to update shadows, wait for one frame, and then update reflection probes.