PPTonemapping.bsl 2.0 KB

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