Game Development Community

Camer Focus

by Travis Vroman · in Torque Game Engine · 05/31/2003 (7:11 pm) · 3 replies

does anyone know how to make the camera focus in TGE? For instance, blurring far away objects... Also, is there a way to load the buildings an such as they come into focus?

#1
05/31/2003 (8:37 pm)
Depth of field effects (AKA 'camera focus') are fairly rare in video games. AFAIK Torque doesn't do this, so you'll have to code it yourself.

Nvidia has a technique using vertex/fragment programs: http://developer.nvidia.com/view.asp?IO=depth_field

Alternately, you can use the accumulation buffer and jitter the eye point a bit to get a nice depth of field effect. Here's some info on that: http://www.sgi.com/software/opengl/advanced96/node42.html
#2
06/10/2003 (2:31 pm)
The common approach for depth-of-field using pixel shaders involves rendering the scene twice.

In the first pass, you render to a low-res texture. In the second pass, you render as normal... except -- for a given pixel, you need the normalized screen coordinates of every pixel. I guess you'd have to do this in a vertex shader (projecting the vertex point) and pass it along as a texture coordinate (and included with the relative pixel position, is also the depth value).

Anyway, using this texcoord and the depth value, you compare against the "focal depth" and use that as a key to linearly interpolate between the ordinary computed pixel color value and the same pixel in the low-res texture (lookup using the same normalized coordinate). The low-res texture will use bilinear filtering and what not and come out nice and blurry as opposed to the primary rendering. So as the lerp factor gets closer to choosing the primary rendering, you get sharp... and as you veer towards the texture, you get more blurry.
#3
06/10/2003 (9:27 pm)
That's a really slick technique. *notes it down*