CameraVelocityCS.hlsl 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // RUN: %dxc -E main -T cs_6_0 %s | FileCheck %s
  2. // CHECK: threadId
  3. // CHECK: textureLoad
  4. // CHECK: textureStore
  5. //
  6. // Copyright (c) Microsoft. All rights reserved.
  7. // This code is licensed under the MIT License (MIT).
  8. // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
  9. // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
  10. // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
  11. // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
  12. //
  13. // Developed by Minigraph
  14. //
  15. // Author: James Stanard
  16. //
  17. #include "MotionBlurRS.hlsli"
  18. // We can use the original depth buffer or a linearized one. In this case, we use linear Z because
  19. // we have discarded the 32-bit depth buffer but still retain a 16-bit linear buffer (previously
  20. // used by SSAO.) Note that hyperbolic Z is reversed by default (TBD) for increased precision, so
  21. // its Z=0 maps to the far plane. With linear Z, Z=0 maps to the eye position. Both extend to Z=1.
  22. #define USE_LINEAR_Z
  23. Texture2D<float> DepthBuffer : register(t0);
  24. RWTexture2D<float2> ReprojectionBuffer : register(u0);
  25. cbuffer ConstantBuffer_x : register(b1)
  26. {
  27. matrix CurToPrevXForm;
  28. }
  29. [RootSignature(MotionBlur_RootSig)]
  30. [numthreads( 8, 8, 1 )]
  31. void main( uint3 DTid : SV_DispatchThreadID )
  32. {
  33. uint2 st = DTid.xy;
  34. float2 CurPixel = st + 0.5;
  35. float Depth = DepthBuffer[st];
  36. #ifdef USE_LINEAR_Z
  37. float4 HPos = float4( CurPixel * Depth, 1.0, Depth );
  38. #else
  39. float4 HPos = float4( CurPixel, Depth, 1.0 );
  40. #endif
  41. float4 PrevHPos = mul( CurToPrevXForm, HPos );
  42. ReprojectionBuffer[st] = PrevHPos.xy / PrevHPos.w - CurPixel;
  43. }