FinalPass_CPU_PS.hlsl 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
  2. // CHECK: sample
  3. // CHECK: sample
  4. // CHECK: storeOutput
  5. //--------------------------------------------------------------------------------------
  6. // File: FinalPass.hlsl
  7. //
  8. // The PSs for doing tone-mapping based on the input luminance, used in CS path of
  9. // HDRToneMappingCS11 sample
  10. //
  11. // Copyright (c) Microsoft Corporation. All rights reserved.
  12. //--------------------------------------------------------------------------------------
  13. struct QuadVS_Input
  14. {
  15. float4 Pos : POSITION;
  16. float2 Tex : TEXCOORD0;
  17. };
  18. struct QuadVS_Output
  19. {
  20. float4 Pos : SV_POSITION;
  21. float2 Tex : TEXCOORD0;
  22. };
  23. QuadVS_Output QuadVS( QuadVS_Input Input )
  24. {
  25. QuadVS_Output Output;
  26. Output.Pos = Input.Pos;
  27. Output.Tex = Input.Tex;
  28. return Output;
  29. }
  30. Texture2D<float4> tex : register( t0 );
  31. StructuredBuffer<float> lum : register( t1 );
  32. Texture2D<float4> bloom : register( t2 );
  33. SamplerState PointSampler : register (s0);
  34. SamplerState LinearSampler : register (s1);
  35. static const float MIDDLE_GRAY = 0.72f;
  36. static const float LUM_WHITE = 1.5f;
  37. cbuffer cbPS : register( b0 )
  38. {
  39. float4 g_param;
  40. };
  41. float4 main( QuadVS_Output Input ) : SV_TARGET
  42. {
  43. float4 vColor = tex.Sample( PointSampler, Input.Tex );
  44. float fLum = g_param.x;
  45. float3 vBloom = bloom.Sample( LinearSampler, Input.Tex );
  46. // Tone mapping
  47. vColor.rgb *= MIDDLE_GRAY / (fLum + 0.001f);
  48. vColor.rgb *= (1.0f + vColor/LUM_WHITE);
  49. vColor.rgb /= (1.0f + vColor);
  50. vColor.rgb += 0.6f * vBloom;
  51. vColor.a = 1.0f;
  52. return vColor;
  53. }