From 645378086488e632618e3ef40f6be1fc31ec179e Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Mon, 15 Apr 2024 22:59:11 +0200 Subject: [PATCH 01/23] Upgrade to Unity 6 --- Assets/DefaultVolumeProfile.asset | 15 ++ Assets/DefaultVolumeProfile.asset.meta | 8 + ...niversalRenderPipelineGlobalSettings.asset | 223 +++++++++++++++++- Assets/XRI.meta | 8 + Assets/XRI/Settings.meta | 8 + Assets/XRI/Settings/Resources.meta | 8 + .../Resources/InteractionLayerSettings.asset | 47 ++++ .../InteractionLayerSettings.asset.meta | 8 + .../Resources/XRDeviceSimulatorSettings.asset | 17 ++ .../XRDeviceSimulatorSettings.asset.meta | 8 + .../XRInteractionEditorSettings.asset | 15 ++ .../XRInteractionEditorSettings.asset.meta | 8 + .../Runtime/Lighting/ToonLighting.cs | 2 +- Packages/manifest.json | 20 +- Packages/packages-lock.json | 141 +++++++---- ProjectSettings/GraphicsSettings.asset | 7 +- ProjectSettings/MultiplayerManager.asset | 7 + ProjectSettings/ProjectVersion.txt | 4 +- ProjectSettings/QualitySettings.asset | 50 +++- 19 files changed, 524 insertions(+), 80 deletions(-) create mode 100644 Assets/DefaultVolumeProfile.asset create mode 100644 Assets/DefaultVolumeProfile.asset.meta create mode 100644 Assets/XRI.meta create mode 100644 Assets/XRI/Settings.meta create mode 100644 Assets/XRI/Settings/Resources.meta create mode 100644 Assets/XRI/Settings/Resources/InteractionLayerSettings.asset create mode 100644 Assets/XRI/Settings/Resources/InteractionLayerSettings.asset.meta create mode 100644 Assets/XRI/Settings/Resources/XRDeviceSimulatorSettings.asset create mode 100644 Assets/XRI/Settings/Resources/XRDeviceSimulatorSettings.asset.meta create mode 100644 Assets/XRI/Settings/XRInteractionEditorSettings.asset create mode 100644 Assets/XRI/Settings/XRInteractionEditorSettings.asset.meta create mode 100644 ProjectSettings/MultiplayerManager.asset diff --git a/Assets/DefaultVolumeProfile.asset b/Assets/DefaultVolumeProfile.asset new file mode 100644 index 00000000..36c3781a --- /dev/null +++ b/Assets/DefaultVolumeProfile.asset @@ -0,0 +1,15 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d7fd9488000d3734a9e00ee676215985, type: 3} + m_Name: DefaultVolumeProfile + m_EditorClassIdentifier: + components: [] diff --git a/Assets/DefaultVolumeProfile.asset.meta b/Assets/DefaultVolumeProfile.asset.meta new file mode 100644 index 00000000..4257ec80 --- /dev/null +++ b/Assets/DefaultVolumeProfile.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3627767964af0be4d98207e41cea5bde +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniversalRenderPipelineGlobalSettings.asset b/Assets/UniversalRenderPipelineGlobalSettings.asset index 783520f2..0ee50978 100644 --- a/Assets/UniversalRenderPipelineGlobalSettings.asset +++ b/Assets/UniversalRenderPipelineGlobalSettings.asset @@ -12,7 +12,51 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 2ec995e51a6e251468d2a3fd8a686257, type: 3} m_Name: UniversalRenderPipelineGlobalSettings m_EditorClassIdentifier: - k_AssetVersion: 3 + m_ShaderStrippingSetting: + m_Version: 0 + m_ExportShaderVariants: 1 + m_ShaderVariantLogLevel: 0 + m_StripRuntimeDebugShaders: 1 + m_URPShaderStrippingSetting: + m_Version: 0 + m_StripUnusedPostProcessingVariants: 0 + m_StripUnusedVariants: 1 + m_StripScreenCoordOverrideVariants: 1 + m_ShaderVariantLogLevel: 0 + m_ExportShaderVariants: 1 + m_StripDebugVariants: 1 + m_StripUnusedPostProcessingVariants: 0 + m_StripUnusedVariants: 1 + m_StripScreenCoordOverrideVariants: 1 + supportRuntimeDebugDisplay: 0 + m_EnableRenderGraph: 0 + m_Settings: + m_SettingsList: + m_List: + - rid: 9103181481788571865 + - rid: 9103181481788571866 + - rid: 9103181481788571867 + - rid: 9103181481788571868 + - rid: 9103181481788571869 + - rid: 9103181481788571870 + - rid: 9103181481788571871 + - rid: 9103181481788571872 + - rid: 9103181481788571873 + - rid: 9103181481788571874 + - rid: 9103181481788571875 + - rid: 9103181481788571876 + - rid: 9103181481788571877 + - rid: 9103181481788571878 + - rid: 9103181481788571879 + - rid: 9103181481788571880 + - rid: 9103181481788571881 + - rid: 9103181481788571882 + - rid: 9103181481788571883 + - rid: 9103181481788571884 + m_RuntimeSettings: + m_List: [] + m_AssetVersion: 8 + m_ObsoleteDefaultVolumeProfile: {fileID: 0} m_RenderingLayerNames: - Default m_ValidRenderingLayers: 1 @@ -24,11 +68,172 @@ MonoBehaviour: lightLayerName5: lightLayerName6: lightLayerName7: - m_StripDebugVariants: 1 - m_StripUnusedPostProcessingVariants: 0 - m_StripUnusedVariants: 1 - m_StripUnusedLODCrossFadeVariants: 1 - m_StripScreenCoordOverrideVariants: 1 - supportRuntimeDebugDisplay: 0 - m_ShaderVariantLogLevel: 0 - m_ExportShaderVariants: 1 + apvScenesData: + obsoleteSceneBounds: + m_Keys: [] + m_Values: [] + obsoleteHasProbeVolumes: + m_Keys: [] + m_Values: + references: + version: 2 + RefIds: + - rid: 9103181481788571865 + type: {class: UniversalRenderPipelineEditorShaders, ns: UnityEngine.Rendering.Universal, asm: Unity.RenderPipelines.Universal.Runtime} + data: + m_AutodeskInteractive: {fileID: 4800000, guid: 0e9d5a909a1f7e84882a534d0d11e49f, type: 3} + m_AutodeskInteractiveTransparent: {fileID: 4800000, guid: 5c81372d981403744adbdda4433c9c11, type: 3} + m_AutodeskInteractiveMasked: {fileID: 4800000, guid: 80aa867ac363ac043847b06ad71604cd, type: 3} + m_TerrainDetailLit: {fileID: 4800000, guid: f6783ab646d374f94b199774402a5144, type: 3} + m_TerrainDetailGrassBillboard: {fileID: 4800000, guid: 29868e73b638e48ca99a19ea58c48d90, type: 3} + m_TerrainDetailGrass: {fileID: 4800000, guid: e507fdfead5ca47e8b9a768b51c291a1, type: 3} + m_DefaultSpeedTree7Shader: {fileID: 4800000, guid: 0f4122b9a743b744abe2fb6a0a88868b, type: 3} + m_DefaultSpeedTree8Shader: {fileID: -6465566751694194690, guid: 9920c1f1781549a46ba081a2a15a16ec, type: 3} + m_DefaultSpeedTree9Shader: {fileID: -6465566751694194690, guid: cbd3e1cc4ae141c42a30e33b4d666a61, type: 3} + - rid: 9103181481788571866 + type: {class: UniversalRenderPipelineDebugShaders, ns: UnityEngine.Rendering.Universal, asm: Unity.RenderPipelines.Universal.Runtime} + data: + m_DebugReplacementPS: {fileID: 4800000, guid: cf852408f2e174538bcd9b7fda1c5ae7, type: 3} + m_HdrDebugViewPS: {fileID: 4800000, guid: 573620ae32aec764abd4d728906d2587, type: 3} + m_ProbeVolumeSamplingDebugComputeShader: {fileID: 7200000, guid: 53626a513ea68ce47b59dc1299fe3959, type: 3} + - rid: 9103181481788571867 + type: {class: Renderer2DResources, ns: UnityEngine.Rendering.Universal, asm: Unity.RenderPipelines.Universal.Runtime} + data: + m_Version: 0 + m_LightShader: {fileID: 4800000, guid: 3f6c848ca3d7bca4bbe846546ac701a1, type: 3} + m_ProjectedShadowShader: {fileID: 4800000, guid: ce09d4a80b88c5a4eb9768fab4f1ee00, type: 3} + m_SpriteShadowShader: {fileID: 4800000, guid: 44fc62292b65ab04eabcf310e799ccf6, type: 3} + m_SpriteUnshadowShader: {fileID: 4800000, guid: de02b375720b5c445afe83cd483bedf3, type: 3} + m_GeometryShadowShader: {fileID: 4800000, guid: 19349a0f9a7ed4c48a27445bcf92e5e1, type: 3} + m_GeometryUnshadowShader: {fileID: 4800000, guid: 77774d9009bb81447b048c907d4c6273, type: 3} + m_FallOffLookup: {fileID: 2800000, guid: 5688ab254e4c0634f8d6c8e0792331ca, type: 3} + m_DefaultCustomMaterial: {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2} + m_DefaultLitMaterial: {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2} + m_DefaultUnlitMaterial: {fileID: 2100000, guid: 9dfc825aed78fcd4ba02077103263b40, type: 2} + m_DefaultMaskMaterial: {fileID: 2100000, guid: 15d0c3709176029428a0da2f8cecf0b5, type: 2} + - rid: 9103181481788571868 + type: {class: UniversalRendererResources, ns: UnityEngine.Rendering.Universal, asm: Unity.RenderPipelines.Universal.Runtime} + data: + m_Version: 0 + m_CopyDepthPS: {fileID: 4800000, guid: d6dae50ee9e1bfa4db75f19f99355220, type: 3} + m_CameraMotionVector: {fileID: 4800000, guid: c56b7e0d4c7cb484e959caeeedae9bbf, type: 3} + m_StencilDeferredPS: {fileID: 4800000, guid: e9155b26e1bc55942a41e518703fe304, type: 3} + m_DBufferClear: {fileID: 4800000, guid: f056d8bd2a1c7e44e9729144b4c70395, type: 3} + - rid: 9103181481788571869 + type: {class: UniversalRenderPipelineEditorMaterials, ns: UnityEngine.Rendering.Universal, asm: Unity.RenderPipelines.Universal.Runtime} + data: + m_DefaultMaterial: {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2} + m_DefaultParticleMaterial: {fileID: 2100000, guid: e823cd5b5d27c0f4b8256e7c12ee3e6d, type: 2} + m_DefaultLineMaterial: {fileID: 2100000, guid: e823cd5b5d27c0f4b8256e7c12ee3e6d, type: 2} + m_DefaultTerrainMaterial: {fileID: 2100000, guid: 594ea882c5a793440b60ff72d896021e, type: 2} + m_DefaultDecalMaterial: {fileID: 2100000, guid: 31d0dcc6f2dd4e4408d18036a2c93862, type: 2} + - rid: 9103181481788571870 + type: {class: URPDefaultVolumeProfileSettings, ns: UnityEngine.Rendering.Universal, asm: Unity.RenderPipelines.Universal.Runtime} + data: + m_Version: 0 + m_VolumeProfile: {fileID: 0} + - rid: 9103181481788571871 + type: {class: URPShaderStrippingSetting, ns: UnityEngine.Rendering.Universal, asm: Unity.RenderPipelines.Universal.Runtime} + data: + m_Version: 0 + m_StripUnusedPostProcessingVariants: 0 + m_StripUnusedVariants: 1 + m_StripScreenCoordOverrideVariants: 1 + - rid: 9103181481788571872 + type: {class: UniversalRenderPipelineRuntimeTextures, ns: UnityEngine.Rendering.Universal, asm: Unity.RenderPipelines.Universal.Runtime} + data: + m_Version: 1 + m_BlueNoise64LTex: {fileID: 2800000, guid: e3d24661c1e055f45a7560c033dbb837, type: 3} + m_BayerMatrixTex: {fileID: 2800000, guid: f9ee4ed84c1d10c49aabb9b210b0fc44, type: 3} + m_DebugFontTex: {fileID: 2800000, guid: 26a413214480ef144b2915d6ff4d0beb, type: 3} + - rid: 9103181481788571873 + type: {class: RenderGraphSettings, ns: UnityEngine.Rendering.Universal, asm: Unity.RenderPipelines.Universal.Runtime} + data: + m_Version: 0 + m_EnableRenderCompatibilityMode: 1 + - rid: 9103181481788571874 + type: {class: UniversalRenderPipelineRuntimeShaders, ns: UnityEngine.Rendering.Universal, asm: Unity.RenderPipelines.Universal.Runtime} + data: + m_Version: 0 + m_FallbackErrorShader: {fileID: 4800000, guid: e6e9a19c3678ded42a3bc431ebef7dbd, type: 3} + m_BlitHDROverlay: {fileID: 4800000, guid: a89bee29cffa951418fc1e2da94d1959, type: 3} + m_CoreBlitPS: {fileID: 4800000, guid: 93446b5c5339d4f00b85c159e1159b7c, type: 3} + m_CoreBlitColorAndDepthPS: {fileID: 4800000, guid: d104b2fc1ca6445babb8e90b0758136b, type: 3} + m_SamplingPS: {fileID: 4800000, guid: 04c410c9937594faa893a11dceb85f7e, type: 3} + - rid: 9103181481788571875 + type: {class: UniversalRenderPipelineRuntimeXRResources, ns: UnityEngine.Rendering.Universal, asm: Unity.RenderPipelines.Universal.Runtime} + data: + m_xrOcclusionMeshPS: {fileID: 4800000, guid: 4431b1f1f743fbf4eb310a967890cbea, type: 3} + m_xrMirrorViewPS: {fileID: 4800000, guid: d5a307c014552314b9f560906d708772, type: 3} + - rid: 9103181481788571876 + type: {class: GPUResidentDrawerResources, ns: UnityEngine.Rendering, asm: Unity.RenderPipelines.GPUDriven.Runtime} + data: + m_Version: 0 + m_InstanceDataBufferCopyKernels: {fileID: 7200000, guid: f984aeb540ded8b4fbb8a2047ab5b2e2, type: 3} + m_InstanceDataBufferUploadKernels: {fileID: 7200000, guid: 53864816eb00f2343b60e1a2c5a262ef, type: 3} + m_TransformUpdaterKernels: {fileID: 7200000, guid: 2a567b9b2733f8d47a700c3c85bed75b, type: 3} + m_WindDataUpdaterKernels: {fileID: 7200000, guid: fde76746e4fd0ed418c224f6b4084114, type: 3} + m_OccluderDepthPyramidKernels: {fileID: 7200000, guid: 08b2b5fb307b0d249860612774a987da, type: 3} + m_InstanceOcclusionCullingKernels: {fileID: 7200000, guid: f6d223acabc2f974795a5a7864b50e6c, type: 3} + m_OcclusionCullingDebugKernels: {fileID: 7200000, guid: b23e766bcf50ca4438ef186b174557df, type: 3} + m_DebugOcclusionTestPS: {fileID: 4800000, guid: d3f0849180c2d0944bc71060693df100, type: 3} + m_DebugOccluderPS: {fileID: 4800000, guid: b3c92426a88625841ab15ca6a7917248, type: 3} + - rid: 9103181481788571877 + type: {class: ProbeVolumeBakingResources, ns: UnityEngine.Rendering, asm: Unity.RenderPipelines.Core.Runtime} + data: + m_Version: 1 + dilationShader: {fileID: 7200000, guid: 6bb382f7de370af41b775f54182e491d, type: 3} + subdivideSceneCS: {fileID: 7200000, guid: bb86f1f0af829fd45b2ebddda1245c22, type: 3} + voxelizeSceneShader: {fileID: 4800000, guid: c8b6a681c7b4e2e4785ffab093907f9e, type: 3} + traceVirtualOffsetCS: {fileID: 7200000, guid: 805f10d263aac4b4098c0279cd37a4f3, type: 3} + traceVirtualOffsetRT: {fileID: 4807578003741378534, guid: b60511f4aa1443f4d8c0b18f4fec92f4, type: 3} + skyOcclusionCS: {fileID: 7200000, guid: 798f52ec82fa04048a12826bbbbcf7b4, type: 3} + skyOcclusionRT: {fileID: 4807578003741378534, guid: dfaf42b38dd001f49a72d8102b709f29, type: 3} + - rid: 9103181481788571878 + type: {class: RenderGraphGlobalSettings, ns: UnityEngine.Rendering, asm: Unity.RenderPipelines.Core.Runtime} + data: + m_version: 0 + m_EnableCompilationCaching: 1 + m_EnableValidityChecks: 1 + - rid: 9103181481788571879 + type: {class: ProbeVolumeGlobalSettings, ns: UnityEngine.Rendering, asm: Unity.RenderPipelines.Core.Runtime} + data: + m_Version: 1 + m_ProbeVolumeDisableStreamingAssets: 0 + - rid: 9103181481788571880 + type: {class: STP/RuntimeResources, ns: UnityEngine.Rendering, asm: Unity.RenderPipelines.Core.Runtime} + data: + m_setupCS: {fileID: 7200000, guid: 33be2e9a5506b2843bdb2bdff9cad5e1, type: 3} + m_preTaaCS: {fileID: 7200000, guid: a679dba8ec4d9ce45884a270b0e22dda, type: 3} + m_taaCS: {fileID: 7200000, guid: 3923900e2b41b5e47bc25bfdcbcdc9e6, type: 3} + - rid: 9103181481788571881 + type: {class: ProbeVolumeDebugResources, ns: UnityEngine.Rendering, asm: Unity.RenderPipelines.Core.Runtime} + data: + m_Version: 1 + probeVolumeDebugShader: {fileID: 4800000, guid: 3b21275fd12d65f49babb5286f040f2d, type: 3} + probeVolumeFragmentationDebugShader: {fileID: 4800000, guid: 3a80877c579b9144ebdcc6d923bca303, type: 3} + probeVolumeSamplingDebugShader: {fileID: 4800000, guid: bf54e6528c79a224e96346799064c393, type: 3} + probeVolumeOffsetDebugShader: {fileID: 4800000, guid: db8bd7436dc2c5f4c92655307d198381, type: 3} + probeSamplingDebugMesh: {fileID: -3555484719484374845, guid: 20be25aac4e22ee49a7db76fb3df6de2, type: 3} + numbersDisplayTex: {fileID: 2800000, guid: 73fe53b428c5b3440b7e87ee830b608a, type: 3} + - rid: 9103181481788571882 + type: {class: IncludeAdditionalRPAssets, ns: UnityEngine.Rendering, asm: Unity.RenderPipelines.Core.Runtime} + data: + m_version: 0 + m_IncludeReferencedInScenes: 0 + m_IncludeAssetsByLabel: 0 + m_LabelToInclude: + - rid: 9103181481788571883 + type: {class: ShaderStrippingSetting, ns: UnityEngine.Rendering, asm: Unity.RenderPipelines.Core.Runtime} + data: + m_Version: 0 + m_ExportShaderVariants: 1 + m_ShaderVariantLogLevel: 0 + m_StripRuntimeDebugShaders: 1 + - rid: 9103181481788571884 + type: {class: ProbeVolumeRuntimeResources, ns: UnityEngine.Rendering, asm: Unity.RenderPipelines.Core.Runtime} + data: + m_Version: 1 + probeVolumeBlendStatesCS: {fileID: 7200000, guid: a3f7b8c99de28a94684cb1daebeccf5d, type: 3} + probeVolumeUploadDataCS: {fileID: 7200000, guid: 0951de5992461754fa73650732c4954c, type: 3} + probeVolumeUploadDataL2CS: {fileID: 7200000, guid: 6196f34ed825db14b81fb3eb0ea8d931, type: 3} diff --git a/Assets/XRI.meta b/Assets/XRI.meta new file mode 100644 index 00000000..6a7afa17 --- /dev/null +++ b/Assets/XRI.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9b395339e7994d34f907cc4b3a335bf8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/XRI/Settings.meta b/Assets/XRI/Settings.meta new file mode 100644 index 00000000..1f6e2bad --- /dev/null +++ b/Assets/XRI/Settings.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0a36a2da02f52c84b8f1f8601e567c42 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/XRI/Settings/Resources.meta b/Assets/XRI/Settings/Resources.meta new file mode 100644 index 00000000..91db45ed --- /dev/null +++ b/Assets/XRI/Settings/Resources.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cc41100c934dd094c8906dfb6786cb81 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/XRI/Settings/Resources/InteractionLayerSettings.asset b/Assets/XRI/Settings/Resources/InteractionLayerSettings.asset new file mode 100644 index 00000000..3f314b5d --- /dev/null +++ b/Assets/XRI/Settings/Resources/InteractionLayerSettings.asset @@ -0,0 +1,47 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 191492db6e452eb468b95433ec162164, type: 3} + m_Name: InteractionLayerSettings + m_EditorClassIdentifier: + m_LayerNames: + - Default + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - diff --git a/Assets/XRI/Settings/Resources/InteractionLayerSettings.asset.meta b/Assets/XRI/Settings/Resources/InteractionLayerSettings.asset.meta new file mode 100644 index 00000000..1fd7aeb6 --- /dev/null +++ b/Assets/XRI/Settings/Resources/InteractionLayerSettings.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 02b8c2f02c28fe54baca28d5a44c926e +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/XRI/Settings/Resources/XRDeviceSimulatorSettings.asset b/Assets/XRI/Settings/Resources/XRDeviceSimulatorSettings.asset new file mode 100644 index 00000000..4b8bcf39 --- /dev/null +++ b/Assets/XRI/Settings/Resources/XRDeviceSimulatorSettings.asset @@ -0,0 +1,17 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 690929a59dc7a42da9030305190d391f, type: 3} + m_Name: XRDeviceSimulatorSettings + m_EditorClassIdentifier: + m_AutomaticallyInstantiateSimulatorPrefab: 0 + m_AutomaticallyInstantiateInEditorOnly: 1 + m_SimulatorPrefab: {fileID: 0} diff --git a/Assets/XRI/Settings/Resources/XRDeviceSimulatorSettings.asset.meta b/Assets/XRI/Settings/Resources/XRDeviceSimulatorSettings.asset.meta new file mode 100644 index 00000000..523b79a7 --- /dev/null +++ b/Assets/XRI/Settings/Resources/XRDeviceSimulatorSettings.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f8ac69b1be516e246900336570205db6 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/XRI/Settings/XRInteractionEditorSettings.asset b/Assets/XRI/Settings/XRInteractionEditorSettings.asset new file mode 100644 index 00000000..0332a62f --- /dev/null +++ b/Assets/XRI/Settings/XRInteractionEditorSettings.asset @@ -0,0 +1,15 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2d38fb1463c5c804b8847c20e8873623, type: 3} + m_Name: XRInteractionEditorSettings + m_EditorClassIdentifier: + m_InputReaderPropertyDrawerMode: 0 diff --git a/Assets/XRI/Settings/XRInteractionEditorSettings.asset.meta b/Assets/XRI/Settings/XRInteractionEditorSettings.asset.meta new file mode 100644 index 00000000..cc2080b0 --- /dev/null +++ b/Assets/XRI/Settings/XRInteractionEditorSettings.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ff6f0380f1056904bb9fc094178d21eb +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.deltation.toon-rp/Runtime/Lighting/ToonLighting.cs b/Packages/com.deltation.toon-rp/Runtime/Lighting/ToonLighting.cs index 8b24b5f2..6957b85b 100644 --- a/Packages/com.deltation.toon-rp/Runtime/Lighting/ToonLighting.cs +++ b/Packages/com.deltation.toon-rp/Runtime/Lighting/ToonLighting.cs @@ -204,7 +204,7 @@ private void SetupAdditionalLights(NativeArray indexMap, in NativeArray Date: Mon, 15 Apr 2024 23:04:16 +0200 Subject: [PATCH 02/23] Change package Unity version --- Packages/com.deltation.toon-rp/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/com.deltation.toon-rp/package.json b/Packages/com.deltation.toon-rp/package.json index f0ff1d95..ac8f21fb 100644 --- a/Packages/com.deltation.toon-rp/package.json +++ b/Packages/com.deltation.toon-rp/package.json @@ -3,7 +3,7 @@ "displayName": "Toon RP", "description": "A Scriptable Render Pipeline (SRP) designed for toon/stylized visuals (WIP).", "version": "0.9.0", - "unity": "2022.3", + "unity": "2023.3", "unityRelease": "0f1", "author": { "name": "Vladislav Kantaev", From 1d97782976724309bd9284bc306d7c9643f0bd76 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Mon, 15 Apr 2024 23:04:32 +0200 Subject: [PATCH 03/23] Upgrade package dependencies --- Packages/com.deltation.toon-rp/package.json | 8 ++++---- Packages/packages-lock.json | 12 ++++++------ ProjectSettings/ShaderGraphSettings.asset | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Packages/com.deltation.toon-rp/package.json b/Packages/com.deltation.toon-rp/package.json index ac8f21fb..f5a01540 100644 --- a/Packages/com.deltation.toon-rp/package.json +++ b/Packages/com.deltation.toon-rp/package.json @@ -11,11 +11,11 @@ "url": "https://deltation.tatar/" }, "dependencies": { - "com.unity.render-pipelines.core": "14.0.9", - "com.unity.shadergraph": "14.0.9", + "com.unity.render-pipelines.core": "17.0.2", + "com.unity.shadergraph": "17.0.2", "com.unity.modules.uielements": "1.0.0", "com.unity.mathematics": "1.2.6", "com.unity.burst": "1.8.9", - "com.unity.collections": "2.1.4" + "com.unity.collections": "2.4.0" } -} +} \ No newline at end of file diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index d7ed4135..a8886b63 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -12,12 +12,12 @@ "depth": 0, "source": "embedded", "dependencies": { - "com.unity.render-pipelines.core": "14.0.9", - "com.unity.shadergraph": "14.0.9", + "com.unity.render-pipelines.core": "17.0.2", + "com.unity.shadergraph": "17.0.2", "com.unity.modules.uielements": "1.0.0", "com.unity.mathematics": "1.2.6", "com.unity.burst": "1.8.9", - "com.unity.collections": "2.1.4" + "com.unity.collections": "2.4.0" } }, "com.tayx.graphy": { @@ -47,13 +47,13 @@ "url": "https://packages.unity.com" }, "com.unity.collections": { - "version": "2.4.0-pre.2", + "version": "2.4.0", "depth": 1, "source": "registry", "dependencies": { - "com.unity.burst": "1.8.10", + "com.unity.burst": "1.8.12", "com.unity.nuget.mono-cecil": "1.11.4", - "com.unity.test-framework": "1.3.8", + "com.unity.test-framework": "1.4.3", "com.unity.test-framework.performance": "3.0.3" }, "url": "https://packages.unity.com" diff --git a/ProjectSettings/ShaderGraphSettings.asset b/ProjectSettings/ShaderGraphSettings.asset index 3250b068..e66042a7 100644 --- a/ProjectSettings/ShaderGraphSettings.asset +++ b/ProjectSettings/ShaderGraphSettings.asset @@ -15,3 +15,4 @@ MonoBehaviour: shaderVariantLimit: 128 customInterpolatorErrorThreshold: 32 customInterpolatorWarningThreshold: 16 + customHeatmapValues: {fileID: 0} From c8febac86dcf2380c8f82595a6a301cc2f3e8455 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Mon, 15 Apr 2024 23:08:01 +0200 Subject: [PATCH 04/23] Fix warning in ToonRenderPipelineAsset.cs --- .../com.deltation.toon-rp/Runtime/ToonRenderPipelineAsset.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/com.deltation.toon-rp/Runtime/ToonRenderPipelineAsset.cs b/Packages/com.deltation.toon-rp/Runtime/ToonRenderPipelineAsset.cs index c5cbc78f..e25648d1 100644 --- a/Packages/com.deltation.toon-rp/Runtime/ToonRenderPipelineAsset.cs +++ b/Packages/com.deltation.toon-rp/Runtime/ToonRenderPipelineAsset.cs @@ -17,7 +17,7 @@ namespace DELTation.ToonRP { [CreateAssetMenu(menuName = "Toon RP/Toon Render Pipeline Asset")] - public sealed class ToonRenderPipelineAsset : RenderPipelineAsset + public sealed class ToonRenderPipelineAsset : RenderPipelineAsset { private static readonly string[] ForceIncludedShaderNames = { From c6ffc34e13afc5efe0bd26ea5ec33c4a71192ef1 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Mon, 15 Apr 2024 23:08:10 +0200 Subject: [PATCH 05/23] Fix deprecated warning in LightRotation --- Assets/Samples/TiledLighting/LightRotation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Samples/TiledLighting/LightRotation.cs b/Assets/Samples/TiledLighting/LightRotation.cs index 4339f499..240d6d94 100644 --- a/Assets/Samples/TiledLighting/LightRotation.cs +++ b/Assets/Samples/TiledLighting/LightRotation.cs @@ -12,7 +12,7 @@ public class LightRotation : MonoBehaviour private void Awake() { - _lights = FindObjectsOfType() + _lights = FindObjectsByType(FindObjectsSortMode.None) .Where(l => l.type == LightType.Point) .Select(l => { From a253492f926e56959c21ccca96d449edfc24342a Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Mon, 15 Apr 2024 23:08:20 +0200 Subject: [PATCH 06/23] Update OpenXR Package Settings.asset --- Assets/XR/Settings/OpenXR Package Settings.asset | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Assets/XR/Settings/OpenXR Package Settings.asset b/Assets/XR/Settings/OpenXR Package Settings.asset index d9eadb30..96bacf12 100644 --- a/Assets/XR/Settings/OpenXR Package Settings.asset +++ b/Assets/XR/Settings/OpenXR Package Settings.asset @@ -49,6 +49,7 @@ MonoBehaviour: - {fileID: 5689474454540423095} m_renderMode: 1 m_depthSubmissionMode: 0 + m_optimizeBufferDiscards: 0 m_symmetricProjection: 0 --- !u!114 &-7915400067761800864 MonoBehaviour: @@ -290,6 +291,7 @@ MonoBehaviour: - {fileID: -3075017112203589251} m_renderMode: 1 m_depthSubmissionMode: 0 + m_optimizeBufferDiscards: 0 m_symmetricProjection: 0 --- !u!114 &-3546199860015881971 MonoBehaviour: @@ -465,6 +467,7 @@ MonoBehaviour: features: [] m_renderMode: 1 m_depthSubmissionMode: 0 + m_optimizeBufferDiscards: 0 m_symmetricProjection: 0 --- !u!114 &1321407770044777543 MonoBehaviour: @@ -481,6 +484,7 @@ MonoBehaviour: features: [] m_renderMode: 1 m_depthSubmissionMode: 0 + m_optimizeBufferDiscards: 0 m_symmetricProjection: 0 --- !u!114 &1387978956390654346 MonoBehaviour: @@ -637,6 +641,7 @@ MonoBehaviour: forceRemoveInternetPermission: 1 symmetricProjection: 0 systemSplashScreen: {fileID: 0} + optimizeBufferDiscards: 1 lateLatchingMode: 0 lateLatchingDebug: 0 --- !u!114 &7573713023116417563 From ccd2380b4e416ced7d8147b5bb3279ab76172cc6 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Mon, 15 Apr 2024 23:20:40 +0200 Subject: [PATCH 07/23] Upgrade format usage in ToonCameraRenderer.cs --- .../com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs b/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs index 948ba8e9..8a7d3f34 100644 --- a/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs +++ b/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs @@ -82,15 +82,15 @@ public static GraphicsFormat GetRenderTextureColorFormat(in ToonCameraRendererSe } GraphicsFormat rawGraphicsFormat = settings.RenderTextureFormat; - FormatUsage formatUsage = FormatUsage.Render; + GraphicsFormatUsage formatUsage = GraphicsFormatUsage.Render; if (!ignoreMsaa) { // ReSharper disable once BitwiseOperatorOnEnumWithoutFlags formatUsage |= settings.Msaa switch { - MsaaMode._2x => FormatUsage.MSAA2x, - MsaaMode._4x => FormatUsage.MSAA4x, - MsaaMode._8x => FormatUsage.MSAA8x, + MsaaMode._2x => GraphicsFormatUsage.MSAA2x, + MsaaMode._4x => GraphicsFormatUsage.MSAA4x, + MsaaMode._8x => GraphicsFormatUsage.MSAA8x, _ => 0, }; } From 35587950e6c1fc6e2440ded723a5eaff3374645b Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Mon, 15 Apr 2024 23:22:28 +0200 Subject: [PATCH 08/23] Upgrade skybox draw API --- .../Runtime/ToonCameraRenderer.cs | 38 +++++++------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs b/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs index 8a7d3f34..27d96417 100644 --- a/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs +++ b/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs @@ -104,6 +104,7 @@ public static ToonPrePassRequirement GetOverridePrePassRequirement(in ToonCamera { ToonPrePassRequirement requirement; requirement.Mode = settings.PrePass; + // assuming that if the pipeline settings ask for a pre-pass, it should be not earlier than BeforeTransparent (e.g., soft particles) requirement.Event = settings.PrePass != PrePassMode.Off ? ToonRenderingEvent.BeforeTransparent @@ -907,46 +908,35 @@ ref renderStateBlockValue private void DrawSkybox(CommandBuffer cmd) { -#if ENABLE_VR && ENABLE_XR_MODULE + RendererList rendererList; - // XRTODO: Remove this code once Skybox pass is moved to SRP land. +#if ENABLE_VR && ENABLE_XR_MODULE XRPass xrPass = _additionalCameraData.XrPass; if (xrPass.enabled) { - // Setup Legacy XR buffer states if (xrPass.singlePassEnabled) { - // Use legacy stereo instancing mode to have legacy XR code path configured - cmd.SetSinglePassStereo(SystemInfo.supportsMultiview - ? SinglePassStereoMode.Multiview - : SinglePassStereoMode.Instancing + rendererList = _context.CreateSkyboxRendererList( + _camera, + xrPass.GetProjMatrix(0), xrPass.GetViewMatrix(0), + xrPass.GetProjMatrix(1), xrPass.GetViewMatrix(1) ); - _context.ExecuteCommandBuffer(cmd); - cmd.Clear(); - - // Calling into built-in skybox pass - _context.DrawSkybox(_camera); - - // Disable Legacy XR path - cmd.SetSinglePassStereo(SinglePassStereoMode.None); - _context.ExecuteCommandBuffer(cmd); - - // We do not need to submit here due to special handling of stereo matrices in core. - // context.Submit(); - cmd.Clear(); - - ToonXr.UpdateCameraStereoMatrices(_camera, xrPass); } else { - _context.DrawSkybox(_camera); + rendererList = _context.CreateSkyboxRendererList(_camera, + xrPass.GetProjMatrix(), xrPass.GetViewMatrix() + ); } } else #endif { - _context.DrawSkybox(_camera); + rendererList = _context.CreateSkyboxRendererList(_camera); } + + cmd.DrawRendererList(rendererList); + _context.ExecuteCommandBufferAndClear(cmd); } partial void DrawGizmosPreImageEffects(); From 9fcfa5bb36f9974a72f1a9c03424c0363992b945 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Mon, 15 Apr 2024 23:23:58 +0200 Subject: [PATCH 09/23] Upgrade format usage in ToonShadowMapFormatUtils.cs --- .../Runtime/Shadows/ToonShadowMapFormatUtils.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMapFormatUtils.cs b/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMapFormatUtils.cs index 006308e9..0be861d1 100644 --- a/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMapFormatUtils.cs +++ b/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMapFormatUtils.cs @@ -23,7 +23,7 @@ public static (GraphicsFormat format, int bits) GetSupportedShadowMapFormat(Shad const int stencilBits = 0; GraphicsFormat format = GraphicsFormatUtility.GetDepthStencilFormat((int) shadowMapBits, stencilBits); - if (SystemInfo.IsFormatSupported(format, FormatUsage.Render | FormatUsage.Sample)) + if (SystemInfo.IsFormatSupported(format, GraphicsFormatUsage.Render | GraphicsFormatUsage.Sample)) { return (format, (int) shadowMapBits); } @@ -48,7 +48,7 @@ public static GraphicsFormat GetSupportedVsmTextureFormat(VsmTexturePrecision de }; return UnityEngine.SystemInfo.IsFormatSupported(desiredFormat, - FormatUsage.Render | FormatUsage.Sample | FormatUsage.Linear + GraphicsFormatUsage.Render | GraphicsFormatUsage.Sample | GraphicsFormatUsage.Linear ) ? desiredFormat : halfFormat; From 3e8961f104ef6d5076a82d234f0433a0f0ef6b79 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Mon, 15 Apr 2024 23:28:33 +0200 Subject: [PATCH 10/23] Fix GLES2 deprecation warning in ToonGraphicsApi.cs --- Packages/com.deltation.toon-rp/Runtime/ToonGraphicsApi.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Packages/com.deltation.toon-rp/Runtime/ToonGraphicsApi.cs b/Packages/com.deltation.toon-rp/Runtime/ToonGraphicsApi.cs index e25e13cf..39e251a1 100644 --- a/Packages/com.deltation.toon-rp/Runtime/ToonGraphicsApi.cs +++ b/Packages/com.deltation.toon-rp/Runtime/ToonGraphicsApi.cs @@ -17,7 +17,9 @@ public static bool OpenGlStyleClipDepth GraphicsDeviceType api = SystemInfo.graphicsDeviceType; return api is GraphicsDeviceType.OpenGLCore or +#if !UNITY_2023_1_OR_NEWER GraphicsDeviceType.OpenGLES2 or +#endif // !UNITY_2023_1_OR_NEWER GraphicsDeviceType.OpenGLES3; #endif // UNITY_WEBGL } From eee319767962ed82108ca16e68416e28a9a9de9c Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Mon, 15 Apr 2024 23:42:17 +0200 Subject: [PATCH 11/23] Upgrade the creation of directional ShadowDrawingSettings --- .../Runtime/Shadows/ToonShadowMaps.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMaps.cs b/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMaps.cs index fe3b58f5..103ea56e 100644 --- a/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMaps.cs +++ b/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMaps.cs @@ -370,12 +370,7 @@ private static Color GetShadowmapClearColor() private void RenderDirectionalShadows(CommandBuffer cmd, int index, int split, int tileSize) { ShadowedDirectionalLight light = _shadowedDirectionalLights[index]; - var shadowSettings = - new ShadowDrawingSettings(_cullingResults, light.VisibleLightIndex -#if UNITY_2022_2_OR_NEWER - , BatchCullingProjectionType.Orthographic // directional shadows are rendered with orthographic projection -#endif // UNITY_2022_2_OR_NEWER - ); + var shadowSettings = new ShadowDrawingSettings(_cullingResults, light.VisibleLightIndex); int cascadeCount = _shadowMapsSettings.Directional.CascadeCount; int tileOffset = index * cascadeCount; Vector3 ratios = _shadowMapsSettings.Directional.GetRatios(); From 4a4f8255347e03f85249bda6070ed04cf470bf19 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Mon, 15 Apr 2024 23:50:49 +0200 Subject: [PATCH 12/23] Upgrade to renderer lists in ToonDepthPrePass.cs and ToonMotionVectorsPrePass.cs --- .../Runtime/NativeCollectionsUtils.cs | 14 +++++++++++++ .../Runtime/NativeCollectionsUtils.cs.meta | 3 +++ .../Runtime/ToonDepthPrePass.cs | 21 ++++++++++++------- .../Runtime/ToonMotionVectorsPrePass.cs | 11 +++++++--- 4 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 Packages/com.deltation.toon-rp/Runtime/NativeCollectionsUtils.cs create mode 100644 Packages/com.deltation.toon-rp/Runtime/NativeCollectionsUtils.cs.meta diff --git a/Packages/com.deltation.toon-rp/Runtime/NativeCollectionsUtils.cs b/Packages/com.deltation.toon-rp/Runtime/NativeCollectionsUtils.cs new file mode 100644 index 00000000..46dd987b --- /dev/null +++ b/Packages/com.deltation.toon-rp/Runtime/NativeCollectionsUtils.cs @@ -0,0 +1,14 @@ +using Unity.Collections; + +namespace DELTation.ToonRP +{ + public static class NativeCollectionsUtils + { + public static NativeArray CreateTempSingletonArray(T value) where T : struct + { + var array = new NativeArray(1, Allocator.Temp); + array[0] = value; + return array; + } + } +} \ No newline at end of file diff --git a/Packages/com.deltation.toon-rp/Runtime/NativeCollectionsUtils.cs.meta b/Packages/com.deltation.toon-rp/Runtime/NativeCollectionsUtils.cs.meta new file mode 100644 index 00000000..be59fce1 --- /dev/null +++ b/Packages/com.deltation.toon-rp/Runtime/NativeCollectionsUtils.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 557656254e754e51bd11979650376a60 +timeCreated: 1713217766 \ No newline at end of file diff --git a/Packages/com.deltation.toon-rp/Runtime/ToonDepthPrePass.cs b/Packages/com.deltation.toon-rp/Runtime/ToonDepthPrePass.cs index b04cf362..e004bef9 100644 --- a/Packages/com.deltation.toon-rp/Runtime/ToonDepthPrePass.cs +++ b/Packages/com.deltation.toon-rp/Runtime/ToonDepthPrePass.cs @@ -123,9 +123,9 @@ public void Cleanup(ref ScriptableRenderContext context) CommandBufferPool.Release(cmd); } - private void DrawRenderers(CommandBuffer cmd, ref RenderContext renderContext) + private void DrawRenderers(CommandBuffer cmd, ref RenderContext context) { - Camera camera = renderContext.Camera; + Camera camera = context.Camera; var sortingSettings = new SortingSettings(camera) { @@ -134,18 +134,23 @@ private void DrawRenderers(CommandBuffer cmd, ref RenderContext renderContext) ShaderTagId shaderPassName = _normals ? DepthNormalsShaderTagId : DepthOnlyShaderTagId; var drawingSettings = new DrawingSettings(shaderPassName, sortingSettings) { - enableDynamicBatching = renderContext.Settings.UseDynamicBatching, + enableDynamicBatching = context.Settings.UseDynamicBatching, }; var filteringSettings = new FilteringSettings(RenderQueueRange.opaque, camera.cullingMask); var renderStateBlock = new RenderStateBlock(RenderStateMask.Nothing); - renderContext.Srp.DrawRenderers(renderContext.CullingResults, - ref drawingSettings, ref filteringSettings, ref renderStateBlock - ); + var rendererListParams = new RendererListParams(context.CullingResults, drawingSettings, filteringSettings) + { + stateBlocks = NativeCollectionsUtils.CreateTempSingletonArray(renderStateBlock), + tagValues = NativeCollectionsUtils.CreateTempSingletonArray(shaderPassName), + }; + RendererList rendererList = context.Srp.CreateRendererList(ref rendererListParams); + cmd.DrawRendererList(rendererList); + context.Srp.ExecuteCommandBufferAndClear(cmd); - renderContext.ExtensionsCollection.OnPrePass( + context.ExtensionsCollection.OnPrePass( _normals ? PrePassMode.Normals | PrePassMode.Depth : PrePassMode.Depth, - ref renderContext.Srp, cmd, + ref context.Srp, cmd, ref drawingSettings, ref filteringSettings, ref renderStateBlock ); } diff --git a/Packages/com.deltation.toon-rp/Runtime/ToonMotionVectorsPrePass.cs b/Packages/com.deltation.toon-rp/Runtime/ToonMotionVectorsPrePass.cs index 5c6a37f7..7dd4ccab 100644 --- a/Packages/com.deltation.toon-rp/Runtime/ToonMotionVectorsPrePass.cs +++ b/Packages/com.deltation.toon-rp/Runtime/ToonMotionVectorsPrePass.cs @@ -82,9 +82,14 @@ private void DrawRenderers(CommandBuffer cmd, ref RenderContext context) depthState = new DepthState { writeEnabled = true, compareFunction = CompareFunction.LessEqual }, }; - context.Srp.DrawRenderers(context.CullingResults, - ref drawingSettings, ref filteringSettings, ref renderStateBlock - ); + var rendererListParams = new RendererListParams(context.CullingResults, drawingSettings, filteringSettings) + { + stateBlocks = NativeCollectionsUtils.CreateTempSingletonArray(renderStateBlock), + tagValues = NativeCollectionsUtils.CreateTempSingletonArray(MotionVectorsShaderTagId), + }; + RendererList rendererList = context.Srp.CreateRendererList(ref rendererListParams); + cmd.DrawRendererList(rendererList); + context.Srp.ExecuteCommandBufferAndClear(cmd); context.ExtensionsCollection.OnPrePass(PrePassMode.MotionVectors, ref context.Srp, cmd, From a4155713e484dd8ca92c5605bea5f498bc38b7d4 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Mon, 15 Apr 2024 23:58:26 +0200 Subject: [PATCH 13/23] Upgrade DrawUnsupportedShaders in ToonCameraRenderer.Editor.cs --- .../Runtime/ToonCameraRenderer.Editor.cs | 6 ++++-- .../com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.Editor.cs b/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.Editor.cs index 28596656..c09fbdda 100644 --- a/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.Editor.cs +++ b/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.Editor.cs @@ -56,7 +56,7 @@ partial void PrepareBufferName() _cmdName = _camera.name; } - partial void DrawUnsupportedShaders() + partial void DrawUnsupportedShaders(CommandBuffer cmd) { if (_errorMaterial == null) { @@ -74,7 +74,9 @@ partial void DrawUnsupportedShaders() } FilteringSettings filteringSettings = FilteringSettings.defaultValue; - _context.DrawRenderers(_cullingResults, ref drawingSettings, ref filteringSettings); + var rendererListParams = new RendererListParams(_cullingResults, drawingSettings, filteringSettings); + RendererList rendererList = _context.CreateRendererList(ref rendererListParams); + cmd.DrawRendererList(rendererList); } #endif // UNITY_EDITOR || DEBUG } diff --git a/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs b/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs index 27d96417..f31a0124 100644 --- a/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs +++ b/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs @@ -640,7 +640,7 @@ private void GeometryRenderPass(CommandBuffer cmd, in ToonRenderPipelineSharedCo DrawOcclusionMesh(cmd); DrawVisibleGeometry(cmd); - DrawUnsupportedShaders(); + DrawUnsupportedShaders(cmd); DrawGizmosPreImageEffects(); _context.ExecuteCommandBufferAndClear(cmd); @@ -942,7 +942,7 @@ private void DrawSkybox(CommandBuffer cmd) partial void DrawGizmosPreImageEffects(); partial void DrawGizmosPostImageEffects(); - partial void DrawUnsupportedShaders(); + partial void DrawUnsupportedShaders(CommandBuffer cmd); public void InvalidateExtensions() { From 7f25715851b21ab0d18f451fdd1e2d2d61dd579c Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Tue, 16 Apr 2024 00:40:58 +0200 Subject: [PATCH 14/23] Upgrade ToonInvertedHullOutline to renderer lists --- .../BuiltIn/ToonInvertedHullOutline.cs | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Packages/com.deltation.toon-rp/Runtime/Extensions/BuiltIn/ToonInvertedHullOutline.cs b/Packages/com.deltation.toon-rp/Runtime/Extensions/BuiltIn/ToonInvertedHullOutline.cs index 437cf1e0..66057df2 100644 --- a/Packages/com.deltation.toon-rp/Runtime/Extensions/BuiltIn/ToonInvertedHullOutline.cs +++ b/Packages/com.deltation.toon-rp/Runtime/Extensions/BuiltIn/ToonInvertedHullOutline.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering; +using UnityEngine.Rendering.RendererUtils; using static DELTation.ToonRP.Extensions.BuiltIn.ToonInvertedHullOutlineSettings; using static DELTation.ToonRP.ToonCameraRenderer; @@ -171,15 +172,6 @@ private void Render(CommandBuffer cmd, ref ScriptableRenderContext context, cameraOverride.OverrideIfEnabled(cmd, pass.CameraOverrides); context.ExecuteCommandBufferAndClear(cmd); - drawingSettings.overrideMaterial = material; - - for (int i = 0; i < ShaderTagIds.Length; i++) - { - drawingSettings.SetShaderPassName(i, ShaderTagIds[i]); - } - - filteringSettings.layerMask = pass.LayerMask; - renderStateBlock.mask |= RenderStateMask.Raster | RenderStateMask.Stencil; renderStateBlock.rasterState = new RasterState(CullMode.Front, 0, pass.DepthBias); @@ -201,9 +193,18 @@ private void Render(CommandBuffer cmd, ref ScriptableRenderContext context, renderStateBlock.stencilState = new StencilState(false); } - context.DrawRenderers(_cullingResults, - ref drawingSettings, ref filteringSettings, ref renderStateBlock - ); + var rendererListDesc = new RendererListDesc(ShaderTagIds, _cullingResults, _camera) + { + stateBlock = renderStateBlock, + layerMask = pass.LayerMask, + overrideMaterial = material, + renderQueueRange = filteringSettings.renderQueueRange, + sortingCriteria = drawingSettings.sortingSettings.criteria, + overrideMaterialPassIndex = drawingSettings.overrideMaterialPassIndex, + rendererConfiguration = drawingSettings.perObjectData, + }; + RendererList rendererList = context.CreateRendererList(rendererListDesc); + cmd.DrawRendererList(rendererList); cmd.SetGlobalDepthBias(0, 0); cameraOverride.Restore(cmd); From 456283aeb2fca5c72ec4529782068b3db5349344 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Tue, 16 Apr 2024 21:39:00 +0200 Subject: [PATCH 15/23] Migrate to renderer lists in ToonCameraRenderer.DrawGeometry --- .../BuiltIn/ToonOffScreenTransparency.cs | 8 +-- .../Extensions/BuiltIn/ToonRenderObjects.cs | 27 ++++----- .../Runtime/ToonCameraRenderer.cs | 56 +++++++------------ 3 files changed, 36 insertions(+), 55 deletions(-) diff --git a/Packages/com.deltation.toon-rp/Runtime/Extensions/BuiltIn/ToonOffScreenTransparency.cs b/Packages/com.deltation.toon-rp/Runtime/Extensions/BuiltIn/ToonOffScreenTransparency.cs index edb5b64c..17250245 100644 --- a/Packages/com.deltation.toon-rp/Runtime/Extensions/BuiltIn/ToonOffScreenTransparency.cs +++ b/Packages/com.deltation.toon-rp/Runtime/Extensions/BuiltIn/ToonOffScreenTransparency.cs @@ -114,10 +114,6 @@ public override void Render() _srpContext.ExecuteCommandBufferAndClear(cmd); { - var sortingSettings = new SortingSettings(_camera) - { - criteria = SortingCriteria.CommonTransparent, - }; // See 23-3: https://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-23-high-speed-screen-particles RenderTargetBlendState renderTargetBlendState = _settings.BlendMode switch { @@ -134,7 +130,8 @@ public override void Render() }; const bool includesTransparent = true; ToonCameraRenderer.DrawGeometry(_cameraRendererSettings, - ref _srpContext, _cullingResults, sortingSettings, RenderQueueRange.transparent, + ref _srpContext, cmd, _camera, _cullingResults, + SortingCriteria.CommonTransparent, RenderQueueRange.transparent, includesTransparent, _settings.LayerMask, new RenderStateBlock(RenderStateMask.Blend) @@ -145,6 +142,7 @@ public override void Render() }, } ); + _srpContext.ExecuteCommandBufferAndClear(cmd); } } diff --git a/Packages/com.deltation.toon-rp/Runtime/Extensions/BuiltIn/ToonRenderObjects.cs b/Packages/com.deltation.toon-rp/Runtime/Extensions/BuiltIn/ToonRenderObjects.cs index 57ad5154..8a1dee8d 100644 --- a/Packages/com.deltation.toon-rp/Runtime/Extensions/BuiltIn/ToonRenderObjects.cs +++ b/Packages/com.deltation.toon-rp/Runtime/Extensions/BuiltIn/ToonRenderObjects.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System; using UnityEngine; using UnityEngine.Rendering; @@ -6,13 +6,13 @@ namespace DELTation.ToonRP.Extensions.BuiltIn { public class ToonRenderObjects : ToonRenderingExtensionBase { - private readonly List _lightModeTags = new(); private ToonAdditionalCameraData _additionalCameraData; private Camera _camera; private ToonCameraRendererSettings _cameraRendererSettings; private ToonCameraRenderTarget _cameraRenderTarget; private ScriptableRenderContext _context; private CullingResults _cullingResults; + private ShaderTagId[] _lightModeTags = new ShaderTagId[1]; private ToonRenderObjectsSettings _settings; public override void Setup(in ToonRenderingExtensionContext context, @@ -38,13 +38,16 @@ public override void Render() using (new ProfilingScope(cmd, NamedProfilingSampler.Get(passName))) { bool overrideLightModeTags = false; - if (_settings.Filters.LightModeTags is { Length: > 0 }) + string[] lightModeTags = _settings.Filters.LightModeTags; + if (lightModeTags is { Length: > 0 }) { overrideLightModeTags = true; - _lightModeTags.Clear(); - foreach (string lightMode in _settings.Filters.LightModeTags) + + Array.Resize(ref _lightModeTags, lightModeTags.Length); + + for (int index = 0; index < lightModeTags.Length; index++) { - _lightModeTags.Add(new ShaderTagId(lightMode)); + _lightModeTags[index] = new ShaderTagId(lightModeTags[index]); } } @@ -53,19 +56,17 @@ public override void Render() _context.ExecuteCommandBufferAndClear(cmd); bool opaque = _settings.Filters.Queue == ToonRenderObjectsSettings.FilterSettings.RenderQueue.Opaque; - var sortingSettings = new SortingSettings(_camera) - { - criteria = opaque - ? SortingCriteria.CommonOpaque - : SortingCriteria.CommonTransparent, - }; + SortingCriteria sortingCriteria = opaque + ? SortingCriteria.CommonOpaque + : SortingCriteria.CommonTransparent; ClearRenderTargetIfEnabled(cmd); RenderStateBlock? renderStateBlock = ConstructRenderStateBlock(); RenderQueueRange renderQueueRange = opaque ? RenderQueueRange.opaque : RenderQueueRange.transparent; bool includesTransparent = !opaque; - ToonCameraRenderer.DrawGeometry(_cameraRendererSettings, ref _context, _cullingResults, sortingSettings, + ToonCameraRenderer.DrawGeometry(_cameraRendererSettings, ref _context, cmd, _camera, _cullingResults, + sortingCriteria, renderQueueRange, includesTransparent, _settings.Filters.LayerMask, renderStateBlock, overrideLightModeTags ? _lightModeTags : null, false, diff --git a/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs b/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs index f31a0124..433553cd 100644 --- a/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs +++ b/Packages/com.deltation.toon-rp/Runtime/ToonCameraRenderer.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using DELTation.ToonRP.Extensions; using DELTation.ToonRP.Lighting; using DELTation.ToonRP.PostProcessing; @@ -10,6 +9,7 @@ using UnityEngine; using UnityEngine.Experimental.Rendering; using UnityEngine.Rendering; +using UnityEngine.Rendering.RendererUtils; using static DELTation.ToonRP.ToonCameraRendererSettings; namespace DELTation.ToonRP @@ -782,11 +782,11 @@ private void DrawVisibleGeometry(CommandBuffer cmd) using (new ProfilingScope(cmd, NamedProfilingSampler.Get(ToonRpPassId.OpaqueGeometry))) { - _context.ExecuteCommandBufferAndClear(cmd); - DrawGeometry(false); + DrawGeometry(cmd, false); } _context.ExecuteCommandBufferAndClear(cmd); + _extensionsCollection.RenderEvent(ToonRenderingEvent.AfterOpaque); } @@ -815,8 +815,7 @@ private void DrawVisibleGeometry(CommandBuffer cmd) using (new ProfilingScope(cmd, NamedProfilingSampler.Get(ToonRpPassId.TransparentGeometry))) { - _context.ExecuteCommandBufferAndClear(cmd); - DrawGeometry(true); + DrawGeometry(cmd, true); } _context.ExecuteCommandBufferAndClear(cmd); @@ -825,25 +824,21 @@ private void DrawVisibleGeometry(CommandBuffer cmd) } } - private void DrawGeometry(bool transparent) + private void DrawGeometry(CommandBuffer cmd, bool transparent) { (SortingCriteria sortingCriteria, RenderQueueRange renderQueueRange, int layerMask) = transparent ? (SortingCriteria.CommonTransparent, RenderQueueRange.transparent, _settings.TransparentLayerMask) : (SortingCriteria.CommonOpaque, RenderQueueRange.opaque, _settings.OpaqueLayerMask); - var sortingSettings = new SortingSettings(_camera) - { - criteria = sortingCriteria, - }; - DrawGeometry(_settings, ref _context, _cullingResults, sortingSettings, renderQueueRange, transparent, - layerMask + DrawGeometry(_settings, ref _context, cmd, _camera, _cullingResults, + sortingCriteria, renderQueueRange, transparent, layerMask ); } - public static void DrawGeometry(in ToonCameraRendererSettings settings, ref ScriptableRenderContext context, - in CullingResults cullingResults, in SortingSettings sortingSettings, RenderQueueRange renderQueueRange, + public static void DrawGeometry(in ToonCameraRendererSettings settings, ref ScriptableRenderContext context, CommandBuffer cmd, Camera camera, + in CullingResults cullingResults, SortingCriteria sortingCriteria, RenderQueueRange renderQueueRange, bool includesTransparent, int layerMask = -1, in RenderStateBlock? renderStateBlock = null, - IReadOnlyList shaderTagIds = null, bool? perObjectLightDataOverride = null, + ShaderTagId[] shaderTagIds = null, bool? perObjectLightDataOverride = null, Material overrideMaterial = null) { PerObjectData perObjectData = PerObjectData.None; @@ -879,31 +874,18 @@ public static void DrawGeometry(in ToonCameraRendererSettings settings, ref Scri } shaderTagIds ??= ShaderTagIds; - var drawingSettings = new DrawingSettings(shaderTagIds[0], sortingSettings) + + var rendererListDesc = new RendererListDesc(shaderTagIds, cullingResults, camera) { - enableDynamicBatching = settings.UseDynamicBatching, - perObjectData = perObjectData, + rendererConfiguration = perObjectData, overrideMaterial = overrideMaterial, + renderQueueRange = renderQueueRange, + sortingCriteria = sortingCriteria, + stateBlock = renderStateBlock, + layerMask = layerMask, }; - - for (int i = 0; i < shaderTagIds.Count; i++) - { - drawingSettings.SetShaderPassName(i, shaderTagIds[i]); - } - - var filteringSettings = new FilteringSettings(renderQueueRange, layerMask); - - if (renderStateBlock == null) - { - context.DrawRenderers(cullingResults, ref drawingSettings, ref filteringSettings); - } - else - { - RenderStateBlock renderStateBlockValue = renderStateBlock.Value; - context.DrawRenderers(cullingResults, ref drawingSettings, ref filteringSettings, - ref renderStateBlockValue - ); - } + RendererList rendererList = context.CreateRendererList(rendererListDesc); + cmd.DrawRendererList(rendererList); } private void DrawSkybox(CommandBuffer cmd) From b8d9baab1666968080eb9f806336d47b74f21c36 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Wed, 17 Apr 2024 19:28:37 +0200 Subject: [PATCH 16/23] Remove deprecated VS Code package --- Packages/manifest.json | 1 - Packages/packages-lock.json | 7 ------- 2 files changed, 8 deletions(-) diff --git a/Packages/manifest.json b/Packages/manifest.json index ad6b7d53..f9ef0c86 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -7,7 +7,6 @@ "com.unity.feature.vr": "1.0.1", "com.unity.ide.rider": "3.0.28", "com.unity.ide.visualstudio": "2.0.22", - "com.unity.ide.vscode": "1.2.5", "com.unity.mobile.android-logcat": "1.4.0", "com.unity.render-pipelines.core": "17.0.2", "com.unity.render-pipelines.universal": "17.0.2", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index a8886b63..51c6515b 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -113,13 +113,6 @@ }, "url": "https://packages.unity.com" }, - "com.unity.ide.vscode": { - "version": "1.2.5", - "depth": 0, - "source": "registry", - "dependencies": {}, - "url": "https://packages.unity.com" - }, "com.unity.inputsystem": { "version": "1.8.1", "depth": 2, From 6dbfd6285d2957ca2ca898cb3a94e2107c33c78d Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Tue, 23 Apr 2024 23:16:56 +0200 Subject: [PATCH 17/23] BakedBlobShadowImporter.cs: force linear format --- .../Editor/BlobShadowBake/BakedBlobShadowImporter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Packages/com.deltation.toon-rp/Editor/BlobShadowBake/BakedBlobShadowImporter.cs b/Packages/com.deltation.toon-rp/Editor/BlobShadowBake/BakedBlobShadowImporter.cs index 2e2786b1..b4b7afdf 100644 --- a/Packages/com.deltation.toon-rp/Editor/BlobShadowBake/BakedBlobShadowImporter.cs +++ b/Packages/com.deltation.toon-rp/Editor/BlobShadowBake/BakedBlobShadowImporter.cs @@ -63,8 +63,8 @@ public override void OnImportAsset(AssetImportContext ctx) }; var depthRt = RenderTexture.GetTemporary(Width, Height, 32, RenderTextureFormat.Depth); - var tempRt1 = RenderTexture.GetTemporary(Width, Height, 0, RenderTextureFormat.R8); - var tempRt2 = RenderTexture.GetTemporary(Width, Height, 0, RenderTextureFormat.R8); + var tempRt1 = RenderTexture.GetTemporary(Width, Height, 0, RenderTextureFormat.R8, RenderTextureReadWrite.Linear); + var tempRt2 = RenderTexture.GetTemporary(Width, Height, 0, RenderTextureFormat.R8, RenderTextureReadWrite.Linear); Shader blurShader = AssetDatabase.LoadAssetAtPath(BlurShaderPath); var blurMaterial = new Material(blurShader); From d2fbe4526a6f65f988930e7731625f053bb2343f Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Tue, 23 Apr 2024 23:17:14 +0200 Subject: [PATCH 18/23] CustomSceneRenderPipeline.cs: GraphicsSettings.renderPipelineAsset -> GraphicsSettings.defaultRenderPipeline --- Assets/Runtime/CustomSceneRenderPipeline.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Runtime/CustomSceneRenderPipeline.cs b/Assets/Runtime/CustomSceneRenderPipeline.cs index 266005dc..48c26baa 100644 --- a/Assets/Runtime/CustomSceneRenderPipeline.cs +++ b/Assets/Runtime/CustomSceneRenderPipeline.cs @@ -22,7 +22,7 @@ private void SetPipeline() { if (_pipelineAsset != null) { - GraphicsSettings.renderPipelineAsset = _pipelineAsset; + GraphicsSettings.defaultRenderPipeline = _pipelineAsset; } } } From 825de0ef550f7419d119ce8133ce9de633d57dd1 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Tue, 23 Apr 2024 23:18:06 +0200 Subject: [PATCH 19/23] Upgrade to Unity 6000.0.0b16 --- Packages/manifest.json | 6 +++--- Packages/packages-lock.json | 29 +++++++++++++++-------------- ProjectSettings/ProjectVersion.txt | 4 ++-- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Packages/manifest.json b/Packages/manifest.json index f9ef0c86..384a686c 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -7,9 +7,9 @@ "com.unity.feature.vr": "1.0.1", "com.unity.ide.rider": "3.0.28", "com.unity.ide.visualstudio": "2.0.22", - "com.unity.mobile.android-logcat": "1.4.0", - "com.unity.render-pipelines.core": "17.0.2", - "com.unity.render-pipelines.universal": "17.0.2", + "com.unity.mobile.android-logcat": "1.4.1", + "com.unity.render-pipelines.core": "17.0.3", + "com.unity.render-pipelines.universal": "17.0.3", "com.unity.test-framework": "1.4.3", "com.unity.ugui": "2.0.0", "com.unity.xr.mock-hmd": "1.3.1-preview.1", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 51c6515b..eec8d9dd 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -90,7 +90,7 @@ "depth": 0, "source": "builtin", "dependencies": { - "com.unity.xr.interaction.toolkit": "3.0.0-pre.1", + "com.unity.xr.interaction.toolkit": "3.0.1", "com.unity.xr.oculus": "4.2.0", "com.unity.xr.openxr": "1.10.0" } @@ -130,7 +130,7 @@ "url": "https://packages.unity.com" }, "com.unity.mobile.android-logcat": { - "version": "1.4.0", + "version": "1.4.1", "depth": 0, "source": "registry", "dependencies": {}, @@ -151,7 +151,7 @@ "url": "https://packages.unity.com" }, "com.unity.render-pipelines.core": { - "version": "17.0.2", + "version": "17.0.3", "depth": 0, "source": "builtin", "dependencies": { @@ -165,23 +165,23 @@ } }, "com.unity.render-pipelines.universal": { - "version": "17.0.2", + "version": "17.0.3", "depth": 0, "source": "builtin", "dependencies": { "com.unity.mathematics": "1.2.1", "com.unity.burst": "1.8.9", - "com.unity.render-pipelines.core": "17.0.2", - "com.unity.shadergraph": "17.0.2", - "com.unity.render-pipelines.universal-config": "17.0.1" + "com.unity.render-pipelines.core": "17.0.3", + "com.unity.shadergraph": "17.0.3", + "com.unity.render-pipelines.universal-config": "17.0.3" } }, "com.unity.render-pipelines.universal-config": { - "version": "17.0.1", + "version": "17.0.3", "depth": 1, "source": "builtin", "dependencies": { - "com.unity.render-pipelines.core": "17.0.1" + "com.unity.render-pipelines.core": "17.0.3" } }, "com.unity.rendering.light-transport": { @@ -190,7 +190,8 @@ "source": "builtin", "dependencies": { "com.unity.collections": "2.2.0", - "com.unity.mathematics": "1.2.4" + "com.unity.mathematics": "1.2.4", + "com.unity.modules.terrain": "1.0.0" } }, "com.unity.searcher": { @@ -208,11 +209,11 @@ "url": "https://packages.unity.com" }, "com.unity.shadergraph": { - "version": "17.0.2", + "version": "17.0.3", "depth": 1, "source": "builtin", "dependencies": { - "com.unity.render-pipelines.core": "17.0.2", + "com.unity.render-pipelines.core": "17.0.3", "com.unity.searcher": "4.9.2" } }, @@ -266,11 +267,11 @@ "url": "https://packages.unity.com" }, "com.unity.xr.interaction.toolkit": { - "version": "3.0.0-pre.1", + "version": "3.0.1", "depth": 1, "source": "registry", "dependencies": { - "com.unity.inputsystem": "1.7.0", + "com.unity.inputsystem": "1.8.1", "com.unity.mathematics": "1.2.6", "com.unity.ugui": "1.0.0", "com.unity.xr.core-utils": "2.2.3", diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index af45f2f7..ee886bb5 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 6000.0.0b13 -m_EditorVersionWithRevision: 6000.0.0b13 (21aeb48b6ed2) +m_EditorVersion: 6000.0.0b16 +m_EditorVersionWithRevision: 6000.0.0b16 (1ddb887463a9) From 72a130d8f4d62013d31e5d059860850ddc95a3e2 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Wed, 24 Apr 2024 00:04:12 +0200 Subject: [PATCH 20/23] Move directional shadows to renderer lists --- .../Runtime/Shadows/ToonShadowLightsUtils.cs | 143 +++++++++++++++++ .../Shadows/ToonShadowLightsUtils.cs.meta | 3 + .../Runtime/Shadows/ToonShadowMaps.cs | 144 +++++++++++------- 3 files changed, 231 insertions(+), 59 deletions(-) create mode 100644 Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowLightsUtils.cs create mode 100644 Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowLightsUtils.cs.meta diff --git a/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowLightsUtils.cs b/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowLightsUtils.cs new file mode 100644 index 00000000..d98ee8e5 --- /dev/null +++ b/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowLightsUtils.cs @@ -0,0 +1,143 @@ +using Unity.Collections; +using Unity.Mathematics; +using UnityEngine; +using UnityEngine.Assertions; +using UnityEngine.Rendering; + +namespace DELTation.ToonRP.Shadows +{ + public static class ToonShadowLightsUtils + { + public const int MaxSlicesPerLight = 4; + + public static void Init(ref Data data, int maxDirectionalLightShadows, int maxAdditionalLightShadows) + { + int lightsCount = data.CullingResults.visibleLights.Length; + + Assert.IsFalse(data.ShadowCastersCullingInfos.splitBuffer.IsCreated); + Assert.IsFalse(data.ShadowCastersCullingInfos.perLightInfos.IsCreated); + + int maxTotalShadowLights = maxAdditionalLightShadows + maxDirectionalLightShadows; + data.ShadowCastersCullingInfos = new ShadowCastersCullingInfos + { + splitBuffer = new NativeArray(MaxSlicesPerLight * math.min(lightsCount, maxTotalShadowLights), data.Allocator, NativeArrayOptions.UninitializedMemory), + perLightInfos = new NativeArray(lightsCount, Allocator.Persistent, NativeArrayOptions.ClearMemory), + }; + data.CurrentShadowSplitBufferOffset = 0; + + data.DirectionalLights = new NativeList(maxDirectionalLightShadows, data.Allocator); + data.AdditionalLights = new NativeList(maxAdditionalLightShadows, data.Allocator); + } + + public static void AddDirectionLightShadowInfo(ref Data data, int visibleLightIndex, Vector3 ratios, int cascadeCount, int shadowResolution, float nearPlaneOffset) + { + Assert.IsTrue(data.DirectionalLights.IsCreated); + + var lightInfo = new LightInfo + { + VisibleLightIndex = visibleLightIndex, + Slices = new NativeArray(cascadeCount, data.Allocator, NativeArrayOptions.UninitializedMemory), + }; + + var splitRange = new RangeInt(data.CurrentShadowSplitBufferOffset, cascadeCount); + + for (int i = 0; i < cascadeCount; i++) + { + LightSliceInfo lightSliceInfo; + + bool computeSuccess = data.CullingResults.ComputeDirectionalShadowMatricesAndCullingPrimitives( + visibleLightIndex, i, cascadeCount, ratios, shadowResolution, nearPlaneOffset, + out lightSliceInfo.ViewMatrix, out lightSliceInfo.ProjectionMatrix, out ShadowSplitData splitData + ); + Assert.IsTrue(computeSuccess); + + data.ShadowCastersCullingInfos.splitBuffer[data.CurrentShadowSplitBufferOffset] = splitData; + ++data.CurrentShadowSplitBufferOffset; + + lightInfo.Slices[i] = lightSliceInfo; + } + + data.ShadowCastersCullingInfos.perLightInfos[visibleLightIndex] = new LightShadowCasterCullingInfo + { + projectionType = BatchCullingProjectionType.Orthographic, + splitRange = splitRange, + }; + data.DirectionalLights.Add(lightInfo); + } + + public static bool TryAddSpotLightShadowInfo(ref Data data, int visibleLightIndex) + { + Assert.IsTrue(data.AdditionalLights.IsCreated); + + LightSliceInfo lightSliceInfo; + + if (data.CullingResults.ComputeSpotShadowMatricesAndCullingPrimitives(visibleLightIndex, out lightSliceInfo.ViewMatrix, out lightSliceInfo.ProjectionMatrix, out ShadowSplitData splitData)) + { + return false; + } + + const int slices = 1; + var splitRange = new RangeInt(data.CurrentShadowSplitBufferOffset, slices); + + data.ShadowCastersCullingInfos.splitBuffer[data.CurrentShadowSplitBufferOffset] = splitData; + ++data.CurrentShadowSplitBufferOffset; + + data.ShadowCastersCullingInfos.perLightInfos[visibleLightIndex] = new LightShadowCasterCullingInfo + { + projectionType = BatchCullingProjectionType.Perspective, + splitRange = splitRange, + }; + + var lightInfo = new LightInfo + { + VisibleLightIndex = visibleLightIndex, + Slices = new NativeArray(slices, data.Allocator, NativeArrayOptions.UninitializedMemory) + { + [0] = lightSliceInfo, + }, + }; + data.AdditionalLights.Add(lightInfo); + return true; + } + + public static void CullShadowCasters(ref Data data) + { + data.ScriptableRenderContext.CullShadowCasters(data.CullingResults, data.ShadowCastersCullingInfos); + } + + public struct Data + { + public ScriptableRenderContext ScriptableRenderContext; + public CullingResults CullingResults; + public readonly Allocator Allocator; + + public ShadowCastersCullingInfos ShadowCastersCullingInfos; + public int CurrentShadowSplitBufferOffset; + public NativeList DirectionalLights; + public NativeList AdditionalLights; + + public Data(ScriptableRenderContext scriptableRenderContext, CullingResults cullingResults, Allocator allocator) + { + ScriptableRenderContext = scriptableRenderContext; + CullingResults = cullingResults; + Allocator = allocator; + ShadowCastersCullingInfos = default; + CurrentShadowSplitBufferOffset = 0; + DirectionalLights = default; + AdditionalLights = default; + } + } + + public struct LightInfo + { + public int VisibleLightIndex; + public NativeArray Slices; + } + + public struct LightSliceInfo + { + public Matrix4x4 ViewMatrix; + public Matrix4x4 ProjectionMatrix; + } + } +} \ No newline at end of file diff --git a/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowLightsUtils.cs.meta b/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowLightsUtils.cs.meta new file mode 100644 index 00000000..0b179275 --- /dev/null +++ b/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowLightsUtils.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 08cf0b75aecb41cab244ccf1c7ce9708 +timeCreated: 1713907340 \ No newline at end of file diff --git a/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMaps.cs b/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMaps.cs index 11479278..24b2c4a1 100644 --- a/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMaps.cs +++ b/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMaps.cs @@ -1,5 +1,6 @@ using System; using DELTation.ToonRP.Lighting; +using Unity.Collections; using UnityEngine; using UnityEngine.Experimental.Rendering; using UnityEngine.Rendering; @@ -94,6 +95,7 @@ public sealed class ToonShadowMaps : IDisposable private ToonCameraRendererSettings _cameraRendererSettings; private ScriptableRenderContext _context; private CullingResults _cullingResults; + private ToonShadowLightsUtils.Data _data; private ToonShadowSettings _settings; private int _shadowedDirectionalLightCount; private ToonShadowMapsSettings _shadowMapsSettings; @@ -142,13 +144,14 @@ in ToonCameraRendererSettings cameraRendererSettings _cameraRendererSettings = cameraRendererSettings; _shadowMapsSettings = settings.ShadowMaps; _shadowedDirectionalLightCount = 0; + _data = new ToonShadowLightsUtils.Data(context, cullingResults, Allocator.Temp); + ToonShadowLightsUtils.Init(ref _data, MaxShadowedDirectionalLightsCount, MaxShadowedAdditionalLightsCount); } public void ReserveDirectionalShadows(Light light, int visibleLightIndex) { if (_shadowedDirectionalLightCount < MaxShadowedDirectionalLightsCount && - light.shadows != LightShadows.None && light.shadowStrength > 0f && - _cullingResults.GetShadowCasterBounds(visibleLightIndex, out Bounds _) + light.shadows != LightShadows.None && light.shadowStrength > 0f ) { _shadowedDirectionalLights[_shadowedDirectionalLightCount++] = new ShadowedDirectionalLight @@ -156,17 +159,26 @@ public void ReserveDirectionalShadows(Light light, int visibleLightIndex) VisibleLightIndex = visibleLightIndex, NearPlaneOffset = light.shadowNearPlane, }; + + ref DirectionalShadows directionalShadowSettings = ref _shadowMapsSettings.Directional; + Vector3 ratios = directionalShadowSettings.GetRatios(); + int cascadeCount = _shadowMapsSettings.Directional.CascadeCount; + + int atlasSize = (int) _shadowMapsSettings.Directional.AtlasSize; + int tileSize = ComputeDirectionalLightShadowTileSize(atlasSize, out int _); + ToonShadowLightsUtils.AddDirectionLightShadowInfo(ref _data, visibleLightIndex, ratios, cascadeCount, tileSize, light.shadowNearPlane); } } public void Render(in ToonLightsData lightsData) { + ToonShadowLightsUtils.CullShadowCasters(ref _data); + CommandBuffer cmd = CommandBufferPool.Get(); (GraphicsFormat _, int depthBits) = ToonShadowMapFormatUtils.GetSupportedShadowMapFormat(_shadowMapsSettings.GetShadowMapDepthBits()); - // TODO: check if additional lights are enabled using (new ProfilingScope(cmd, NamedProfilingSampler.Get(ToonRpPassId.AdditionalLightsShadows))) { RenderAdditionalShadows(cmd, depthBits, lightsData); @@ -296,9 +308,7 @@ private void RenderDirectionalShadows(CommandBuffer cmd, int depthBits) _context.ExecuteCommandBufferAndClear(cmd); - int tiles = _shadowedDirectionalLightCount * _shadowMapsSettings.Directional.CascadeCount; - int split = tiles <= 1 ? 1 : tiles <= 4 ? 2 : 4; - int tileSize = atlasSize / split; + int tileSize = ComputeDirectionalLightShadowTileSize(atlasSize, out int split); for (int i = 0; i < _shadowedDirectionalLightCount; ++i) { @@ -343,6 +353,14 @@ private void RenderDirectionalShadows(CommandBuffer cmd, int depthBits) _context.ExecuteCommandBufferAndClear(cmd); } + private int ComputeDirectionalLightShadowTileSize(int atlasSize, out int split) + { + int tiles = MaxShadowedDirectionalLightsCount * _shadowMapsSettings.Directional.CascadeCount; + split = tiles <= 1 ? 1 : tiles <= 4 ? 2 : 4; + int tileSize = atlasSize / split; + return tileSize; + } + private static void BindLightParams(CommandBuffer cmd, Light light, float depthBias, float normalBias, float slopeBias) { cmd.SetGlobalDepthBias(0.0f, slopeBias); @@ -413,28 +431,32 @@ private static Color GetShadowmapClearColor() private void RenderDirectionalShadows(CommandBuffer cmd, int index, int split, int tileSize) { ShadowedDirectionalLight shadowedLight = _shadowedDirectionalLights[index]; + + if (!_cullingResults.GetShadowCasterBounds(shadowedLight.VisibleLightIndex, out Bounds _)) + return; + var shadowSettings = new ShadowDrawingSettings(_cullingResults, shadowedLight.VisibleLightIndex); int cascadeCount = _shadowMapsSettings.Directional.CascadeCount; int tileOffset = index * cascadeCount; - ref var directionalShadowSettings = ref _shadowMapsSettings.Directional; - Vector3 ratios = directionalShadowSettings.GetRatios(); + ref readonly DirectionalShadows directionalShadowSettings = ref _shadowMapsSettings.Directional; cmd.BeginSample(RenderShadowsSample); Light light = _cullingResults.visibleLights[shadowedLight.VisibleLightIndex].light; BindLightParams(cmd, light, directionalShadowSettings.DepthBias, directionalShadowSettings.NormalBias, directionalShadowSettings.SlopeBias); + ToonShadowLightsUtils.LightInfo lightInfo = _data.DirectionalLights[shadowedLight.VisibleLightIndex]; + LightShadowCasterCullingInfo lightShadowCasterCullingInfo = _data.ShadowCastersCullingInfos.perLightInfos[shadowedLight.VisibleLightIndex]; + for (int i = 0; i < cascadeCount; i++) { using (new ProfilingScope(cmd, NamedProfilingSampler.Get(CascadeProfilingNames[i]))) { - _cullingResults.ComputeDirectionalShadowMatricesAndCullingPrimitives( - shadowedLight.VisibleLightIndex, i, cascadeCount, ratios, tileSize, shadowedLight.NearPlaneOffset, - out Matrix4x4 viewMatrix, out Matrix4x4 projectionMatrix, out ShadowSplitData splitData - ); - shadowSettings.splitData = splitData; + ToonShadowLightsUtils.LightSliceInfo lightInfoSlice = lightInfo.Slices[i]; + ShadowSplitData shadowSplitData = _data.ShadowCastersCullingInfos.splitBuffer[lightShadowCasterCullingInfo.splitRange.start + i]; + if (index == 0) { - Vector4 cullingSphere = splitData.cullingSphere; + Vector4 cullingSphere = shadowSplitData.cullingSphere; cullingSphere.w *= cullingSphere.w; _cascadeCullingSpheres[i] = cullingSphere; } @@ -442,13 +464,12 @@ private void RenderDirectionalShadows(CommandBuffer cmd, int index, int split, i int tileIndex = tileOffset + i; SetTileViewport(cmd, tileIndex, split, tileSize, out Vector2 offset); _directionalShadowMatricesVp[tileIndex] = - ConvertToAtlasMatrix(projectionMatrix * viewMatrix, offset, split, _settings.ShadowMaps.Blur == BlurMode.None); - _directionalShadowMatricesV[tileIndex] = viewMatrix; - cmd.SetViewProjectionMatrices(viewMatrix, projectionMatrix); - - _context.ExecuteCommandBufferAndClear(cmd); + ConvertToAtlasMatrix(lightInfoSlice.ProjectionMatrix * lightInfoSlice.ViewMatrix, offset, split, _settings.ShadowMaps.Blur == BlurMode.None); + _directionalShadowMatricesV[tileIndex] = lightInfoSlice.ViewMatrix; + cmd.SetViewProjectionMatrices(lightInfoSlice.ViewMatrix, lightInfoSlice.ProjectionMatrix); - _context.DrawShadows(ref shadowSettings); + RendererList rendererList = _context.CreateShadowRendererList(ref shadowSettings); + cmd.DrawRendererList(rendererList); } } @@ -463,45 +484,7 @@ private void RenderAdditionalShadows(CommandBuffer cmd, int depthBits, in ToonLi { int shadowLightsCount = 0; - if (_settings.ShadowMaps.Additional.Enabled && _cameraRendererSettings.AdditionalLights == ToonCameraRendererSettings.AdditionalLightsMode.PerPixel) - { - // Mark shadowed lights - for (int additionalLightIndex = 0; additionalLightIndex < lightsData.AdditionalLights.Count; additionalLightIndex++) - { - ToonLightsData.AdditionalLight additionalLight = lightsData.AdditionalLights[additionalLightIndex]; - VisibleLight visibleLight = _cullingResults.visibleLights[additionalLight.VisibleLightIndex]; - if (visibleLight.light.shadows == LightShadows.None) - { - continue; - } - - if (additionalLightIndex >= _additionalShadowMetadata.Length) - { - continue; - } - - if (!_cullingResults.GetShadowCasterBounds(additionalLight.VisibleLightIndex, out Bounds _)) - { - continue; - } - - // TODO: add point light later - if (visibleLight.lightType is LightType.Spot) - { - additionalLight.ShadowLightIndex = shadowLightsCount; - lightsData.AdditionalLights[additionalLightIndex] = additionalLight; - - ++shadowLightsCount; - } - } - - var defaultMetadata = new Vector4(-1, 0, 0, 0); - - for (int i = 0; i < _additionalShadowMetadata.Length; i++) - { - _additionalShadowMetadata[i] = defaultMetadata; - } - } + shadowLightsCount = CollectAdditionalLightShadows(lightsData, shadowLightsCount); if (shadowLightsCount > 0) { @@ -550,6 +533,49 @@ private void RenderAdditionalShadows(CommandBuffer cmd, int depthBits, in ToonLi cmd.DisableKeyword(ToonShadows.AdditionalShadowsGlobalKeyword); } } + private int CollectAdditionalLightShadows(ToonLightsData lightsData, int shadowLightsCount) + { + if (_settings.ShadowMaps.Additional.Enabled && _cameraRendererSettings.AdditionalLights == ToonCameraRendererSettings.AdditionalLightsMode.PerPixel) + { + // Mark shadowed lights + for (int additionalLightIndex = 0; additionalLightIndex < lightsData.AdditionalLights.Count; additionalLightIndex++) + { + ToonLightsData.AdditionalLight additionalLight = lightsData.AdditionalLights[additionalLightIndex]; + VisibleLight visibleLight = _cullingResults.visibleLights[additionalLight.VisibleLightIndex]; + if (visibleLight.light.shadows == LightShadows.None) + { + continue; + } + + if (additionalLightIndex >= _additionalShadowMetadata.Length) + { + continue; + } + + if (!_cullingResults.GetShadowCasterBounds(additionalLight.VisibleLightIndex, out Bounds _)) + { + continue; + } + + // TODO: add point light later + if (visibleLight.lightType is LightType.Spot) + { + additionalLight.ShadowLightIndex = shadowLightsCount; + lightsData.AdditionalLights[additionalLightIndex] = additionalLight; + + ++shadowLightsCount; + } + } + + var defaultMetadata = new Vector4(-1, 0, 0, 0); + + for (int i = 0; i < _additionalShadowMetadata.Length; i++) + { + _additionalShadowMetadata[i] = defaultMetadata; + } + } + return shadowLightsCount; + } private void ExecuteBlur(CommandBuffer cmd) { From 5728e33603744fb24d66a4d01c2375a9cbd4bdc5 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Wed, 24 Apr 2024 00:24:23 +0200 Subject: [PATCH 21/23] Move additional shadows to renderer lists --- .../Runtime/Shadows/ToonShadowLightsUtils.cs | 2 +- .../Runtime/Shadows/ToonShadowMaps.cs | 123 ++++++++++-------- 2 files changed, 69 insertions(+), 56 deletions(-) diff --git a/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowLightsUtils.cs b/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowLightsUtils.cs index d98ee8e5..566712bb 100644 --- a/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowLightsUtils.cs +++ b/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowLightsUtils.cs @@ -71,7 +71,7 @@ public static bool TryAddSpotLightShadowInfo(ref Data data, int visibleLightInde LightSliceInfo lightSliceInfo; - if (data.CullingResults.ComputeSpotShadowMatricesAndCullingPrimitives(visibleLightIndex, out lightSliceInfo.ViewMatrix, out lightSliceInfo.ProjectionMatrix, out ShadowSplitData splitData)) + if (!data.CullingResults.ComputeSpotShadowMatricesAndCullingPrimitives(visibleLightIndex, out lightSliceInfo.ViewMatrix, out lightSliceInfo.ProjectionMatrix, out ShadowSplitData splitData)) { return false; } diff --git a/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMaps.cs b/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMaps.cs index 24b2c4a1..acaa9af4 100644 --- a/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMaps.cs +++ b/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMaps.cs @@ -157,7 +157,6 @@ public void ReserveDirectionalShadows(Light light, int visibleLightIndex) _shadowedDirectionalLights[_shadowedDirectionalLightCount++] = new ShadowedDirectionalLight { VisibleLightIndex = visibleLightIndex, - NearPlaneOffset = light.shadowNearPlane, }; ref DirectionalShadows directionalShadowSettings = ref _shadowMapsSettings.Directional; @@ -172,6 +171,8 @@ public void ReserveDirectionalShadows(Light light, int visibleLightIndex) public void Render(in ToonLightsData lightsData) { + CollectAdditionalLightShadows(lightsData); + ToonShadowLightsUtils.CullShadowCasters(ref _data); CommandBuffer cmd = CommandBufferPool.Get(); @@ -356,6 +357,8 @@ private void RenderDirectionalShadows(CommandBuffer cmd, int depthBits) private int ComputeDirectionalLightShadowTileSize(int atlasSize, out int split) { int tiles = MaxShadowedDirectionalLightsCount * _shadowMapsSettings.Directional.CascadeCount; + + // ReSharper disable once ConditionIsAlwaysTrueOrFalse split = tiles <= 1 ? 1 : tiles <= 4 ? 2 : 4; int tileSize = atlasSize / split; return tileSize; @@ -433,7 +436,9 @@ private void RenderDirectionalShadows(CommandBuffer cmd, int index, int split, i ShadowedDirectionalLight shadowedLight = _shadowedDirectionalLights[index]; if (!_cullingResults.GetShadowCasterBounds(shadowedLight.VisibleLightIndex, out Bounds _)) + { return; + } var shadowSettings = new ShadowDrawingSettings(_cullingResults, shadowedLight.VisibleLightIndex); int cascadeCount = _shadowMapsSettings.Directional.CascadeCount; @@ -480,12 +485,57 @@ private void RenderDirectionalShadows(CommandBuffer cmd, int index, int split, i ExecuteBlur(cmd); } - private void RenderAdditionalShadows(CommandBuffer cmd, int depthBits, in ToonLightsData lightsData) + private void CollectAdditionalLightShadows(ToonLightsData lightsData) { - int shadowLightsCount = 0; + if (_settings.ShadowMaps.Additional.Enabled && _cameraRendererSettings.AdditionalLights == ToonCameraRendererSettings.AdditionalLightsMode.PerPixel) + { + int shadowLightsCount = 0; - shadowLightsCount = CollectAdditionalLightShadows(lightsData, shadowLightsCount); + // Mark shadowed lights + for (int additionalLightIndex = 0; additionalLightIndex < lightsData.AdditionalLights.Count; additionalLightIndex++) + { + ToonLightsData.AdditionalLight additionalLight = lightsData.AdditionalLights[additionalLightIndex]; + VisibleLight visibleLight = _cullingResults.visibleLights[additionalLight.VisibleLightIndex]; + if (visibleLight.light.shadows == LightShadows.None) + { + continue; + } + if (!_cullingResults.GetShadowCasterBounds(additionalLight.VisibleLightIndex, out Bounds _)) + { + continue; + } + + if (additionalLightIndex >= _additionalShadowMetadata.Length) + { + continue; + } + + // TODO: add point light later + if (visibleLight.lightType is LightType.Spot) + { + if (ToonShadowLightsUtils.TryAddSpotLightShadowInfo(ref _data, additionalLight.VisibleLightIndex)) + { + additionalLight.ShadowLightIndex = shadowLightsCount; + lightsData.AdditionalLights[additionalLightIndex] = additionalLight; + + ++shadowLightsCount; + } + } + } + + var defaultMetadata = new Vector4(-1, 0, 0, 0); + + for (int i = 0; i < _additionalShadowMetadata.Length; i++) + { + _additionalShadowMetadata[i] = defaultMetadata; + } + } + } + + private void RenderAdditionalShadows(CommandBuffer cmd, int depthBits, in ToonLightsData lightsData) + { + int shadowLightsCount = _data.AdditionalLights.Length; if (shadowLightsCount > 0) { int resolution = (int) _settings.ShadowMaps.Additional.AtlasSize; @@ -506,21 +556,28 @@ private void RenderAdditionalShadows(CommandBuffer cmd, int depthBits, in ToonLi } int visibleLightIndex = additionalLight.VisibleLightIndex; + if (!_cullingResults.GetShadowCasterBounds(visibleLightIndex, out Bounds _)) + { + continue; + } + Light light = _cullingResults.visibleLights[visibleLightIndex].light; - if (_cullingResults.ComputeSpotShadowMatricesAndCullingPrimitives(visibleLightIndex, out Matrix4x4 viewMatrix, out Matrix4x4 projectionMatrix, out ShadowSplitData _)) + int shadowLightIndex = additionalLight.ShadowLightIndex.Value; + + ToonShadowLightsUtils.LightInfo lightInfo = _data.AdditionalLights[shadowLightIndex]; + foreach (ToonShadowLightsUtils.LightSliceInfo lightSliceInfo in lightInfo.Slices) { - int shadowLightIndex = additionalLight.ShadowLightIndex.Value; SetTileViewport(cmd, shadowLightIndex, split, tileSize, out Vector2 offset); - _additionalShadowMatricesVp[shadowLightIndex] = ConvertToAtlasMatrix(projectionMatrix * viewMatrix, offset, split); + _additionalShadowMatricesVp[shadowLightIndex] = ConvertToAtlasMatrix(lightSliceInfo.ProjectionMatrix * lightSliceInfo.ViewMatrix, offset, split); _additionalShadowMetadata[additionalLightIndex] = new Vector4(shadowLightIndex, 0, 0, 0); - cmd.SetViewProjectionMatrices(viewMatrix, projectionMatrix); + cmd.SetViewProjectionMatrices(lightSliceInfo.ViewMatrix, lightSliceInfo.ProjectionMatrix); BindLightParams(cmd, light, light.shadowBias, -light.shadowNormalBias, 0.0f); - _context.ExecuteCommandBufferAndClear(cmd); + var shadowDrawingSettings = new ShadowDrawingSettings(_cullingResults, visibleLightIndex); + RendererList rendererList = _context.CreateShadowRendererList(ref shadowDrawingSettings); - var shadowSettings = new ShadowDrawingSettings(_cullingResults, visibleLightIndex, BatchCullingProjectionType.Perspective); - _context.DrawShadows(ref shadowSettings); + cmd.DrawRendererList(rendererList); } } @@ -533,49 +590,6 @@ private void RenderAdditionalShadows(CommandBuffer cmd, int depthBits, in ToonLi cmd.DisableKeyword(ToonShadows.AdditionalShadowsGlobalKeyword); } } - private int CollectAdditionalLightShadows(ToonLightsData lightsData, int shadowLightsCount) - { - if (_settings.ShadowMaps.Additional.Enabled && _cameraRendererSettings.AdditionalLights == ToonCameraRendererSettings.AdditionalLightsMode.PerPixel) - { - // Mark shadowed lights - for (int additionalLightIndex = 0; additionalLightIndex < lightsData.AdditionalLights.Count; additionalLightIndex++) - { - ToonLightsData.AdditionalLight additionalLight = lightsData.AdditionalLights[additionalLightIndex]; - VisibleLight visibleLight = _cullingResults.visibleLights[additionalLight.VisibleLightIndex]; - if (visibleLight.light.shadows == LightShadows.None) - { - continue; - } - - if (additionalLightIndex >= _additionalShadowMetadata.Length) - { - continue; - } - - if (!_cullingResults.GetShadowCasterBounds(additionalLight.VisibleLightIndex, out Bounds _)) - { - continue; - } - - // TODO: add point light later - if (visibleLight.lightType is LightType.Spot) - { - additionalLight.ShadowLightIndex = shadowLightsCount; - lightsData.AdditionalLights[additionalLightIndex] = additionalLight; - - ++shadowLightsCount; - } - } - - var defaultMetadata = new Vector4(-1, 0, 0, 0); - - for (int i = 0; i < _additionalShadowMetadata.Length; i++) - { - _additionalShadowMetadata[i] = defaultMetadata; - } - } - return shadowLightsCount; - } private void ExecuteBlur(CommandBuffer cmd) { @@ -708,7 +722,6 @@ private static Matrix4x4 ConvertToAtlasMatrix(Matrix4x4 m, Vector2 offset, int s private struct ShadowedDirectionalLight { public int VisibleLightIndex; - public float NearPlaneOffset; } } } \ No newline at end of file From b18fe4dd1a37506b1bb58ab75cb4d151e38c1db2 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Mon, 8 Jul 2024 21:47:51 +0200 Subject: [PATCH 22/23] Don't assert when ComputeDirectionalShadowMatricesAndCullingPrimitives returns false --- .../Runtime/Shadows/ToonShadowLightsUtils.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowLightsUtils.cs b/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowLightsUtils.cs index 566712bb..0595e995 100644 --- a/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowLightsUtils.cs +++ b/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowLightsUtils.cs @@ -45,11 +45,10 @@ public static void AddDirectionLightShadowInfo(ref Data data, int visibleLightIn { LightSliceInfo lightSliceInfo; - bool computeSuccess = data.CullingResults.ComputeDirectionalShadowMatricesAndCullingPrimitives( + data.CullingResults.ComputeDirectionalShadowMatricesAndCullingPrimitives( visibleLightIndex, i, cascadeCount, ratios, shadowResolution, nearPlaneOffset, out lightSliceInfo.ViewMatrix, out lightSliceInfo.ProjectionMatrix, out ShadowSplitData splitData ); - Assert.IsTrue(computeSuccess); data.ShadowCastersCullingInfos.splitBuffer[data.CurrentShadowSplitBufferOffset] = splitData; ++data.CurrentShadowSplitBufferOffset; From 6c95c38b09869cf4fb7858c1d0b645862515cf8e Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Mon, 8 Jul 2024 23:06:50 +0200 Subject: [PATCH 23/23] Implement proper ZClip for shadow maps --- .../Editor/ShaderGUI/PropertyNames.cs | 1 + .../Editor/ShaderGraph/Targets/ToonTarget.cs | 534 +++++++++--------- .../Runtime/Shadows/ToonShadowMaps.cs | 219 +++---- .../Particles/ToonRPParticlesUnlit.shader | 1 + .../Shaders/ToonRPDefault.shader | 1 + .../Shaders/ToonRPDefaultLite.shader | 1 + .../Shaders/ToonRPUnlit.shader | 1 + 7 files changed, 386 insertions(+), 372 deletions(-) diff --git a/Packages/com.deltation.toon-rp/Editor/ShaderGUI/PropertyNames.cs b/Packages/com.deltation.toon-rp/Editor/ShaderGUI/PropertyNames.cs index 7a2ed776..2b79ffd7 100644 --- a/Packages/com.deltation.toon-rp/Editor/ShaderGUI/PropertyNames.cs +++ b/Packages/com.deltation.toon-rp/Editor/ShaderGUI/PropertyNames.cs @@ -45,6 +45,7 @@ public static class PropertyNames // For ShaderGraph shaders only public const string ZTest = "_ZTest"; + public const string ZClip = "_ZClip"; public const string RenderQueue = "_RenderQueue"; public const string QueueOffset = "_QueueOffset"; public const string QueueControl = "_QueueControl"; diff --git a/Packages/com.deltation.toon-rp/Editor/ShaderGraph/Targets/ToonTarget.cs b/Packages/com.deltation.toon-rp/Editor/ShaderGraph/Targets/ToonTarget.cs index 2c58d665..d03801cf 100644 --- a/Packages/com.deltation.toon-rp/Editor/ShaderGraph/Targets/ToonTarget.cs +++ b/Packages/com.deltation.toon-rp/Editor/ShaderGraph/Targets/ToonTarget.cs @@ -22,14 +22,14 @@ internal enum SurfaceType Opaque, Transparent, } - + internal enum ZWriteControl { Auto = 0, ForceEnabled = 1, ForceDisabled = 2, } - + internal enum ZTestMode // the values here match UnityEngine.Rendering.CompareFunction { Disabled = 0, @@ -42,7 +42,7 @@ internal enum ZTestMode // the values here match UnityEngine.Rendering.CompareFu GEqual = 7, Always = 8, } - + internal enum AlphaMode { Alpha, @@ -50,19 +50,19 @@ internal enum AlphaMode Additive, Multiply, } - + internal enum RenderFace { Front = 2, // = CullMode.Back -- render front face only Back = 1, // = CullMode.Front -- render back face only Both = 0, // = CullMode.Off -- render both faces } - + internal sealed class ToonTarget : Target, IHasMetadata { public const string UberTemplatePath = "Packages/com.deltation.toon-rp/Editor/ShaderGraph/Templates/ShaderPass.template"; - + // Constants private static readonly GUID SourceCodeGuid = new("5887ebecda26f434fbc73c8064f0525a"); // ToonTarget.cs public static readonly string[] SharedTemplateDirectories = GenerationUtils @@ -73,13 +73,13 @@ internal sealed class ToonTarget : Target, IHasMetadata ).ToArray(); private readonly List _subTargetNames; private TextField _customGUIField; - + // View private PopupField _subTargetField; - + // SubTarget private List _subTargets; - + public ToonTarget() { displayName = "Toon"; @@ -87,21 +87,21 @@ public ToonTarget() _subTargetNames = _subTargets.Select(x => x.displayName).ToList(); TargetUtils.ProcessSubTargetList(ref _activeSubTarget, ref _subTargets); } - + public override int latestVersion => 1; private int ActiveSubTargetIndex => _subTargets.IndexOf(_activeSubTarget); - + internal override bool ignoreCustomInterpolators => false; internal override int padCustomInterpolatorLimit => 4; internal override bool prefersSpritePreview => _activeSubTarget.value is ToonParticlesUnlitSubTarget; - + public string RenderType => SurfaceType == SurfaceType.Transparent ? $"{UnityEditor.ShaderGraph.RenderType.Transparent}" : $"{UnityEditor.ShaderGraph.RenderType.Opaque}"; - + // this sets up the default renderQueue -- but it can be overridden by ResetMaterialKeywords() public string RenderQueueString => RenderQueue.ToString(); - + public RenderQueue RenderQueue { get @@ -110,113 +110,113 @@ public RenderQueue RenderQueue { return RenderQueue.Transparent; } - + return AlphaClip ? RenderQueue.AlphaTest : RenderQueue.Geometry; } } - + public SubTarget ActiveSubTarget { get => _activeSubTarget.value; set => _activeSubTarget = value; } - + public bool AllowMaterialOverride { get => _allowMaterialOverride; private set => _allowMaterialOverride = value; } - + public SurfaceType SurfaceType { get => _surfaceType; set => _surfaceType = value; } - + public ZWriteControl ZWriteControl { get => _zWriteControl; private set => _zWriteControl = value; } - + public ZTestMode ZTestMode { get => _zTestMode; private set => _zTestMode = value; } - + public AlphaMode AlphaMode { get => _alphaMode; private set => _alphaMode = value; } - + public RenderFace RenderFace { get => _renderFace; private set => _renderFace = value; } - + public bool AlphaClip { get => _alphaClip; set => _alphaClip = value; } - + public bool AlphaToCoverage { get => _alphaToCoverage; private set => _alphaToCoverage = value; } - + public bool ControlStencil { get => _controlStencil; set => _controlStencil = value; } - + public bool ControlStencilEffectivelyEnabled => ControlStencil && ControlStencilCanBeEnabled; - + private bool ControlStencilCanBeEnabled => true; - + public bool CastShadows { get => _castShadows; private set => _castShadows = value; } - + public bool ReceiveShadows { get => _receiveShadows; private set => _receiveShadows = value; } - + public PrePassMode IgnoredPrePasses { get => _ignoredPrePasses; private set => _ignoredPrePasses = value; } - + public bool Fog { get => _fog; private set => _fog = value; } - + public bool CustomFog { get => _customFog; private set => _customFog = value; } - + private string CustomEditorGUI { get => _customEditorGUI; set => _customEditorGUI = value; } - + // generally used to know if we need to build a depth pass public bool MayWriteDepth { @@ -227,7 +227,7 @@ public bool MayWriteDepth // material may or may not choose to write depth... we should create the depth pass return true; } - + return ZWriteControl switch { ZWriteControl.Auto => SurfaceType == SurfaceType.Opaque, @@ -236,55 +236,55 @@ public bool MayWriteDepth }; } } - + public override object saveContext => _activeSubTarget.value?.saveContext; - + public override bool IsActive() { bool isUniversalRenderPipeline = GraphicsSettings.currentRenderPipeline is ToonRenderPipelineAsset; return isUniversalRenderPipeline && ActiveSubTarget.IsActive(); } - + public override bool IsNodeAllowedByTarget(Type nodeType) { SRPFilterAttribute srpFilter = NodeClassCache.GetAttributeOnNodeType(nodeType); bool worksWithThisSrp = srpFilter == null || srpFilter.srpTypes.Contains(typeof(ToonRenderPipeline)); - + SubTargetFilterAttribute subTargetFilter = NodeClassCache.GetAttributeOnNodeType(nodeType); bool worksWithThisSubTarget = subTargetFilter == null || subTargetFilter.subTargetTypes.Contains(ActiveSubTarget.GetType()); - + return worksWithThisSrp && worksWithThisSubTarget && base.IsNodeAllowedByTarget(nodeType); } - + public override void Setup(ref TargetSetupContext context) { // Setup the Target context.AddAssetDependency(SourceCodeGuid, AssetCollection.Flags.SourceDependency); - + // Override EditorGUI (replaces the ToonRP material editor by a custom one) if (!string.IsNullOrEmpty(_customEditorGUI)) { context.AddCustomEditorForRenderPipeline(_customEditorGUI, typeof(ToonRenderPipelineAsset)); } - + // Setup the active SubTarget TargetUtils.ProcessSubTargetList(ref _activeSubTarget, ref _subTargets); _activeSubTarget.value.target = this; _activeSubTarget.value.Setup(ref context); } - + public override void OnAfterMultiDeserialize(string json) { TargetUtils.ProcessSubTargetList(ref _activeSubTarget, ref _subTargets); _activeSubTarget.value.target = this; } - + public override void GetFields(ref TargetFieldContext context) { BlockFieldDescriptor[] descs = context.blocks.Select(x => x.descriptor).ToArray(); - + // Core fields context.AddField(Fields.GraphVertex, descs.Contains(ToonBlockFields.VertexDescription.Position) || descs.Contains(ToonBlockFields.VertexDescription.Normal) || @@ -292,11 +292,11 @@ public override void GetFields(ref TargetFieldContext context) descs.Contains(ToonBlockFields.VertexDescription.DepthBias) ); context.AddField(Fields.GraphPixel); - + // SubTarget fields _activeSubTarget.value.GetFields(ref context); } - + public override void GetActiveBlocks(ref TargetActiveBlockContext context) { // Core blocks @@ -304,28 +304,28 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) context.AddBlock(ToonBlockFields.VertexDescription.Normal); context.AddBlock(ToonBlockFields.VertexDescription.Tangent); context.AddBlock(ToonBlockFields.VertexDescription.DepthBias); - + context.AddBlock(ToonBlockFields.SurfaceDescription.Albedo); context.AddBlock(ToonBlockFields.SurfaceDescription.Emission); - + // SubTarget blocks _activeSubTarget.value.GetActiveBlocks(ref context); } - + public override void ProcessPreviewMaterial(Material material) { _activeSubTarget.value.ProcessPreviewMaterial(material); } - + public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) { base.CollectShaderProperties(collector, generationMode); ActiveSubTarget.CollectShaderProperties(collector, generationMode); - + // SubTarget blocks _activeSubTarget.value.CollectShaderProperties(collector, generationMode); } - + public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) { @@ -337,16 +337,16 @@ public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Acti { return; } - + registerUndo("Change Material"); _activeSubTarget = _subTargets[_subTargetField.index]; onChange(); } ); - + // SubTarget properties _activeSubTarget.value.GetPropertiesGUI(ref context, onChange, registerUndo); - + // Custom Editor GUI // Requires FocusOutEvent _customGUIField = new TextField("") { value = CustomEditorGUI }; @@ -356,7 +356,7 @@ public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Acti { return; } - + registerUndo("Change Custom Editor GUI"); CustomEditorGUI = _customGUIField.value; onChange(); @@ -364,7 +364,7 @@ public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Acti ); context.AddProperty("Custom Editor GUI", _customGUIField, _ => { }); } - + public void AddDefaultMaterialOverrideGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) { @@ -381,7 +381,7 @@ public void AddDefaultMaterialOverrideGUI(ref TargetPropertyGUIContext context, // } // ); } - + public void AddDefaultSurfacePropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo, bool showReceiveShadows) { @@ -391,13 +391,13 @@ public void AddDefaultSurfacePropertiesGUI(ref TargetPropertyGUIContext context, { return; } - + registerUndo("Change Surface"); SurfaceType = (SurfaceType) evt.newValue; onChange(); } ); - + context.AddProperty("Blending Mode", new EnumField(AlphaMode.Alpha) { value = AlphaMode }, SurfaceType == SurfaceType.Transparent, evt => { @@ -405,39 +405,39 @@ public void AddDefaultSurfacePropertiesGUI(ref TargetPropertyGUIContext context, { return; } - + registerUndo("Change Blend"); AlphaMode = (AlphaMode) evt.newValue; onChange(); } ); - + context.AddProperty("Render Face", new EnumField(RenderFace.Front) { value = RenderFace }, evt => { if (Equals(RenderFace, evt.newValue)) { return; } - + registerUndo("Change Render Face"); RenderFace = (RenderFace) evt.newValue; onChange(); } ); - + context.AddProperty("Depth Write", new EnumField(ZWriteControl.Auto) { value = ZWriteControl }, evt => { if (Equals(ZWriteControl, evt.newValue)) { return; } - + registerUndo("Change Depth Write Control"); ZWriteControl = (ZWriteControl) evt.newValue; onChange(); } ); - + context.AddProperty("Depth Test", new EnumField(ZTestModeForUI.LEqual) { value = (ZTestModeForUI) ZTestMode }, evt => { @@ -445,26 +445,26 @@ public void AddDefaultSurfacePropertiesGUI(ref TargetPropertyGUIContext context, { return; } - + registerUndo("Change Depth Test"); ZTestMode = (ZTestMode) evt.newValue; onChange(); } ); - + context.AddProperty("Alpha Clipping", new Toggle { value = AlphaClip }, evt => { if (Equals(AlphaClip, evt.newValue)) { return; } - + registerUndo("Change Alpha Clip"); AlphaClip = evt.newValue; onChange(); } ); - + if (AlphaClip) { context.AddProperty("Alpha To Coverage", new Toggle { value = AlphaToCoverage }, evt => @@ -473,14 +473,14 @@ public void AddDefaultSurfacePropertiesGUI(ref TargetPropertyGUIContext context, { return; } - + registerUndo("Change Alpha To Coverage"); AlphaToCoverage = evt.newValue; onChange(); } ); } - + if (ControlStencilCanBeEnabled) { context.AddProperty("Control Stencil", @@ -491,29 +491,29 @@ public void AddDefaultSurfacePropertiesGUI(ref TargetPropertyGUIContext context, { return; } - + registerUndo("Change Control Stencil"); ControlStencil = evt.newValue; onChange(); } ); } - + AddDefaultFogProperties(ref context, onChange, registerUndo); - + context.AddProperty("Cast Shadows", new Toggle { value = CastShadows }, evt => { if (Equals(CastShadows, evt.newValue)) { return; } - + registerUndo("Change Cast Shadows"); CastShadows = evt.newValue; onChange(); } ); - + if (showReceiveShadows) { context.AddProperty("Receive Shadows", new Toggle { value = ReceiveShadows }, evt => @@ -522,14 +522,14 @@ public void AddDefaultSurfacePropertiesGUI(ref TargetPropertyGUIContext context, { return; } - + registerUndo("Change Receive Shadows"); ReceiveShadows = evt.newValue; onChange(); } ); } - + context.AddProperty("Ignored Pre-Passes", new EnumFlagsField(PrePassMode.Off) { value = IgnoredPrePasses }, evt => { @@ -537,14 +537,14 @@ public void AddDefaultSurfacePropertiesGUI(ref TargetPropertyGUIContext context, { return; } - + registerUndo("Change Ignored Pre-Passes"); IgnoredPrePasses = (PrePassMode) evt.newValue; onChange(); } ); } - + public void AddDefaultFogProperties(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) { @@ -554,34 +554,34 @@ public void AddDefaultFogProperties(ref TargetPropertyGUIContext context, Action { return; } - + registerUndo("Change Fog"); Fog = evt.newValue; onChange(); } ); - + context.AddProperty("Custom Fog", new Toggle { value = CustomFog }, evt => { if (Equals(CustomFog, evt.newValue)) { return; } - + registerUndo("Change Custom Fog"); CustomFog = evt.newValue; onChange(); } ); } - + public bool TrySetActiveSubTarget(Type subTargetType) { if (!subTargetType.IsSubclassOf(typeof(SubTarget))) { return false; } - + foreach (SubTarget subTarget in _subTargets) { if (subTarget.GetType() == subTargetType) @@ -590,25 +590,25 @@ public bool TrySetActiveSubTarget(Type subTargetType) return true; } } - + return false; } - + public override bool WorksWithSRP(RenderPipelineAsset scriptableRenderPipeline) => - + // ReSharper disable once Unity.NoNullPropagation scriptableRenderPipeline?.GetType() == typeof(ToonRenderPipelineAsset); - + public override void OnAfterDeserialize(string json) { base.OnAfterDeserialize(json); - + if (sgVersion < latestVersion) { ChangeVersion(latestVersion); } } - + // this is a copy of ZTestMode, but hides the "Disabled" option, which is invalid [SuppressMessage("ReSharper", "UnusedMember.Local")] private enum ZTestModeForUI @@ -622,10 +622,10 @@ private enum ZTestModeForUI GEqual = 7, Always = 8, } - + // ReSharper disable Unity.RedundantSerializeFieldAttribute [SerializeField] private JsonData _activeSubTarget; - + // when checked, allows the material to control ALL surface settings (uber shader style) [SerializeField] private bool _allowMaterialOverride; [SerializeField] private SurfaceType _surfaceType = SurfaceType.Opaque; @@ -642,11 +642,11 @@ private enum ZTestModeForUI [SerializeField] private bool _fog = true; [SerializeField] private bool _customFog; [SerializeField] private string _customEditorGUI; - + // ReSharper restore Unity.RedundantSerializeFieldAttribute - + #region Metadata - + string IHasMetadata.identifier { get @@ -656,11 +656,11 @@ string IHasMetadata.identifier { return subTargetHasMetaData.identifier; } - + return null; } } - + ScriptableObject IHasMetadata.GetMetadataObject(GraphDataReadOnly graph) { // defer to subtarget @@ -668,19 +668,19 @@ ScriptableObject IHasMetadata.GetMetadataObject(GraphDataReadOnly graph) { return subTargetHasMetaData.GetMetadataObject(graph); } - + return null; } - + #endregion } - + #region Passes - + internal static class CorePasses { public delegate void PassConfigurator(ref PassDescriptor passDescriptor); - + private static void AddAlphaClipControlToPass(ref PassDescriptor pass, ToonTarget target) { if (target.AllowMaterialOverride) @@ -692,7 +692,7 @@ private static void AddAlphaClipControlToPass(ref PassDescriptor pass, ToonTarge pass.defines.Add(CoreKeywordDescriptors.AlphaTestOn, 1); } } - + internal static void AddFogControlToPass(ref PassDescriptor pass, ToonTarget target) { if (target.AllowMaterialOverride) @@ -704,7 +704,7 @@ internal static void AddFogControlToPass(ref PassDescriptor pass, ToonTarget tar pass.defines.Add(CoreKeywordDescriptors.ForceDisableFog, 1); } } - + internal static void AddCustomFogControlToPass(ref PassDescriptor pass, ToonTarget target) { if (target.AllowMaterialOverride) @@ -716,7 +716,7 @@ internal static void AddCustomFogControlToPass(ref PassDescriptor pass, ToonTarg pass.defines.Add(CoreKeywordDescriptors.CustomFog, 1); } } - + private static void AddOutlinesControlToPass(ref PassDescriptor pass, ToonTarget target) { if (target.ControlStencilEffectivelyEnabled || target.AllowMaterialOverride) @@ -724,7 +724,7 @@ private static void AddOutlinesControlToPass(ref PassDescriptor pass, ToonTarget pass.keywords.Add(CoreKeywordDescriptors.StencilOverride); } } - + internal static void AddTargetSurfaceControlsToPass(ref PassDescriptor pass, ToonTarget target) { // the surface settings can either be material controlled or target controlled @@ -741,19 +741,19 @@ internal static void AddTargetSurfaceControlsToPass(ref PassDescriptor pass, Too { pass.defines.Add(CoreKeywordDescriptors.SurfaceTypeTransparent, 1); } - + if (target.AlphaMode == AlphaMode.Premultiply) { pass.defines.Add(CoreKeywordDescriptors.AlphaPremultiplyOn, 1); } } - + AddAlphaClipControlToPass(ref pass, target); AddFogControlToPass(ref pass, target); AddCustomFogControlToPass(ref pass, target); AddOutlinesControlToPass(ref pass, target); } - + public static void AddPrePasses(ToonTarget target, ref SubShaderDescriptor subShaderDescriptor, [CanBeNull] PassConfigurator configurePass = null) { @@ -765,19 +765,19 @@ public static void AddPrePasses(ToonTarget target, ref SubShaderDescriptor subSh { subShaderDescriptor.passes.Add(DepthOnly(target, configurePass)); } - + if (!target.IgnoredPrePasses.Includes(PrePassMode.Depth | PrePassMode.Normals)) { subShaderDescriptor.passes.Add(DepthNormals(target, configurePass)); } - + if (!target.IgnoredPrePasses.Includes(PrePassMode.MotionVectors)) { subShaderDescriptor.passes.Add(MotionVectors(target, configurePass)); } } } - + public static PassDescriptor DepthOnly(ToonTarget target, [CanBeNull] PassConfigurator configurePass = null) { ref readonly ToonPasses.Pass pass = ref ToonPasses.DepthOnly; @@ -788,36 +788,36 @@ public static PassDescriptor DepthOnly(ToonTarget target, [CanBeNull] PassConfig referenceName = pass.ReferenceName, lightMode = pass.LightMode, useInPreview = true, - + // Template passTemplatePath = ToonTarget.UberTemplatePath, sharedTemplateDirectories = ToonTarget.SharedTemplateDirectories, - + // Port Mask validVertexBlocks = CoreBlockMasks.Vertex, validPixelBlocks = CoreBlockMasks.FragmentAlphaOnly, - + // Fields structs = CoreStructCollections.Default, fieldDependencies = CoreFieldDependencies.Default, - + // Conditional State renderStates = CoreRenderStates.DepthOnly(target), pragmas = CorePragmas.Instanced, defines = new DefineCollection(), keywords = new KeywordCollection(), includes = CoreIncludes.DepthOnly, - + // Custom Interpolator Support customInterpolators = CoreCustomInterpDescriptors.Common, }; - + AddAlphaClipControlToPass(ref result, target); configurePass?.Invoke(ref result); - + return result; } - + public static PassDescriptor DepthNormals(ToonTarget target, [CanBeNull] PassConfigurator configurePass = null) { ref readonly ToonPasses.Pass pass = ref ToonPasses.DepthNormals; @@ -828,37 +828,37 @@ public static PassDescriptor DepthNormals(ToonTarget target, [CanBeNull] PassCon referenceName = pass.ReferenceName, lightMode = pass.LightMode, useInPreview = false, - + // Template passTemplatePath = ToonTarget.UberTemplatePath, sharedTemplateDirectories = ToonTarget.SharedTemplateDirectories, - + // Port Mask validVertexBlocks = CoreBlockMasks.Vertex, validPixelBlocks = CoreBlockMasks.FragmentDepthNormals, - + // Fields structs = CoreStructCollections.Default, requiredFields = CoreRequiredFields.DepthNormals, fieldDependencies = CoreFieldDependencies.Default, - + // Conditional State renderStates = CoreRenderStates.DepthNormals(target), pragmas = CorePragmas.Instanced, defines = new DefineCollection(), keywords = new KeywordCollection(), includes = CoreIncludes.DepthNormals, - + // Custom Interpolator Support customInterpolators = CoreCustomInterpDescriptors.Common, }; - + AddAlphaClipControlToPass(ref result, target); configurePass?.Invoke(ref result); - + return result; } - + public static PassDescriptor MotionVectors(ToonTarget target, [CanBeNull] PassConfigurator configurePass = null) { ref readonly ToonPasses.Pass pass = ref ToonPasses.MotionVectors; @@ -869,37 +869,37 @@ public static PassDescriptor MotionVectors(ToonTarget target, [CanBeNull] PassCo referenceName = pass.ReferenceName, lightMode = pass.LightMode, useInPreview = false, - + // Template passTemplatePath = ToonTarget.UberTemplatePath, sharedTemplateDirectories = ToonTarget.SharedTemplateDirectories, - + // Port Mask validVertexBlocks = CoreBlockMasks.Vertex, validPixelBlocks = CoreBlockMasks.MotionVectors, - + // Fields structs = CoreStructCollections.Default, requiredFields = CoreRequiredFields.MotionVectors, fieldDependencies = CoreFieldDependencies.Default, - + // Conditional State renderStates = CoreRenderStates.MotionVectors(target), pragmas = CorePragmas.Instanced, defines = new DefineCollection(), keywords = new KeywordCollection(), includes = CoreIncludes.MotionVectors, - + // Custom Interpolator Support customInterpolators = CoreCustomInterpDescriptors.Common, }; - + AddAlphaClipControlToPass(ref result, target); configurePass?.Invoke(ref result); - + return result; } - + public static void AddShadowCasterPass(ToonTarget target, ref SubShaderDescriptor subShaderDescriptor, [CanBeNull] PassConfigurator configurePass = null) { @@ -909,7 +909,7 @@ public static void AddShadowCasterPass(ToonTarget target, ref SubShaderDescripto subShaderDescriptor.passes.Add(ShadowCaster(target, configurePass)); } } - + private static PassDescriptor ShadowCaster(ToonTarget target, [CanBeNull] PassConfigurator configurePass = null) { ref readonly ToonPasses.Pass pass = ref ToonPasses.ShadowCaster; @@ -919,43 +919,43 @@ private static PassDescriptor ShadowCaster(ToonTarget target, [CanBeNull] PassCo displayName = pass.Name, referenceName = pass.ReferenceName, lightMode = pass.LightMode, - + // Template passTemplatePath = ToonTarget.UberTemplatePath, sharedTemplateDirectories = ToonTarget.SharedTemplateDirectories, - + // Port Mask validVertexBlocks = CoreBlockMasks.Vertex, validPixelBlocks = CoreBlockMasks.FragmentAlphaOnly, - + // Fields structs = CoreStructCollections.Default, requiredFields = CoreRequiredFields.ShadowCaster, fieldDependencies = CoreFieldDependencies.Default, - + // Conditional State renderStates = CoreRenderStates.ShadowCaster(target), pragmas = CorePragmas.Instanced, defines = new DefineCollection(), keywords = DefaultKeywords.ShadowCaster, includes = CoreIncludes.ShadowCaster, - + // Custom Interpolator Support customInterpolators = CoreCustomInterpDescriptors.Common, }; - + AddAlphaClipControlToPass(ref result, target); configurePass?.Invoke(ref result); - + return result; } - + public static void AddMetaPass(ToonTarget target, ref SubShaderDescriptor subShaderDescriptor, [CanBeNull] PassConfigurator configurePass = null) { subShaderDescriptor.passes.Add(Meta(target, configurePass)); } - + private static PassDescriptor Meta(ToonTarget target, [CanBeNull] PassConfigurator configurePass = null) { ref readonly ToonPasses.Pass pass = ref ToonPasses.Meta; @@ -965,42 +965,42 @@ private static PassDescriptor Meta(ToonTarget target, [CanBeNull] PassConfigurat displayName = pass.Name, referenceName = pass.ReferenceName, lightMode = pass.LightMode, - + // Template passTemplatePath = ToonTarget.UberTemplatePath, sharedTemplateDirectories = ToonTarget.SharedTemplateDirectories, - + // Port Mask validVertexBlocks = CoreBlockMasks.Vertex, validPixelBlocks = CoreBlockMasks.FragmentColorAlpha, - + // Fields structs = CoreStructCollections.Default, requiredFields = CoreRequiredFields.Meta, fieldDependencies = CoreFieldDependencies.Default, - + // Conditional State renderStates = CoreRenderStates.Meta(target), pragmas = CorePragmas.Instanced, defines = new DefineCollection(), keywords = DefaultKeywords.Meta, includes = CoreIncludes.Meta, - + // Custom Interpolator Support customInterpolators = CoreCustomInterpDescriptors.Common, }; - + AddAlphaClipControlToPass(ref result, target); configurePass?.Invoke(ref result); - + return result; } } - + #endregion - + #region PortMasks - + internal static class CoreBlockMasks { public static readonly BlockFieldDescriptor[] Vertex = @@ -1016,7 +1016,7 @@ internal static class CoreBlockMasks ToonBlockFields.SurfaceDescription.Alpha, ToonBlockFields.SurfaceDescription.AlphaClipThreshold, }; - + public static readonly BlockFieldDescriptor[] FragmentColor = { ToonBlockFields.SurfaceDescription.PositionWs, @@ -1025,7 +1025,7 @@ internal static class CoreBlockMasks ToonBlockFields.SurfaceDescription.CustomFogFactor, ToonBlockFields.SurfaceDescription.CustomFogColor, }; - + public static readonly BlockFieldDescriptor[] FragmentColorAlpha = { ToonBlockFields.SurfaceDescription.PositionWs, @@ -1036,7 +1036,7 @@ internal static class CoreBlockMasks ToonBlockFields.SurfaceDescription.Alpha, ToonBlockFields.SurfaceDescription.AlphaClipThreshold, }; - + public static readonly BlockFieldDescriptor[] FragmentDepthNormals = { ToonBlockFields.SurfaceDescription.PositionWs, @@ -1046,7 +1046,7 @@ internal static class CoreBlockMasks ToonBlockFields.SurfaceDescription.Alpha, ToonBlockFields.SurfaceDescription.AlphaClipThreshold, }; - + public static readonly BlockFieldDescriptor[] FragmentDepthNormalsNoAlpha = { ToonBlockFields.SurfaceDescription.PositionWs, @@ -1054,7 +1054,7 @@ internal static class CoreBlockMasks ToonBlockFields.SurfaceDescription.NormalTs, ToonBlockFields.SurfaceDescription.NormalWs, }; - + public static readonly BlockFieldDescriptor[] MotionVectors = { ToonBlockFields.SurfaceDescription.PositionWs, @@ -1062,11 +1062,11 @@ internal static class CoreBlockMasks ToonBlockFields.SurfaceDescription.AlphaClipThreshold, }; } - + #endregion - + #region StructCollections - + internal static class CoreStructCollections { public static readonly StructCollection Default = new() @@ -1077,11 +1077,11 @@ internal static class CoreStructCollections Structs.VertexDescriptionInputs, }; } - + #endregion - + #region RequiredFields - + internal static class CoreRequiredFields { public static readonly FieldCollection ShadowCaster = new() @@ -1089,20 +1089,20 @@ internal static class CoreRequiredFields ToonStructFields.Varyings.vsmDepth, StructFields.Varyings.positionWS, }; - + public static readonly FieldCollection DepthNormals = new() { StructFields.Varyings.normalWS, StructFields.Varyings.tangentWS, }; - + public static readonly FieldCollection MotionVectors = new() { ToonStructFields.Attributes.positionOld, ToonStructFields.Varyings.positionCsNoJitter, ToonStructFields.Varyings.previousPositionCsNoJitter, }; - + public static readonly FieldCollection Meta = new() { StructFields.Attributes.uv0, @@ -1113,28 +1113,28 @@ internal static class CoreRequiredFields ToonStructFields.Varyings.lightCoord, }; } - + #endregion - + #region Keywords - + internal static class DefaultKeywords { public static readonly KeywordCollection ShadowCaster = new() { CoreKeywordDescriptors.ToonRpVsmShadowCaster, }; - + public static readonly KeywordCollection Meta = new() { CoreKeywordDescriptors.EditorVisualization, }; } - + #endregion - + #region FieldDependencies - + internal static class CoreFieldDependencies { public static readonly DependencyCollection Default = new() @@ -1148,11 +1148,11 @@ internal static class CoreFieldDependencies ), }; } - + #endregion - + #region RenderStates - + internal static class CoreRenderStates { private static readonly RenderStateCollection MaterialControlledRenderState = new() @@ -1163,7 +1163,7 @@ internal static class CoreRenderStates RenderState.Blend(Uniforms.SrcBlend, Uniforms.DstBlend ), //, Uniforms.alphaSrcBlend, Uniforms.alphaDstBlend) }, }; - + private static Cull RenderFaceToCull(RenderFace renderFace) => renderFace switch { @@ -1172,19 +1172,19 @@ private static Cull RenderFaceToCull(RenderFace renderFace) => RenderFace.Both => Cull.Off, _ => Cull.Back, }; - + public static RenderStateCollection UberSwitchedRenderState(ToonTarget target) { if (target.AllowMaterialOverride) { return MaterialControlledRenderState; } - + var result = new RenderStateCollection { RenderState.ZTest(target.ZTestMode.ToString()), }; - + switch (target.ZWriteControl) { case ZWriteControl.Auto: @@ -1201,9 +1201,9 @@ public static RenderStateCollection UberSwitchedRenderState(ToonTarget target) result.Add(RenderState.ZWrite(ZWrite.Off)); break; } - + result.Add(RenderState.Cull(RenderFaceToCull(target.RenderFace))); - + if (target.SurfaceType == SurfaceType.Opaque) { result.Add(RenderState.Blend(Blend.One, Blend.Zero)); @@ -1234,13 +1234,13 @@ public static RenderStateCollection UberSwitchedRenderState(ToonTarget target) throw new ArgumentOutOfRangeException(); } } - + UberSwitchedAlphaToCoverageRenderState(target, result); StencilControlRenderState(target, result); - + return result; } - + public static void StencilControlRenderState(ToonTarget target, RenderStateCollection renderStateCollection) { if (target.ControlStencilEffectivelyEnabled) @@ -1257,12 +1257,12 @@ public static void StencilControlRenderState(ToonTarget target, RenderStateColle ); } } - + private static RenderStateDescriptor UberSwitchedCullRenderState(ToonTarget target) => target.AllowMaterialOverride ? RenderState.Cull(Uniforms.CullMode) : RenderState.Cull(RenderFaceToCull(target.RenderFace)); - + private static void UberSwitchedAlphaToCoverageRenderState(ToonTarget target, RenderStateCollection renderStateCollection) { @@ -1271,7 +1271,7 @@ private static void UberSwitchedAlphaToCoverageRenderState(ToonTarget target, renderStateCollection.Add(RenderState.AlphaToMask("On")); } } - + public static RenderStateCollection ShadowCaster(ToonTarget target) { var result = new RenderStateCollection @@ -1280,10 +1280,11 @@ public static RenderStateCollection ShadowCaster(ToonTarget target) RenderState.ZWrite(ZWrite.On), UberSwitchedCullRenderState(target), RenderState.ColorMask("ColorMask RG"), + RenderState.ZClip(Uniforms.ZClip), }; return result; } - + public static RenderStateCollection Meta(ToonTarget target) { var result = new RenderStateCollection @@ -1292,7 +1293,7 @@ public static RenderStateCollection Meta(ToonTarget target) }; return result; } - + public static RenderStateCollection DepthOnly(ToonTarget target) { var result = new RenderStateCollection @@ -1302,12 +1303,12 @@ public static RenderStateCollection DepthOnly(ToonTarget target) UberSwitchedCullRenderState(target), RenderState.ColorMask("ColorMask 0"), }; - + StencilControlRenderState(target, result); - + return result; } - + public static RenderStateCollection DepthNormals(ToonTarget target) { var result = new RenderStateCollection @@ -1317,12 +1318,12 @@ public static RenderStateCollection DepthNormals(ToonTarget target) UberSwitchedCullRenderState(target), RenderState.ColorMask("ColorMask RGB"), }; - + StencilControlRenderState(target, result); - + return result; } - + public static RenderStateCollection MotionVectors(ToonTarget target) { var result = new RenderStateCollection @@ -1332,12 +1333,12 @@ public static RenderStateCollection MotionVectors(ToonTarget target) UberSwitchedCullRenderState(target), RenderState.ColorMask("ColorMask RG"), }; - + StencilControlRenderState(target, result); - + return result; } - + private static class Uniforms { public const string SrcBlend = "[" + PropertyNames.BlendSrc + "]"; @@ -1345,7 +1346,8 @@ private static class Uniforms public const string CullMode = "[" + PropertyNames.RenderFace + "]"; public const string ZWrite = "[" + PropertyNames.ZWrite + "]"; public const string ZTest = "[" + PropertyNames.ZTest + "]"; - + public const string ZClip = "[" + PropertyNames.ZClip + "]"; + public const string ForwardStencilRef = "[" + PropertyNames.ForwardStencilRef + "]"; public const string ForwardStencilReadMask = "[" + PropertyNames.ForwardStencilReadMask + "]"; public const string ForwardStencilWriteMask = "[" + PropertyNames.ForwardStencilWriteMask + "]"; @@ -1353,23 +1355,23 @@ private static class Uniforms public const string ForwardStencilPass = "[" + PropertyNames.ForwardStencilPass + "]"; } } - + #endregion - + #region Pragmas - + internal static class CorePragmas { private static readonly PragmaDescriptor VS = Pragma.Vertex("VS"); private static readonly PragmaDescriptor PS = Pragma.Fragment("PS"); - + public static readonly PragmaCollection Default = new() { Pragma.Target(ShaderModel.Target20), VS, PS, }; - + public static readonly PragmaCollection Instanced = new() { Pragma.Target(ShaderModel.Target20), @@ -1377,7 +1379,7 @@ internal static class CorePragmas VS, PS, }; - + public static readonly PragmaCollection Forward = new() { Pragma.Target(ShaderModel.Target35), @@ -1388,17 +1390,17 @@ internal static class CorePragmas PS, }; } - + #endregion - + #region Includes - + internal static class CoreIncludes { private const string CoreColor = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"; private const string CoreTexture = "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"; private const string CoreMetaPass = "Packages/com.unity.render-pipelines.core/ShaderLibrary/MetaPass.hlsl"; - + private const string Common = "Packages/com.deltation.toon-rp/ShaderLibrary/Common.hlsl"; private const string Lighting = "Packages/com.deltation.toon-rp/ShaderLibrary/Lighting.hlsl"; private const string Shadows = "Packages/com.deltation.toon-rp/ShaderLibrary/Shadows.hlsl"; @@ -1418,7 +1420,7 @@ internal static class CoreIncludes "Packages/com.deltation.toon-rp/Editor/ShaderGraph/Includes/ShadowCasterPass.hlsl"; public const string MetaPass = "Packages/com.deltation.toon-rp/Editor/ShaderGraph/Includes/MetaPass.hlsl"; - + public static readonly IncludeCollection CorePregraph = new() { { Common, IncludeLocation.Pregraph }, @@ -1428,79 +1430,79 @@ internal static class CoreIncludes { Shadows, IncludeLocation.Pregraph }, { Textures, IncludeLocation.Pregraph }, }; - + public static readonly IncludeCollection ShaderGraphPregraph = new() { { GraphFunctions, IncludeLocation.Pregraph }, }; - + public static readonly IncludeCollection CorePostgraph = new() { { ShaderPass, IncludeLocation.Pregraph }, { Varyings, IncludeLocation.Postgraph }, }; - + public static readonly IncludeCollection DepthOnly = new() { // Pre-graph CorePregraph, ShaderGraphPregraph, - + // Post-graph CorePostgraph, { DepthOnlyPass, IncludeLocation.Postgraph }, }; - + public static readonly IncludeCollection DepthNormals = new() { // Pre-graph CorePregraph, ShaderGraphPregraph, - + // Post-graph CorePostgraph, { DepthNormalsPass, IncludeLocation.Postgraph }, }; - + public static readonly IncludeCollection MotionVectors = new() { // Pre-graph CorePregraph, ShaderGraphPregraph, - + // Post-graph CorePostgraph, { MotionVectorsPass, IncludeLocation.Postgraph }, }; - + public static readonly IncludeCollection ShadowCaster = new() { // Pre-graph CorePregraph, ShaderGraphPregraph, - + // Post-graph CorePostgraph, { ShadowCasterPass, IncludeLocation.Postgraph }, }; - + public static readonly IncludeCollection Meta = new() { // Pre-graph CorePregraph, { CoreMetaPass, IncludeLocation.Pregraph }, ShaderGraphPregraph, - + // Post-graph CorePostgraph, { MetaPass, IncludeLocation.Postgraph }, }; } - + #endregion - + #region KeywordDescriptors - + internal static class CoreKeywordDescriptors { public static readonly KeywordDescriptor AlphaTestOn = new() @@ -1512,7 +1514,7 @@ internal static class CoreKeywordDescriptors scope = KeywordScope.Local, stages = KeywordShaderStage.Fragment, }; - + public static readonly KeywordDescriptor AlphaPremultiplyOn = new() { displayName = ShaderKeywords.AlphaPremultiplyOn, @@ -1522,7 +1524,7 @@ internal static class CoreKeywordDescriptors scope = KeywordScope.Local, stages = KeywordShaderStage.Fragment, }; - + public static readonly KeywordDescriptor SurfaceTypeTransparent = new() { displayName = ShaderKeywords.SurfaceTypeTransparent, @@ -1532,7 +1534,7 @@ internal static class CoreKeywordDescriptors scope = KeywordScope.Local, stages = KeywordShaderStage.Fragment, }; - + public static readonly KeywordDescriptor ReceiveBlobShadows = new() { displayName = ShaderKeywords.ReceiveBlobShadows, @@ -1542,7 +1544,7 @@ internal static class CoreKeywordDescriptors scope = KeywordScope.Local, stages = KeywordShaderStage.Fragment, }; - + public static readonly KeywordDescriptor OverrideRamp = new() { displayName = ShaderKeywords.OverrideRamp, @@ -1552,7 +1554,7 @@ internal static class CoreKeywordDescriptors scope = KeywordScope.Local, stages = KeywordShaderStage.Fragment, }; - + public static readonly KeywordDescriptor Specular = new() { displayName = ShaderKeywords.Specular, @@ -1562,7 +1564,7 @@ internal static class CoreKeywordDescriptors scope = KeywordScope.Local, stages = KeywordShaderStage.Fragment, }; - + public static readonly KeywordDescriptor AdditionalLightsSpecular = new() { displayName = ShaderKeywords.AdditionalLightsSpecular, @@ -1572,7 +1574,7 @@ internal static class CoreKeywordDescriptors scope = KeywordScope.Local, stages = KeywordShaderStage.Fragment, }; - + public static readonly KeywordDescriptor Rim = new() { displayName = ShaderKeywords.Rim, @@ -1582,7 +1584,7 @@ internal static class CoreKeywordDescriptors scope = KeywordScope.Local, stages = KeywordShaderStage.Fragment, }; - + public static readonly KeywordDescriptor ForceDisableFog = new() { displayName = ShaderKeywords.ForceDisableFog, @@ -1591,7 +1593,7 @@ internal static class CoreKeywordDescriptors definition = KeywordDefinition.ShaderFeature, scope = KeywordScope.Local, }; - + public static readonly KeywordDescriptor CustomFog = new() { displayName = ShaderKeywords.CustomFog, @@ -1601,7 +1603,7 @@ internal static class CoreKeywordDescriptors scope = KeywordScope.Local, stages = KeywordShaderStage.Fragment, }; - + public static readonly KeywordDescriptor ForceDisableEnvironmentLight = new() { displayName = ShaderKeywords.ForceDisableEnvironmentLight, @@ -1611,7 +1613,7 @@ internal static class CoreKeywordDescriptors scope = KeywordScope.Local, stages = KeywordShaderStage.Fragment, }; - + public static readonly KeywordDescriptor StencilOverride = new() { displayName = ShaderKeywords.StencilOverride, @@ -1621,7 +1623,7 @@ internal static class CoreKeywordDescriptors scope = KeywordScope.Local, stages = KeywordShaderStage.Vertex, }; - + public static readonly KeywordDescriptor ToonRpVsmShadowCaster = new() { displayName = "Toon RP VSM", @@ -1630,7 +1632,7 @@ internal static class CoreKeywordDescriptors definition = KeywordDefinition.MultiCompile, scope = KeywordScope.Global, }; - + public static readonly KeywordDescriptor EditorVisualization = new() { displayName = "Editor Visualization", @@ -1639,7 +1641,7 @@ internal static class CoreKeywordDescriptors definition = KeywordDefinition.ShaderFeature, scope = KeywordScope.Global, }; - + public static readonly KeywordDescriptor ToonRpGlobalRamp = new() { displayName = "Toon RP Global Ramp", @@ -1655,7 +1657,7 @@ internal static class CoreKeywordDescriptors new() { displayName = "Texture", referenceName = "TOON_RP_GLOBAL_RAMP_TEXTURE" }, }, }; - + public static readonly KeywordDescriptor ToonRpDirectionalShadows = new() { displayName = "Toon RP Directional Shadows", @@ -1671,7 +1673,7 @@ internal static class CoreKeywordDescriptors new() { displayName = "Blob", referenceName = "TOON_RP_BLOB_SHADOWS" }, }, }; - + public static readonly KeywordDescriptor ToonRpAdditionalShadows = new() { displayName = "Toon RP Additional Shadows", @@ -1680,7 +1682,7 @@ internal static class CoreKeywordDescriptors definition = KeywordDefinition.MultiCompile, scope = KeywordScope.Global, }; - + public static readonly KeywordDescriptor ToonRpShadowSmoothingMode = new() { displayName = "Toon RP Shadow Smoothing Mode", @@ -1696,7 +1698,7 @@ internal static class CoreKeywordDescriptors new() { displayName = "VSM", referenceName = "TOON_RP_VSM" }, }, }; - + public static readonly KeywordDescriptor ToonRpPoissonSamplingMode = new() { displayName = "Toon RP Poisson Sampling Mode", @@ -1712,7 +1714,7 @@ internal static class CoreKeywordDescriptors new() { displayName = "Rotated", referenceName = "TOON_RP_POISSON_SAMPLING_ROTATED" }, }, }; - + public static readonly KeywordDescriptor ToonRpPoissonSamplingEarlyBail = new() { displayName = "Toon RP Poisson Sampling Early Bail", @@ -1722,7 +1724,7 @@ internal static class CoreKeywordDescriptors scope = KeywordScope.Global, stages = KeywordShaderStage.Fragment, }; - + public static readonly KeywordDescriptor ToonRpShadowsRampCrisp = new() { displayName = "Toon RP Shadows Ramp Crisp", @@ -1732,7 +1734,7 @@ internal static class CoreKeywordDescriptors scope = KeywordScope.Global, stages = KeywordShaderStage.Fragment, }; - + public static readonly KeywordDescriptor ToonRpShadowsPattern = new() { displayName = "Toon RP Shadows Pattern", @@ -1742,7 +1744,7 @@ internal static class CoreKeywordDescriptors scope = KeywordScope.Global, stages = KeywordShaderStage.Fragment, }; - + public static readonly KeywordDescriptor ToonRpAdditionalLights = new() { displayName = "Toon RP Additional Lights", @@ -1758,7 +1760,7 @@ internal static class CoreKeywordDescriptors new() { displayName = "Per Vertex", referenceName = "TOON_RP_ADDITIONAL_LIGHTS_VERTEX" }, }, }; - + public static readonly KeywordDescriptor LightmapShadowMixing = new() { displayName = "Lightmap Shadow Mixing", @@ -1767,7 +1769,7 @@ internal static class CoreKeywordDescriptors definition = KeywordDefinition.MultiCompile, scope = KeywordScope.Global, }; - + public static readonly KeywordDescriptor ShadowsShadowmask = new() { displayName = "Shadows Shadowmask", @@ -1776,7 +1778,7 @@ internal static class CoreKeywordDescriptors definition = KeywordDefinition.MultiCompile, scope = KeywordScope.Global, }; - + public static readonly KeywordDescriptor DirLightmapCombined = new() { displayName = "Directional Lightmap Combined", @@ -1785,7 +1787,7 @@ internal static class CoreKeywordDescriptors definition = KeywordDefinition.MultiCompile, scope = KeywordScope.Global, }; - + public static readonly KeywordDescriptor LightmapOn = new() { displayName = "Lightmap On", @@ -1794,7 +1796,7 @@ internal static class CoreKeywordDescriptors definition = KeywordDefinition.MultiCompile, scope = KeywordScope.Global, }; - + public static readonly KeywordDescriptor ToonRpSsao = new() { displayName = "Toon RP SSAO", @@ -1811,11 +1813,11 @@ internal static class CoreKeywordDescriptors }, }; } - + #endregion - + #region CustomInterpolators - + internal static class CoreCustomInterpDescriptors { public static readonly CustomInterpSubGen.Collection Common = new() @@ -1823,7 +1825,7 @@ internal static class CoreCustomInterpDescriptors // Custom interpolators are not explicitly defined in the SurfaceDescriptionInputs template. // This entry point will let us generate a block of pass-through assignments for each field. CustomInterpSubGen.Descriptor.MakeBlock(CustomInterpSubGen.Splice.k_spliceCopyToSDI, "output", "input"), - + // sgci_PassThroughFunc is called from BuildVaryings in Varyings.hlsl to copy custom interpolators from vertex descriptions. // this entry point allows for the function to be defined before it is used. CustomInterpSubGen.Descriptor.MakeFunc(CustomInterpSubGen.Splice.k_splicePreSurface, @@ -1832,6 +1834,6 @@ internal static class CoreCustomInterpDescriptors ), }; } - + #endregion } \ No newline at end of file diff --git a/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMaps.cs b/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMaps.cs index acaa9af4..bc1f7a17 100644 --- a/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMaps.cs +++ b/Packages/com.deltation.toon-rp/Runtime/Shadows/ToonShadowMaps.cs @@ -12,25 +12,25 @@ public sealed class ToonShadowMaps : IDisposable { private const string RenderShadowsSample = "Render Shadows"; private const string BlurSample = "Blur"; - + private const int MaxShadowedDirectionalLightsCount = 1; private const int MaxShadowedAdditionalLightsCount = 16; public const int MaxCascades = 4; - + // Should mirror the value in VSM.hlsl private const float DepthScale = 0.1f; private const FilterMode ShadowmapFiltering = FilterMode.Bilinear; private const RenderTextureFormat DepthRenderTextureFormat = RenderTextureFormat.Shadowmap; - + public const string BlurShaderName = "Hidden/Toon RP/VSM Blur"; public const string BlurHighQualityKeywordName = "_TOON_RP_VSM_BLUR_HIGH_QUALITY"; public const string BlurEarlyBailKeywordName = "_TOON_RP_VSM_BLUR_EARLY_BAIL"; private const int MaxPoissonDiskSize = 16; private static readonly int DirectionalShadowPoissonDiskId = Shader.PropertyToID("_ToonRP_DirectionalShadowPoissonDisk"); - + private static readonly string[] CascadeProfilingNames; - + private static readonly int DirectionalShadowsAtlasId = Shader.PropertyToID("_ToonRP_DirectionalShadowAtlas"); private static readonly int DirectionalShadowsAtlasDepthId = Shader.PropertyToID("_ToonRP_DirectionalShadowAtlas_Depth"); @@ -55,12 +55,14 @@ public sealed class ToonShadowMaps : IDisposable private static readonly int InvPoissonDiskSizeId = Shader.PropertyToID("_ToonRP_InvPoissonDiskSize"); private static readonly int RotatedPoissonSamplingTextureId = Shader.PropertyToID("_ToonRP_RotatedPoissonSamplingTexture"); - + private static readonly int LightDirectionPositionId = Shader.PropertyToID("_ToonRP_LightDirectionPosition"); private static readonly int AdditionalShadowsDepthId = Shader.PropertyToID("_ToonRP_AdditionalShadows"); private static readonly int AdditionalShadowsVpId = Shader.PropertyToID("_ToonRP_AdditionalShadowMatrices_VP"); private static readonly int AdditionalShadowsMetadataId = Shader.PropertyToID("_ToonRP_AdditionalShadows_Metadata"); - + + private static readonly int ZClipId = Shader.PropertyToID("_ZClip"); + private static readonly Vector2[] PoissonDiskRaw = { new(-0.94201624f, -0.39906216f), @@ -80,7 +82,7 @@ public sealed class ToonShadowMaps : IDisposable new(0.19984126f, 0.78641367f), new(0.14383161f, -0.14100790f), }; - + private readonly Matrix4x4[] _additionalShadowMatricesVp = new Matrix4x4[MaxShadowedAdditionalLightsCount]; private readonly Vector4[] _additionalShadowMetadata = new Vector4[MaxShadowedAdditionalLightsCount]; private readonly ToonPipelineMaterial _blurMaterial; @@ -89,7 +91,7 @@ public sealed class ToonShadowMaps : IDisposable private readonly Matrix4x4[] _directionalShadowMatricesV = new Matrix4x4[MaxShadowedDirectionalLightsCount * MaxCascades]; private readonly Matrix4x4[] _directionalShadowMatricesVp = new Matrix4x4[MaxShadowedDirectionalLightsCount * MaxCascades]; private readonly Vector4[] _poissonDiskAdjusted = new Vector4[MaxPoissonDiskSize]; - + private readonly ShadowedDirectionalLight[] _shadowedDirectionalLights = new ShadowedDirectionalLight[MaxShadowedDirectionalLightsCount]; private ToonCameraRendererSettings _cameraRendererSettings; @@ -99,23 +101,23 @@ public sealed class ToonShadowMaps : IDisposable private ToonShadowSettings _settings; private int _shadowedDirectionalLightCount; private ToonShadowMapsSettings _shadowMapsSettings; - + static ToonShadowMaps() { CascadeProfilingNames = new string[MaxCascades]; - + for (int i = 0; i < MaxCascades; i++) { CascadeProfilingNames[i] = $"Cascade {i}"; } } - + public ToonShadowMaps() { _blurShader = Shader.Find(BlurShaderName); _blurMaterial = new ToonPipelineMaterial(_blurShader, "Toon RP VSM Blur"); } - + private string DirectionalShadowPassName { get @@ -126,12 +128,12 @@ private string DirectionalShadowPassName return passName; } } - + public void Dispose() { _blurMaterial.Dispose(); } - + public void Setup(in ScriptableRenderContext context, in CullingResults cullingResults, in ToonShadowSettings settings, @@ -147,7 +149,7 @@ in ToonCameraRendererSettings cameraRendererSettings _data = new ToonShadowLightsUtils.Data(context, cullingResults, Allocator.Temp); ToonShadowLightsUtils.Init(ref _data, MaxShadowedDirectionalLightsCount, MaxShadowedAdditionalLightsCount); } - + public void ReserveDirectionalShadows(Light light, int visibleLightIndex) { if (_shadowedDirectionalLightCount < MaxShadowedDirectionalLightsCount && @@ -158,33 +160,33 @@ public void ReserveDirectionalShadows(Light light, int visibleLightIndex) { VisibleLightIndex = visibleLightIndex, }; - + ref DirectionalShadows directionalShadowSettings = ref _shadowMapsSettings.Directional; Vector3 ratios = directionalShadowSettings.GetRatios(); int cascadeCount = _shadowMapsSettings.Directional.CascadeCount; - + int atlasSize = (int) _shadowMapsSettings.Directional.AtlasSize; int tileSize = ComputeDirectionalLightShadowTileSize(atlasSize, out int _); ToonShadowLightsUtils.AddDirectionLightShadowInfo(ref _data, visibleLightIndex, ratios, cascadeCount, tileSize, light.shadowNearPlane); } } - + public void Render(in ToonLightsData lightsData) { CollectAdditionalLightShadows(lightsData); - + ToonShadowLightsUtils.CullShadowCasters(ref _data); - + CommandBuffer cmd = CommandBufferPool.Get(); - + (GraphicsFormat _, int depthBits) = ToonShadowMapFormatUtils.GetSupportedShadowMapFormat(_shadowMapsSettings.GetShadowMapDepthBits()); - + using (new ProfilingScope(cmd, NamedProfilingSampler.Get(ToonRpPassId.AdditionalLightsShadows))) { RenderAdditionalShadows(cmd, depthBits, lightsData); } - + using (new ProfilingScope(cmd, NamedProfilingSampler.Get(DirectionalShadowPassName))) { if (_shadowMapsSettings.Directional.Enabled && _shadowedDirectionalLightCount > 0) @@ -219,7 +221,7 @@ _shadowMapsSettings is } ); cmd.SetKeyword(ToonShadows.ShadowsRampCrisp, _settings.CrispAntiAliased); - + RenderDirectionalShadows(cmd, depthBits); } else @@ -239,11 +241,11 @@ _shadowMapsSettings is cmd.DisableKeyword(ToonShadows.ShadowsRampCrisp); } } - + _context.ExecuteCommandBufferAndClear(cmd); CommandBufferPool.Release(cmd); } - + public void Cleanup() { CommandBuffer cmd = CommandBufferPool.Get(); @@ -253,11 +255,11 @@ public void Cleanup() _context.ExecuteCommandBufferAndClear(cmd); CommandBufferPool.Release(cmd); } - + private void RenderDirectionalShadows(CommandBuffer cmd, int depthBits) { int atlasSize = (int) _shadowMapsSettings.Directional.AtlasSize; - + using (new ProfilingScope(cmd, NamedProfilingSampler.Get("Prepare Shadowmaps"))) { if (_shadowMapsSettings.Blur != BlurMode.None) @@ -302,23 +304,23 @@ private void RenderDirectionalShadows(CommandBuffer cmd, int depthBits) RenderBufferStoreAction.Store ); } - - + + cmd.ClearRenderTarget(true, true, GetShadowmapClearColor()); } - + _context.ExecuteCommandBufferAndClear(cmd); - + int tileSize = ComputeDirectionalLightShadowTileSize(atlasSize, out int split); - + for (int i = 0; i < _shadowedDirectionalLightCount; ++i) { RenderDirectionalShadows(cmd, i, split, tileSize); } - + cmd.SetGlobalInteger(CascadeCountId, _shadowMapsSettings.Directional.CascadeCount); cmd.SetGlobalVectorArray(CascadeCullingSpheresId, _cascadeCullingSpheres); - + if (_shadowMapsSettings.Blur != BlurMode.None) { BakeViewSpaceZIntoMatrix(); @@ -334,7 +336,7 @@ private void RenderDirectionalShadows(CommandBuffer cmd, int depthBits) cmd.SetGlobalInt(PoissonDiskSizeId, poissonDiskSize); cmd.SetGlobalFloat(FPoissonDiskSizeId, poissonDiskSize); cmd.SetGlobalFloat(InvPoissonDiskSizeId, 1.0f / poissonDiskSize); - + const int spreadReferenceResolution = 1024; float spread = _shadowMapsSettings.SoftShadows.Spread / spreadReferenceResolution; cmd.SetGlobalTexture(RotatedPoissonSamplingTextureId, @@ -343,40 +345,40 @@ private void RenderDirectionalShadows(CommandBuffer cmd, int depthBits) FillPoissonDiskValues(poissonDiskSize, spread); cmd.SetGlobalVectorArray(DirectionalShadowPoissonDiskId, _poissonDiskAdjusted); } - + cmd.SetGlobalMatrixArray(DirectionalShadowsMatricesVpId, _directionalShadowMatricesVp); if (_shadowMapsSettings.Blur != BlurMode.None) { cmd.SetGlobalFloat(LightBleedingReductionId, _shadowMapsSettings.LightBleedingReduction); cmd.SetGlobalFloat(PrecisionCompensationId, _shadowMapsSettings.PrecisionCompensation); } - + _context.ExecuteCommandBufferAndClear(cmd); } - + private int ComputeDirectionalLightShadowTileSize(int atlasSize, out int split) { int tiles = MaxShadowedDirectionalLightsCount * _shadowMapsSettings.Directional.CascadeCount; - + // ReSharper disable once ConditionIsAlwaysTrueOrFalse split = tiles <= 1 ? 1 : tiles <= 4 ? 2 : 4; int tileSize = atlasSize / split; return tileSize; } - + private static void BindLightParams(CommandBuffer cmd, Light light, float depthBias, float normalBias, float slopeBias) { cmd.SetGlobalDepthBias(0.0f, slopeBias); cmd.SetGlobalVector(ShadowBiasId, PackShadowBias(depthBias, normalBias)); cmd.SetGlobalVector(LightDirectionPositionId, PackLightDirectionPosition(light)); } - + private static Vector4 PackShadowBias(float depthBias, float normalBias) => new(-depthBias, normalBias); - + private static Vector4 PackLightDirectionPosition(Light light) { Vector4 result; - + if (light.type == LightType.Directional) { result = -light.transform.forward; @@ -387,30 +389,30 @@ private static Vector4 PackLightDirectionPosition(Light light) result = light.transform.position; result.w = 1.0f; } - + return result; } - + private void BakeViewSpaceZIntoMatrix() { for (int index = 0; index < _directionalShadowMatricesVp.Length; index++) { ref Matrix4x4 matrix = ref _directionalShadowMatricesVp[index]; ref readonly Matrix4x4 viewMatrix = ref _directionalShadowMatricesV[index]; - + float scale = DepthScale; if (SystemInfo.usesReversedZBuffer) { scale *= -1; } - + matrix.m20 = scale * viewMatrix.m20; matrix.m21 = scale * viewMatrix.m21; matrix.m22 = scale * viewMatrix.m22; matrix.m23 = scale * viewMatrix.m23; } } - + private void FillPoissonDiskValues(int diskSize, float spread) { for (int i = 0; i < diskSize; ++i) @@ -418,79 +420,82 @@ private void FillPoissonDiskValues(int diskSize, float spread) _poissonDiskAdjusted[i] = PoissonDiskRaw[i] * spread; } } - + private static Color GetShadowmapClearColor() { var color = new Color(Mathf.NegativeInfinity, Mathf.Infinity, 0.0f, 0.0f); - + if (SystemInfo.usesReversedZBuffer) { color.r *= -1; } - + return color; } - + private void RenderDirectionalShadows(CommandBuffer cmd, int index, int split, int tileSize) { ShadowedDirectionalLight shadowedLight = _shadowedDirectionalLights[index]; - + if (!_cullingResults.GetShadowCasterBounds(shadowedLight.VisibleLightIndex, out Bounds _)) { return; } - + var shadowSettings = new ShadowDrawingSettings(_cullingResults, shadowedLight.VisibleLightIndex); int cascadeCount = _shadowMapsSettings.Directional.CascadeCount; int tileOffset = index * cascadeCount; ref readonly DirectionalShadows directionalShadowSettings = ref _shadowMapsSettings.Directional; - + cmd.BeginSample(RenderShadowsSample); Light light = _cullingResults.visibleLights[shadowedLight.VisibleLightIndex].light; BindLightParams(cmd, light, directionalShadowSettings.DepthBias, directionalShadowSettings.NormalBias, directionalShadowSettings.SlopeBias); - + ToonShadowLightsUtils.LightInfo lightInfo = _data.DirectionalLights[shadowedLight.VisibleLightIndex]; LightShadowCasterCullingInfo lightShadowCasterCullingInfo = _data.ShadowCastersCullingInfos.perLightInfos[shadowedLight.VisibleLightIndex]; - + for (int i = 0; i < cascadeCount; i++) { using (new ProfilingScope(cmd, NamedProfilingSampler.Get(CascadeProfilingNames[i]))) { ToonShadowLightsUtils.LightSliceInfo lightInfoSlice = lightInfo.Slices[i]; ShadowSplitData shadowSplitData = _data.ShadowCastersCullingInfos.splitBuffer[lightShadowCasterCullingInfo.splitRange.start + i]; - + if (index == 0) { Vector4 cullingSphere = shadowSplitData.cullingSphere; cullingSphere.w *= cullingSphere.w; _cascadeCullingSpheres[i] = cullingSphere; } - + int tileIndex = tileOffset + i; SetTileViewport(cmd, tileIndex, split, tileSize, out Vector2 offset); _directionalShadowMatricesVp[tileIndex] = - ConvertToAtlasMatrix(lightInfoSlice.ProjectionMatrix * lightInfoSlice.ViewMatrix, offset, split, _settings.ShadowMaps.Blur == BlurMode.None); + ConvertToAtlasMatrix(lightInfoSlice.ProjectionMatrix * lightInfoSlice.ViewMatrix, offset, split, + _settings.ShadowMaps.Blur == BlurMode.None + ); _directionalShadowMatricesV[tileIndex] = lightInfoSlice.ViewMatrix; cmd.SetViewProjectionMatrices(lightInfoSlice.ViewMatrix, lightInfoSlice.ProjectionMatrix); - + RendererList rendererList = _context.CreateShadowRendererList(ref shadowSettings); + cmd.SetGlobalFloat(ZClipId, 0); cmd.DrawRendererList(rendererList); } } - + cmd.SetGlobalDepthBias(0f, 0.0f); cmd.EndSample(RenderShadowsSample); _context.ExecuteCommandBufferAndClear(cmd); - + ExecuteBlur(cmd); } - + private void CollectAdditionalLightShadows(ToonLightsData lightsData) { if (_settings.ShadowMaps.Additional.Enabled && _cameraRendererSettings.AdditionalLights == ToonCameraRendererSettings.AdditionalLightsMode.PerPixel) { int shadowLightsCount = 0; - + // Mark shadowed lights for (int additionalLightIndex = 0; additionalLightIndex < lightsData.AdditionalLights.Count; additionalLightIndex++) { @@ -500,17 +505,17 @@ private void CollectAdditionalLightShadows(ToonLightsData lightsData) { continue; } - + if (!_cullingResults.GetShadowCasterBounds(additionalLight.VisibleLightIndex, out Bounds _)) { continue; } - + if (additionalLightIndex >= _additionalShadowMetadata.Length) { continue; } - + // TODO: add point light later if (visibleLight.lightType is LightType.Spot) { @@ -518,21 +523,21 @@ private void CollectAdditionalLightShadows(ToonLightsData lightsData) { additionalLight.ShadowLightIndex = shadowLightsCount; lightsData.AdditionalLights[additionalLightIndex] = additionalLight; - + ++shadowLightsCount; } } } - + var defaultMetadata = new Vector4(-1, 0, 0, 0); - + for (int i = 0; i < _additionalShadowMetadata.Length; i++) { _additionalShadowMetadata[i] = defaultMetadata; } } } - + private void RenderAdditionalShadows(CommandBuffer cmd, int depthBits, in ToonLightsData lightsData) { int shadowLightsCount = _data.AdditionalLights.Length; @@ -542,11 +547,11 @@ private void RenderAdditionalShadows(CommandBuffer cmd, int depthBits, in ToonLi int split = Mathf.CeilToInt(Mathf.Sqrt(shadowLightsCount)); int tileSize = resolution / split; resolution = tileSize * split; - + cmd.GetTemporaryRT(AdditionalShadowsDepthId, resolution, resolution, depthBits, ShadowmapFiltering, DepthRenderTextureFormat); cmd.SetRenderTarget(AdditionalShadowsDepthId, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store); cmd.ClearRenderTarget(true, false, Color.clear); - + for (int additionalLightIndex = 0; additionalLightIndex < lightsData.AdditionalLights.Count; additionalLightIndex++) { ToonLightsData.AdditionalLight additionalLight = lightsData.AdditionalLights[additionalLightIndex]; @@ -554,33 +559,35 @@ private void RenderAdditionalShadows(CommandBuffer cmd, int depthBits, in ToonLi { continue; } - + int visibleLightIndex = additionalLight.VisibleLightIndex; if (!_cullingResults.GetShadowCasterBounds(visibleLightIndex, out Bounds _)) { continue; } - + Light light = _cullingResults.visibleLights[visibleLightIndex].light; int shadowLightIndex = additionalLight.ShadowLightIndex.Value; - + ToonShadowLightsUtils.LightInfo lightInfo = _data.AdditionalLights[shadowLightIndex]; foreach (ToonShadowLightsUtils.LightSliceInfo lightSliceInfo in lightInfo.Slices) { SetTileViewport(cmd, shadowLightIndex, split, tileSize, out Vector2 offset); - _additionalShadowMatricesVp[shadowLightIndex] = ConvertToAtlasMatrix(lightSliceInfo.ProjectionMatrix * lightSliceInfo.ViewMatrix, offset, split); + _additionalShadowMatricesVp[shadowLightIndex] = + ConvertToAtlasMatrix(lightSliceInfo.ProjectionMatrix * lightSliceInfo.ViewMatrix, offset, split); _additionalShadowMetadata[additionalLightIndex] = new Vector4(shadowLightIndex, 0, 0, 0); - + cmd.SetViewProjectionMatrices(lightSliceInfo.ViewMatrix, lightSliceInfo.ProjectionMatrix); BindLightParams(cmd, light, light.shadowBias, -light.shadowNormalBias, 0.0f); - + var shadowDrawingSettings = new ShadowDrawingSettings(_cullingResults, visibleLightIndex); RendererList rendererList = _context.CreateShadowRendererList(ref shadowDrawingSettings); - + + cmd.SetGlobalFloat(ZClipId, 1); cmd.DrawRendererList(rendererList); } } - + cmd.SetGlobalMatrixArray(AdditionalShadowsVpId, _additionalShadowMatricesVp); cmd.SetGlobalVectorArray(AdditionalShadowsMetadataId, _additionalShadowMetadata); cmd.EnableKeyword(ToonShadows.AdditionalShadowsGlobalKeyword); @@ -590,23 +597,23 @@ private void RenderAdditionalShadows(CommandBuffer cmd, int depthBits, in ToonLi cmd.DisableKeyword(ToonShadows.AdditionalShadowsGlobalKeyword); } } - + private void ExecuteBlur(CommandBuffer cmd) { // TODO: try using _blurCmd.SetKeyword if (_shadowMapsSettings.Blur != BlurMode.None) { cmd.BeginSample(BlurSample); - + float blurScatter = Mathf.Max(1.0f, _settings.ShadowMaps.BlurScatter); cmd.SetGlobalFloat(BlurScatterId, blurScatter); - + const int gaussianHorizontalPass = 0; const int gaussianVerticalPass = 1; const int boxBlurPass = 2; - + Material blurMaterial = _blurMaterial.GetOrCreate(); - + if (_shadowMapsSettings.Blur == BlurMode.Box) { { @@ -628,7 +635,7 @@ private void ExecuteBlur(CommandBuffer cmd) blurMaterial.SetKeyword(new LocalKeyword(_blurShader, BlurHighQualityKeywordName), highQualityBlur ); - + blurMaterial.SetKeyword(new LocalKeyword(_blurShader, BlurEarlyBailKeywordName), _shadowMapsSettings.IsBlurEarlyBailEnabled ); @@ -638,7 +645,7 @@ private void ExecuteBlur(CommandBuffer cmd) _shadowMapsSettings.BlurEarlyBailThreshold * DepthScale ); } - + // Horizontal { cmd.SetRenderTarget(DirectionalShadowsAtlasTempId, @@ -650,11 +657,11 @@ private void ExecuteBlur(CommandBuffer cmd) ); Color shadowmapClearColor = GetShadowmapClearColor(); cmd.ClearRenderTarget(false, true, shadowmapClearColor); - + // ReSharper disable once RedundantArgumentDefaultValue ToonBlitter.Blit(cmd, blurMaterial, true, gaussianHorizontalPass); } - + // Vertical { cmd.SetRenderTarget(DirectionalShadowsAtlasId, @@ -667,14 +674,14 @@ private void ExecuteBlur(CommandBuffer cmd) ToonBlitter.Blit(cmd, blurMaterial, true, gaussianVerticalPass); } } - - + + cmd.EndSample(BlurSample); } - + _context.ExecuteCommandBufferAndClear(cmd); } - + private static void SetTileViewport(CommandBuffer cmd, int index, int split, int tileSize, out Vector2 offset) { // ReSharper disable once PossibleLossOfFraction @@ -687,38 +694,38 @@ private static void SetTileViewport(CommandBuffer cmd, int index, int split, int ) ); } - + private static Matrix4x4 ConvertToAtlasMatrix(Matrix4x4 m, Vector2 offset, int split, bool correctZ = true) { Matrix4x4 remap = Matrix4x4.identity; remap.m00 = remap.m11 = 0.5f; // scale [-1; 1] -> [-0.5, 0.5] remap.m03 = remap.m13 = 0.5f; // translate [-0.5, 0.5] -> [0, 1] - + if (correctZ) { remap.m22 = 0.5f; // scale [-1; 1] -> [-0.5, 0.5] - + if (SystemInfo.usesReversedZBuffer) { remap.m22 *= -1; } - + remap.m23 = 0.5f; // translate [-0.5, 0.5] -> [0, 1] } - + m = remap * m; - + float scale = 1f / split; remap = Matrix4x4.identity; remap.m00 = remap.m11 = scale; remap.m03 = offset.x * scale; remap.m13 = offset.y * scale; - + m = remap * m; - + return m; } - + private struct ShadowedDirectionalLight { public int VisibleLightIndex; diff --git a/Packages/com.deltation.toon-rp/Shaders/Particles/ToonRPParticlesUnlit.shader b/Packages/com.deltation.toon-rp/Shaders/Particles/ToonRPParticlesUnlit.shader index 4dd1e1e5..666ff869 100644 --- a/Packages/com.deltation.toon-rp/Shaders/Particles/ToonRPParticlesUnlit.shader +++ b/Packages/com.deltation.toon-rp/Shaders/Particles/ToonRPParticlesUnlit.shader @@ -77,6 +77,7 @@ Tags{ "LightMode" = "ShadowCaster" } ColorMask RG + ZClip [_ZClip] HLSLPROGRAM diff --git a/Packages/com.deltation.toon-rp/Shaders/ToonRPDefault.shader b/Packages/com.deltation.toon-rp/Shaders/ToonRPDefault.shader index 7ec48624..4807eea0 100644 --- a/Packages/com.deltation.toon-rp/Shaders/ToonRPDefault.shader +++ b/Packages/com.deltation.toon-rp/Shaders/ToonRPDefault.shader @@ -115,6 +115,7 @@ Tags{ "LightMode" = "ShadowCaster" } ColorMask RG + ZClip [_ZClip] HLSLPROGRAM diff --git a/Packages/com.deltation.toon-rp/Shaders/ToonRPDefaultLite.shader b/Packages/com.deltation.toon-rp/Shaders/ToonRPDefaultLite.shader index b4058f95..583af892 100644 --- a/Packages/com.deltation.toon-rp/Shaders/ToonRPDefaultLite.shader +++ b/Packages/com.deltation.toon-rp/Shaders/ToonRPDefaultLite.shader @@ -109,6 +109,7 @@ Tags{ "LightMode" = "ShadowCaster" } ColorMask RG + ZClip [_ZClip] HLSLPROGRAM diff --git a/Packages/com.deltation.toon-rp/Shaders/ToonRPUnlit.shader b/Packages/com.deltation.toon-rp/Shaders/ToonRPUnlit.shader index 64606fb1..6ae8b4e0 100644 --- a/Packages/com.deltation.toon-rp/Shaders/ToonRPUnlit.shader +++ b/Packages/com.deltation.toon-rp/Shaders/ToonRPUnlit.shader @@ -90,6 +90,7 @@ Tags{ "LightMode" = "ShadowCaster" } ColorMask RG + ZClip [_ZClip] HLSLPROGRAM