浏览代码

Homegenize code of motion vector + fix discrepency between object and camera motion blur

/main
sebastienlagarde 7 年前
当前提交
ded6bbde
共有 5 个文件被更改,包括 26 次插入13 次删除
  1. 7
      com.unity.render-pipelines.high-definition/HDRP/Debug/DebugFullScreen.shader
  2. 4
      com.unity.render-pipelines.high-definition/HDRP/Material/Builtin/BuiltinData.hlsl
  3. 1
      com.unity.render-pipelines.high-definition/HDRP/Material/MaterialUtilities.hlsl
  4. 23
      com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/CameraMotionVectors.shader
  5. 4
      com.unity.render-pipelines.high-definition/HDRP/ShaderPass/ShaderPassVelocity.hlsl

7
com.unity.render-pipelines.high-definition/HDRP/Debug/DebugFullScreen.shader


#include "HDRP/Material/Lit/Lit.cs.hlsl"
#include "../ShaderVariables.hlsl"
#include "../Debug/DebugDisplay.cs.hlsl"
#include "../Material/Builtin/BuiltinData.hlsl"
CBUFFER_START (UnityDebug)
float _FullScreenDebugMode;

return d;
}
// return motion vector in NDC space [0..1]
return SAMPLE_TEXTURE2D(_DebugFullScreenTexture, s_point_clamp_sampler, coords).xy;
float2 velocityNDC;
DecodeVelocity(SAMPLE_TEXTURE2D(_DebugFullScreenTexture, s_point_clamp_sampler, coords), velocityNDC);
return velocityNDC;
}
// end motion vector utilties

4
com.unity.render-pipelines.high-definition/HDRP/Material/Builtin/BuiltinData.hlsl


shadowMask = inBuffer;
}
// TODO: CAUTION: current DecodeVelocity is not used in motion vector / TAA pass as it come from Postprocess stack
// This will be fix when postprocess will be integrated into HD, but it mean that we must not change the
// EncodeVelocity / DecodeVelocity code for now, i.e it must do nothing like it is doing currently.
// Note2: Motion blur code of posptrocess stack do * 2 - 1 to uncompress velocity which is not expected, TAA is correct.
// Design note: We assume that velocity/distortion fit into a single buffer (i.e not spread on several buffer)
void EncodeVelocity(float2 velocity, out float4 outBuffer)
{

1
com.unity.render-pipelines.high-definition/HDRP/Material/MaterialUtilities.hlsl


return rawOcclusionMask;
}
// Calculate velocity in Clip space [-1..1]
float2 CalculateVelocity(float4 positionCS, float4 previousPositionCS)
{
// This test on define is required to remove warning of divide by 0 when initializing empty struct

23
com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/CameraMotionVectors.shader


#include "../ShaderPass/FragInputs.hlsl"
#include "../ShaderPass/VaryingMesh.hlsl"
#include "../ShaderPass/VertMesh.hlsl"
#include "../Material/Builtin/BuiltinData.hlsl"
struct Attributes
{

return output;
}
float4 Frag(Varyings input) : SV_Target
void Frag(Varyings input, out float4 outColor : SV_Target0)
{
float depth = LOAD_TEXTURE2D(_CameraDepthTexture, input.positionCS.xy).x;

float4 prevClipPos = mul(_PrevViewProjMatrix, prevPos);
float4 curClipPos = mul(_NonJitteredViewProjMatrix, worldPos);
float2 prevHPos = prevClipPos.xy / prevClipPos.w;
float2 curHPos = curClipPos.xy / curClipPos.w;
float2 previousPositionCS = (prevHPos + 1.0) / 2.0;
float2 positionCS = (curHPos + 1.0) / 2.0;
float2 previousPositionCS = prevClipPos.xy / prevClipPos.w;
float2 positionCS = curClipPos.xy / curClipPos.w;
#if UNITY_UV_STARTS_AT_TOP
previousPositionCS.y = 1.0 - previousPositionCS.y;
positionCS.y = 1.0 - positionCS.y;
#endif
return float4(positionCS - previousPositionCS, 0.0, 1.0);
// Convert from Clip space (-1..1) to NDC 0..1 space
float2 velocity = (positionCS - previousPositionCS);
#if UNITY_UV_STARTS_AT_TOP
velocity.y = -velocity.y;
#endif
// Convert velocity from Clip space (-1..1) to NDC 0..1 space
// Note: ((positionCS * 0.5 + 0.5) - (previousPositionCS * 0.5 + 0.5)) = (velocity * 0.5)
EncodeVelocity(velocity * 0.5, outColor);
}
ENDHLSL

4
com.unity.render-pipelines.high-definition/HDRP/ShaderPass/ShaderPassVelocity.hlsl


// TODO: How to allow overriden velocity vector from GetSurfaceAndBuiltinData ?
float2 velocity = CalculateVelocity(inputPass.positionCS, inputPass.previousPositionCS);
EncodeVelocity(velocity, outColor);
// Convert from Clip space (-1..1) to NDC 0..1 space
// Note: ((positionCS * 0.5 + 0.5) - (previousPositionCS * 0.5 + 0.5)) = (velocity * 0.5)
EncodeVelocity(velocity * 0.5, outColor);
// Note: unity_MotionVectorsParams.y is 0 is forceNoMotion is enabled
bool forceNoMotion = unity_MotionVectorsParams.y == 0.0;

正在加载...
取消
保存