debug_matid.shader 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. shader_type canvas_item;
  2. render_mode blend_mix;
  3. uniform sampler2D iChannel0;
  4. const float dv=0.25;
  5. int decode_mid(float mid){
  6. if(mid<dv){
  7. return -1;
  8. }
  9. return int(mid/dv)-1;
  10. }
  11. float DigitBin(in int x)
  12. {
  13. if (x==0)return 480599.0;
  14. else if(x==1) return 139810.0;
  15. else if(x==2) return 476951.0;
  16. else if(x==3) return 476999.0;
  17. else if(x==4) return 350020.0;
  18. else if(x==5) return 464711.0;
  19. else if(x==6) return 464727.0;
  20. else if(x==7) return 476228.0;
  21. else if(x==8) return 481111.0;
  22. else if(x==9) return 481095.0;
  23. return 0.0;
  24. }
  25. float PrintValue(vec2 fragCoord, vec2 pixelCoord, vec2 fontSize, float value,
  26. float digits, float decimals) {
  27. vec2 charCoord = (fragCoord - pixelCoord) / fontSize;
  28. if(charCoord.y < 0.0 || charCoord.y >= 1.0) return 0.0;
  29. float bits = 0.0;
  30. float digitIndex1 = digits - floor(charCoord.x)+ 1.0;
  31. if(- digitIndex1 <= decimals) {
  32. float pow1 = pow(10.0, digitIndex1);
  33. float absValue = abs(value);
  34. float pivot = max(absValue, 1.5) * 10.0;
  35. if(pivot < pow1) {
  36. if(value < 0.0 && pivot >= pow1 * 0.1) bits = 1792.0;
  37. } else if(digitIndex1 == 0.0) {
  38. if(decimals > 0.0) bits = 2.0;
  39. } else {
  40. value = digitIndex1 < 0.0 ? fract(absValue) : absValue * 10.0;
  41. bits = DigitBin(int (mod(value / pow1, 10.0)));
  42. }
  43. }
  44. return floor(mod(bits / pow(2.0, floor(fract(charCoord.x) * 4.0) + floor(charCoord.y * 5.0) * 4.0), 2.0));
  45. }
  46. float print_n(in vec2 uv ,float nm){
  47. uv.x+=0.5;
  48. vec2 vPixelCoord2 = vec2(0.);
  49. float fValue2 = nm;
  50. float fDigits = 2.0;
  51. float fDecimalPlaces = 0.0;
  52. vec2 fontSize = vec2(8.)/vec2(16.,9.);
  53. float fIsDigit2 = PrintValue(uv, vPixelCoord2, fontSize, fValue2, fDigits, fDecimalPlaces);
  54. return fIsDigit2;
  55. }
  56. void mainImage( out vec4 fragColor, in vec2 fragCoord, in vec2 iResolution )
  57. {
  58. vec2 uv = fragCoord/iResolution.xy;
  59. vec4 data=texelFetch(iChannel0,ivec2(fragCoord),0);
  60. int mid=decode_mid(data.r*data.a);
  61. vec3 c=vec3(0.);
  62. if(mid<0){
  63. c=vec3(0.5);
  64. }else{
  65. switch(mid%5){
  66. case 0:c=vec3(0.8,0.05,0.05);break;
  67. case 1:c=vec3(0.05,0.8,0.05);break;
  68. case 2:c=vec3(0.05,0.05,0.8);break;
  69. case 3:c=vec3(0.8,0.8,0.05);break;
  70. case 4:c=vec3(0.05,0.8,0.8);break;
  71. }
  72. }
  73. vec2 guv=fract(uv*20.);
  74. float d=print_n(guv,float(mid));
  75. fragColor=vec4(c*d,d*(0.85));
  76. }
  77. void fragment(){
  78. vec2 iResolution=1./TEXTURE_PIXEL_SIZE;
  79. mainImage(COLOR,FRAGCOORD.xy,iResolution);
  80. COLOR=vec4(vec3(texture(iChannel0,UV).r*texture(iChannel0,UV).a),1.);
  81. }