CPU_object.tscn 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. [gd_scene load_steps=6 format=2]
  2. [ext_resource path="res://font.png" type="Texture" id=1]
  3. [ext_resource path="res://round.png" type="Texture" id=2]
  4. [ext_resource path="res://CPU_object.gd" type="Script" id=3]
  5. [sub_resource type="Shader" id=1]
  6. code = "shader_type canvas_item;
  7. render_mode blend_add;
  8. uniform vec4 color:hint_color;
  9. uniform vec4 text_col:hint_color;
  10. uniform int value;
  11. uniform int len;
  12. uniform sampler2D iChannel3;
  13. uniform float zoom_val; //only for outside zoom
  14. //https://www.shadertoy.com/view/tsdGzN
  15. // include global zoom
  16. void C(inout vec2 U, inout vec4 T, in int c, float z_v){
  17. U.x+=.5;
  18. if(U.x<.0||U.x>1.||U.y<0.||U.y>1. ){
  19. T+= vec4(0);
  20. }
  21. else{
  22. vec2 tu=U/16. + fract( vec2(float(c), float(15-c/16)) / 16.);
  23. tu.y=1.-tu.y;
  24. T+= textureGrad( iChannel3,tu, dFdx(tu/(16.*max(z_v,0.001))),dFdy(tu/(16.*max(z_v,0.001))));
  25. }
  26. }
  27. // X dig max
  28. float print_int(vec2 U, int val, float z_v) {
  29. vec4 T = vec4(0);
  30. int cval=val;
  31. int X=7;
  32. for(int i=0;i<X;i++){
  33. if(cval>0){
  34. int tv=cval%10;
  35. C(U,T,48+tv,z_v);
  36. cval=cval/10;
  37. }
  38. else{
  39. if(length(T.yz)==0.)
  40. return -1.;
  41. else return T.x;
  42. }
  43. }
  44. if(length(T.yz)==0.)
  45. return -1.;
  46. else return T.x;
  47. }
  48. vec4 add_text(in vec2 p, float z_v) {
  49. vec2 res=vec2(1.,.5);
  50. vec2 uv=(p-0.25)*2.;
  51. uv.y=1.-uv.y;
  52. int a=0;
  53. vec2 epos=vec2(-0.12*(float(len+a)-0.5),0.25);
  54. float c=print_int((uv*res-res/2.+epos)*2.,value,z_v);
  55. c=clamp(c,0.,1.);
  56. return vec4(c)*text_col*step(0.02,z_v);
  57. }
  58. void mainImage( out vec4 fragColor, in vec2 fragCoord, in vec2 iResolution , sampler2D iChannel0, float z_v)
  59. {
  60. vec2 uv=fragCoord/iResolution;
  61. vec4 tx=texture(iChannel0,uv);
  62. tx.rgb=tx.rgb+color.rgb*(1.-(tx.rgb));
  63. vec4 tf=add_text(uv,z_v);
  64. tx.rgb=mix(0.8*tx.rgb,tf.rgb*3.,tf.a);
  65. fragColor=tx;
  66. }
  67. void fragment(){
  68. vec2 iResolution=1./TEXTURE_PIXEL_SIZE;
  69. float z_v=zoom_val*iResolution.y/(1./SCREEN_PIXEL_SIZE).y;
  70. mainImage(COLOR,UV*iResolution,iResolution,TEXTURE,z_v);
  71. }"
  72. [sub_resource type="ShaderMaterial" id=2]
  73. shader = SubResource( 1 )
  74. shader_param/color = Color( 0.74902, 0.180392, 0.180392, 1 )
  75. shader_param/text_col = Color( 0.992157, 1, 0.207843, 1 )
  76. shader_param/value = 1234567
  77. shader_param/len = 7
  78. shader_param/zoom_val = 1.0
  79. shader_param/iChannel3 = ExtResource( 1 )
  80. [node name="CPU_object" type="Sprite"]
  81. material = SubResource( 2 )
  82. position = Vector2( 515.562, 327.28 )
  83. texture = ExtResource( 2 )
  84. script = ExtResource( 3 )