We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
depth of field (Read 1471 times)
depth of field
Aug 13th, 2008, 11:56pm
 
Hi all, I would like to apply a depth of field on my render. Does anyone know how I can do this? Luckily, all my objects are black, and are fogged white into the distance - so I can use my actual render as a depth map if need be. I tried mocking it up in aftereffects using the Lens Blur filter and using my render as the depth map as well, and it looks gorgeous ... If I can do that in realtime I would be very happy Tongue

I've googled it and found some places explaining how to do it.. but I'm not too keen on writing it all from scratch to be honest Tongue
Re: depth of field
Reply #1 - Aug 14th, 2008, 12:13am
 
How it can be done, is to render the scene say 10 times, each at 10% opacity, and jitter the camera position a small amount (with the same focus point) between each render.

Of course this relies on you being able to render the scene 10 times in a short space of time.
Re: depth of field
Reply #2 - Aug 14th, 2008, 6:46am
 
Hi John, thanks for the reply. In this particular case, my scene is actually orthographic so I'm not sure moving the camera will make a difference. The reasons behind why I've done that is in this thread
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=OpenGL;action=display;num=1216660583

but basically I've got ortho projection setup and am doing a fake 3D effect by fogging and scaling down all of my objects (nodes) relative to each ones center. So I dont think the camera jitter method would work in my case.

I thought I could blur the whole thing using a shader (I can already do that using the GLGraphics library) and then overlay it over the original using the zdepth as a mask, but that gives a weird black glow over things which are halfway away. So I was hoping there could be some GLSL shader which uses the zdepth information to adjust the radius of the blur, but couldn't find anything...
Re: depth of field
Reply #3 - Aug 14th, 2008, 11:11am
 
Yeah, I don't think the jitter method will work with Ortho stuff.

I'd have assumed that it should be possible to do it with GLSL, but I've not found anything.

Another possibility is to draw your objects to a separate PGraphics, then blur that the amount required for a given distance, and draw that image to the screen. But again, it depends how many objects you need to draw.
Re: depth of field
Reply #4 - Aug 14th, 2008, 9:24pm
 
Hi John, I've got it working now thanks using the GLGraphics library. I have hundreds of objects, all of which are long ribbons - so the post-process GLSL approach seemed the most appropiate. Summary of what I'm doing is:
- render scene to FBO
- run a fragment shader over the rendered texture N times (e.g. 20)
- the shader is a modified 3x3 Gaussian blur which also takes a depth map, and also the number of blur iteration we are doing.
- If the pixel from the depth map is greater than the normalized blur iteration we are doing, then do the blur, otherwise leave the fragment untouched.

I"ll post the code when its tidyed up and I'm sure its the best way to do it...
Re: depth of field
Reply #5 - Aug 21st, 2008, 5:43pm
 
hey memo, would be cool to see the code, it made me curious
Re: depth of field
Reply #6 - Aug 21st, 2008, 11:00pm
 
Hi, I posted the code I"m using at http://www.memo.tv/realtime_gpu_based_depth_of_field_backlight_in_processing_with_glsl_v0_1

though it is very very specific to my case... details are on the site... hope it helps in some way though
Page Index Toggle Pages: 1