diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index e82b141ec66..571d6e5aa39 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - VFX: Removed irrelevant queues in render queue selection from HDRP outputs +- VFX: Motion Vector are correctly renderered with MSAA [Case 1240754](https://issuetracker.unity3d.com/product/unity/issues/guid/1240754/) ## [7.3.0] - 2020-03-11 diff --git a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/Mesh/PassDepth.template b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/Mesh/PassDepth.template index 42ee4dc8cb4..de17493e2c4 100644 --- a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/Mesh/PassDepth.template +++ b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/Mesh/PassDepth.template @@ -7,6 +7,8 @@ Pass HLSLPROGRAM #define VFX_PASSDEPTH VFX_PASSDEPTH_ACTUAL + #pragma multi_compile _ WRITE_NORMAL_BUFFER + #pragma multi_compile _ WRITE_MSAA_DEPTH ${VFXIncludeRP("Templates/Mesh/PassDepthOrMV.template")} diff --git a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/Mesh/PassDepthOrMV.template b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/Mesh/PassDepthOrMV.template index 7b001e67032..0cac1fe2922 100644 --- a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/Mesh/PassDepthOrMV.template +++ b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/Mesh/PassDepthOrMV.template @@ -1,7 +1,6 @@ #pragma target 4.5 #define UNITY_MATERIAL_LIT -#pragma multi_compile _ WRITE_NORMAL_BUFFER struct ps_input { @@ -75,82 +74,4 @@ ${VFXHDRPLitFillVaryings} ${VFXEnd} ${VFXInclude("Shaders/ParticleMeshes/Pass.template")} -#if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR -${VFXPassVelocityDefine} -#else -${VFXPassDepthDefine} -#endif -${VFXIncludeRP("VFXLit.template")} - -${SHADERGRAPH_PIXEL_CODE_DEPTHONLY} - -#if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION -int _ObjectId; -int _PassValue; -#endif - -#pragma fragment frag -void frag(ps_input i -#if USE_DOUBLE_SIDED - , bool frontFace : SV_IsFrontFace -#endif - -#if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR - , out float4 outMotionVector : SV_Target0 - #ifdef WRITE_NORMAL_BUFFER - , out float4 outNormalBuffer : SV_Target1 - #endif -#else - #ifdef WRITE_NORMAL_BUFFER - , out float4 outNormalBuffer : SV_Target0 - #elif VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION - , out float4 outColor : SV_Target0 - #endif -#endif - ) -{ - UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); - VFXTransformPSInputs(i); - ${VFXComputeNormalWS} - - #ifdef VFX_SHADERGRAPH - ${VFXAdditionalInterpolantsPreparation} - ${SHADERGRAPH_PIXEL_CALL_DEPTHONLY} - - float alpha = OUTSG.${SHADERGRAPH_PARAM_ALPHA}; - #else - float alpha = VFXGetFragmentColor(i).a; - #if HDRP_USE_BASE_COLOR_MAP_ALPHA - alpha *= VFXGetTextureColor(VFX_SAMPLER(baseColorMap),i).a; - #endif - #endif - VFXClipFragmentColor(alpha,i); - - #ifdef WRITE_NORMAL_BUFFER - #ifndef VFX_SHADERGRAPH - VFXComputePixelOutputToNormalBuffer(i,normalWS,uvData,outNormalBuffer); - #else - #if HAS_SHADERGRAPH_PARAM_NORMAL - float3 n = OUTSG.Normal_8; - normalWS = mul(n,tbn); - #endif - SurfaceData surface = (SurfaceData)0; - - surface.normalWS = normalWS; - - EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surface), i.VFX_VARYING_POSCS.xy, outNormalBuffer); - #endif - #endif - - #if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR - ${VFXComputeOutputMotionVector} - outMotionVector = encodedMotionVector; - #elif VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION - // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly - outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); - #elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL - //void - #else - #error VFX_PASSDEPTH undefined - #endif -} +${VFXPassDepthCommonFragmentLit} diff --git a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/Mesh/PassVelocity.template b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/Mesh/PassVelocity.template index cdb019c70c9..de1c08ddc8b 100644 --- a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/Mesh/PassVelocity.template +++ b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/Mesh/PassVelocity.template @@ -9,6 +9,8 @@ Pass HLSLPROGRAM #define VFX_PASSDEPTH VFX_PASSDEPTH_MOTION_VECTOR + #pragma multi_compile _ WRITE_NORMAL_BUFFER + #pragma multi_compile _ WRITE_MSAA_DEPTH ${VFXIncludeRP("Templates/Mesh/PassDepthOrMV.template")} ENDHLSL } diff --git a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassDepth.template b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassDepth.template index 613cf05d3b3..ce8a3f56c54 100644 --- a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassDepth.template +++ b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassDepth.template @@ -7,6 +7,8 @@ Pass HLSLPROGRAM #define VFX_PASSDEPTH VFX_PASSDEPTH_ACTUAL + #pragma multi_compile _ WRITE_NORMAL_BUFFER + #pragma multi_compile _ WRITE_MSAA_DEPTH ${VFXIncludeRP("Templates/PlanarPrimitive/PassDepthOrMV.template")} ENDHLSL diff --git a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassDepthOrMV.template b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassDepthOrMV.template index 052a22bdd23..abb859d54e1 100644 --- a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassDepthOrMV.template +++ b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassDepthOrMV.template @@ -1,6 +1,5 @@ #pragma target 4.5 #define UNITY_MATERIAL_LIT -#pragma multi_compile _ WRITE_NORMAL_BUFFER #define NEEDS_NORMAL defined(WRITE_NORMAL_BUFFER) || FORCE_NORMAL_VARYING || SHADERGRAPH_NEEDS_NORMAL_DEPTHONLY #define NEEDS_TANGENT USE_NORMAL_MAP || USE_NORMAL_BENDING || SHADERGRAPH_NEEDS_TANGENT_DEPTHONLY @@ -81,84 +80,4 @@ ${VFXHDRPLitFillVaryings} ${VFXEnd} ${VFXInclude("Shaders/ParticlePlanarPrimitives/Pass.template")} -#if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR -${VFXPassVelocityDefine} -#else -${VFXPassDepthDefine} -#endif -${VFXIncludeRP("VFXLit.template")} - -${SHADERGRAPH_PIXEL_CODE_DEPTHONLY} - -#if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION -int _ObjectId; -int _PassValue; -#endif - -#pragma fragment frag -void frag(ps_input i -#if USE_DOUBLE_SIDED - , bool frontFace : SV_IsFrontFace -#endif - -#if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR - , out float4 outMotionVector : SV_Target0 - #ifdef WRITE_NORMAL_BUFFER - , out float4 outNormalBuffer : SV_Target1 - #endif -#else - #ifdef WRITE_NORMAL_BUFFER - , out float4 outNormalBuffer : SV_Target0 - #elif VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION - , out float4 outColor : SV_Target0 - #endif -#endif - ) -{ - UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); - VFXTransformPSInputs(i); - ${VFXComputeNormalWS} - - #ifdef VFX_SHADERGRAPH - - ${VFXAdditionalInterpolantsPreparation} - - ${SHADERGRAPH_PIXEL_CALL_DEPTHONLY} - - float alpha = OUTSG.${SHADERGRAPH_PARAM_ALPHA}; - #else - float alpha = VFXGetFragmentColor(i).a; - #if HDRP_USE_BASE_COLOR_MAP_ALPHA - alpha *= VFXGetTextureColor(VFX_SAMPLER(baseColorMap),i).a; - #endif - #endif - VFXClipFragmentColor(alpha,i); - - #ifdef WRITE_NORMAL_BUFFER - #ifndef VFX_SHADERGRAPH - VFXComputePixelOutputToNormalBuffer(i,normalWS,uvData,outNormalBuffer); - #else - #if HAS_SHADERGRAPH_PARAM_NORMAL - float3 n = OUTSG.Normal_8; - normalWS = mul(n,tbn); - #endif - SurfaceData surface = (SurfaceData)0; - - surface.normalWS = normalWS; - - EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surface), i.VFX_VARYING_POSCS.xy, outNormalBuffer); - #endif - #endif - - #if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR - ${VFXComputeOutputMotionVector} - outMotionVector = encodedMotionVector; - #elif VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION - // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly - outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); - #elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL - //void - #else - #error VFX_PASSDEPTH undefined - #endif -} +${VFXPassDepthCommonFragmentLit} diff --git a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassVelocity.template b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassVelocity.template index 576fdaa9457..8f5fd5cc481 100644 --- a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassVelocity.template +++ b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/Templates/PlanarPrimitive/PassVelocity.template @@ -9,6 +9,8 @@ Pass HLSLPROGRAM #define VFX_PASSDEPTH VFX_PASSDEPTH_MOTION_VECTOR + #pragma multi_compile _ WRITE_NORMAL_BUFFER + #pragma multi_compile _ WRITE_MSAA_DEPTH ${VFXIncludeRP("Templates/PlanarPrimitive/PassDepthOrMV.template")} ENDHLSL } diff --git a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/VFXPasses.template b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/VFXPasses.template index e277a05b4d1..06aab10a488 100644 --- a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/VFXPasses.template +++ b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/VFXPasses.template @@ -8,7 +8,9 @@ ${VFXBegin:VFXPassForwardDefine}#define SHADERPASS SHADERPASS_FORWARD_UNLIT${VFX ${VFXBegin:VFXPassShadowDefine}#define SHADERPASS SHADERPASS_SHADOWS${VFXEnd} ${VFXBegin:VFXPassVelocityDefine}#define SHADERPASS SHADERPASS_MOTION_VECTORS${VFXEnd} +${VFXBegin:VFXPassDepthAdditionalPragma}#pragma multi_compile _ WRITE_MSAA_DEPTH${VFXEnd} ${VFXBegin:VFXPassForwardAdditionalPragma}#pragma multi_compile _ DEBUG_DISPLAY${VFXEnd} +${VFXBegin:VFXPassVelocityAdditionalPragma}#pragma multi_compile _ WRITE_MSAA_DEPTH${VFXEnd} ${VFXBegin:VFXShaderGraphFunctionsInclude} #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" @@ -21,3 +23,106 @@ ${VFXBegin:VFXShaderGraphFunctionsInclude} #endif #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl" ${VFXEnd} + +${VFXBegin:VFXPassDepthCommonFragmentLit} +#if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR +${VFXPassVelocityDefine} +#else +${VFXPassDepthDefine} +#endif +${VFXIncludeRP("VFXLit.template")} + +${SHADERGRAPH_PIXEL_CODE_DEPTHONLY} + +#if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION +int _ObjectId; +int _PassValue; +#endif + +#pragma fragment frag +void frag(ps_input i +#if USE_DOUBLE_SIDED + , bool frontFace : SV_IsFrontFace +#endif +#if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 outDepthColor : SV_Target0 + , out float4 outMotionVector : SV_Target1 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target2 + #endif + #else + // When no MSAA, the motion vector is always the first buffer + , out float4 outMotionVector : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #endif +#elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 outDepthColor : SV_Target0 + #ifdef WRITE_NORMAL_BUFFER + , out float4 outNormalBuffer : SV_Target1 + #endif + #elif defined(WRITE_NORMAL_BUFFER) + , out float4 outNormalBuffer : SV_Target0 + #endif +#elif VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION + , out float4 outColor : SV_Target0 +#endif +) +{ + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + VFXTransformPSInputs(i); + ${VFXComputeNormalWS} + + #ifdef VFX_SHADERGRAPH + ${VFXAdditionalInterpolantsPreparation} + ${SHADERGRAPH_PIXEL_CALL_DEPTHONLY} + float alpha = OUTSG.${SHADERGRAPH_PARAM_ALPHA}; + #else + + float alpha = VFXGetFragmentColor(i).a; + + #if HDRP_USE_BASE_COLOR_MAP_ALPHA + alpha *= VFXGetTextureColor(VFX_SAMPLER(baseColorMap),i).a; + #endif + #endif + VFXClipFragmentColor(alpha,i); + + #ifdef WRITE_NORMAL_BUFFER + #ifndef VFX_SHADERGRAPH + VFXComputePixelOutputToNormalBuffer(i,normalWS,uvData,outNormalBuffer); + #else + #if HAS_SHADERGRAPH_PARAM_NORMAL + float3 n = OUTSG.Normal_8; + normalWS = mul(n,tbn); + #endif + SurfaceData surface = (SurfaceData)0; + surface.normalWS = normalWS; + EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surface), i.VFX_VARYING_POSCS.xy, outNormalBuffer); + #endif + #endif + + #ifdef WRITE_MSAA_DEPTH + outDepthColor = i.VFX_VARYING_POSCS.z; + #if VFX_USE_ALPHA_TO_MASK + outDepthColor.a = alpha; + #endif + #endif + + #if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR + ${VFXComputeOutputMotionVector} + outMotionVector = encodedMotionVector; + #elif VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION + // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly + outColor = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL + //void + #else + #error VFX_PASSDEPTH undefined + #endif +} +${VFXEnd} 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 e0319e33497..4457d50d787 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 @@ -15,7 +15,7 @@ float4 VFXTransformPositionWorldToNonJitteredClip(float3 posWS) #if VFX_WORLD_SPACE posWS = GetCameraRelativePositionWS(posWS); #endif - return mul(_NonJitteredViewProjMatrix, float4(posWS, 1.0f)); + return mul(UNITY_MATRIX_UNJITTERED_VP, float4(posWS, 1.0f)); } float4 VFXTransformPositionWorldToPreviousClip(float3 posWS) @@ -23,7 +23,7 @@ float4 VFXTransformPositionWorldToPreviousClip(float3 posWS) #if VFX_WORLD_SPACE posWS = GetCameraRelativePositionWS(posWS); #endif - return mul(_PrevViewProjMatrix, float4(posWS, 1.0f)); + return mul(UNITY_MATRIX_PREV_VP, float4(posWS, 1.0f)); } #ifdef VFX_VARYING_PS_INPUTS diff --git a/com.unity.visualeffectgraph/Shaders/ParticleHexahedron/PassDepth.template b/com.unity.visualeffectgraph/Shaders/ParticleHexahedron/PassDepth.template index e8002b8f86b..719415c5004 100644 --- a/com.unity.visualeffectgraph/Shaders/ParticleHexahedron/PassDepth.template +++ b/com.unity.visualeffectgraph/Shaders/ParticleHexahedron/PassDepth.template @@ -8,6 +8,7 @@ Pass HLSLPROGRAM #define VFX_PASSDEPTH VFX_PASSDEPTH_ACTUAL + ${VFXPassDepthAdditionalPragma} ${VFXInclude("Shaders/ParticleHexahedron/PassDepthOrMV.template")} ENDHLSL -} \ No newline at end of file +} diff --git a/com.unity.visualeffectgraph/Shaders/ParticleHexahedron/PassDepthOrMV.template b/com.unity.visualeffectgraph/Shaders/ParticleHexahedron/PassDepthOrMV.template index 4a7d134caa9..a87df9990cd 100644 --- a/com.unity.visualeffectgraph/Shaders/ParticleHexahedron/PassDepthOrMV.template +++ b/com.unity.visualeffectgraph/Shaders/ParticleHexahedron/PassDepthOrMV.template @@ -29,31 +29,10 @@ struct ps_input #if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR ${VFXPassVelocityDefine} -#else +#elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL ${VFXPassDepthDefine} #endif -${VFXInclude("Shaders/ParticleHexahedron/Pass.template")} - -#if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION -int _ObjectId; -int _PassValue; -#endif -#pragma fragment frag -float4 frag(ps_input i) : SV_Target0 -{ - UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); - VFXTransformPSInputs(i); - float alpha = VFXGetFragmentColor(i).a; - VFXClipFragmentColor(alpha,i); - #if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR - ${VFXComputeOutputMotionVector} - return encodedMotionVector; - #elif VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION - return float4(_ObjectId, _PassValue, 1.0, 1.0); - #elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL - return (float4)0; - #else - #error VFX_PASSDEPTH undefined - #endif -} +${VFXInclude("Shaders/ParticleHexahedron/Pass.template")} +#define VFX_SUPPORT_MAIN_TEXTURE_SAMPLING_IN_FRAGMENT_DEPTH 0 +${VFXPassDepthCommonFragmentUnlit} diff --git a/com.unity.visualeffectgraph/Shaders/ParticleHexahedron/PassVelocity.template b/com.unity.visualeffectgraph/Shaders/ParticleHexahedron/PassVelocity.template index 997846298dd..863f2fa5652 100644 --- a/com.unity.visualeffectgraph/Shaders/ParticleHexahedron/PassVelocity.template +++ b/com.unity.visualeffectgraph/Shaders/ParticleHexahedron/PassVelocity.template @@ -9,6 +9,7 @@ Pass HLSLPROGRAM #define VFX_PASSDEPTH VFX_PASSDEPTH_MOTION_VECTOR + ${VFXPassVelocityAdditionalPragma} ${VFXInclude("Shaders/ParticleHexahedron/PassDepthOrMV.template")} ENDHLSL } diff --git a/com.unity.visualeffectgraph/Shaders/ParticleLines/PassDepth.template b/com.unity.visualeffectgraph/Shaders/ParticleLines/PassDepth.template index 4f7a4450ae9..5f9eb482cb6 100644 --- a/com.unity.visualeffectgraph/Shaders/ParticleLines/PassDepth.template +++ b/com.unity.visualeffectgraph/Shaders/ParticleLines/PassDepth.template @@ -8,7 +8,7 @@ Pass HLSLPROGRAM #define VFX_PASSDEPTH VFX_PASSDEPTH_ACTUAL - ${VFXPassDepthDefine} + ${VFXPassDepthAdditionalPragma} ${VFXInclude("Shaders/ParticleLines/PassDepthOrMV.template")} ENDHLSL } diff --git a/com.unity.visualeffectgraph/Shaders/ParticleLines/PassDepthOrMV.template b/com.unity.visualeffectgraph/Shaders/ParticleLines/PassDepthOrMV.template index 531a3ca61ec..8769bdd4f0e 100644 --- a/com.unity.visualeffectgraph/Shaders/ParticleLines/PassDepthOrMV.template +++ b/com.unity.visualeffectgraph/Shaders/ParticleLines/PassDepthOrMV.template @@ -14,27 +14,13 @@ struct ps_input #define VFX_VARYING_POSCS pos #define VFX_VARYING_ALPHA builtInInterpolants.y #define VFX_VARYING_ALPHATHRESHOLD builtInInterpolants.x - -${VFXInclude("Shaders/ParticleLines/Pass.template")} -#if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION -int _ObjectId; -int _PassValue; -#endif - -#pragma fragment frag -float4 frag(ps_input i) : SV_TARGET -{ - UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); - VFXTransformPSInputs(i); - float alpha = VFXGetFragmentColor(i).a; - VFXClipFragmentColor(alpha,i); -#if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION - return float4(_ObjectId, _PassValue, 1.0, 1.0); +#if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR +${VFXPassVelocityDefine} #elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL - return (float4)0; -#else -#error VFX_PASSDEPTH undefined +${VFXPassDepthDefine} #endif - -} \ No newline at end of file + +${VFXInclude("Shaders/ParticleLines/Pass.template")} +#define VFX_SUPPORT_MAIN_TEXTURE_SAMPLING_IN_FRAGMENT_DEPTH 0 +${VFXPassDepthCommonFragmentUnlit} diff --git a/com.unity.visualeffectgraph/Shaders/ParticleLinesSW/PassDepth.template b/com.unity.visualeffectgraph/Shaders/ParticleLinesSW/PassDepth.template index 43292e9d575..38c4d398451 100644 --- a/com.unity.visualeffectgraph/Shaders/ParticleLinesSW/PassDepth.template +++ b/com.unity.visualeffectgraph/Shaders/ParticleLinesSW/PassDepth.template @@ -8,7 +8,7 @@ Pass HLSLPROGRAM #define VFX_PASSDEPTH VFX_PASSDEPTH_ACTUAL - ${VFXPassDepthDefine} + ${VFXPassDepthAdditionalPragma} ${VFXInclude("Shaders/ParticleLinesSW/PassDepthOrMV.template")} ENDHLSL } diff --git a/com.unity.visualeffectgraph/Shaders/ParticleLinesSW/PassDepthOrMV.template b/com.unity.visualeffectgraph/Shaders/ParticleLinesSW/PassDepthOrMV.template index b66b3b04031..2d7e9badd88 100644 --- a/com.unity.visualeffectgraph/Shaders/ParticleLinesSW/PassDepthOrMV.template +++ b/com.unity.visualeffectgraph/Shaders/ParticleLinesSW/PassDepthOrMV.template @@ -14,26 +14,13 @@ struct ps_input #define VFX_VARYING_POSCS pos #define VFX_VARYING_ALPHA builtInInterpolants.y #define VFX_VARYING_ALPHATHRESHOLD builtInInterpolants.x - -${VFXInclude("Shaders/ParticleLinesSW/Pass.template")} -#if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION -int _ObjectId; -int _PassValue; -#endif - -#pragma fragment frag -float4 frag(ps_input i) : SV_TARGET -{ - UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); - VFXTransformPSInputs(i); - float alpha = VFXGetFragmentColor(i).a; - VFXClipFragmentColor(alpha,i); -#if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION - return float4(_ObjectId, _PassValue, 1.0, 1.0); +#if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR +${VFXPassVelocityDefine} #elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL - return (float4)0; -#else -#error VFX_PASSDEPTH undefined +${VFXPassDepthDefine} #endif -} \ No newline at end of file + +${VFXInclude("Shaders/ParticleLinesSW/Pass.template")} +#define VFX_SUPPORT_MAIN_TEXTURE_SAMPLING_IN_FRAGMENT_DEPTH 0 +${VFXPassDepthCommonFragmentUnlit} \ No newline at end of file diff --git a/com.unity.visualeffectgraph/Shaders/ParticleMeshes/PassDepth.template b/com.unity.visualeffectgraph/Shaders/ParticleMeshes/PassDepth.template index f777f28fbb0..07a5f9bde18 100644 --- a/com.unity.visualeffectgraph/Shaders/ParticleMeshes/PassDepth.template +++ b/com.unity.visualeffectgraph/Shaders/ParticleMeshes/PassDepth.template @@ -8,6 +8,7 @@ Pass HLSLPROGRAM #define VFX_PASSDEPTH VFX_PASSDEPTH_ACTUAL + ${VFXPassDepthAdditionalPragma} ${VFXInclude("Shaders/ParticleMeshes/PassDepthOrMV.template")} ENDHLSL } diff --git a/com.unity.visualeffectgraph/Shaders/ParticleMeshes/PassDepthOrMV.template b/com.unity.visualeffectgraph/Shaders/ParticleMeshes/PassDepthOrMV.template index 975a8d730de..da52d45a4f0 100644 --- a/com.unity.visualeffectgraph/Shaders/ParticleMeshes/PassDepthOrMV.template +++ b/com.unity.visualeffectgraph/Shaders/ParticleMeshes/PassDepthOrMV.template @@ -63,44 +63,13 @@ struct ps_input #define VFX_VARYING_VELOCITY_CPOS_PREVIOUS cPosPrevious #endif -#if IS_MOTION_VECTORS_PASS +#if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR ${VFXPassVelocityDefine} -#else +#elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL ${VFXPassDepthDefine} #endif -${VFXInclude("Shaders/ParticleMeshes/Pass.template")} - -${SHADERGRAPH_PIXEL_CODE_DEPTHONLY} -#if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION -int _ObjectId; -int _PassValue; -#endif +${VFXInclude("Shaders/ParticleMeshes/Pass.template")} +#define VFX_SUPPORT_MAIN_TEXTURE_SAMPLING_IN_FRAGMENT_DEPTH 1 +${VFXPassDepthCommonFragmentUnlit} -#pragma fragment frag -float4 frag(ps_input i) : SV_TARGET -{ - UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); - VFXTransformPSInputs(i); - #ifdef VFX_SHADERGRAPH - ${VFXAdditionalInterpolantsPreparation} - ${SHADERGRAPH_PIXEL_CALL_DEPTHONLY} - - float alpha = OUTSG.${SHADERGRAPH_PARAM_ALPHA}; - #else - float alpha = VFXGetFragmentColor(i).a; - alpha *= VFXGetTextureColor(VFX_SAMPLER(mainTexture),i).a; - #endif - VFXClipFragmentColor(alpha,i); - - #if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR - ${VFXComputeOutputMotionVector} - return encodedMotionVector; - #elif VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION - return float4(_ObjectId, _PassValue, 1.0, 1.0); - #elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL - return (float4)0; - #else - #error VFX_PASSDEPTH undefined - #endif -} diff --git a/com.unity.visualeffectgraph/Shaders/ParticleMeshes/PassVelocity.template b/com.unity.visualeffectgraph/Shaders/ParticleMeshes/PassVelocity.template index 4664ec9f82d..bc4634c480f 100644 --- a/com.unity.visualeffectgraph/Shaders/ParticleMeshes/PassVelocity.template +++ b/com.unity.visualeffectgraph/Shaders/ParticleMeshes/PassVelocity.template @@ -9,6 +9,7 @@ Pass HLSLPROGRAM #define VFX_PASSDEPTH VFX_PASSDEPTH_MOTION_VECTOR + ${VFXPassVelocityAdditionalPragma} ${VFXInclude("Shaders/ParticleMeshes/PassDepthOrMV.template")} ENDHLSL } diff --git a/com.unity.visualeffectgraph/Shaders/ParticlePlanarPrimitives/PassDepth.template b/com.unity.visualeffectgraph/Shaders/ParticlePlanarPrimitives/PassDepth.template index 8046f2594c5..8a3cf70852c 100644 --- a/com.unity.visualeffectgraph/Shaders/ParticlePlanarPrimitives/PassDepth.template +++ b/com.unity.visualeffectgraph/Shaders/ParticlePlanarPrimitives/PassDepth.template @@ -8,6 +8,7 @@ Pass HLSLPROGRAM #define VFX_PASSDEPTH VFX_PASSDEPTH_ACTUAL + ${VFXPassDepthAdditionalPragma} ${VFXInclude("Shaders/ParticlePlanarPrimitives/PassDepthOrMV.template")} ENDHLSL } diff --git a/com.unity.visualeffectgraph/Shaders/ParticlePlanarPrimitives/PassDepthOrMV.template b/com.unity.visualeffectgraph/Shaders/ParticlePlanarPrimitives/PassDepthOrMV.template index 1b6ea9ac98b..c15440b5a66 100644 --- a/com.unity.visualeffectgraph/Shaders/ParticlePlanarPrimitives/PassDepthOrMV.template +++ b/com.unity.visualeffectgraph/Shaders/ParticlePlanarPrimitives/PassDepthOrMV.template @@ -53,44 +53,10 @@ struct ps_input #if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR ${VFXPassVelocityDefine} -#else +#elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL ${VFXPassDepthDefine} #endif -${VFXInclude("Shaders/ParticlePlanarPrimitives/Pass.template")} - -#if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION -int _ObjectId; -int _PassValue; -#endif - -${SHADERGRAPH_PIXEL_CODE_DEPTHONLY} - -#pragma fragment frag -float4 frag(ps_input i) : SV_TARGET -{ - UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); - VFXTransformPSInputs(i); - #ifdef VFX_SHADERGRAPH - ${VFXAdditionalInterpolantsPreparation} - - ${SHADERGRAPH_PIXEL_CALL_DEPTHONLY} - - float alpha = OUTSG.${SHADERGRAPH_PARAM_ALPHA}; - #else - float alpha = VFXGetFragmentColor(i).a; - alpha *= VFXGetTextureColor(VFX_SAMPLER(mainTexture),i).a; - #endif - VFXClipFragmentColor(alpha,i); - - #if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR - ${VFXComputeOutputMotionVector} - return encodedMotionVector; - #elif VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION - return float4(_ObjectId, _PassValue, 1.0, 1.0); - #elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL - return (float4)0; - #else - #error VFX_PASSDEPTH undefined - #endif -} +${VFXInclude("Shaders/ParticlePlanarPrimitives/Pass.template")} +#define VFX_SUPPORT_MAIN_TEXTURE_SAMPLING_IN_FRAGMENT_DEPTH 1 +${VFXPassDepthCommonFragmentUnlit} diff --git a/com.unity.visualeffectgraph/Shaders/ParticlePlanarPrimitives/PassVelocity.template b/com.unity.visualeffectgraph/Shaders/ParticlePlanarPrimitives/PassVelocity.template index 1ad19d47c80..f14172968fa 100644 --- a/com.unity.visualeffectgraph/Shaders/ParticlePlanarPrimitives/PassVelocity.template +++ b/com.unity.visualeffectgraph/Shaders/ParticlePlanarPrimitives/PassVelocity.template @@ -9,6 +9,7 @@ Pass HLSLPROGRAM #define VFX_PASSDEPTH VFX_PASSDEPTH_MOTION_VECTOR + ${VFXPassVelocityAdditionalPragma} ${VFXInclude("Shaders/ParticlePlanarPrimitives/PassDepthOrMV.template")} ENDHLSL } diff --git a/com.unity.visualeffectgraph/Shaders/ParticlePoints/PassDepth.template b/com.unity.visualeffectgraph/Shaders/ParticlePoints/PassDepth.template index 50b9b49809b..6f526ee57be 100644 --- a/com.unity.visualeffectgraph/Shaders/ParticlePoints/PassDepth.template +++ b/com.unity.visualeffectgraph/Shaders/ParticlePoints/PassDepth.template @@ -8,7 +8,7 @@ Pass HLSLPROGRAM #define VFX_PASSDEPTH VFX_PASSDEPTH_ACTUAL - ${VFXPassDepthDefine} + ${VFXPassDepthAdditionalPragma} ${VFXInclude("Shaders/ParticlePoints/PassDepthOrMV.template")} ENDHLSL } diff --git a/com.unity.visualeffectgraph/Shaders/ParticlePoints/PassDepthOrMV.template b/com.unity.visualeffectgraph/Shaders/ParticlePoints/PassDepthOrMV.template index 6b5f85e8af1..a0bad6f8b57 100644 --- a/com.unity.visualeffectgraph/Shaders/ParticlePoints/PassDepthOrMV.template +++ b/com.unity.visualeffectgraph/Shaders/ParticlePoints/PassDepthOrMV.template @@ -20,25 +20,12 @@ struct ps_input #undef VFX_VARYING_INVSOFTPARTICLEFADEDISTANCE #define VFX_VARYING_ALPHATHRESHOLD builtInInterpolants.y -${VFXInclude("Shaders/ParticlePoints/Pass.template")} - -#if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION -int _ObjectId; -int _PassValue; -#endif - -#pragma fragment frag -float4 frag(ps_input i) : SV_TARGET -{ - UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); - VFXTransformPSInputs(i); - float alpha = VFXGetFragmentColor(i).a; - VFXClipFragmentColor(alpha,i); -#if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION - return float4(_ObjectId, _PassValue, 1.0, 1.0); +#if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR +${VFXPassVelocityDefine} #elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL - return (float4)0; -#else - #error VFX_PASSDEPTH undefined +${VFXPassDepthDefine} #endif -} \ No newline at end of file + +${VFXInclude("Shaders/ParticlePoints/Pass.template")} +#define VFX_SUPPORT_MAIN_TEXTURE_SAMPLING_IN_FRAGMENT_DEPTH 0 +${VFXPassDepthCommonFragmentUnlit} diff --git a/com.unity.visualeffectgraph/Shaders/VFXParticleCommon.template b/com.unity.visualeffectgraph/Shaders/VFXParticleCommon.template index a93a574f0b8..33b3bbf3f03 100644 --- a/com.unity.visualeffectgraph/Shaders/VFXParticleCommon.template +++ b/com.unity.visualeffectgraph/Shaders/VFXParticleCommon.template @@ -155,3 +155,76 @@ float4 color = VFXGetFragmentColor(i); #endif ${VFXEnd} + +${VFXBegin:VFXPassDepthCommonFragmentUnlit} + +#ifndef VFX_SUPPORT_MAIN_TEXTURE_SAMPLING_IN_FRAGMENT_DEPTH +#define VFX_SUPPORT_MAIN_TEXTURE_SAMPLING_IN_FRAGMENT_DEPTH 0 +#endif + +#ifdef VFX_SHADERGRAPH +${SHADERGRAPH_PIXEL_CODE_DEPTHONLY} +#endif + +#if VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION +int _ObjectId; +int _PassValue; +#endif + +#pragma fragment frag +void frag(ps_input i +#if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR + #ifdef WRITE_MSAA_DEPTH + // We need the depth color as SV_Target0 for alpha to coverage + , out float4 outDepthColor : SV_Target0 + , out float4 outMotionVector : SV_Target1 + #else + // When no MSAA, the motion vector is always the first buffer + , out float4 outMotionVector : SV_Target0 + #endif +#elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL + #ifdef WRITE_MSAA_DEPTH + , out float4 outDepthColor : SV_Target0 + #else + , out float4 dummy : SV_Target0 + #endif +#elif VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION + , out float4 outSelection : SV_Target0 +#endif +) +{ + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); + VFXTransformPSInputs(i); + #ifdef VFX_SHADERGRAPH + ${VFXAdditionalInterpolantsPreparation} + ${SHADERGRAPH_PIXEL_CALL_DEPTHONLY} + float alpha = OUTSG.${SHADERGRAPH_PARAM_ALPHA}; + #else + float alpha = VFXGetFragmentColor(i).a; + #if VFX_SUPPORT_MAIN_TEXTURE_SAMPLING_IN_FRAGMENT_DEPTH + alpha *= VFXGetTextureColor(VFX_SAMPLER(mainTexture),i).a; + #endif + #endif + VFXClipFragmentColor(alpha,i); + + #ifdef WRITE_MSAA_DEPTH + outDepthColor = i.VFX_VARYING_POSCS.z; + #if VFX_USE_ALPHA_TO_MASK + outDepthColor.a = alpha; + #endif + #endif + + #if VFX_PASSDEPTH == VFX_PASSDEPTH_MOTION_VECTOR + ${VFXComputeOutputMotionVector} + outMotionVector = encodedMotionVector; + #elif VFX_PASSDEPTH == VFX_PASSDEPTH_SELECTION + outSelection = float4(_ObjectId, _PassValue, 1.0, 1.0); + #elif VFX_PASSDEPTH == VFX_PASSDEPTH_ACTUAL + #ifndef WRITE_MSAA_DEPTH + dummy = (float4)0; + #endif + #else + #error VFX_PASSDEPTH undefined + #endif +} +${VFXEnd}