PPTonemapping.bsl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include "$ENGINE$\PPTonemapCommon.bslinc"
  2. Parameters =
  3. {
  4. Sampler2D gInputSamp : alias("gInputTex");
  5. Texture2D gInputTex;
  6. Sampler3D gColorLUTSamp : alias("gColorLUT");
  7. Texture3D gColorLUT;
  8. Texture2D gEyeAdaptationTex;
  9. };
  10. Blocks =
  11. {
  12. Block Input;
  13. };
  14. Technique : inherits("PPTonemapCommon") =
  15. {
  16. Pass =
  17. {
  18. DepthWrite = false;
  19. DepthRead = false;
  20. Common =
  21. {
  22. struct VStoFS
  23. {
  24. float4 position : SV_POSITION;
  25. float2 uv0 : TEXCOORD0;
  26. float exposureScale : TEXCOORD1;
  27. };
  28. };
  29. Vertex =
  30. {
  31. struct VertexInput
  32. {
  33. float2 screenPos : POSITION;
  34. float2 uv0 : TEXCOORD0;
  35. };
  36. Texture2D gEyeAdaptationTex;
  37. VStoFS main(VertexInput input)
  38. {
  39. VStoFS output;
  40. output.position = float4(input.screenPos, 0, 1);
  41. output.uv0 = input.uv0;
  42. output.exposureScale = gEyeAdaptationTex.Load(int3(0, 0, 0)).r;
  43. return output;
  44. }
  45. };
  46. Fragment =
  47. {
  48. SamplerState gInputSamp;
  49. Texture2D gInputTex;
  50. SamplerState gColorLUTSamp;
  51. Texture3D gColorLUT;
  52. cbuffer Input
  53. {
  54. float gRawGamma;
  55. float gManualExposureScale;
  56. }
  57. float3 ColorLookupTable(float3 linearColor)
  58. {
  59. float3 logColor = LinearToLogColor(linearColor);
  60. float3 UVW = logColor * ((LUT_SIZE - 1) / (float)LUT_SIZE) + (0.5f / LUT_SIZE);
  61. float3 gradedColor = gColorLUT.Sample(gColorLUTSamp, UVW).rgb;
  62. return gradedColor;
  63. }
  64. float4 main(VStoFS input) : SV_Target0
  65. {
  66. float4 sceneColor = gInputTex.Sample(gInputSamp, input.uv0);
  67. #if AUTO_EXPOSURE
  68. sceneColor.rgb = sceneColor.rgb * input.exposureScale;
  69. #else
  70. sceneColor.rgb = sceneColor.rgb * gManualExposureScale;
  71. #endif
  72. #if GAMMA_ONLY
  73. sceneColor.rgb = pow(sceneColor.rgb, gRawGamma);
  74. #else
  75. sceneColor.rgb = ColorLookupTable(sceneColor.rgb);
  76. #endif
  77. return sceneColor;
  78. }
  79. };
  80. };
  81. };