Real time depth of field effect.

Blitz3D Forums/Blitz3D Programming/Real time depth of field effect.

CyberHeater(Posted 2004) [#1]
In a game. Is this possible. How would you go about it.


Rob Farley(Posted 2004) [#2]
No idea what you're talking about...

But if you're talking about changing the camera fog range, then yes you can.


Mustang(Posted 2004) [#3]
DoF? Sure, we had it in our 3DMark03 and the recent ATI Ruby demo has that too. Possible with Blitz3D as it is? No.


Rob Farley(Posted 2004) [#4]
What is Depth of Field?


koekjesbaby(Posted 2004) [#5]
sure its possible, first render the "far away part" by setting the camera near value to the distance where the blur should begin. and copy that to an image, blur the image en draw it. then set the clsmode of your camera to 0 and the far range to what the near value was above.

it's not the prettiest or fastest dof, but it is possible in blitz.

rob: depth of field is the blurring of far away and close up objects, a photography term really. in games it usually means that the background is blurred. as seen in the wind waker and mario kart double dash.


Rob Farley(Posted 2004) [#6]
If you want to blur things in the distance do a low res render of the "far away part" stick it on a quad and make the quad the full screen side, let the hardware do the blurring.


koekjesbaby(Posted 2004) [#7]
that's also an option, but standard hardware blurring is ugly. so i suggest using sswifts blurring method for better blurring.


Rob(Posted 2004) [#8]
more importantly, the transition between blur and non blur has to be nice.

Shaders are the only quality way


fredborg(Posted 2004) [#9]
It isn't that difficult in Blitz, I'll post an example later...


CyberHeater(Posted 2004) [#10]
Cheers Fredborg.


fredborg(Posted 2004) [#11]
Here: http://www.blitzbasic.com/codearcs/codearcs.php?code=1030

Have fun!


Avrigus(Posted 2004) [#12]
Fredborg you are a genius! If I start a thread asking to make my Blitz3D game look like Halo will you come back in a few days time with a code example? :-)


RifRaf(Posted 2004) [#13]
you think it would take him a few days ? :)


RifRaf(Posted 2004) [#14]
adds wicked cool depth.. but is a bit slow

http://www.brianedey.com\rifraf\dof.jpg


Mustang(Posted 2004) [#15]
Damn you Fredborg! :)

Allrighty, it IS possible to do using Blitz3D, sort of... "proper" way to do it would be something like this:

http://www.ati.com/developer/gdc/Scheuermann_DepthOfField.pdf

We used different technique in 3DMark03, but the basic principles were the same.


aCiD2(Posted 2004) [#16]
imho, that DoF looks more like radial (or zoom) blurring


Rob(Posted 2004) [#17]
Has anyone tried it with sswift's texture blur?


AntonyWells(Posted 2004) [#18]
Zombie Apocalypse alpha 1 had depth of field using the above method...copycat...;p
but as rob said without pixel shaders it's next to impossible to achieve a smooth transistion.
(Pats vividGL on back and makes love to it's pixel shader skins)

But as for the above shot, I'd say fred is making each 'blur' frame bigger or smaller than the last. This isn't the optimal way(because it creats a radial shilloute(sp?))
What you want to do is shift the 'frame buffer' around on it's x,y plane but always keep it at the same distance from the camera.

i.e for 10 frames,

for j=1 to 10
moveEntity depthLayer(j),centreX+cos(j*36),centreY+sin(j*36),centreZ
next

This cretes a very convincing and easily adjustable blur. because,

centreX+cos(j*36) cna be altered to, centreX+cos(j*36)*blurFactor...
bigger blur factor = more out of focus.

Reason for moveEntity is you parent the depth layers to the camera. So you can move it on it's x,y while still being perfectly aligned to the camera.(I.e to prevent any radial leakage.)


fredborg(Posted 2004) [#19]
Hi,

It was some old code I had lying around, so I didn't check it properly :) The effect is better now!


RifRaf(Posted 2004) [#20]
fredborg.. that looks good on your cubes, but throw the effect in to a real scene with any real distance and you get this.




fredborg(Posted 2004) [#21]
Change the spread value to something lower!


RifRaf(Posted 2004) [#22]
i put it to .01 and still did it..


RifRaf(Posted 2004) [#23]
nevermind.. i was using the second param as spread value :)
its causes a tear in the scene where the blur begins though.