PPTonemapping.bsl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. Technique =
  11. {
  12. Language = "HLSL11";
  13. Pass =
  14. {
  15. DepthWrite = false;
  16. DepthRead = false;
  17. Common =
  18. {
  19. struct VStoFS
  20. {
  21. float4 position : SV_POSITION;
  22. float2 uv0 : TEXCOORD0;
  23. float exposureScale : TEXCOORD1;
  24. };
  25. };
  26. Vertex =
  27. {
  28. struct VertexInput
  29. {
  30. float2 screenPos : POSITION;
  31. float2 uv0 : TEXCOORD0;
  32. };
  33. Texture2D gEyeAdaptationTex;
  34. VStoFS main(VertexInput input)
  35. {
  36. VStoFS output;
  37. output.position = float4(input.screenPos, 0, 1);
  38. output.uv0 = input.uv0;
  39. output.exposureScale = gEyeAdaptationTex.Load(int3(0, 0, 0)).r;
  40. return output;
  41. }
  42. };
  43. Fragment =
  44. {
  45. SamplerState gInputSamp;
  46. Texture2D gInputTex;
  47. SamplerState gColorLUTSamp;
  48. Texture3D gColorLUT;
  49. cbuffer Input
  50. {
  51. float gRawGamma;
  52. float gManualExposureScale;
  53. }
  54. float3 ColorLookupTable(float3 linearColor)
  55. {
  56. float3 logColor = LinearToLogColor(linearColor);
  57. float3 UVW = logColor * ((LUT_SIZE - 1) / (float)LUT_SIZE) + (0.5f / LUT_SIZE);
  58. float3 gradedColor = gColorLUT.Sample(gColorLUTSamp, UVW).rgb;
  59. return gradedColor;
  60. }
  61. float4 main(VStoFS input) : SV_Target0
  62. {
  63. float4 sceneColor = gInputTex.Sample(gInputSamp, input.uv0);
  64. #if AUTO_EXPOSURE
  65. sceneColor.rgb = sceneColor.rgb * input.exposureScale;
  66. #else
  67. sceneColor.rgb = sceneColor.rgb * gManualExposureScale;
  68. #endif
  69. #if GAMMA_ONLY
  70. sceneColor.rgb = pow(sceneColor.rgb, gRawGamma);
  71. #else
  72. sceneColor.rgb = ColorLookupTable(sceneColor.rgb);
  73. #endif
  74. return sceneColor;
  75. }
  76. };
  77. };
  78. };
  79. Technique =
  80. {
  81. Language = "GLSL";
  82. Pass =
  83. {
  84. Fragment =
  85. {
  86. // TODO
  87. };
  88. };
  89. };