Advertisement
Lakamfo

Godot 4.x Crosshair shader

Mar 2nd, 2024
1,075
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Godot GLSL 3.78 KB | Source Code | 0 0
  1. shader_type canvas_item;
  2.  
  3.  
  4. float shape_polygon(vec2 uv, float sides, float size, float edge) {
  5.     uv = 2.0*uv-1.0;
  6.     edge = max(edge, 1.0e-8);
  7.     float angle = atan(uv.x, uv.y)+3.14159265359;
  8.     float slice = 6.28318530718/sides;
  9.     return clamp((1.0-(cos(floor(0.5+angle/slice)*slice-angle)*length(uv))/size)/edge, 0.0, 1.0);
  10. }
  11.  
  12.  
  13. vec2 transform2_clamp(vec2 uv) {
  14.     return clamp(uv, vec2(0.0), vec2(1.0));
  15. }
  16.  
  17. vec2 transform2(vec2 uv, vec2 translate, float rotate, vec2 scale) {
  18.     vec2 rv;
  19.     uv -= translate;
  20.     uv -= vec2(0.5);
  21.     rv.x = cos(rotate)*uv.x + sin(rotate)*uv.y;
  22.     rv.y = -sin(rotate)*uv.x + cos(rotate)*uv.y;
  23.     rv /= scale;
  24.     rv += vec2(0.5);
  25.     return rv;
  26. }
  27.  
  28.  
  29. uniform float width = 0.1;
  30. uniform float lenght = 0.4;
  31. uniform float spread = 0.265;
  32.  
  33. const float p_o166635_translate_y = 0.000000000;
  34. const float p_o166635_rotate = 90.000000000;
  35.  
  36. const float p_o68924_sides = 4.000000000;
  37. const float p_o68924_radius = 0.990000000;
  38. const float p_o68924_edge = 0.000000000;
  39. const float p_o262102_translate_y = 0.000000000;
  40. const float p_o262102_rotate = 90.000000000;
  41. const float p_o262105_sides = 4.000000000;
  42. const float p_o262105_radius = 0.990000000;
  43. const float p_o262105_edge = 0.000000000;
  44. const float p_o329162_translate_x = 0.000000000;
  45. const float p_o329162_rotate = 0.000000000;
  46. const float p_o329171_sides = 4.000000000;
  47. const float p_o329171_radius = 0.990000000;
  48. const float p_o329171_edge = 0.000000000;
  49. const float p_o329165_translate_x = 0.000000000;
  50. const float p_o329165_rotate = 0.000000000;
  51. const float p_o329168_sides = 4.000000000;
  52. const float p_o329168_radius = 0.990000000;
  53. const float p_o329168_edge = 0.000000000;
  54.  
  55. void fragment() {
  56. float o68924_0_1_f = shape_polygon((transform2_clamp(transform2((UV), vec2(spread*(2.0*1.0-1.0), p_o166635_translate_y*(2.0*1.0-1.0)), p_o166635_rotate*0.01745329251*(2.0*1.0-1.0), vec2(width*(2.0*1.0-1.0), lenght*(2.0*1.0-1.0))))), p_o68924_sides, p_o68924_radius*1.0, p_o68924_edge*1.0);
  57. vec4 o166635_0_1_rgba = vec4(vec3(o68924_0_1_f), 1.0);
  58. float o262105_0_1_f = shape_polygon((transform2_clamp(transform2((UV), vec2(-spread*(2.0*1.0-1.0), p_o262102_translate_y*(2.0*1.0-1.0)), p_o262102_rotate*0.01745329251*(2.0*1.0-1.0), vec2(width*(2.0*1.0-1.0), lenght*(2.0*1.0-1.0))))), p_o262105_sides, p_o262105_radius*1.0, p_o262105_edge*1.0);
  59. vec4 o262102_0_1_rgba = vec4(vec3(o262105_0_1_f), 1.0);
  60. float o329171_0_1_f = shape_polygon((transform2_clamp(transform2((UV), vec2(p_o329162_translate_x*(2.0*1.0-1.0), spread*(2.0*1.0-1.0)), p_o329162_rotate*0.01745329251*(2.0*1.0-1.0), vec2(width*(2.0*1.0-1.0), lenght*(2.0*1.0-1.0))))), p_o329171_sides, p_o329171_radius*1.0, p_o329171_edge*1.0);
  61. vec4 o329162_0_1_rgba = vec4(vec3(o329171_0_1_f), 1.0);
  62. float o329168_0_1_f = shape_polygon((transform2_clamp(transform2((UV), vec2(p_o329165_translate_x*(2.0*1.0-1.0), -spread*(2.0*1.0-1.0)), p_o329165_rotate*0.01745329251*(2.0*1.0-1.0), vec2(width*(2.0*1.0-1.0), lenght*(2.0*1.0-1.0))))), p_o329168_sides, p_o329168_radius*1.0, p_o329168_edge*1.0);
  63. vec4 o329165_0_1_rgba = vec4(vec3(o329168_0_1_f), 1.0);
  64. float o293599_0_h = 0.0;
  65. int o293599_0_i = 0;
  66.  
  67. float o293599_0_h1 = (dot((o166635_0_1_rgba).rgb, vec3(1.0))/3.0);
  68. if (o293599_0_h1 > o293599_0_h) {
  69.     o293599_0_h = o293599_0_h1;
  70.     o293599_0_i = 1;
  71. }
  72.  
  73. float o293599_0_h2 = (dot((o262102_0_1_rgba).rgb, vec3(1.0))/3.0);
  74. if (o293599_0_h2 > o293599_0_h) {
  75.     o293599_0_h = o293599_0_h2;
  76.     o293599_0_i = 2;
  77. }
  78.  
  79. float o293599_0_h3 = (dot((o329162_0_1_rgba).rgb, vec3(1.0))/3.0);
  80. if (o293599_0_h3 > o293599_0_h) {
  81.     o293599_0_h = o293599_0_h3;
  82.     o293599_0_i = 3;
  83. }
  84.  
  85. float o293599_0_h4 = (dot((o329165_0_1_rgba).rgb, vec3(1.0))/3.0);
  86. if (o293599_0_h4 > o293599_0_h) {
  87.     o293599_0_h = o293599_0_h4;
  88.     o293599_0_i = 4;
  89. }
  90. float o293599_0_1_f = o293599_0_h;
  91.     COLOR = vec4(vec3(o293599_0_1_f), o293599_0_1_f);
  92. }
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement