I am using Unity 2020.1.10f1 HDRP, rendering set to both (deferred/forward), shadow filtering medium. I have a scene with 12 connected terrains at 300x300. When turning Cast Shadows on and a single directional light, the shadows on the terrain actually change depending on where the camera is looking. Moving the camera a tiny bit to the left or right can mean no shadows, to shadows in different places. Changing the shadow cascades also affects this. I have tried bumping the draw distance and shadow distance very high, to very low. Nothing seems to solve this. Additionally, turning Draw Instanced off removes all shadows from the terrain (not that I want to do that, just mentioning I tried and saw that behavior).
What am I doing wrong? Is this a known bug? I’ve experienced some weird shadow artifacts in HDRP in previous versions as well (shadows moving or turning on/off) for non-terrain stuff, but in this project, I’m only noticing it at the moment for this.
Any advice on what this is and how to fix it? I’ve played with all the settings I know of, and nothing is making this stable.
I noticed something like this after enabling PCSS shadows recently. Pretty much the same problem when a shadow from a high radius light source to a distant object. Shadows are set to refresh every frame. I think what is happening has to do with using a large shadow area with multiple splits and the angle of the blocker search (which is based on light source radius) involves going outside of the split boundary.
Try setting the sun light radius to 0 degrees (hobbles PCSS algorithm), or in the HDRP render pipeline asset Lighting->Shadows->Filtering Quality, set it to “Medium” (disables PCSS). If either of those make the problem go away then it’s probably to do with PCSS.
I’m actually noticing similar behavior now with a point light. Please note for all above comments: I am using deferred and/or both, but not specifically Forward, so I do not have the high quality shadows turned on. This is using medium quality … nothing fancy to my knowledge, should just work?
In the attached photo, the only thing changing is the rotation of the camera. Very, very slightly. I mean, a microscopic rotation while the game is playing with my first person controller changes those shadows.
I don’t know if this is the same bug, but its the same consistent behavior I’ve seen in multiple projects now.
For reference, the light is the players “torch” casting the shadow in the room. Toggling the shadowmap off on the light looks the same as the bug in the photo.
I’ve played with having the near place much closer and further, so don’t pay attention to the exact numbers you see.
[Edit – Added two more, c and d, so you can see the overhead of the scene while thats happening]
Okay, maximum shadows on screen is what caused the point light. However, even setting that number to 10000 doesnt change this behavior for the terrain shadows. There’s probably another setting I need to change, but no idea what it would be!
Without a test scene, it’s difficult to help you. If you could report a bug and attach a small sample project to it, that would be great (in Unity, Help > Report Bug).
Regarding your other problems with the shadows, it seems you had too many lights rendered in general: try to use the “Light fade distance” to cull the lights in your scene beyond a certain distance from the active camera. This will ensure the engine doesn’t waste resources trying to render their shadows when they aren’t necessarily on screen. There is a similar option for Shadow fade distances too. It is a way better alternative than brute-forcing the maximum number of lights/shadows rendered at any given time in the HDRP asset.
Thanks!! I didn’t notice you replied until now … very much appreciated. Great tip on the fade distance.
Quick question along these lines: does occlusion culling have any effect on lights being rendered? Meaning, if I am in room A looking at room B, and room B has a light but is also not rendered because of OC, will that light still be doing anything given that in theory it could be reaching something that isn’t culled I guess? My initial tests seem to show it is still on and affecting performance (and assumably the max light threshold), but I could have done something wrong so confirming with you that was expected behavior and not more user error.
Basically, in a standard dungeon type set up, is fade distance + OC the best way to handle this, understanding that if the fade distance still covers an area which shouldn’t be affected by the light (ie: outside of the room with no visibility into it nor of anything affected by it), it will still be active?
If so, would it be beneficial to create my own project-specific system to know if lights should be turned on / off?
Hi, I’ve discovered what triggers this bug (At least in my case), it happens only and exclusively when adding large structures to the scene (or scaling an object up by a lot). I haven’t found a solution though. This problem does not occur with small object shadows.
Update: I’ve discovered that using custom Shader Graphs instead of the HDRP/Lit shader for the materials caused the problem. Adding a material with the default shader instantly fixes the issue. I’m going to find out if it’s something specific of the shader graph that’s causing the bug.
FOUND THE SOLUTION. Apparently HDRP doesn’t really like using standard shader graphs for large objects. The solution: USE A HDRP SHADER GRAPH. To create one Right Click on the Project window > Shader > HDRP > Lit Shader. And that’s pretty much it. Can I get the confirmation that a Unity developer has read this? If I don’t I will file a bug report.
Can you explain with more detail what problem you solved? I listed two issues: one was terrain shadows were having issues, and one was point lights not showing up. This sounds like you are having a completely different issue, except you said “I’m having the same exact issue on Unity 2020.1.11f1.”.
Glad you solved the problem, but would be great to know the exact problem solved :). I had an issue with my entire screen going black when using a model with a custom shader built with ASE (noticed the normals went wonky too) after hitting save when its been working for months, then when I rebuilt basically the same exact shader it stopped doing that. Switching the model to a standard HDRP/Lit shader also made the issue go away. It sounds like maybe you are talking about something similar to that … but that’s a completely different issue than the lighting issues described above.
If so, you should probably make a new thread for that!
I fixed the terrain shadows bug. If I moved the camera or rotated it, close shadows would appear and disappear depending on the camera rotation, while the far away shadows always looked ok. This only happened to me with large objects.