PPTonemapping.bsl 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "$ENGINE$\PPTonemapCommon.bslinc"
  2. technique PPTonemapping
  3. {
  4. mixin PPTonemapCommon;
  5. depth
  6. {
  7. read = false;
  8. write = false;
  9. };
  10. code
  11. {
  12. struct VStoFS
  13. {
  14. float4 position : SV_POSITION;
  15. float2 uv0 : TEXCOORD0;
  16. float exposureScale : TEXCOORD1;
  17. };
  18. struct VertexInput
  19. {
  20. float2 screenPos : POSITION;
  21. float2 uv0 : TEXCOORD0;
  22. };
  23. Texture2D gEyeAdaptationTex;
  24. VStoFS vsmain(VertexInput input)
  25. {
  26. VStoFS output;
  27. output.position = float4(input.screenPos, 0, 1);
  28. output.uv0 = input.uv0;
  29. output.exposureScale = gEyeAdaptationTex.Load(int3(0, 0, 0)).r;
  30. return output;
  31. }
  32. SamplerState gInputSamp;
  33. Texture2D gInputTex;
  34. SamplerState gColorLUTSamp;
  35. Texture3D gColorLUT;
  36. cbuffer Input
  37. {
  38. float gRawGamma;
  39. float gManualExposureScale;
  40. }
  41. float3 ColorLookupTable(float3 linearColor)
  42. {
  43. float3 logColor = LinearToLogColor(linearColor);
  44. float3 UVW = logColor * ((LUT_SIZE - 1) / (float)LUT_SIZE) + (0.5f / LUT_SIZE);
  45. float3 gradedColor = gColorLUT.Sample(gColorLUTSamp, UVW).rgb;
  46. return gradedColor;
  47. }
  48. float4 fsmain(VStoFS input) : SV_Target0
  49. {
  50. float4 sceneColor = gInputTex.Sample(gInputSamp, input.uv0);
  51. #if AUTO_EXPOSURE
  52. sceneColor.rgb = sceneColor.rgb * input.exposureScale;
  53. #else
  54. sceneColor.rgb = sceneColor.rgb * gManualExposureScale;
  55. #endif
  56. #if GAMMA_ONLY
  57. sceneColor.rgb = pow(sceneColor.rgb, gRawGamma);
  58. #else
  59. sceneColor.rgb = ColorLookupTable(sceneColor.rgb);
  60. #endif
  61. return sceneColor;
  62. }
  63. };
  64. };