FinalPass_PS.hlsl 1.6 KB

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