Skip to content

a gpu-side n-body simulation in lua/glsl, with love

License

Notifications You must be signed in to change notification settings

1bardesign/enbody

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enbody

Enbody is a real-time multi-function n-body sim on the gpu in under 700 lines of lua and glsl, made with love.

It features multiple different attractor functions to generate lots of different visually interesting animations.

Easy-to-run packaged builds are available on itch.io.

Explanation

Storage:

  • 3x 32 bit float texture buffer for particles (position, velocity, acceleration; rgb as 3d vector, alpha unused for now)
  • 1x mesh used as uv storage
  • 1x half resolution 16 bit float framebuffer

Procedure:

  • initialise the particles with a random walk
  • update acceleration with a pixel shader
    • sample all particle positions in order
    • calculate force from each other body based on attractor function
    • scale by computed particle mass
  • update velocity and position with simple additive rendering and alpha
    • apply acceleration to velocity
    • apply velocity to position
  • render particles with another shader into hdr framebuffer texture
    • fade existing rendering by some amount
    • render mesh as points
    • look up the position for the point from the texture
    • generate a nice colour based on the velocity
  • render framebuffer with sharpen shader
    • generate pixel-based outlines on bright particles

License

See the license file; MIT.

About

a gpu-side n-body simulation in lua/glsl, with love

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published