builtin-debug-renderer.effect 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
  2. CCEffect %{
  3. techniques:
  4. - passes:
  5. - vert: debug-renderer-vs:vert
  6. frag: debug-renderer-fs:frag
  7. priority: max
  8. depthStencilState:
  9. depthTest: false
  10. depthWrite: false
  11. blendState:
  12. targets:
  13. - blend: true
  14. blendSrc: src_alpha
  15. blendDst: one_minus_src_alpha
  16. blendDstAlpha: one_minus_src_alpha
  17. rasterizerState:
  18. cullMode: none
  19. }%
  20. CCProgram debug-renderer-vs %{
  21. precision mediump float;
  22. #include <builtin/uniforms/cc-global>
  23. #include <common/common-define>
  24. in vec2 a_position;
  25. in vec2 a_texCoord;
  26. in vec4 a_color;
  27. out vec2 v_texCoord;
  28. out vec4 v_color;
  29. vec4 vert () {
  30. int orientation = int(cc_surfaceTransform.x);
  31. vec4 transform = vec4(1.0, 0.0, 0.0, 1.0);
  32. if (orientation == 0) {
  33. transform = vec4(1.0, 0.0, 0.0, 1.0);
  34. } else if (orientation == 1) {
  35. transform = vec4(0.0, 1.0, -1.0, 0.0);
  36. } else if (orientation == 2) {
  37. transform = vec4(-1.0, 0.0, 0.0, -1.0);
  38. } else if (orientation == 3) {
  39. transform = vec4(0.0, -1.0, 1.0, 0.0);
  40. }
  41. vec2 invScreenSize = (orientation == 1 || orientation == 3) ? cc_screenSize.wz : cc_screenSize.zw;
  42. vec2 position = a_position * invScreenSize;
  43. position = position * vec2(2.0, -2.0) + vec2(-1.0, 1.0);
  44. vec2 clipPos = vec2(dot(transform.xy, position), dot(transform.zw, position));
  45. CC_HANDLE_GET_CLIP_FLIP(clipPos);
  46. v_texCoord = a_texCoord;
  47. v_color = a_color;
  48. return vec4(clipPos, 0.0, 1.0);
  49. }
  50. }%
  51. CCProgram debug-renderer-fs %{
  52. precision mediump float;
  53. #include <legacy/output>
  54. in vec2 v_texCoord;
  55. in vec4 v_color;
  56. uniform sampler2D mainTexture;
  57. vec4 frag () {
  58. vec4 color = vec4(v_color.rgb, v_color.a * texture(mainTexture, v_texCoord).r);
  59. return CCFragOutput(color);
  60. }
  61. }%