gpu particle simulation

Showcase your libraries, tools and other projects that help your fellow love users.
jonbro
Prole
Posts: 8
Joined: Tue Oct 02, 2012 10:18 am

gpu particle simulation

Post by jonbro »

ink dr_p

I threw together a little GPU based particle system in love2d this weekend. All simulation and display happens in shaders, so it is fast as heck, and displaying 262k particles.

Image

There are a few strange implementation details, but hopefully the code is pretty readable. You can check it out on github, along with a few notes on how it all works.
User avatar
skyHights
Citizen
Posts: 78
Joined: Mon Aug 25, 2014 12:14 pm

Re: gpu particle simulation

Post by skyHights »

This looks amazing, I'm going to check it out and look through the code.
Learning to Löve.
User avatar
alberto_lara
Party member
Posts: 372
Joined: Wed Oct 30, 2013 8:59 pm

Re: gpu particle simulation

Post by alberto_lara »

This looks pretty cool, is there any interaction with the window or is just a random behavior?
User avatar
Skeiks
Citizen
Posts: 51
Joined: Wed Jan 28, 2015 1:51 pm

Re: gpu particle simulation

Post by Skeiks »

JonBro! How's it going? This is a really cool particle sim, I'm going to look through the code later. I can't wait to see what you make using Love2D, I really enjoy developing with it.
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: gpu particle simulation

Post by pgimeno »

I only see a dot moving slowly with a black background and clean cut borders. Not sure why.

Image
jonbro
Prole
Posts: 8
Joined: Tue Oct 02, 2012 10:18 am

Re: gpu particle simulation

Post by jonbro »

pgimeno wrote:I only see a dot moving slowly with a black background and clean cut borders. Not sure why.
there is

Code: Select all

local debug = false
up at the top of the code... if you turn that on, what kind of output do you get? Also, are you on 0.10? Also, this requires both shader and canvas support, and I don't know how widespread that is.
alberto_lara wrote:This looks pretty cool, is there any interaction with the window or is just a random behavior?
In this version it is just using curl noise to move the particles around. I have attached a version that has the particles influenced by the mouse position at the beginning of their life, and then noise at the end. Give this a second to warm up, because the particles fade in at the beginning of their life.
particles_with_mouse.love
(168.82 KiB) Downloaded 246 times
This version also is doing sorting on the particles, so older ones are drawn closer to the camera.
particles_no_alpha.love
(172.01 KiB) Downloaded 223 times
this one has the alpha turned off, so you can see the sorting behavior better. I also swapped in a particle with a little dropshadow.
Screen Shot 2016-03-09 at 1.08.00 PM.png
Screen Shot 2016-03-09 at 1.08.00 PM.png (649.18 KiB) Viewed 6751 times
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: gpu particle simulation

Post by pgimeno »

jonbro wrote:
pgimeno wrote:I only see a dot moving slowly with a black background and clean cut borders. Not sure why.
there is

Code: Select all

local debug = false
up at the top of the code... if you turn that on, what kind of output do you get? Also, are you on 0.10? Also, this requires both shader and canvas support, and I don't know how widespread that is.
I get this when enabling debug:
Image

It eventually fills the screen.

Yes, I'm on 0.10.1, and yes, my GC supports shaders and canvases. I've used both myself. OpenGL version supported is 3.3.0. My driver is admittedly old (nVidia 334.21, while the newest is 361.28), but it hasn't broken this bad so far.

EDIT: Just to ensure that the problem is not related to combining multicanvas and shaders, I've made a quick test. It worked as expected.

Code: Select all

local shader = love.graphics.newShader[[
    void effects( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords )
    {
        love_Canvases[0] = vec4(1.0, 0.5, 0.0, 1.0);
        love_Canvases[1] = vec4(0.0, 0.5, 1.0, 1.0);
    }
]]

local c1, c2 = love.graphics.newCanvas(), love.graphics.newCanvas()

function love.draw()
  love.graphics.setCanvas(c1, c2)
  love.graphics.setShader(shader)
  local sx, sy = love.graphics.getDimensions()
  love.graphics.circle("fill", sx/2, sy/2, sx/2)
  love.graphics.setCanvas()
  love.graphics.setShader()
  love.graphics.draw(c1, -sx/2, 0)
  love.graphics.draw(c2, sx/2, 0)
end
Image
jonbro
Prole
Posts: 8
Joined: Tue Oct 02, 2012 10:18 am

Re: gpu particle simulation

Post by jonbro »

huh, that is super strange. Like the data for the particles is there, but it seems it is failing to read the position texture in the render texture, or actually, it is reading only one position rather than getting the particle data lookup. I suspect I am doing some math in the glsl that is failing on your card. Specifically, the line that calculates texture coords in render_vert.glsl:

Code: Select all

vec4 lookup = Texel(posTexture, vec2(mod(SpriteCount,particleCountSQRT)*1.0/particleCountSQRT+1/512.0, floor(SpriteCount/particleCountSQRT)/particleCountSQRT+1/512.0));
The alternate issue is that something about the mesh creation code is jacked, and it isn't storing the correct data, but that feels less likely to me...
User avatar
Skeiks
Citizen
Posts: 51
Joined: Wed Jan 28, 2015 1:51 pm

Re: gpu particle simulation

Post by Skeiks »

I attempted to run this on my home PC and I received an error. I don't have the message handy but it mentioned that you have an unused variable in one of your shaders. It might just be a quirk of my specific video card but I've found that externs and variables that don't an impact the final pixel throw errors. When I get home I'll try it again and post the error if I still receive it. Maybe that's related to the weirdness pgimeno is getting?

On my work laptop though it runs fine.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: gpu particle simulation

Post by Ref »

Windows 7, canvases and shaders are fine, Love 10.1 - get blank white screen.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 7 guests