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 4d3c2f3a1f2..0311e85b8c0 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 @@ -118,11 +118,6 @@ float VFXSampleDepth(float4 posSS) return LoadCameraDepth(posSS.xy); } -float VFXLinearEyeDepth(float depth) -{ - return LinearEyeDepth(depth,_ZBufferParams); -} - void VFXApplyShadowBias(inout float4 posCS, inout float3 posWS, float3 normalWS) { } diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index 08e781e970c..3c1719931ab 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -111,6 +111,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed terrain hole shadowing [case 1349305] - Fixed soft shadows shader variants not set to multi_compile_fragment on some shaders (gbuffer pass, speedtree shaders, WavingGrass shader). - Fixed artifacts in Speed Tree 8 billboard LODs due to SpeedTree LOD smoothing/crossfading [case 1348407] +- VFX: Fixed soft particles when HDR or Opaque texture isn't enabled +- VFX: Fixed OpenGL soft particles fallback when depth texture isn't available ## [10.2.0] - 2020-10-19 diff --git a/com.unity.visualeffectgraph/CHANGELOG.md b/com.unity.visualeffectgraph/CHANGELOG.md index 675fe8f6256..512beb32500 100644 --- a/com.unity.visualeffectgraph/CHANGELOG.md +++ b/com.unity.visualeffectgraph/CHANGELOG.md @@ -61,6 +61,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Remove unexpected expression in spawn context evaluation [Case 1318412](https://issuetracker.unity3d.com/product/unity/issues/guid/1318412/) - Fix incorrect buffer type for strips - Compilation issue when normal is used in shadergraph for opacity with unlit output +- Fix Soft Particle depth computation when using an orthographic camera [Case 1309961](https://issuetracker.unity3d.com/product/unity/issues/guid/1309961) ## [10.2.0] - 2020-10-19 ### Added 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/RenderPipeline/Universal/VFXCommon.hlsl b/com.unity.visualeffectgraph/Shaders/RenderPipeline/Universal/VFXCommon.hlsl index a26bf89fdc0..06e6f1a2300 100644 --- a/com.unity.visualeffectgraph/Shaders/RenderPipeline/Universal/VFXCommon.hlsl +++ b/com.unity.visualeffectgraph/Shaders/RenderPipeline/Universal/VFXCommon.hlsl @@ -105,12 +105,13 @@ float4x4 VFXGetViewToWorldMatrix() float VFXSampleDepth(float4 posSS) { - return LoadSceneDepth(uint2(posSS.xy)); -} + float2 screenUV = GetNormalizedScreenSpaceUV(posSS.xy); -float VFXLinearEyeDepth(float depth) -{ - return LinearEyeDepth(depth, _ZBufferParams); + // 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); + + return depth; } void VFXApplyShadowBias(inout float4 posCS, inout float3 posWS, float3 normalWS) diff --git a/com.unity.visualeffectgraph/Shaders/VFXCommonOutput.hlsl b/com.unity.visualeffectgraph/Shaders/VFXCommonOutput.hlsl index 33151287782..e57a2989fe6 100644 --- a/com.unity.visualeffectgraph/Shaders/VFXCommonOutput.hlsl +++ b/com.unity.visualeffectgraph/Shaders/VFXCommonOutput.hlsl @@ -96,12 +96,36 @@ 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; #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;