DebugLuminanceHdrCS.hlsl 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // RUN: %dxc -E main -T cs_6_0 %s | FileCheck %s
  2. // CHECK: threadId
  3. // CHECK: textureLoad
  4. // CHECK: sampleLevel
  5. // CHECK: Exp
  6. // CHECK: dot3
  7. // CHECK: Log
  8. // CHECK: textureStore
  9. //
  10. // Copyright (c) Microsoft. All rights reserved.
  11. // This code is licensed under the MIT License (MIT).
  12. // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
  13. // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
  14. // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
  15. // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
  16. //
  17. // Developed by Minigraph
  18. //
  19. // Author: James Stanard
  20. //
  21. #include "ShaderUtility.hlsli"
  22. #include "PostEffectsRS.hlsli"
  23. Texture2D<float3> SrcColor : register( t0 );
  24. StructuredBuffer<float> Exposure : register( t1 );
  25. Texture2D<float3> bloom : register( t2 );
  26. RWTexture2D<float3> DstColor : register( u0 );
  27. RWTexture2D<float> OutLuma : register( u1 );
  28. SamplerState LinearSampler : register( s0 );
  29. cbuffer ConstantBuffer_x : register( b0 )
  30. {
  31. float2 g_RcpBufferDim;
  32. float g_BloomStrength;
  33. float g_LumaGamma;
  34. };
  35. [RootSignature(PostEffects_RootSig)]
  36. [numthreads( 8, 8, 1 )]
  37. void main( uint3 DTid : SV_DispatchThreadID )
  38. {
  39. float2 TexCoord = (DTid.xy + 0.5) * g_RcpBufferDim;
  40. // Load HDR and bloom
  41. float3 hdrColor = SrcColor[DTid.xy] + g_BloomStrength * bloom.SampleLevel( LinearSampler, TexCoord, 0 );
  42. // Tone map to LDR and convert to greyscale
  43. float luma = RGBToLuminance( ToneMap(hdrColor * Exposure[2]) );
  44. float logLuma = LinearToLogLuminance(luma, g_LumaGamma);
  45. DstColor[DTid.xy] = luma.xxx;
  46. OutLuma[DTid.xy] = logLuma;
  47. }