float-output-process.effect 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
  2. CCEffect %{
  3. techniques:
  4. - passes:
  5. - vert: tonemap-vs
  6. frag: copy-fs
  7. pass: copy-pass
  8. depthTest: false
  9. depthWrite: false
  10. - vert: tonemap-vs
  11. frag: tonemap-fs
  12. pass: tone-mapping
  13. depthStencilState:
  14. depthTest: false
  15. depthWrite: false
  16. rasterizerState:
  17. cullMode: none
  18. }%
  19. CCProgram tonemap-vs %{
  20. #include <./post-process/chunks/vs>
  21. }%
  22. CCProgram copy-fs %{
  23. precision highp float;
  24. #include <builtin/uniforms/cc-global>
  25. #include <common/data/packing>
  26. #pragma rate depthRaw pass
  27. uniform sampler2D depthRaw;
  28. in vec2 v_uv;
  29. layout(location = 0) out vec4 fragColor;
  30. void main() {
  31. float depth = texture(depthRaw, v_uv).r;
  32. fragColor = packDepthToRGBA(depth);
  33. }
  34. }%
  35. CCProgram tonemap-fs %{
  36. precision highp float;
  37. #define CC_SURFACES_ENABLE_DEBUG_VIEW 1
  38. #include <builtin/uniforms/cc-global>
  39. #include <common/common-define>
  40. #include <common/data/packing>
  41. #include <common/debug/debug-view-define>
  42. #include <common/color/gamma>
  43. #include <common/color/tone-mapping>
  44. #include <common/math/coordinates>
  45. #include <builtin/functionalities/fog>
  46. in vec2 v_uv;
  47. #pragma rate u_texSampler pass
  48. layout(binding = 0) uniform sampler2D u_texSampler;
  49. #pragma rate DepthTex pass
  50. layout(binding = 1) uniform sampler2D DepthTex; //Sample_Point_Clamp
  51. layout(location = 0) out vec4 fragColor;
  52. vec4 CCFragOutput_PostProcess(vec4 color) {
  53. // fog related
  54. vec4 worldPos = vec4(0.0);
  55. #if CC_USE_FOG != CC_FOG_NONE
  56. float depth = unpackRGBAToDepth(texture(DepthTex, v_uv));
  57. vec3 posHS = vec3(v_uv, depth) * 2.0 - vec3(1.0);
  58. CC_HANDLE_GET_CLIP_FLIP(posHS.xy);
  59. worldPos = GetWorldPosFromNDCPosRH(posHS, cc_matProj, cc_matViewProjInv);
  60. #endif
  61. // HDR fog
  62. // todo: apply fogColorBrightness to linear fogColor for supporting scatter lighting with HDR
  63. #if CC_USE_FOG != CC_FOG_NONE
  64. float fogFactor = 1.0;
  65. CC_TRANSFER_FOG_BASE(worldPos, fogFactor);
  66. CC_APPLY_FOG_BASE(color, fogFactor);
  67. #endif
  68. // tone mapping
  69. if (!DebugViewNeedDisplayOriginalData()) {
  70. #if CC_USE_FLOAT_OUTPUT
  71. color.rgb = HDRToLDR(color.rgb);
  72. color.rgb = LinearToSRGB(color.rgb);
  73. #endif
  74. }
  75. // LDR fog
  76. return color;
  77. }
  78. void main () {
  79. vec4 o = texture(u_texSampler, v_uv);
  80. fragColor = CCFragOutput_PostProcess(o);
  81. }
  82. }%