MotionBlurPrePassCS.hlsl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // RUN: %dxc -E main -T cs_6_0 %s | FileCheck %s
  2. // CHECK: threadId
  3. // CHECK: Sqrt
  4. // CHECK: Round_ni
  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. Texture2D<float3> ColorBuffer : register(t0);
  19. Texture2D<float2> MotionBuffer : register(t1);
  20. RWTexture2D<float4> PrepBuffer : register(u0);
  21. float4 GetSampleData( uint2 st )
  22. {
  23. return float4(ColorBuffer[st], 1.0) * saturate(length(MotionBuffer[st]) * 32.0 / 4.0);
  24. }
  25. [RootSignature(MotionBlur_RootSig)]
  26. [numthreads( 8, 8, 1 )]
  27. void main( uint3 Gid : SV_GroupID, uint GI : SV_GroupIndex, uint3 GTid : SV_GroupThreadID, uint3 DTid : SV_DispatchThreadID )
  28. {
  29. uint2 corner = DTid.xy << 1;
  30. float4 sample0 = GetSampleData( corner + uint2(0, 0) );
  31. float4 sample1 = GetSampleData( corner + uint2(1, 0) );
  32. float4 sample2 = GetSampleData( corner + uint2(0, 1) );
  33. float4 sample3 = GetSampleData( corner + uint2(1, 1) );
  34. float combinedMotionWeight = sample0.a + sample1.a + sample2.a + sample3.a + 0.0001;
  35. PrepBuffer[DTid.xy] = floor(0.25 * combinedMotionWeight * 3.0) / 3.0 * float4(
  36. (sample0.rgb + sample1.rgb + sample2.rgb + sample3.rgb) / combinedMotionWeight, 1.0 );
  37. }