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.
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.
gpu particle simulation
Re: gpu particle simulation
This looks amazing, I'm going to check it out and look through the code.
Learning to Löve.
- alberto_lara
- Party member
- Posts: 372
- Joined: Wed Oct 30, 2013 8:59 pm
Re: gpu particle simulation
This looks pretty cool, is there any interaction with the window or is just a random behavior?
Re: gpu particle simulation
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.
Re: gpu particle simulation
I only see a dot moving slowly with a black background and clean cut borders. Not sure why.
Re: gpu particle simulation
there ispgimeno wrote:I only see a dot moving slowly with a black background and clean cut borders. Not sure why.
Code: Select all
local debug = false
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.alberto_lara wrote:This looks pretty cool, is there any interaction with the window or is just a random behavior?
This version also is doing sorting on the particles, so older ones are drawn closer to the camera.
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.
Re: gpu particle simulation
I get this when enabling debug:jonbro wrote:there ispgimeno wrote:I only see a dot moving slowly with a black background and clean cut borders. Not sure why.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.Code: Select all
local debug = false
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
Re: gpu particle simulation
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:
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...
Code: Select all
vec4 lookup = Texel(posTexture, vec2(mod(SpriteCount,particleCountSQRT)*1.0/particleCountSQRT+1/512.0, floor(SpriteCount/particleCountSQRT)/particleCountSQRT+1/512.0));
Re: gpu particle simulation
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.
On my work laptop though it runs fine.
Re: gpu particle simulation
Windows 7, canvases and shaders are fine, Love 10.1 - get blank white screen.
Who is online
Users browsing this forum: No registered users and 3 guests