profiler.effect 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
  2. CCEffect %{
  3. techniques:
  4. - passes:
  5. - vert: profiler-vs:vert
  6. frag: profiler-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 profiler-vs %{
  21. precision mediump float;
  22. #include <builtin/uniforms/cc-global>
  23. #pragma define COLS 8 // multiple of 4
  24. #pragma define ROWS 11
  25. #pragma define VECTOR_COUNT COLS * ROWS / 4
  26. in vec3 a_position;
  27. in vec4 a_color;
  28. out vec2 v_uv;
  29. uniform Constants {
  30. vec4 offset; // xy: bottom-left corner offset, z: symbol width
  31. };
  32. uniform PerFrameInfo {
  33. vec4 digits[VECTOR_COUNT];
  34. };
  35. float getComponent(vec4 v, float i) {
  36. if (i < 1.0) { return v.x; }
  37. else if (i < 2.0) { return v.y; }
  38. else if (i < 3.0) { return v.z; }
  39. else { return v.w; }
  40. }
  41. vec4 vert () {
  42. mat2 proj = mat2(cc_matProj[0].xy, cc_matProj[1].xy);
  43. proj /= abs(proj[1].x + proj[1].y);
  44. vec2 position = proj * a_position.xy + offset.xy;
  45. v_uv = a_color.xy;
  46. if (a_color.z >= 0.0) {
  47. float n = getComponent(digits[int(a_color.z)], a_color.w);
  48. v_uv += vec2(offset.z * n, 0.0);
  49. }
  50. return vec4(position, 0.0, 1.0);
  51. }
  52. }%
  53. CCProgram profiler-fs %{
  54. precision mediump float;
  55. #include <legacy/output>
  56. in vec2 v_uv;
  57. uniform sampler2D mainTexture;
  58. vec4 frag () {
  59. return CCFragOutput(texture(mainTexture, v_uv));
  60. }
  61. }%