post-process.effect 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
  2. CCEffect %{
  3. techniques:
  4. - passes:
  5. - vert: post-process-vs
  6. frag: post-process-fs
  7. pass: post-process
  8. depthStencilState:
  9. depthTest: false
  10. depthWrite: false
  11. rasterizerState:
  12. cullMode: none
  13. blendState:
  14. targets:
  15. - blend: true
  16. blendSrc: src_alpha
  17. blendDst: one_minus_src_alpha
  18. blendSrcAlpha: src_alpha
  19. blendDstAlpha: one_minus_src_alpha
  20. }%
  21. CCProgram post-process-vs %{
  22. precision highp float;
  23. #include <legacy/decode-standard>
  24. #include <builtin/uniforms/cc-global>
  25. #include <common/common-define>
  26. out vec2 v_uv;
  27. void main () {
  28. StandardVertInput In;
  29. CCDecode(In);
  30. CC_HANDLE_GET_CLIP_FLIP(In.position.xy);
  31. gl_Position = In.position;
  32. v_uv = a_texCoord;
  33. }
  34. }%
  35. CCProgram post-process-fs %{
  36. precision highp float;
  37. #include <builtin/uniforms/cc-global>
  38. #include <post-process/anti-aliasing>
  39. in vec2 v_uv;
  40. #pragma rate outputResultMap pass
  41. layout(binding = 0) uniform sampler2D outputResultMap;
  42. layout(location = 0) out vec4 fragColor;
  43. void texcoords(vec2 fragCoord, vec2 resolution,
  44. out vec2 v_rgbNW, out vec2 v_rgbNE,
  45. out vec2 v_rgbSW, out vec2 v_rgbSE,
  46. out vec2 v_rgbM) {
  47. vec2 inverseVP = 1.0 / resolution.xy;
  48. v_rgbNW = (fragCoord + vec2(-1.0, -1.0)) * inverseVP;
  49. v_rgbNE = (fragCoord + vec2(1.0, -1.0)) * inverseVP;
  50. v_rgbSW = (fragCoord + vec2(-1.0, 1.0)) * inverseVP;
  51. v_rgbSE = (fragCoord + vec2(1.0, 1.0)) * inverseVP;
  52. v_rgbM = vec2(fragCoord * inverseVP);
  53. }
  54. void main () {
  55. #if ANTIALIAS_TYPE == 1
  56. mediump vec2 v_rgbNW;
  57. mediump vec2 v_rgbNE;
  58. mediump vec2 v_rgbSW;
  59. mediump vec2 v_rgbSE;
  60. mediump vec2 v_rgbM;
  61. vec2 resolution = cc_screenSize.xy;
  62. vec2 fragCoord = v_uv * resolution;
  63. texcoords(fragCoord, resolution, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);
  64. fragColor = fxaa(outputResultMap, fragCoord, resolution, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM);
  65. #elif ANTIALIAS_TYPE == 2
  66. vec3 color = FxaaPixelShader(v_uv, outputResultMap, 1.0 / cc_screenSize.xy);
  67. fragColor = vec4(color, texture(outputResultMap, v_uv).a);
  68. #else
  69. fragColor = texture(outputResultMap, v_uv);
  70. #endif
  71. }
  72. }%