Quake 4 & Doom 3: Nested Lights for Volumetric Light Mapping

Discussion for Level editing, modeling, programming, or any of the other technical aspects of Quake
Post Reply
nbohr1more
Posts: 140
Joined: Thu Sep 09, 2010 1:44 pm

Quake 4 & Doom 3: Nested Lights for Volumetric Light Mapping

Post by nbohr1more »

After playing around in Doom 3's pak000.pk4 I stumbled upon a light shader with two map stages in it. After digging around the web I found an old Doom3world discussion that explains that having two maps in one light shader material definition is less expensive than two overlapping lights as the vertex and shadow calculations are only done once. Armed with this I am proposing a Volume Light Map solution for these engines that does not require any changes to the Interaction Shader.

Code: Select all

lights/My_Custom_Light1

{
  
  {

    lightFalloffImage makeIntensity( textures/My_Custom_Light1_Z ) // Falloff Image

    { 
     forceHighQuality
     map textures/My_Custom_Light1_XY // Z-Projection Image
     zeroClamp
     scale num, num
    }

  } 
  
  {

    lightFalloffImage makeIntensity( textures/My_Custom_Light2_Z ) // Falloff Image

    { 
     forceHighQuality
     map textures/My_Custom_Light2_XY // Z-Projection Image
     zeroClamp
     scale num, num
    }

  } 

}

The process:

1) Use some application to bake a 3D ambient map for your level to a 3D texture
2) Slice the texture into 2D projections and 1D falloffs (based on height)
3) Optimize the number of needed slices by combining parallel brightness values
4) Create a "texture atlas" that has all the slices for both image types
5) Use the scale keyword to only access the needed image within the atlas per stage

So the problem is:

Will anyone create a tool that automates this conversion from 3D texture to texture atlas?

Maybe someday I will be a good enough coder to achieve such a feat but I thought I would throw this possibility out and see if anyone will bite.

You could, of course, manually imagine the needed shapes and falloffs but it would be time consuming...

...and it would require a pretty high IQ...

:)
o'dium
Posts: 11712
Joined: Sun Mar 25, 2001 8:00 am

Re: Quake 4 & Doom 3: Nested Lights for Volumetric Light Mapping

Post by o'dium »

Prey did something like this. Simply put its just an ambient light that covers the entire level to simulate a little colour bounce and difference in tone/shading, rather than a single flat colour. It gets rid of the black shadows, but also looks a little more like lightmapping.

However it only works in Z space, which means its still a projection map for directly over head. That means no multiple levels in the map (without hacking the lights up) and what appears on the ground will also be on the ceiling.

You can add volumetric lights but those are more expensive (6 passes) but they would work better, however would need to be done per room.
nbohr1more
Posts: 140
Joined: Thu Sep 09, 2010 1:44 pm

Re: Quake 4 & Doom 3: Nested Lights for Volumetric Light Mapping

Post by nbohr1more »

Yeah.

This is the best solution with Doom 3 assets "as is". IMHO, it's way better than pha3z's modeled blend decal approach.

I would love to see someone make a nice big map with Sikkpin's Cubemap lighting though...
nbohr1more
Posts: 140
Joined: Thu Sep 09, 2010 1:44 pm

Re: Quake 4 & Doom 3: Nested Lights for Volumetric Light Mapping

Post by nbohr1more »

I am very very very dumb. I swore I saw two LightFalloffImage references in a light shader but my eyes must've fooled me. It's a global keyword :(

My only hope to reclaim any dignity is if you can assign FragmantPrograms to the light materials...

Super embarassed. Oh well...
wattro
Posts: 375
Joined: Mon Feb 20, 2006 1:12 am

Re: Quake 4 & Doom 3: Nested Lights for Volumetric Light Mapping

Post by wattro »

if it's any consolation... i've done waaay dumber. so dumb that it would create dignity for anyone who is not me within a 10,000 mile radius
VolumetricSteve
Posts: 449
Joined: Sat Nov 06, 2010 2:33 am

Re: Quake 4 & Doom 3: Nested Lights for Volumetric Light Mapping

Post by VolumetricSteve »

wattro wrote:if it's any consolation... i've done waaay dumber. so dumb that it would create dignity for anyone who is not me within a 10,000 mile radius
Seconded.
nbohr1more
Posts: 140
Joined: Thu Sep 09, 2010 1:44 pm

Re: Quake 4 & Doom 3: Nested Lights for Volumetric Light Mapping

Post by nbohr1more »

Thanks guys...

I might have my shot after all.

I tried placing a call to HeatHaze.vfp in my light material and it crashed Doom 3. If it were outright impossible, then Doom 3 would have ignored the request to pass the shader result to another shader.

That's still not too hopeful though, even the most basic shader operations are known to crash Doom 3... It's walking on egg-shells...

This stunt is extra risky...
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Quake 4 & Doom 3: Nested Lights for Volumetric Light Mapping

Post by ^misantropia^ »

nbohr1more wrote:Will anyone create a tool that automates this conversion from 3D texture to texture atlas?

Maybe someday I will be a good enough coder to achieve such a feat but I thought I would throw this possibility out and see if anyone will bite.
I'm not sure what it is that needs to be done, truth be told. But if someone can explain it to me, I'll see what I can do.
nbohr1more
Posts: 140
Joined: Thu Sep 09, 2010 1:44 pm

Re: Quake 4 & Doom 3: Nested Lights for Volumetric Light Mapping

Post by nbohr1more »

Even if a method cannot be worked-out to re-paint the volumes at lower cost, it would still be useful to have such a tool.

For reference: Humus "Volume Light Map" demo

http://www.humus.name/index.php?page=3D&ID=47

To start we will examine the limitations of Id Tech 4's light volume structure. To fill a light volume there is a 1D "Falloff Image" and 2D "Projection Image".

The 1D Falloff Image can be thought of as a map of how bright the light is at relative z-distance to the source.

The 2D Projection Image is just a plain old 2D texture which paints the XY of the volume.

So all the visual elements in the Projection Image become cylindrical prisms if the Falloff Image is full-bright.

You can tease out more complex shapes by playing with the gradients of both images. For example you can make a sphere of light by having a Falloff Image that ramps from black to white to black while having a Projection Image that has a bright center circle that ramps to black.

This would be my idea of the process:

1) Slice a 3D texture into 2D planes and bake the resultant images into memory (the only 3D texture format I am aware of is the one in the demo above)

2) Presuming that the 3D texture Cube was sliced "Top down". Compare the images successively for elements that run parallel to the volume direction. Once you have created a composite that covers the largest number of slices. Bake that to a 2D projection image and create a corresponding 1D falloff Image that brightens and darkens that composite throughout the volume. Try to take advantage of the inherent volumetric gradient side-effects that happen due to interactions between the 2D and 1D projections to increase the amount of data subtraction.

3) At the same time as step 2, bake off unique visual elements into their own projection images and make singe element falloff images for each unique image.

4) Repeat steps 2 through-out the new set of images from step 3

5) Once you have boiled the set down to as few 2D + 1D sets as possible then slice the same 3D texture from a different axis and perform the same comparisons and reductions

6) Determine which Axis requires the lowest number of unique 1d+ 2D sets to reproduce the volume

7) Use the smallest set from step 6 to act as a master set from which the other sets are subtracted from. Try to boil down all sets by looking for ways that the light elements can be composited between up to 6 projection axis.

8) Once the absolute smallest number of 1D+2D sets are created then bake all the 2D projection images into a single long texture (like a filmstrip) while generating a scale + translate table that can snap to any specific "frame" in the strip. Do the same for the Falloff Images. Making sure to label these coordinate references so that you can easily find the which 2D image goes with which 1D falloff.

Extra credit:

Create a tool that does the above but also keeps track of optimal places to break the volume and create new 2D+1D sets per new light volume size and provides the relative sizing of each needed volume.

So:
Volume 1 =
XYZ size + named 1D+2D set A
Volume 2 =
XYZ size + named 1D+2D set B


So that's the challenge.

It could be approximated manually but an automation would allow for precise light map reproduction.

Boiled-down the problem is:

Given a fixed resolution 3D texture what are the least number of 1D+2D sets that can reasonably reproduce the data-set. You are allowed to save data by sharing the work with all 6 projection axis. You are allowed to save data by predicting emergent volumetric structures in the projections.
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Quake 4 & Doom 3: Nested Lights for Volumetric Light Mapping

Post by ^misantropia^ »

Okay, digesting.
The 1D Falloff Image can be thought of as a map of how bright the light is at relative z-distance to the source.
This could in theory be a 1xN grey scale image, right?
The 2D Projection Image is just a plain old 2D texture which paints the XY of the volume. So all the visual elements in the Projection Image become cylindrical prisms if the Falloff Image is full-bright.
Is the volume three-dimensional? How is the 2D point mapped to 3D? I read it as point(XYZ) = point(XY) for all Z.
Given a fixed resolution 3D texture what are the least number of 1D+2D sets that can reasonably reproduce the data-set.
Hah! Sounds like a reworded travelling salesman problem, a NP-hard problem. If it is, there isn't a solution that runs in reasonable time for large inputs.
nbohr1more
Posts: 140
Joined: Thu Sep 09, 2010 1:44 pm

Re: Quake 4 & Doom 3: Nested Lights for Volumetric Light Mapping

Post by nbohr1more »

^misantropia^ wrote:Okay, digesting.
The 1D Falloff Image can be thought of as a map of how bright the light is at relative z-distance to the source.
This could in theory be a 1xN grey scale image, right?

Yes, 1xN grey scale image is the usual format. Even if it's colored the makeintensity keyword turns it back to grey scale.
The 2D Projection Image is just a plain old 2D texture which paints the XY of the volume. So all the visual elements in the Projection Image become cylindrical prisms if the Falloff Image is full-bright.
Is the volume three-dimensional? How is the 2D point mapped to 3D? I read it as point(XYZ) = point(XY) for all Z.

Yes, it's point XY for all Z. But as I said, the brightness gradient in Z and XY can produce apparent XYZ structures because if Z is below a brightness threshold parts of the gradient in the XY image will become black. So the actual gray scale itself is a pseudo dimension.
Given a fixed resolution 3D texture what are the least number of 1D+2D sets that can reasonably reproduce the data-set.
Hah! Sounds like a reworded travelling salesman problem, a NP-hard problem. If it is, there isn't a solution that runs in reasonable time for large inputs.
Yes, I can see that. The result does not have to be fast or ideal. I think the problem is more akin to a video compression encoder that uses motion based compression. I was even thinking that some gray scale noise could be used to paint parts of the 2D projection image in places where no ideal balance can be made without artifacts.

Most usage cases I can imagine now would be. Boil down this 3D texture to no more than 6 projections, you may project them from any axis.
nbohr1more
Posts: 140
Joined: Thu Sep 09, 2010 1:44 pm

Re: Quake 4 & Doom 3: Nested Lights for Volumetric Light Mapping

Post by nbohr1more »

There are scant resources on this but here is tool to view the 3D texture for reference and trouble-shooting:

http://developer.amd.com/gpu/radeon/arc ... fault.aspx

Apparently using low resolution 3D textures for Ambient lighting is a secret spice for even modern engines like Crytech 3 from what I gather over at Beyond3D...

I wonder why it's not spoken about more...
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Quake 4 & Doom 3: Nested Lights for Volumetric Light Mapping

Post by ^misantropia^ »

This is on my mental 'for further review' list but I'm pretty much swamped with by-the-hour work so I probably won't get to it any time soon. It's an interesting challenge though, bump this topic if you haven't heard from me in a week or two or three.
nbohr1more
Posts: 140
Joined: Thu Sep 09, 2010 1:44 pm

Re: Quake 4 & Doom 3: Nested Lights for Volumetric Light Mapping

Post by nbohr1more »

Thanks for your interest ^misantropia^ . If you ever figure this out, you'll essentially crack one of the biggest challenge to automating Lunaran's "Strombine" lighting method...
Hope you get more time to look into this.
:)
nbohr1more
Posts: 140
Joined: Thu Sep 09, 2010 1:44 pm

Re: Quake 4 & Doom 3: Nested Lights for Volumetric Light Mapping

Post by nbohr1more »

As mentioned above, I am bumping this topic. I hope you get a chance to investigate further ^misantropia^, I suspect that many folks (besides myself) in the Id Tech 4 scene would appreciate this tool.

On a side note, I have been thinking of using triggered light volume fades to do a kinda "poor man's dynamic radiosity" and this tool would also help there. :)

Thanks.
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Quake 4 & Doom 3: Nested Lights for Volumetric Light Mapping

Post by ^misantropia^ »

I probably won't have time for this in the near future. Still swamped. :/
nbohr1more
Posts: 140
Joined: Thu Sep 09, 2010 1:44 pm

Re: Quake 4 & Doom 3: Nested Lights for Volumetric Light Mapping

Post by nbohr1more »

Thanks for the update. :)
Post Reply