From 5d79f0e0ebc9738bb64c685802fe4a8fb882762a Mon Sep 17 00:00:00 2001 From: Ludovic Theobald Date: Tue, 13 Apr 2021 12:29:13 +0200 Subject: [PATCH 1/7] Update changelog # Conflicts: # com.unity.visualeffectgraph/CHANGELOG.md --- com.unity.visualeffectgraph/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.visualeffectgraph/CHANGELOG.md b/com.unity.visualeffectgraph/CHANGELOG.md index 732c57f8d9b..8c89e85c70c 100644 --- a/com.unity.visualeffectgraph/CHANGELOG.md +++ b/com.unity.visualeffectgraph/CHANGELOG.md @@ -65,6 +65,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fix unexpected Spawn context execution ordering - Fix incorrect buffer type for strips - Enabled an optimization for motion vectors, storing projected positions for vertices instead of the transform matrix +- Fix Soft Particle depth computation when using an orthographic camera [Case 1309961](https://issuetracker.unity3d.com/product/unity/issues/guid/1309961/) ## [11.0.0] - 2020-10-21 ### Added From 94cd3e8c400600bd0cd4398d9c4d7983c0da2b5d Mon Sep 17 00:00:00 2001 From: Ludovic Theobald Date: Mon, 1 Feb 2021 15:45:07 +0100 Subject: [PATCH 2/7] Different depth computation for orthographic camera # Conflicts: # com.unity.visualeffectgraph/CHANGELOG.md --- .../Runtime/VFXGraph/Shaders/VFXCommon.hlsl | 7 +++++++ com.unity.visualeffectgraph/CHANGELOG.md | 2 +- .../Shaders/VFXCommonOutput.hlsl | 15 +++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl index 3757269bc20..73b2a25ac71 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl @@ -148,6 +148,13 @@ float VFXLinearEyeDepth(float depth) { return LinearEyeDepth(depth,_ZBufferParams); } +float VFXLinearEyeDepthOrthographic(float depth) +{ +#if UNITY_REVERSED_Z + depth = 1 - depth; +#endif + return _ProjectionParams.y + depth * (_ProjectionParams.z - _ProjectionParams.y); +} void VFXApplyShadowBias(inout float4 posCS, inout float3 posWS, float3 normalWS) { diff --git a/com.unity.visualeffectgraph/CHANGELOG.md b/com.unity.visualeffectgraph/CHANGELOG.md index 8c89e85c70c..3d3cbd8c034 100644 --- a/com.unity.visualeffectgraph/CHANGELOG.md +++ b/com.unity.visualeffectgraph/CHANGELOG.md @@ -65,7 +65,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fix unexpected Spawn context execution ordering - Fix incorrect buffer type for strips - Enabled an optimization for motion vectors, storing projected positions for vertices instead of the transform matrix -- Fix Soft Particle depth computation when using an orthographic camera [Case 1309961](https://issuetracker.unity3d.com/product/unity/issues/guid/1309961/) +- Fix Soft Particle depth computation when using an orthographic camera [Case 1309961](https://issuetracker.unity3d.com/product/unity/issues/guid/1309961) ## [11.0.0] - 2020-10-21 ### Added diff --git a/com.unity.visualeffectgraph/Shaders/VFXCommonOutput.hlsl b/com.unity.visualeffectgraph/Shaders/VFXCommonOutput.hlsl index 33151287782..20264fb4e0b 100644 --- a/com.unity.visualeffectgraph/Shaders/VFXCommonOutput.hlsl +++ b/com.unity.visualeffectgraph/Shaders/VFXCommonOutput.hlsl @@ -100,8 +100,19 @@ float VFXGetSoftParticleFade(VFX_VARYING_PS_INPUTS i) { float fade = 1.0f; #if USE_SOFT_PARTICLE && defined(VFX_VARYING_INVSOFTPARTICLEFADEDISTANCE) - float sceneZ = VFXLinearEyeDepth(VFXSampleDepth(i.VFX_VARYING_POSCS)); - fade = saturate(i.VFX_VARYING_INVSOFTPARTICLEFADEDISTANCE * (sceneZ - i.VFX_VARYING_POSCS.w)); + float sceneZ, selfZ; + if(IsPerspectiveProjection()) + { + sceneZ = VFXLinearEyeDepth(VFXSampleDepth(i.VFX_VARYING_POSCS)); + selfZ = i.VFX_VARYING_POSCS.w; + + } + else + { + sceneZ = VFXLinearEyeDepthOrthographic(VFXSampleDepth(i.VFX_VARYING_POSCS)); + selfZ = VFXLinearEyeDepthOrthographic(i.VFX_VARYING_POSCS.z); + } + fade = saturate(i.VFX_VARYING_INVSOFTPARTICLEFADEDISTANCE * (sceneZ - selfZ)); fade = fade * fade * (3.0 - (2.0 * fade)); // Smoothsteping the fade #endif return fade; From ee3f85b62323359d979f0040b83cd71bf6993d8f Mon Sep 17 00:00:00 2001 From: Paul Demeulenaere Date: Mon, 31 May 2021 17:10:53 +0200 Subject: [PATCH 3/7] Restore change from https://github.cds.internal.unity3d.com/unity/vfx-graphics/pull/211/commits/8169e083d9b68114bd7a248ebba1dfba38fca3f5 But using URP specific helper "LinearDepthToEyeDepth" --- .../Runtime/VFXGraph/Shaders/VFXCommon.hlsl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl b/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl index fe82aa677eb..5ffe0a7b2e3 100644 --- a/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl +++ b/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl @@ -124,6 +124,11 @@ float VFXLinearEyeDepth(float depth) return LinearEyeDepth(depth, _ZBufferParams); } +float VFXLinearEyeDepthOrthographic(float depth) +{ + return LinearDepthToEyeDepth(depth); +} + void VFXApplyShadowBias(inout float4 posCS, inout float3 posWS, float3 normalWS) { posWS = ApplyShadowBias(posWS, normalWS, _LightDirection); From 69aeec3b2057203b1d04dc1d52f7f541db74ec5e Mon Sep 17 00:00:00 2001 From: Paul Demeulenaere Date: Mon, 31 May 2021 17:25:35 +0200 Subject: [PATCH 4/7] FIx issue 1330697 Correctly applying the flip-y when appropriate while sampling --- com.unity.render-pipelines.universal/CHANGELOG.md | 2 ++ .../Runtime/VFXGraph/Shaders/VFXCommon.hlsl | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index 5c371e88600..c26d762a8be 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -132,6 +132,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed renderer creation in playmode to have its property reloaded. [case 1333463] - Fixed gizmos no longer allocate memory in game view. [case 1328852] - Fixed an issue where shadow artefacts appeared between cascades on Terrain Detail objects. +- VFX: Fixed soft particles when HDR or Opaque texture isn't enabled +- VFX: Fixed OpenGL soft particles fallback when depth texture isn't avaiable ### Changed - Change Asset/Create/Shader/Universal Render Pipeline/Lit Shader Graph to Asset/Create/Shader Graph/URP/Lit Shader Graph diff --git a/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl b/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl index 5ffe0a7b2e3..18d2e93e31a 100644 --- a/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl +++ b/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl @@ -116,7 +116,18 @@ float3 GetWorldStereoOffset() float VFXSampleDepth(float4 posSS) { - return LoadSceneDepth(uint2(posSS.xy)); + float2 screenUV = posSS.xy * frac(_ScreenParams.zw); + +#if UNITY_UV_STARTS_AT_TOP + if (_ProjectionParams.x == 1.0f) + screenUV.y = 1.0f - screenUV.y; +#endif + + //In URP, the depth texture is optionnal and could be 4x4 white texture, Load isn't approriate in that case. + //float depth = LoadSceneDepth(screenUV * _ScreenParams.xy); + float depth = SampleSceneDepth(screenUV); + + return depth; } float VFXLinearEyeDepth(float depth) From e73718cda2f9976acdd2f664c5a11e8d9d8c65ec Mon Sep 17 00:00:00 2001 From: Paul Demeulenaere Date: Mon, 31 May 2021 17:42:43 +0200 Subject: [PATCH 5/7] Fix scaling using dedicated URP helper It's simpler than reimplement the space transform and equivalent --- .../Runtime/VFXGraph/Shaders/VFXCommon.hlsl | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl b/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl index 18d2e93e31a..d18c7236369 100644 --- a/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl +++ b/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl @@ -116,12 +116,7 @@ float3 GetWorldStereoOffset() float VFXSampleDepth(float4 posSS) { - float2 screenUV = posSS.xy * frac(_ScreenParams.zw); - -#if UNITY_UV_STARTS_AT_TOP - if (_ProjectionParams.x == 1.0f) - screenUV.y = 1.0f - screenUV.y; -#endif + float2 screenUV = GetNormalizedScreenSpaceUV(posSS.xy); //In URP, the depth texture is optionnal and could be 4x4 white texture, Load isn't approriate in that case. //float depth = LoadSceneDepth(screenUV * _ScreenParams.xy); From 6d552a7a5993e8296cea815dea63ef6ce0bf00e6 Mon Sep 17 00:00:00 2001 From: Paul Demeulenaere Date: Tue, 1 Jun 2021 10:32:09 +0200 Subject: [PATCH 6/7] Update com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix comment Co-authored-by: Elvar Örn Unnþórsson --- .../Runtime/VFXGraph/Shaders/VFXCommon.hlsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl b/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl index d18c7236369..fe673a6ce59 100644 --- a/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl +++ b/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl @@ -118,7 +118,7 @@ float VFXSampleDepth(float4 posSS) { float2 screenUV = GetNormalizedScreenSpaceUV(posSS.xy); - //In URP, the depth texture is optionnal and could be 4x4 white texture, Load isn't approriate in that case. + // In URP, the depth texture is optional and could be 4x4 white texture, Load isn't appropriate in that case. //float depth = LoadSceneDepth(screenUV * _ScreenParams.xy); float depth = SampleSceneDepth(screenUV); From 91e182aecbfadb0ce7a813a08435759b2d950e45 Mon Sep 17 00:00:00 2001 From: Paul Demeulenaere Date: Thu, 3 Jun 2021 10:35:48 +0200 Subject: [PATCH 7/7] Fix issue https://github.com/Unity-Technologies/Graphics/pull/4733#discussion_r643037035 Remove VFXLinearEyeDepth & VFXLinearEyeDepthOrthographic from the SRP specific implementation Synchronize implementation for VFXLinearEyeDepth in VFXCommonCompute.hlsl (not used anyway) TODO : Move LinearDepthToEyeDepth in core for 21.2 --- .../Runtime/VFXGraph/Shaders/VFXCommon.hlsl | 12 ------------ .../Runtime/VFXGraph/Shaders/VFXCommon.hlsl | 10 ---------- .../Shaders/Common/VFXCommonCompute.hlsl | 7 ++++++- .../Shaders/VFXCommonOutput.hlsl | 15 ++++++++++++++- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl index 73b2a25ac71..efba7d6b5f4 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/VFXGraph/Shaders/VFXCommon.hlsl @@ -144,18 +144,6 @@ float VFXSampleDepth(float4 posSS) return LoadCameraDepth(posSS.xy); } -float VFXLinearEyeDepth(float depth) -{ - return LinearEyeDepth(depth,_ZBufferParams); -} -float VFXLinearEyeDepthOrthographic(float depth) -{ -#if UNITY_REVERSED_Z - depth = 1 - depth; -#endif - return _ProjectionParams.y + depth * (_ProjectionParams.z - _ProjectionParams.y); -} - void VFXApplyShadowBias(inout float4 posCS, inout float3 posWS, float3 normalWS) { } diff --git a/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl b/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl index fe673a6ce59..d41a2ef65c0 100644 --- a/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl +++ b/com.unity.render-pipelines.universal/Runtime/VFXGraph/Shaders/VFXCommon.hlsl @@ -125,16 +125,6 @@ float VFXSampleDepth(float4 posSS) return depth; } -float VFXLinearEyeDepth(float depth) -{ - return LinearEyeDepth(depth, _ZBufferParams); -} - -float VFXLinearEyeDepthOrthographic(float depth) -{ - return LinearDepthToEyeDepth(depth); -} - void VFXApplyShadowBias(inout float4 posCS, inout float3 posWS, float3 normalWS) { posWS = ApplyShadowBias(posWS, normalWS, _LightDirection); diff --git a/com.unity.visualeffectgraph/Shaders/Common/VFXCommonCompute.hlsl b/com.unity.visualeffectgraph/Shaders/Common/VFXCommonCompute.hlsl index ebf560bcd28..e9cd9f3c701 100644 --- a/com.unity.visualeffectgraph/Shaders/Common/VFXCommonCompute.hlsl +++ b/com.unity.visualeffectgraph/Shaders/Common/VFXCommonCompute.hlsl @@ -54,7 +54,12 @@ float3 VFXGetViewWorldPosition() return (float3)0.0f; } -float VFXLinearEyeDepth(float4 posSS) +float VFXLinearEyeDepth(float depth) +{ + return 0.0f; +} + +float VFXLinearEyeDepthOrthographic(float depth) { return 0.0f; } diff --git a/com.unity.visualeffectgraph/Shaders/VFXCommonOutput.hlsl b/com.unity.visualeffectgraph/Shaders/VFXCommonOutput.hlsl index 20264fb4e0b..e57a2989fe6 100644 --- a/com.unity.visualeffectgraph/Shaders/VFXCommonOutput.hlsl +++ b/com.unity.visualeffectgraph/Shaders/VFXCommonOutput.hlsl @@ -96,6 +96,20 @@ float4 VFXGetParticleColor(VFX_VARYING_PS_INPUTS i) return color; } +float VFXLinearEyeDepth(float depth) +{ + return LinearEyeDepth(depth, _ZBufferParams); +} + +float VFXLinearEyeDepthOrthographic(float depth) +{ +#if UNITY_REVERSED_Z + return float(_ProjectionParams.z - (_ProjectionParams.z - _ProjectionParams.y) * depth); +#else + return float(_ProjectionParams.y + (_ProjectionParams.z - _ProjectionParams.y) * depth); +#endif +} + float VFXGetSoftParticleFade(VFX_VARYING_PS_INPUTS i) { float fade = 1.0f; @@ -105,7 +119,6 @@ float VFXGetSoftParticleFade(VFX_VARYING_PS_INPUTS i) { sceneZ = VFXLinearEyeDepth(VFXSampleDepth(i.VFX_VARYING_POSCS)); selfZ = i.VFX_VARYING_POSCS.w; - } else {