Depth of field effect

Another feature (probably easire to do than shadowmapping the other thing i was whining for :wink: ). What do you think? Probably a simple render pass that uses distance from camera and blurs the meshes?? Or how do they used to do it normally? :slight_smile:

Hi,

There are many techniques to implement DoF, but this : http://www.reanmachine.com/2008/03/11/depth-of-field-simplified/ can be a good start I think. Never tryed to implement it myself but those explanations seems quite clear.



I would love to have DoF in JME !

There's a 3 pass GLSL depth of field example in ATI's RenderMonkey tool. It should be fairly easy to port that to jME.

it's very easy to modify the blur shader used in our bloom effects etc to adjust the sample distance based on the z distance.



i tried it some 2.5 years ago: http://www.jmonkeyengine.com/jmeforum/index.php?topic=2663.msg20203#msg20203

MrCoder said:

it's very easy to modify the blur shader used in our bloom effects etc to adjust the sample distance based on the z distance.

i tried it some 2.5 years ago: http://www.jmonkeyengine.com/jmeforum/index.php?topic=2663.msg20203#msg20203


thanks! I've modified by your advice - uncommenting the lines in it. I don't know why this isn't already as a separate render pass in jME if you've done it 2.5 years ago and yet bloom is in - but this is really cool! :)



http://forum.freegamedev.net/index.php?t=msg&goto=10282

The thing is to comment out in the GLSL shaders some lines plus modifying the BloomRenderPass to set a 'depth' parameter, and fine tune the parameters of the shader. I've created a DepthOfFieldPass in jcrpg based on it. I can create a package /patch later if you want. (I'm yet using jme 1.0)

okay, I've talked a bit about this with MrCoder, and it seems it's not a perfect implementation because some z checks and such should be added. So probably this should be made a bit more advanced. Anyway I'll post it somehow here so we can work on it a bit more before a perfect version will be realized.


http://1.bp.blogspot.com/_f57_nB05Gno/SK9cZSXqopI/AAAAAAAAAv4/mAZzS6HUwg0/s1600-h/DoF2.jpg

a better shot for showing what the deal is about.

I don't see any depth of field effect in that screenshot.

Momoko_Fan said:

I don't see any depth of field effect in that screenshot.


Do you have your glasses on?  }:-@ :) Well probably the fog state is making it hard to spot, but if you don't see it there it will be hard to convince you that it's there! I hope others have better luck with it.  8)

Maybe a side-by-side showing the same view with and without the depth, that would be cool.

Ah, I see it now. You might want to use a skybox, cause the blue stuff looks awefully wierd. The depth of field is so subtle that it makes the whole effect useless… You might want to decrease the distance at which it blurs and increase the blur intensity.

Well, now I've been tinkering around with this, and I've decided to drop this version - it isn't working quite well it's just an illusion how it blurs the distant parts because of the light colors of the far away parts (fogged). I'll be working on porting http://dword.dk/blog/software/ogre/dof/  this to have a real good DoF.

Is it possible to have a DoF as obvious as here : http://i78.photobucket.com/albums/j86/Goku1983d/Crysis/ScreenShot0003.jpg  ?

Pretty obvious in the old posts i sent a link to above isnt it? (http://www.jmonkeyengine.com/jmeforum/index.php?topic=2663.msg20203#msg20203)

I’m on it currently half way there. When its ready i’ll release the code:



currently the final shader needs work yet, but depth texture generation is okay:

http://imagebin.org/25076

Oh yeah, here we go:







http://forum.freegamedev.net/index.php?t=getfile&id=1269&private=0



It’s now a fully working DoF :slight_smile:



Soon codes will follow…i have to clean it up, and add some parameters

Oooh… Looks cool  :smiley:

Can't wait to try it.  XD

thats cool, this effect can also be used to show result of eating poisoned mushrooms :slight_smile:

on the close up trees you can see the bleeding issues i was talking about. if you wanna get rid of those you need to test for diff in z

MrCoder said:

on the close up trees you can see the bleeding issues i was talking about. if you wanna get rid of those you need to test for diff in z


Well, two things occurred to me since the shots:

- I didn't add texture alpha channel check to the Depth Texture drawing shader. Now this closed much of the 'bleeding', because transparent parts of the foliage quads were handled as opaque. Now i've solved this:


   vec4 texCol = texture2D(mainTexture,gl_TexCoord[0].st);
...
   if (texCol.a<0.1)
   {
      texCol.a = 0;
   }
   sum.a = texCol.a;
   gl_FragColor = sum;



This way transparent parts are not drawn over the image preventing that kind of problem like missing or inadequate blurring at foliage textures.

The second thing - yeah, this still doesn't solve bleeding at parts where blurred/non-blurred parts are near to each other.

But my idea would be (instead of z check which would mean another pass with rendered spacial) to use the depth texture part and when blurring not only sample the full screen quad texture (the prerendered scene image), but the depth image as well at the blur points to check if the given point is at the same depth - and if not don't use it for blurring. Any comment on this idea?