PPTonemapping.bsl 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. DepthWrite = false;
  89. DepthRead = false;
  90. Vertex =
  91. {
  92. in vec2 bs_position;
  93. in vec2 bs_texcoord0;
  94. out VStoFS
  95. {
  96. vec2 uv0;
  97. float exposureScale;
  98. } VSOutput;
  99. uniform sampler2D gEyeAdaptationTex;
  100. out gl_PerVertex
  101. {
  102. vec4 gl_Position;
  103. };
  104. void main()
  105. {
  106. gl_Position = vec4(bs_position, 0, 1);
  107. VSOutput.uv0 = bs_texcoord0;
  108. VSOutput.exposureScale = texelFetch(gEyeAdaptationTex, ivec2(0, 0), 0).r;
  109. }
  110. };
  111. Fragment =
  112. {
  113. in VStoFS
  114. {
  115. vec2 uv0;
  116. float exposureScale;
  117. } FSInput;
  118. uniform sampler2D gInputTex;
  119. uniform sampler3D gColorLUT;
  120. uniform Input
  121. {
  122. float gRawGamma;
  123. float gManualExposureScale;
  124. };
  125. out vec4 fragColor;
  126. void ColorLookupTable(vec3 linearColor, out vec3 result)
  127. {
  128. vec3 logColor;
  129. LinearToLogColor(linearColor, logColor);
  130. vec3 UVW = logColor * ((LUT_SIZE - 1) / float(LUT_SIZE)) + (0.5f / LUT_SIZE);
  131. vec3 gradedColor = texture(gColorLUT, UVW).rgb;
  132. result = gradedColor;
  133. }
  134. void main()
  135. {
  136. vec4 sceneColor = texture2D(gInputTex, FSInput.uv0);
  137. #if AUTO_EXPOSURE
  138. sceneColor.rgb = sceneColor.rgb * FSInput.exposureScale;
  139. #else
  140. sceneColor.rgb = sceneColor.rgb * gManualExposureScale;
  141. #endif
  142. #if GAMMA_ONLY
  143. sceneColor.rgb = pow(sceneColor.rgb, vec3(gRawGamma));
  144. #else
  145. vec3 lookupColor;
  146. ColorLookupTable(sceneColor.rgb, lookupColor);
  147. sceneColor.rgb = lookupColor;
  148. #endif
  149. fragColor = sceneColor;
  150. }
  151. };
  152. };
  153. };