wave-harmonic / crest

A class-leading water system implemented in Unity
MIT License
3.48k stars 480 forks source link

Shadow render failure when no object is present - (crashes some newer android devices!) #884

Closed klauskobald closed 3 years ago

klauskobald commented 3 years ago

Describe the bug When "create shadow data" is active on ocean renderer component without any objects producing shadows the whole ocean gets dimmed as if there is a big shadow all over the place except for some places depending on camera angle. I did not give too much attention to this until one of my Android testers reported to me, that the device is crashing in exact this state during booting. So, it seems as when there is no shadow data produced the shadow lod manager is sending some weird data to the shader.

Screenshots / video Video When monolith is present, it looks good. When turned off ocean goes darker and blue artefacts appear on the lower screen.

Versions URP 10.5.1 Crest 4.12

Platform

Hardware new Huawai, Samsung Galaxy

Workaround I currently turn on shadows when objects are in the scene. That actually can only be done via reflections because the property is private ! Is there a reason for that?

klauskobald commented 3 years ago

I discovered more. It seems, when there is no object within the view of the camera this flickering is happening. The shadowmaps also look somewhat destroyed. As the camare moves you see the oceancolor change. movie1 movie2

When camera is close to objects, everything works. I am using 2 and 4 shadow cascades. Same result.

daleeidd commented 3 years ago

Thanks. I'll look into these. I have another report of shadow weirdness on Discord too which sounds similar.

The first thing I found is that if there is nothing that casts a shadow, the shadow map is unbound. An unbounded texture is usually a grey colour which we treat as shadow. I will look at solving this first.

daleeidd commented 3 years ago

If you add the following to SampleShadowsURP.cs:

if (!renderingData.cullResults.GetShadowCasterBounds(renderingData.lightData.mainLightIndex, out _))
{
    return;
}

After:

if (renderingData.lightData.mainLightIndex == -1)
    return;

It will solve the first issue. Let me know if it also solves the other issues you are seeing too.

klauskobald commented 3 years ago

YES! All shadow lods are clean, no more flickering of ocean surface. I cannot confirm, if this would no longer crash Android but most likely! My suspicion is even that maybe devices are still crashing right now, if a user would turn the camera away from any objects. I think that´s most unlikely to happen, though. Anyway I would say, that is fixed!

daleeidd commented 3 years ago

Thank you. Fix will be out for 4.13.

daleeidd commented 3 years ago

4.13 has been released. Thank you for your help.