// motion blur reconstruction filter pass uniform float4 _ZBufferParams ; inline float Linear01Depth ( float z ) { return 1.0 / ( _ZBufferParams . x * z + _ZBufferParams . y ) ; } struct v2f { float4 pos : POSITION ; float2 uv : TEXCOORD0 ; } ; sampler2D _MainTex ; sampler2D _CameraDepthTexture ; sampler2D _VelTex ; sampler2D _NeighbourMaxTex ; sampler2D _NoiseTex ; float4 _MainTex_TexelSize ; float4 _CameraDepthTexture_TexelSize ; float4 _VelTex_TexelSize ; float4x4 _InvViewProj ; float4x4 _PrevViewProj ; float4x4 _ToPrevViewProjCombined ; float _MaxVelocity ; float _MinVelocity ; float4 _VelBufferSize ; float4 _TileBufferSize ; float4 _BlurDirectionPacked ; float _SoftZDistance ; float2 vmax ( float2 a , float2 b ) { float ma = dot ( a , a ) ; float mb = dot ( b , b ) ; return ( ma > mb ) ? a : b ; } float cone ( float2 x , float2 y , float2 v ) { return clamp ( 1.0 - ( length ( x - y ) / length ( v ) ) , 0.0 , 1.0 ) ; } float cylinder ( float2 x , float2 y , float2 v ) { float lv = length ( v ) ; return 1.0 - smoothstep ( 0.95 * lv , 1.05 * lv , length ( x - y ) ) ; } float softDepthCompare ( float za , float zb ) { return clamp ( 1.0 - ( za - zb ) / _SoftZDistance , 0.0 , 1.0 ) ; } float4 main ( v2f i ) : COLOR { float2 x = i . uv ; float2 xf = x ; float2 x2 = xf * _VelBufferSize . xy / ( _TileBufferSize . xy * ( float ) ( 8 ) ) ; float2 vn = tex2D ( _NeighbourMaxTex , x2 ) . xy ; float4 cx = tex2D ( _MainTex , x ) ; float zx = tex2D ( _CameraDepthTexture , x ) . x ; zx = - Linear01Depth ( zx ) ; float2 vx = tex2D ( _VelTex , xf ) . xy ; int2 pixelCoord = i . uv * _MainTex_TexelSize . zw ; float j = tex2D ( _NoiseTex , i . uv * 4.0f ) . r * ( 0.25f ) ; float weight = 1.0 ; float4 sum = cx * weight ; int centerSample = ( int ) ( ( 13 ) - 1 ) / 2 ; for ( int i = 0 ; i < ( 13 ) ; i ++ ) { float contrib = 1.0f ; if ( i == centerSample ) contrib = 0.0f ; float t = lerp ( - 1.0 , 1.0 , ( i + j + 1.0 ) / ( ( 13 ) + 1.0 ) ) ; float2 y = x + vn * t ; float2 yf = y ; float2 vy = tex2D ( _VelTex , float4 ( yf , 0 , 0 ) . xy ) . xy ; float zy = tex2D ( _CameraDepthTexture , float4 ( y , 0 , 0 ) . xy ) . x ; zy = - Linear01Depth ( zy ) ; float f = softDepthCompare ( zx , zy ) ; float b = softDepthCompare ( zy , zx ) ; float alphay = f * cone ( y , x , vy ) + b * cone ( x , y , vx ) + cylinder ( y , x , vy ) * cylinder ( x , y , vx ) * 2.0 ; float4 cy = tex2D ( _MainTex , float4 ( y , 0 , 0 ) . xy ) ; sum += cy * alphay * contrib ; weight += alphay * contrib ; } sum /= weight ; return sum ; }