Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved shadow fade #3089

Merged
merged 34 commits into from
Feb 11, 2021
Merged

Improved shadow fade #3089

merged 34 commits into from
Feb 11, 2021

Conversation

lukaschod
Copy link
Contributor

@lukaschod lukaschod commented Jan 13, 2021

Purpose of this PR

Fix issues

Shadow fade distance is very short.

Extend with new functionality:

Controlable shadow fade distance.

Also I decided to refactor shadow cascade GUI for HDRP and URP. For several reasons:

Partition sizes inconsistant

Last cascade had extra pixel at end inconsistantly

Any resizing was causing pixel jumping

Did not wanted to increase code duplication as extending URP cascade would resulted in very similar code of HDRP one.
I could not used HDRP solution as I had to move it to renderpipeline public core. HDRP solution was not written to be public code.

New shadow cascade GUI

Includes:

  • Pixel perfect.
  • Supports hovering.
  • Supports focusing and keyboard arrow based value change.
  • Support hidding border handles.
  • New high quality snatch handle images.
  • Gradient no longer recreates textures and uses preloaded texture.

(New urp upper, old urp bottom)

(New hdrp upper, old hdrp bottom)

More info https://docs.google.com/document/d/1MAFk4AINTloYLgw8vBzhpah031LismehPQqVxiUhSx0.


Testing status

  • Compare URP, HDRP and builtin shadow fade.
  • Test if it fixes original issues.
  • Test with multiple lights.
  • Ran gfx tests locally.
  • Performance comparison. There is high chance for small regression on old mobiles as I had to add additional instruction. Sadly nothing can be done. However with baked shadow, I expect it to perform better as I got rid of one inline condition.
  • Test if shadowmask correctly shadow blends to realtime shadow in all cases.
  • Test if shadow fade does not start to happen in near plane, because we are no longer fading from camera, but from last cascade (I have special code path to take care of it).
  • Test if new shadow cascade UI performs correctly in all cases.

TODO

  • Update shadow cascade images in urp docs
  • Update shadow cascade images in hdrp docs
  • Update graphics test templates

Comments to reviewers

I am mostly concerned about UI side if I did not screw up there with images, paths and so on (As rarely touch UI code).

…er functionality. Adding focus keyboard functionality with handles.
…nside internal class no deprecation is needed.
@lukaschod lukaschod changed the title Universal/shadow fade improvements Improving shadow fade Jan 14, 2021
@lukaschod lukaschod changed the title Improving shadow fade Improved shadow fade Jan 14, 2021
static float[] splitTwo = new float[2];
static float[] splitThree = new float[3];
static int splitCount;
public static void DrawCascadeSplitGUI<T>(ref SerializedProperty shadowCascadeSplit, float distance, int cascadeCount, Unit unit)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is inside internal class, I am removing it

static partial class ShadowCascadeSplitGUI
{
[Obsolete("This is obsolete, please use HandleCascadeSliderGUI(ref float[] normalizedCascadePartitions, float distance, EditorUtils.Unit unit) instead.", false)]
public static void HandleCascadeSliderGUI(ref float[] normalizedCascadePartitions)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is inside internal class, I am removing it

@@ -15,207 +15,5 @@ namespace UnityEditor.Rendering.Universal
{
static partial class EditorUtils
{
[Obsolete("This is obsolete, please use DrawCascadeSplitGUI<T>(ref SerializedProperty shadowCascadeSplit, float distance, int cascadeCount, Unit unit) instead.", false)]
public static void DrawCascadeSplitGUI<T>(ref SerializedProperty shadowCascadeSplit)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is inside internal class, I am removing it


cmd.SetGlobalTexture(m_MainLightShadowmap.id, m_MainLightShadowmapTexture);
cmd.SetGlobalMatrixArray(MainLightShadowConstantBuffer._WorldToShadow, m_MainLightShadowMatrices);
ShadowUtils.SetupShadowReceiverConstantBuffer(cmd, m_MainLightShadowParams);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer needed, as additional light calculation no longer uses main light

// it is needed when realtime shadows gets cut to early during fade and causes disconnect between baked shadow
shadowFade = shadowCoord.w == 4 ? 1.0h : shadowFade;
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested, it is no longer needed as we are calculating shadow fade from cascade

This was the problem.
image

@lukaschod lukaschod requested a review from phi-lira January 15, 2021 15:26
lukaschod and others added 2 commits January 21, 2021 14:31
Co-authored-by: Felipe Lira <felipedrl@gmail.com>
Copy link
Contributor

@Verasl Verasl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issues with popping when the shadows lie in the blend range, seems like the overall shadow casting distance is lowered when the blend is there which means things are popping out of being rendered in the shadow map.

wnaOa5bcUd.mp4

UX wise is quite nice, switching between percentage and metric is not 'undo-able' which owuld be nice even though it's purely UI, also I think the end blend shouldnt change when changing in-between cascades, this is kind of annoying:
sMgTc9JAMZ

Other than that I like it very much and want it :D

…ra sphere. It is proved not to be good solution for current stable fit solution as last cascade in some cases might get outside shadow max distance.
…-Technologies/Graphics into universal/shadow-fade-improvements
@lukaschod
Copy link
Contributor Author

Issues with popping when the shadows lie in the blend range, seems like the overall shadow casting distance is lowered when the blend is there which means things are popping out of being rendered in the shadow map.

wnaOa5bcUd.mp4
UX wise is quite nice, switching between percentage and metric is not 'undo-able' which owuld be nice even though it's purely UI, also I think the end blend shouldnt change when changing in-between cascades, this is kind of annoying:
sMgTc9JAMZ

Other than that I like it very much and want it :D

This should be fixed in latest commit.

UI, also I think the end blend shouldnt change when changing in-between cascades, this is kind of annoying
This is from HDRP, maybe we can change it if it really a bad control

@lukaschod
Copy link
Contributor Author

I just reverted shadow fading from last cascade, because it can not really be done for current stable fit solution without sacrficing performance. I will leave this to nigle stable fit fix.

Copy link
Contributor

@Verasl Verasl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shadow popping at end cascade fade gone.
LGTM

@simon-engelbrecht-soerensen simon-engelbrecht-soerensen requested a review from a team January 28, 2021 09:49
@ernestasKupciunas ernestasKupciunas requested review from ernestasKupciunas and removed request for a team January 28, 2021 13:01
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issues I found seem to have been fixed, and there appear to be no performance issues on PC.
Test doc here

Copy link

@ernestasKupciunas ernestasKupciunas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good on the mobile side.
I have found some bugs, but none of them were related to the changes (reproducible on Trunk and Master branches).

Testing doc: https://docs.google.com/document/d/12ZSHCzSR4j5ZW59EzOSyEZCSRSmPrsmYPjZvTWIs0Uo/edit#
Performance sheet: https://docs.google.com/spreadsheets/d/1Xp_OZcZsY14dpY5P9pAviGCrhzKOT6lzI17bT9KL8yg/edit#gid=0

Devices under testing:
VLNQA00217, Razer Phone 2, 9.0.0, Snapdragon 845 SDM845, Adreno 630
VLNQA00268, Samsung Galaxy S10+, 10.0.0, Exynos 9 9820, Mali-G76
OnePlus Nord, 10, Snapdragon 765G SM7250-AB, Adreno 620
VLNQA00108, LGE LG Leon 4G LTE, 5.0.1, Snapdragon 410 MSM8916, Adreno 306
VLNQA00126, Samsung Galaxy S5 Mini, 6.0.1, Exynos 3 Quad 3470, Mali-400 MP
VLNQA00292, iPad Air3, SoC: A12, iOS: 13.2.3
iPad Air4, SoC: 14, iOS: 14.0
iPhone 12Pro, SoC: 14, iOS: 14.1
iPhone XS, SoC: A12, iOS: 14.3

@lukaschod
Copy link
Contributor Author

I went and compared manually every failure that is not dependency against master. I was looking for similar failure not exectly on same base branch as some of the failures are instabilities. Seems like I did not introduced any new failures.

Build HDRP on Linux_Vulkan_mono_Linear_Standalone_build_Player on version trunk
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/master/.yamato%252Fhdrp-linux-vulkan.yml%2523Build_HDRP_Linux_Vulkan_Standalone_mono_Linear_trunk/5272259/job

Build ShaderGraph on Linux_Vulkan_mono_Linear_Standalone_cache_build_Player
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fshadow-fade-improvements/.yamato%252Fshadergraph-linux-vulkan.yml%2523Build_ShaderGraph_Linux_Vulkan_Standalone_cache_mono_Linear_trunk/5273373/job
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/master/.yamato%252Fshadergraph-linux-vulkan.yml%2523Build_ShaderGraph_Linux_Vulkan_Standalone_cache_mono_Linear_trunk/5273420/job

Build Universal_Stereo on Win__mono_Linear_Standalone_cache_build_Player on version
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fshadow-fade-improvements/.yamato%252Funiversal_stereo-win.yml%2523Build_Universal_Stereo_Win_Standalone_cache_mono_Linear_trunk/5273360/job
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/master/.yamato%252Funiversal_stereo-win.yml%2523Build_Universal_Stereo_Win_Standalone_cache_mono_Linear_trunk/5289254/job

Build VFX_URP on Win_DX11_mono_Linear_Standalone_cache_build_Player
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fshadow-fade-improvements/.yamato%252Fvfx_urp-win-dx11.yml%2523Build_VFX_URP_Win_DX11_Standalone_cache_mono_Linear_trunk/5273367/job
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/master/.yamato%252Fvfx_urp-win-dx11.yml%2523Build_VFX_URP_Win_DX11_Standalone_cache_mono_Linear_trunk/5256564/job

Formatting
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fshadow-fade-improvements/.yamato%252F_formatting.yml%2523formatting/5273406/job
vfx missing

HDRP on Linux_Vulkan_playmode_cache_mono_Linear on version trunk
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fshadow-fade-improvements/.yamato%252Fhdrp-linux-vulkan.yml%2523HDRP_Linux_Vulkan_playmode_cache_mono_Linear_trunk/5273394/job
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/master/.yamato%252Fhdrp-linux-vulkan.yml%2523HDRP_Linux_Vulkan_playmode_cache_mono_Linear_trunk/5289316/job

HDRP on OSX_Metal_playmode_cache_mono_Linear on version trunk
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fshadow-fade-improvements/.yamato%252Fhdrp-osx-metal.yml%2523HDRP_OSX_Metal_playmode_cache_mono_Linear_trunk/5273391/job
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/master/.yamato%252Fhdrp-osx-metal.yml%2523HDRP_OSX_Metal_playmode_cache_mono_Linear_trunk/5267775/job

HDRP on Win_DX11_Standalone_cache_mono_Linear on version trunk
https://yamato-artifactviewer.prd.cds.internal.unity3d.com/cb0e627a-b05d-428c-a2c9-b6331edba48b%2Flogs%2FTestProjects%2FHDRP_RuntimeTests%2Ftest-results/TestReportV1.html
System.AggregateException: One or more errors occurred. (The system cannot find the file specified.)
---> System.ComponentModel.Win32Exception (2): The system cannot find the file specified.
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)

HDRP on Win_DX11_playmode_XR_cache_mono_Linear on version trunk
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fshadow-fade-improvements/.yamato%252Fhdrp-win-dx11.yml%2523HDRP_Win_DX11_playmode_XR_cache_mono_Linear_trunk/5273387/job
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/master/.yamato%252Fhdrp-win-dx11.yml%2523HDRP_Win_DX11_playmode_XR_cache_mono_Linear_trunk/5272254/job

HDRP on Win_DX11_playmode_cache_mono_Linear on version trunk
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fshadow-fade-improvements/.yamato%252Fhdrp-win-dx11.yml%2523HDRP_Win_DX11_playmode_cache_mono_Linear_trunk/5273386/job
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/master/.yamato%252Fhdrp-win-dx11.yml%2523HDRP_Win_DX11_playmode_cache_mono_Linear_trunk/5272253/job

HDRP on Win_DX12_playmode_cache_mono_Linear on version trunk
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fshadow-fade-improvements/.yamato%252Fhdrp-win-dx12.yml%2523HDRP_Win_DX12_playmode_cache_mono_Linear_trunk/5273389/job
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/master/.yamato%252Fhdrp-win-dx12.yml%2523HDRP_Win_DX12_playmode_cache_mono_Linear_trunk/5272256/job

HDRP on Win_Vulkan_playmode_cache_mono_Linear on version trunk
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fshadow-fade-improvements/.yamato%252Fhdrp-win-vulkan.yml%2523HDRP_Win_Vulkan_playmode_cache_mono_Linear_trunk/5273390/job
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/master/.yamato%252Fhdrp-win-vulkan.yml%2523HDRP_Win_Vulkan_playmode_cache_mono_Linear_trunk/5267774/job

HDRP_Hybrid on Win_DX11_playmode_cache_mono_Linear on version trunk
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fshadow-fade-improvements/.yamato%252Fhdrp_hybrid-win-dx11.yml%2523HDRP_Hybrid_Win_DX11_playmode_cache_mono_Linear_trunk/5273397/job
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/master/.yamato%252Fhdrp_hybrid-win-dx11.yml%2523HDRP_Hybrid_Win_DX11_playmode_cache_mono_Linear_trunk/5272264/job

Universal on Android_OpenGLES3_Standalone_cache_il2cpp_Linear on version trunk
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fshadow-fade-improvements/.yamato%252Funiversal-android-opengles3.yml%2523Universal_Android_OpenGLES3_Standalone_cache_il2cpp_Linear_trunk/5273353/job
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/master/.yamato%252Funiversal-android-opengles3.yml%2523Universal_Android_OpenGLES3_Standalone_cache_il2cpp_Linear_trunk/5271296/job

Universal on Android_Vulkan_Standalone_cache_il2cpp_Linear on version trunk
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fshadow-fade-improvements/.yamato%252Funiversal-android-vulkan.yml%2523Universal_Android_Vulkan_Standalone_cache_il2cpp_Linear_trunk/5273355/job
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/master/.yamato%252Funiversal-android-vulkan.yml%2523Universal_Android_Vulkan_Standalone_cache_il2cpp_Linear_trunk/5267711/job

Universal_Hybrid on OSX_Metal_playmode_cache_mono_Linear on version trunk
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fshadow-fade-improvements/.yamato%252Funiversal_hybrid-osx-metal.yml%2523Universal_Hybrid_OSX_Metal_playmode_cache_mono_Linear_trunk/5273365/job
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/master/.yamato%252Funiversal_hybrid-osx-metal.yml%2523Universal_Hybrid_OSX_Metal_playmode_cache_mono_Linear_trunk/5267721/job

Universal_Hybrid on Win_DX11_playmode_cache_mono_Linear on version trunk
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fshadow-fade-improvements/.yamato%252Funiversal_hybrid-win-dx11.yml%2523Universal_Hybrid_Win_DX11_playmode_cache_mono_Linear_trunk/5273364/job
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/master/.yamato%252Funiversal_hybrid-win-dx11.yml%2523Universal_Hybrid_Win_DX11_playmode_cache_mono_Linear_trunk/5271298/job

VFX_HDRP on Win_DX11_Standalone_cache_mono_Linear on version trunk
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fshadow-fade-improvements/.yamato%252Fvfx_hdrp-win-dx11.yml%2523VFX_HDRP_Win_DX11_Standalone_cache_mono_Linear_trunk/5273400/job
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/master/.yamato%252Fvfx_hdrp-win-dx11.yml%2523VFX_HDRP_Win_DX11_Standalone_cache_mono_Linear_trunk/5272267/job

VFX_HDRP on Win_DX12_Standalone_cache_mono_Linear on version trunk
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/universal%252Fshadow-fade-improvements/.yamato%252Fvfx_hdrp-win-dx12.yml%2523VFX_HDRP_Win_DX12_Standalone_cache_mono_Linear_trunk/5273403/job
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/master/.yamato%252Fvfx_hdrp-win-dx12.yml%2523VFX_HDRP_Win_DX12_Standalone_cache_mono_Linear_trunk/5272270/job

@phi-lira phi-lira merged commit 47c15c6 into master Feb 11, 2021
@phi-lira phi-lira deleted the universal/shadow-fade-improvements branch February 11, 2021 09:08
@PaulDemeulenaere
Copy link
Contributor

I guess you already noticed but this merge request is leading to a missing .meta due to the addition of the folder com.unity.render-pipelines.core\Editor\Lighting\Shadow.
It isn't a big deal but I think it will make fail the package verification.

@theopnv
Copy link
Collaborator

theopnv commented Feb 12, 2021

^ PR: #3480

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.