Skip to content

Commit

Permalink
[HDRP] MSAA & MotionVector (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulDemeulenaere authored and julienf-unity committed May 14, 2020
1 parent 6631ab9 commit fb12932
Show file tree
Hide file tree
Showing 25 changed files with 235 additions and 328 deletions.
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

#pragma target 4.5
#define UNITY_MATERIAL_LIT
#pragma multi_compile _ WRITE_NORMAL_BUFFER

struct ps_input
{
Expand Down Expand Up @@ -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}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ 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)
{
#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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Pass

HLSLPROGRAM
#define VFX_PASSDEPTH VFX_PASSDEPTH_ACTUAL
${VFXPassDepthAdditionalPragma}
${VFXInclude("Shaders/ParticleHexahedron/PassDepthOrMV.template")}
ENDHLSL
}
}
Loading

0 comments on commit fb12932

Please sign in to comment.