GPU accelerated volumetric shadowbuffer

Showcase your libraries, tools and other projects that help your fellow love users.
Jorzi
Prole
Posts: 7
Joined: Wed Mar 19, 2014 9:14 am

GPU accelerated volumetric shadowbuffer

Post by Jorzi »

After getting inspired by PriorBlue's Light vs Shadow engine, I decided to tackle the problem of semitransparent shadows in arbitrary shapes of varying optical density. Since this requires some serious computing I implemented all the heavy calculations as fragment shaders.

The demo starts with a black screen but you can paint in stuff with lmb and rmb.
Attachments
volumetric_paint.love
(2.1 MiB) Downloaded 424 times
volumetric_shadow_buffer.jpg
volumetric_shadow_buffer.jpg (40.02 KiB) Viewed 7683 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: GPU accelerated volumetric shadowbuffer

Post by Robin »

Holy crap that's heavy. I only get 2 FPS out of it on my trusty laptop.
Help us help you: attach a .love.
Jorzi
Prole
Posts: 7
Joined: Wed Mar 19, 2014 9:14 am

Re: GPU accelerated volumetric shadowbuffer

Post by Jorzi »

Hi, what's your GPU?
What the algorithm does is it starts by converting the map into polar coordinates, then it integrates (cumulative sum) over the radius, i.e. downwards on the texture. The integration is currently very unoptimized and could theoretically be reduced from O(N^2) to O(N), but I have to figure out how to do that on the GPU.

Meanwhile, if you want to hack the code, try lowering the range (the third component) of the light source for a smaller shadow buffer.
I personally get 60FPS on my gtx 560 but I guess that's a little hardcore for a 2d game :P

Btw, forgot to write that you can move the light source with the arrow keys and change the brush size with the mouse wheel.
User avatar
PriorBlue
Prole
Posts: 43
Joined: Fri Feb 28, 2014 3:46 am
Location: Munich, Germany

Re: GPU accelerated volumetric shadowbuffer

Post by PriorBlue »

Wow the shadow quality is amazing, i have made a ray tracing pixel shadow engine by my self (http://www.love2d.org/forums/viewtopic. ... er#p163757) with additional glass effect, but it was very slow so i skipped it. I hope you can make it better :).

Oh and please give the floor a color or texture, so we can see the nice shadow effect more easily :).
Jorzi
Prole
Posts: 7
Joined: Wed Mar 19, 2014 9:14 am

Re: GPU accelerated volumetric shadowbuffer

Post by Jorzi »

Yeah I looked at that one :) I think yours could be pretty fast if done with shaders.

Here's an updated version. I changed the absorption so that it multiplies by the absorption factor rather than subtracting it. Also added background
Attachments
volumetric_paint_v0.1.love
(1.99 MiB) Downloaded 289 times
User avatar
xXxMoNkEyMaNxXx
Party member
Posts: 206
Joined: Thu Jan 10, 2013 6:16 am
Location: Canada

Re: GPU accelerated volumetric shadowbuffer

Post by xXxMoNkEyMaNxXx »

This looks great! To make it as complicated as possible, I would be trying to use a solved integral, but you would probably end up with erf or Ei, so you'd have to implement them if they come up... I like solved integrals. Also, since this is in 2D, wouldn't it be an area-metric shadow buffer? :rofl:
Jorzi
Prole
Posts: 7
Joined: Wed Mar 19, 2014 9:14 am

Re: GPU accelerated volumetric shadowbuffer

Post by Jorzi »

What is a solved integral and can you apply it to numerical computations?
Also, I guess you're right, except area-metric isn't really a word :P You could think of it as volumetric for an infinitesimal slice dz.

Anyway I have tried to calculate the integral(/cumulative product) over the radius more efficiently but I really need to do it purely on the gpu, otherwise it'll be too slow...
The current algorithm recalculates the product of all previous elements for each pixel, but it's still faster than calculating anything in lua.
User avatar
AntonioModer
Party member
Posts: 202
Joined: Fri Jun 15, 2012 5:31 pm
Location: Belarus
Contact:

Re: GPU accelerated volumetric shadowbuffer

Post by AntonioModer »

I run this demo ( volumetric_paint_v0.1) in LOVE 0.9.2, and have bug:
bug in 0.9.2.jpg
bug in 0.9.2.jpg (71.26 KiB) Viewed 6790 times
I try fix this, but not successful.
Help to fix this bug, please.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: GPU accelerated volumetric shadowbuffer

Post by T-Bone »

When I try to run it on Löve 0.9.2 on Windows 8.1, I get

Code: Select all

boot.lua:339: conf.lua:9 attempt to index field 'screen' (a nil value)
User avatar
AntonioModer
Party member
Posts: 202
Joined: Fri Jun 15, 2012 5:31 pm
Location: Belarus
Contact:

Re: GPU accelerated volumetric shadowbuffer

Post by AntonioModer »

T-Bone wrote:When I try to run it on Löve 0.9.2 on Windows 8.1, I get

Code: Select all

boot.lua:339: conf.lua:9 attempt to index field 'screen' (a nil value)
Change in conf.lua variable "screen" to "window".
Help: https://www.love2d.org/wiki/Config_Files
Post Reply

Who is online

Users browsing this forum: No registered users and 161 guests