A game created for the Godot Wild Jam #21
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.2KB

  1. shader_type canvas_item;
  2. uniform vec2 sprite_scale = vec2(1.0, 1.0);
  3. uniform float distortion : hint_range(0.1, 100.0) = 8.0;
  4. uniform vec4 liquid_color_main : hint_color = vec4(0.1, 0.2, 0.8, 0.25);
  5. uniform vec4 liquid_color_surface : hint_color = vec4(0.1, 0.2, 1.0, 0.5);
  6. uniform float liquid_surface_thickness : hint_range(0.0, 1.0) = 0.2;
  7. uniform float wave_amp : hint_range(-1.0, 1.0) = 0.25;
  8. uniform float wave_freq : hint_range(0.0, 1.0) = 1.0;
  9. uniform float wave_scale :hint_range(0.0, 10.0) = 1.0;
  10. float rand(vec2 p){
  11. return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453123);
  12. }
  13. float noise(vec2 p){
  14. vec2 i = floor(p);
  15. vec2 f = fract(p);
  16. float a = rand(i);
  17. float b = rand(i + vec2(1.0, 0.0));
  18. float c = rand(i + vec2(0.0, 1.0));
  19. float d = rand(i + vec2(1.0, 1.0));
  20. vec2 cubic = f * f * (3.0 - (2.0 * f));
  21. return mix(a, b, cubic.x) + (c - a) * cubic.y * (1.0 - cubic.x) + (d - b) * cubic.x * cubic.y;
  22. }
  23. float ramp(float v, float f_min, float f_max){
  24. float res = (v - f_min) / (f_max - f_min);
  25. return max(0.0, min(1.0, res));
  26. }
  27. vec2 wavey_y(vec2 p, float time) {
  28. float dy = wave_amp * sin(wave_freq * (p.x * liquid_surface_thickness) * time);
  29. //return vec2(dx, dy);
  30. return vec2(p.x, p.y + dy);
  31. }
  32. void fragment(){
  33. vec2 noise1 = UV * sprite_scale * distortion;
  34. vec2 noise2 = UV * (sprite_scale * distortion) + 4.0;
  35. vec2 motion1 = vec2(TIME * 0.3, TIME * -0.4);
  36. vec2 motion2 = vec2(TIME * 0.1, TIME * 0.5);
  37. vec2 distort1 = vec2(noise(noise1 + motion1), noise(noise2 + motion1)) - vec2(0.5);
  38. vec2 distort2 = vec2(noise(noise1 + motion2), noise(noise2 + motion2)) - vec2(0.5);
  39. vec2 dsum = (distort1 + distort2) / 60.0;
  40. vec4 color = texture(SCREEN_TEXTURE, SCREEN_UV + dsum);
  41. color = mix(color, liquid_color_main, 0.3);
  42. color.rgb = mix(vec3(0.5), color.rgb, 1.4);
  43. float near_top = 1.0 - clamp((UV.y + dsum.y) / (liquid_surface_thickness / sprite_scale.y), 0.0, 1.0);
  44. color = mix(color, liquid_color_surface, near_top);
  45. float tedge_lower = 0.6;
  46. float tedge_upper = tedge_lower + 0.1;
  47. if (near_top > tedge_lower){
  48. color.a = 0.0;
  49. if (near_top < tedge_upper){
  50. color.a = (tedge_upper - near_top) / (tedge_upper - tedge_lower);
  51. }
  52. }
  53. COLOR = color;
  54. }