A game created for the Godot Wild Jam #21
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

105 行
2.7KB

  1. shader_type canvas_item;
  2. uniform vec4 cell_color : hint_color;
  3. uniform float cell_energy : hint_range(1.0, 20.0) = 1.0;
  4. uniform float rimWidth : hint_range(1.0, 3.0) = 2.0;
  5. uniform vec4 rim_color : hint_color;
  6. uniform float fisheye_power = 2.0;
  7. uniform float wave_amp : hint_range(-1.0, 1.0) = 0.25;
  8. uniform float wave_freq : hint_range(0.0, 1.0) = 0.25;
  9. uniform float wave_scale :hint_range(0.0, 10.0) = 1.0;
  10. vec2 random2(vec2 p){
  11. return fract(sin(vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)))) * 43758.5453);
  12. }
  13. float ramp(float v, float f_min, float f_max){
  14. float res = (v - f_min) / (f_max - f_min);
  15. return max(0.0, min(res, 1.0));
  16. }
  17. float CellularNoise(vec2 vUV, float scale, float time){
  18. // Code modified from...
  19. // https://thebookofshaders.com/12/
  20. vec2 st = vUV * scale;
  21. //st.x = vres.x/vres.y;
  22. vec2 i_st = floor(st);
  23. vec2 f_st = fract(st);
  24. float min_dist = 1.0;
  25. for (int y = -1; y <= 1; y++){
  26. for (int x = -1; x <= 1; x++){
  27. vec2 neighbor = vec2(float(x), float(y));
  28. vec2 point = random2(i_st + neighbor);
  29. point = 0.5 + (0.5 * sin(time + (6.2831 * point)));
  30. float dist = length((neighbor + point) - f_st);
  31. min_dist = min(min_dist, dist);
  32. }
  33. }
  34. return min_dist;
  35. }
  36. vec2 fisheye(vec2 p) {
  37. // Function borrowed and slightly modified from...
  38. // https://gist.github.com/henriquelalves/989fdd72e10c90091188
  39. p *= 2.0;
  40. p -= vec2(1.0, 1.0);
  41. if (length(p) >= 1.5){return p;}
  42. //return p;
  43. if(p.x > 0.0){
  44. float angle = p.y / p.x;
  45. float theta = atan(angle);
  46. float radius = length(p);
  47. radius = pow(radius, fisheye_power);
  48. p.x = radius * cos(theta);
  49. p.y = radius * sin(theta);
  50. } else {
  51. float angle = p.y / p.x;
  52. float theta = atan(angle);
  53. float radius = length(p);
  54. radius = pow(radius, fisheye_power);
  55. p.y = radius * sin(-theta);
  56. p.x = radius * cos(theta);
  57. p.x = - p.x;
  58. }
  59. return 0.5 * (p + vec2(1.0,1.0));
  60. }
  61. vec2 wavey(vec2 p, float time) {
  62. float dx = wave_amp * sin(wave_freq * (p.y * wave_scale) * time);
  63. float dy = wave_amp * cos(wave_freq * (p.x * wave_scale) * time);
  64. //return vec2(dx, dy);
  65. return vec2(p.x + dx, p.y + dy);
  66. }
  67. void fragment(){
  68. float n = ramp(CellularNoise(wavey(fisheye(UV.xy), TIME), 5.0, TIME * cell_energy), 0.2, 0.9);
  69. float rim = length(vec2(0.5, 0.5) - (UV.xy));
  70. float mask = 1.0;
  71. if (rim > 0.5){
  72. rim = 0.0;
  73. mask = 0.0;
  74. }
  75. vec4 r_color = rim_color;
  76. rim = ramp(pow(rim, 4.0 - rimWidth), 0.125, 0.5);
  77. vec4 color = vec4(((cell_color.rgb * 0.5) + (texture(SCREEN_TEXTURE, wavey(SCREEN_UV, TIME*2.0)).rgb * 0.5)) * n, n);
  78. if (mask > 0.0){
  79. if (rim >= 0.9 || rim > n){
  80. color = color + vec4(rim_color.rgb * rim, rim);
  81. }
  82. } else {
  83. color.a = 0.0;
  84. }
  85. COLOR = color;
  86. }