Godot 4: Blob shader (metaballs tutorial)

Поделиться
HTML-код
  • Опубликовано: 23 янв 2025

Комментарии • 6

  • @krzyszt0fus
    @krzyszt0fus 22 дня назад

    Happy New Year! 🥳

  • @gatheesha22
    @gatheesha22 24 дня назад +1

    shader_type canvas_item;
    uniform vec2 resoultion = vec2(600.0,400.0);
    uniform vec3 color: source_color = vec3(0.0, 0.3, 0.9);
    uniform float speed: hint_range(0.0, 1.0, 0.01) = 0.5;
    uniform bool clamped = false;
    struct MetaBall {
    float radius;
    float freq;
    float amp;
    };
    const MetaBall[] balls = {
    MetaBall(0.2, 2.0, 0.9),
    MetaBall(0.5, 1.0, 0.2),
    MetaBall(0.1, 0.2, 0.7)
    };
    float ball(vec2 uv, float radius) {
    return radius / dot(uv,uv);
    }
    void fragment() {
    vec2 uv = UV - 0.5;
    uv.x *= resoultion.x / resoultion.y;
    uv *= 2.0;
    float result = 1.0;
    for (int i = 0; i < balls.length(); i++) {
    float dir = mod(float(i), 2) * 2.0 - 1.0;
    MetaBall b = balls[i];
    vec2 offset = vec2(
    sin(TIME * b.freq * speed) * b.amp,
    cos(TIME * b.freq * speed) * b.amp * dir
    );
    result *= ball(uv + offset, b.radius);
    }
    if (clamped) {
    result = clamp(result, 0.0, 1.0);
    }
    COLOR = vec4(result * color, 1.0);
    }

    • @FencerDevLog
      @FencerDevLog  24 дня назад

      👍🏽

    • @gatheesha22
      @gatheesha22 23 дня назад

      @@FencerDevLog Thank you so much man you uploaded the video few minutes right before i started searching for one haha

    • @FencerDevLog
      @FencerDevLog  22 дня назад

      @@gatheesha22 Nice! And you are welcome. 😎