Forum

Adding volumetric fog to a Quake engine

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

Adding volumetric fog to a Quake engine

Postby goldenboy » Fri Jun 11, 2010 11:45 am

how insane is it, on a scale from 1 - 10?
User avatar
goldenboy
 
Posts: 924
Joined: Fri Sep 05, 2008 11:04 pm
Location: Kiel

Postby leileilol » Fri Jun 11, 2010 11:53 am

heffo did it once, so i'd put it on a 62

The big problem is how are you going to 'define' the fog in just plain Q1BSP? Q3BSP has native support for such thing in surfaceparms with shaders.
i should not be here
leileilol
 
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Postby goldenboy » Fri Jun 11, 2010 11:58 am

content type?

*fog

or func_fog, similar to func_illusionary / func_water?
User avatar
goldenboy
 
Posts: 924
Joined: Fri Sep 05, 2008 11:04 pm
Location: Kiel

Postby Spike » Fri Jun 11, 2010 1:25 pm

you could attach volumetric fog to a func_fog entity, yeah... Then you could move it around... *cough*.

For volumetric fog to be effective, you need to define the fog using a plane. Anything one side is fogged, anything the other is not (unless the view is inside the fog in which case its all fogged relative to the distance to the plane rather than the surface in question).

Due to needing a plane, you can't just attach it to a content type without there being restrictions.
You could flow through ajacent nodes and detect the plane above it and use that for the region.
But then you can't have underwater fog!
Plus its common enough to have multiple such top surfaces.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby metlslime » Fri Jun 11, 2010 6:17 pm

You basically create a brush entity and hard-code the engine to look for a specific classname (such as "fog") I tried this back when i first started fitzquake, and got it about 50% working. I started with teh assumption that fog volumes were convex, but could be placed arbitrarily (including letting you see multiple faces of them) My basic technique was:

1. using each fog front face in turn, create a portal and render all fog backfaces clipped to that portal. (If you are inside the volume, there are no front faces and you can just render the backfaces unclipped.) The alpha of each vertex is determined by the length of the vector through the volume (ray from camera clipped to front face)

2. the only remaining task is drawing the fog blend on top of entities that are inside or partially inside the fog volume. If fully inside, you can render all faces using the same "clip to a portal" technique as above. If they are partially outside, that's the part i never solved. For alias models you could set alpha to zero for any vertex outside teh volume, since alias triangles are small. For brushmodels you might need to split any polygons that cross the boundary.

---

I think there's an opengl extension to make fog easier by letting you define a front plane and it will calculate density correctly based on the distance behind the plane to the surface being drawn. So you could use that to make the above technique easier. Or you could just get really restrictive like quake3 did, and then your work gets really easy. (only one front face and no backfaces allowed to be visible.)
metlslime
 
Posts: 316
Joined: Tue Feb 05, 2008 11:03 pm

Postby Spike » Fri Jun 11, 2010 6:32 pm

If you want to draw emulated fog, the typical way to specify intensities is with a texture coord and a 1d texture(or 2d with a height of 1), with texture clamping instead of wrapping.
The texture coord is then correctly clamped so you do not have to worry about large surfaces crossing the fog plane.
This results in each vertex being processed as just tc_s = DotProduct(vertex,planenormal)-planedist.
Preferably in a vertex program. Your foreground colour is also a constant for every vertex, and your t texture coord does not matter.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK


Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest