Loading...
  OR  Zero-K Name:    Password:   

Depth of Field Shader

12 posts, 627 views
Post comment
Filter:    Player:  
sort
I actually made this for 0ad a while ago, but for various reasons it never made it into the game. Since I've been shadering recently I figured why not port it to zk? We can use all the shinies we can get. :)

The actual shader is really simple. It just interpolates between the full res screen image and a 1/4 scale image based on linear distance. I decided to use 2D distance instead of 3D so that when you have the camera zoomed out things near the camera won't be excessively blurry. That means under normal camera angles the stuff you're looking directly at won't be blurred but things that are 'far away', ie at the top of the screen will. I think the effect is pretty nice and it's not particularly performance heavy either.

Only two pictures this time. :P


+2 / -0

7 years ago
while I love to see graphical improvement, I regret to say that I see no different between this and normal rendering. at least from the screen shot anyway, am I missing something?
+1 / -0
Here's a direct comparison. It might be difficult to see if not full sized.

EDIT: note also that a lot of the ZK start screens show an effect exactly like this even though the game doesn't actually include it.

With:

Without:
+0 / -0

7 years ago
It fixes your lack of antialiasing, but besides that it's just like fog: Making things further away harder to see. Might be considered nice by some, but IMO dof only works on photo-realistic games.
+2 / -0

7 years ago
My lack of MSAA is out of respect for deferred rendering, which doesn't support it. Or shouldn't, unless someone actually went through the ridiculous hacks required to make that work. An FXAA shader is on my to-do list. :P

The same could be said about pretty much everything in zk though. "If the units and buildings looked better it would look better!". Duh. Then HDR and dynalights and so on would be less out of place. I think it's still better than not.
+0 / -0
I guess if you just do the downsampling it's not too bad, but having implemented a more complete DoF shader into Achron (one that takes into account the focus depth of the objects in the camera and does a flat circular blur) I would not recommend doing any more than this. It's a tricky shader to get right, especially for RTS, and it's quite GPU-intensive.
+0 / -0

7 years ago
Really fancy DoF is indeed difficult and expensive. That'd involve circles of confusion and complicated blurs in order to get objects very near the camera to be properly blurred and to get proper boke or at least a lens-resembling blur, and also requires defining the camera's focal point. I knew all that in the first place when I went for the dead simple solution that I ended up using.

Also the fancier DoFs are better suited to games that are character centric, which ZK is not. In RTS it's difficult to predict what the user will actually be looking at so even autofocusing the camera would be impractical and more annoying than cool. I prefer simple and cheap anyway.
+0 / -0
In Achron I went for 2 cheats: Focal lengths were determined such that they guaranteed objects in a circle 1/3rd of the screen wide from the centre were in focus, and the circle of confusion calculations were biased towards blurring distant objects, in a kind of telephoto effect, but only when the center object was really close to the camera. If the center was distant then almost no blurring occurred.
+0 / -0

7 years ago
HDR and DOF are both live (but not enabled by default) as of today.

You can find them under:
Settings/Graphics/HDR (Experimental)
and
Settings/Graphics/Effects/Depth of Field

respectively.
+0 / -0
Skasi
I never understood how anybody could see "reduce image quality" as an actual good game feature. Why would anybody deliberately not want to be able to make out what's on their screen?
+1 / -0
The point of DoF is to make it easier to focus on important elements on the screen. It's kinda silly in an RTS game (speaking as someone who implemented it in one), but in a first or third person over-the-shoulder game it tends to work pretty well. I find it's primarily used in cinematics in practice, for the same reason it's used in film (to direct focus).

Also, USrankaeonios's implementation is very simple and resource-cheap, which is why it's literally just "reduce image quality" rather than a full radial blur. Reducing the image quality causes the GPU to automatically do bilinear filtering, which is similar to (though less thorough and controlled than) what the full blur would do, and usually a full blur shader will use a few copies of the screen at various sizes to handle wider blur radii more efficiently.
+0 / -0

7 years ago
I also reduced the maximum amount of blur so that objects far away won't be obscured as much as they are in the screenshots in this thread. My goal was only to make faraway objects appear softer rather than to blur them to death.

Also there's a modifier for camera height so that when you zoom out the "in-focus" area is larger.
+0 / -0