Simulating 2D Gravity with Compute Shaders in Godot

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

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

  • @Higgsinophysics
    @Higgsinophysics Месяц назад +1

    I always knew the biggest G was the gravity constant. Awesome video

  • @Gunterson-ez4tn
    @Gunterson-ez4tn Месяц назад +1

    Good video! Since you're using compute shaders already, a multi-level integral sum technique would be way more efficient. Hierarchical grid-based methods work great for 2d gravity where accuracy is not required to be perfect, otherwise tree-hut/multipole methods will be better - though way slower. You could use a 2D prefix sum grid (and parallel scan; for better gpu use) to rapidly estimate mass distribution, then gather acceleration contributions at different radii (3^n squares) and directions around each particle. The basic idea is that each particle looks at increasingly large square regions in 8 cardinal directions, summing up total mass from the prefix sum grid to estimate gravitational pull at that scale. This gives O(n) scaling instead of O(n^2), and the hierarchical multi-level approach means nearby particles still interact precisely while distant ones are approximated efficiently. The error scales well with distance. The technique is well-suited for GPU since the lookups are coherent and the prefix sum can be computed in parallel.
    You'd still get visually plausible gravity but with dramatically better performance characteristics. Since you're already using compute shaders, implementing the prefix sum and multi-level lookups should be straightforward. The extra memory overhead from the grid is minimal compared to the computational savings.
    You could probably get ~5-75 million particles running at real-time, depending on your hardware and implementation.

    • @ThePathfindersCodex
      @ThePathfindersCodex  Месяц назад

      Wow thanks! I'll check out multilevel integral sums and grid based approaches and see where that leads.

  • @mikhailhumphries
    @mikhailhumphries Месяц назад +2

    Bro can you do course on shaders basics with mathematics required?

  • @ThePathfindersCodex
    @ThePathfindersCodex  Месяц назад

    Gavity... Lol