Sign in to follow this  
Pthalicus

Particles with DOF

Recommended Posts

Good evening,

I'm just wondering how everyone else tackles the issue of integrating depth of field with particle systems. The usual method of using the depth buffer as input to the DOF effect won't work with transparency since only the nearest depth layer is stored (obviously) - resulting in distant transparent geometry being incorrect when behind closer transparent geometry.

It doesn't need to be perfect, it just needs to [i]look[/i] "ok".

Unfortunately, in this scenario all of the particles are packed throughout the scene - and the focal range for the DOF is fairly small - so the transition between in-focus, and out-of-focus, must be smooth. (So I can't say: "These are out-of-focus, and these are in-focus")

Any suggestions? My google-fu isn't great today.

Cheers,
Tom

Share this post


Link to post
Share on other sites
If you have a way to sort the particles from back to front you can use the particle depth to scale and blur them according to their circle of confusion and mix them all together with alpha blending. You could do the scaling of the bilboards in the geometry shader.

The DoF particles wouldn't really interact with the DoF of the rest of the scene but this shouldn't be too apparent depending on how the particles are used.

Share this post


Link to post
Share on other sites
Hmm. This is not something I've thought through clearly, but what if you scale the particles by their distance from the focal plane, and also bias the mip sample based on the distance? I'm thinking that if you deliberately sample a mipmap that is too small onto an expanded particle, you can create stretching that might make a reasonable fill-in for a blur.

Share this post


Link to post
Share on other sites
Possibly if, while rendering your particles, you take a secound copy of the depth buffer and output the particles depth but alpha blended. This may affect your DoF blur in just the right way. - Or it will look somewhat stupid, have not actually tested it.
Seems kind of excessive if you don't have much particles aswell.

Share this post


Link to post
Share on other sites
I'll agree with everyone else and say the more interesting approaches would be:[list]
[*][b][i]Inferred-lighting style dithered depth[/i][/b]
[list]
[*]Only draw transparency to some pixels and then resolve after DoF.
[*]Should "just work" and give particle lighting (See Volition's rain for an example), but likely low quality.
[/list][*][b][i]Draw particles after DoF and apply manually[/i][/b]
[list]
[*]I've played with this myself but never had the best results. This solves two issues though, one the DoF destroying your particles, and 2 your particles not getting the correct DoF.
[*]Draw the particles and scale and blur them (or cheat with mips and pre-blurred textures) after your DoF pass.
[*]You can have some fun putting e.g. a hexagon in the lower mips of a flame ember particle; Gives interesting results!
[/list][*][b][i]DoF pass per render batch[/i][/b]
[list]
[*]Another I've played with and had interesting (but expensive) results. This works well for larger and rare objects, e.g. a glass window.
[*]When drawing the window, apply DoF on the background based on the window to previous depth distance. Allow the window to depth write and then apply post DoF as usual.
[*]This will give a fairly correct layered DoF when the far original layer written will accumulate layers of DoF.
[*]Using a layered depth buffer approach is likely much cheaper, correct and flexlible though! ;-)
[/list]
[/list]
For the most part this is still just an "unsolved" issue though in most major engines, e.g. CryEngine and Unity both exhibit the artifact. Even the latest Unreal 4 screenshots show this problem, which means they've haven't found a robust real-time solution yet.

Note how most of the below particles are actually in the foreground:

[img]http://attackofthefanboy.com/wp-content/uploads/2012/05/unreal-engine-4-screenshots.jpg[/img]

[img]http://attackofthefanboy.com/wp-content/uploads/2012/05/f_unreal43_ss.jpg[/img] Edited by CukyDoh

Share this post


Link to post
Share on other sites
Thanks guys

ginkgo: Sorting [i]is [/i]possible[i], [/i]but a pain since the particles are generated on the GPU. Though I like the idea Promit and yourself mentioned about scaling the quads and varying the mip-sample. This might work nicely, and if it merges well with the scene DOF, I'll go with that - since it's relatively cheap.

JimC1664: I'm not sure that will look right, something about it doesn't feel right - I could additively blend the depth, then use that to find centre of the particles for that pixel, but that feels wrong.

CukyDoh: Looking at those images, it looks like they just completely ignored the particles depth, and applied the DOF using the scene depth after drawing the particles.
I've seen inferred lighting, and if I were using it, then yes DOF using each layer's depth would be nice.
DOF pass per render batch doesn't seem feasible in this case; the individual particle systems can merge together, so this might introduce "popping" artefacts. Also, there are many systems visible at once - meaning many DOF passes, which is extremely expensive in this case.

I'll go ahead with applying the DoF manually, scaling the particles, and varying the mip level and see how it looks.

Cheers guys.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this