Real-Time Depth of field

About Truespace Archives

These pages are a copy of the official truespace forums prior to their removal somewhere around 2011.

They are retained here for archive purposes only.

Real-Time Depth of field // SDK, Plug-in & 3rd Party Area

1  |  

Post by jayr // Jan 20, 2009, 1:29am

jayr
Total Posts: 1074
pic
Not sure if this should go here or in the tech forum.


Is real time depth of field possible in truespace at the moment or would it need a plugin or script?

Post by Délé // Jan 20, 2009, 1:49am

Délé
Total Posts: 1374
pic
There is no real-time DOF at the moment, but it's got to be possible to create a DOF shader. I made a fog shader some time back, so I know for a fact that it's possible to calculate the distance and adjust an image accordingly. So it should be possible to blur the image (and perhaps apply a bit of alpha on the edges of the model) based on that distance.

That's where I get hung up though. I'm not sure how to blur an image with HLSL right now. Should be entirely possible though.

Post by parva // Jan 20, 2009, 4:53am

parva
Total Posts: 822
pic
Depth of Field is (as far as I know) possible via a scene effect shader like Bloom. The only problem is that you need the scene depth. Means that the depth of the scene and all objects in it are stored in zbuffer.

Currently I know no way to access or write zbuffer in truespace.

Post by jayr // Jan 20, 2009, 8:44am

jayr
Total Posts: 1074
pic
thanks for the replies guys. I'm not a programmer and a lot of the in depth features in 3d programs pass me by so i just wanted to get an idea if this was possible.


Would it be possible to make a new camera for the workspace that could blur things in the distance, or would this hit the z-buffer problem?

Post by parva // Jan 20, 2009, 9:33am

parva
Total Posts: 822
pic
Would it be possible to make a new camera for the workspace that could blur things in the distance, or would this hit the z-buffer problem?


yep, thats the problem.

It's a bit complicate to describe but take the render to texture scene.

This is generally the first step of what all the scene effects are made of.

A camera takes a shot/frame and renders this image into a texture. You now render this image as quad to the viewscreen. You can apply the same effects to that image as you do with general texture at materials. Thats enough for custom color effects (bloom which is nothing else as a kind of blurring and so on) but the tricky part are distances (and for depth of field as you know there is the need to know how far an object is away from the camera).


Now everyone know these greyscale images where objects close to the camera are brighter as in distance (or vice versa).


You can calculate this with the "eye distance" output from the Shaderinput brick but I found no way to use this with the whole scene.

That means that only objects that have a shader applied with this calculaton works.

Things like fog would be possible in this way, again just for individual objects that have this kind of shader applied but for blurring you need the output as render to texture.


If truespace had a similar technique to customize postprocess /scene effects as it does for DX materials then you can be sure a wide range of effects would be possible. Keep in mind the most effects in current games are done on a postprocess base (lensflare, godrays, fog, ambient occlusion, all this kind of visual effects like distortions, nightvision, hdr&tonemapping etc.).

Post by robert // Jan 21, 2009, 2:39pm

robert
Total Posts: 609
pic
Well it might be possible to do it like so: for each object in the scene record it's location, then do a distance calculation to the current view, a.k.a. the eye, and based on that do a post process blur with a blur distance related to the object distance.


Not sure how to implement it as such, but that would be the general idea.

Post by jayr // Feb 27, 2009, 12:44pm

jayr
Total Posts: 1074
pic
i think i may have found a way to fake this.


Is it possible to create a DX shader that adds a subtle blur when held infront of another object?


We could have layers of 'blury' materials that stay a certain distance from the camera (using the camera as it owner-mesh) it could be used to make a crude depth of field effect.

Post by jamesmc // Feb 27, 2009, 1:16pm

jamesmc
Total Posts: 2566
If they make a plug-in for Depth of Field, they should name it Myopia.

Post by parva // Feb 27, 2009, 11:11pm

parva
Total Posts: 822
pic
Is it possible to create a DX shader that adds a subtle blur when held infront of another object?


Like I said you can blur textures so you have to render the scene to a texture. 2 ways how to blur a texture with the gpu (Gauss or Poisson) are in the free Shaderpack.

Post by jayr // Feb 28, 2009, 4:55am

jayr
Total Posts: 1074
pic
i see what you mean parva, basicly render the background out and then re-import it as a texture and use a DX effect to blur it


what i was thinking of (which may not be possible) is something like this:http://www.lothissen.co.uk/depth.jpg


In this image the planes have the 'atmosphere' material applied to them, using a technique like this you could do a basic fog effect, lots of semi-transparent planes building the fog effect like sheets of tracing paper.

What i was wondering is if a very subtle distortion effect could be made into a material to apply to these planes so that the effect would add up the more planes there were i.e. the further away something was, the more planes would be in the way so the more distorted or blured it would look.


Is this possible?

Post by robert // Mar 1, 2009, 6:01am

robert
Total Posts: 609
pic
It would be possible to do a sort of intelligent instancing system.

Just have a bunch of planes and modify their distance based on various parameters.

Wouldn't actually be all too difficult to do, it'll all be in ratios so no complex math even.
Except for the texture maybe, that could very well be the hardest part.

Post by jayr // Mar 1, 2009, 6:16am

jayr
Total Posts: 1074
pic
It would be possible to do a sort of intelligent instancing system.


Just have a bunch of planes and modify their distance based on various parameters.


Wouldn't actually be all too difficult to do, it'll all be in ratios so no complex math even.

Except for the texture maybe, that could very well be the hardest part.


That's what i was thinking, that or just have the planes glued to the camera and have a different camera for different focal distances.


I have no idea about the texture though.

Post by blakeo // Mar 2, 2009, 3:33pm

blakeo
Total Posts: 214
pic
Hi Jayr


How about this as a proof of concept - for the crude/planes version anyway!


Use the "Render to Texture" library (you can find it in the libarary browser) combined with parva's poisson/gaussian blur linked to the camera(s) output(s) to paint the planes. The trick? Use near/far clipping to limit what the cameras see to the zones of blur. :)


How it works (3 cameras, 2 planes example - see image)


1. for each level, or zone, of blur you need a camera that see only what's in that zone - this can be achieved with near/far clipping. Each camera is positioned in exactly the same place. (in the image below there are three cameras at 0,0,0)


2. Postition the planes at the far limit of each zone and match the camera clipping to each zone so that the main camera sees only as far as the first plane, but no further. Camera 2 sees from *just* beyond plane 1 as far as plane 2. Camera 3 sees from plane 2 to infinity.


3. The planes need to increase in size the further from the cameras you go to keep the full effect in the main camrera.


4. Use the render to texture brick (if that's the right term) to paint plane 2 with what camera 3 sees, and use the parva's blur to , er, blur it :) Then paint plane 1 with what camera 2 sees and do the same.


5. Look through Camera 1 to see the effect. I guess you'd glue the cameras and planes to camera1 to be able to move around.


OK - this is *very* crude and doesn't take into account things like lighting/shadow casting of the planes themselves. Also, it would only work to make things more out of focus the further away from the camera they are, not close up. But the concept seems to work.


...and I'm not so good in the LE but learning. To get the hang of the blur effect I watched parva's demo vid that comes with the free shaders several times, and played around with the render to texture project a fair bit. I then exported the blur control and colour shaders for the planes up several levels so that the Render to Texture brick could link in at scene level and the blur effect could be adjusted easier.


...and I've probably made no sense trying to explain it :)


Here's the image.

B

Post by transient // Mar 2, 2009, 4:11pm

transient
Total Posts: 977
pic
That's really clever. :)


I think a real-time post processor is needed if truespace is going to keep up with what's currently on offer with blender. That and exe support.


Of course, we won't know if this is even on the drawing board until it arrives....:rolleyes:

Post by trueBlue // Mar 2, 2009, 6:26pm

trueBlue
Total Posts: 1761
pic
@ blakeo: I was going to try and put this concept together into one neat package and create an UI for it. The Render to Texture also supports Post Process too as in this case for each Camera/Plane. I'm fairly sure the the Clipping could be linked to the Planes, and controlled with a slider. If you want, upload the scene and I will hack away at it.

Post by parva // Mar 2, 2009, 11:58pm

parva
Total Posts: 822
pic
I think a real-time post processor is needed if truespace is going to keep up with what's currently on offer with blender. That and exe support.


You read my mind :D


...

clever solution blakeo indeed :)

Post by jayr // Mar 3, 2009, 1:19am

jayr
Total Posts: 1074
pic
that is really clever blekeo, nice one :D


a real-time post processor would be nice but then so would lightworks being moved over to the workspace.

Post by blakeo // Mar 8, 2009, 1:08pm

blakeo
Total Posts: 214
pic
Thanks everyone.


Trueblue: sorry for the delay! The scene is attached - I've replaced the head with a simple cylinder for filesize reasons :)


It's all a bit messy as I was mucking about with various shaders on the planes and stuff - so there's remnants of things floating around in there....


Let me know if you have any trouble with the file.

B
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2020. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn