Help fixing Q3's dynamic lights

Discuss programming topics for the various GPL'd game engine sources.
Post Reply
Revanic45
Posts: 7
Joined: Sun Nov 21, 2010 1:41 am

Help fixing Q3's dynamic lights

Post by Revanic45 »

Wrote this before on some other forum, but it turns out to not be very active at all which I overlooked >_>

I have recently set out to fix quake 3's dynamic lighting. I have found a way to get dynamic lights to be properly additive. Which is done by a small and easy hack. Though it does break some multiplicative shader stages against lightmaps very slightly, they simply won't get lit right by the dlights.
I've had theories on how to fix that, but haven't really tried.

The main problem is getting these dynamic lights to orientate properly on walls and slopes...

This altered code seems to be heading in the right direction, but it does not work proberly.

texCoords[0] = 0.5f + (dist[0]*scale) - (normal[0]*(dist[2]*scale - dist[0]*scale));
texCoords[1] = 0.5f + (dist[1]*scale) - (normal[1]*(dist[2]*scale - dist[1]*scale));

It gives some mixed results... the dynamic lights appear on some walls correctly whilist sliding up some other walls depending on how far away it is, slopes end up being pretty weird... If anyone would like to help me that would be great!

Image
Image
Vic
Posts: 21
Joined: Sun Nov 07, 2010 12:42 am

Re: Help fixing Q3's dynamic lights

Post by Vic »

What you're trying to accomplish isn't quite possible without using a 3D texture for the lighting attenuation. You might look up qfusion/warsow source code to see how it's done there.
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Help fixing Q3's dynamic lights

Post by mh »

You can use a 2D texture and a 1D texture in two texture units to get the same effect as a 3D texture, with the obvious tradeoff being that it needs two texture units. That's not a big deal unless you really need to run on Voodoo 1 generation hardware.

Here's a fully realtime lit Grisly Grotto using that method:

Image

Rubbish performance and note the rendering glitches - I wrote that code in about 2003/2004 and never finished it.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
Vic
Posts: 21
Joined: Sun Nov 07, 2010 12:42 am

Re: Help fixing Q3's dynamic lights

Post by Vic »

True, but I wouldn't bother with double-pass dynamic lights, really.
Revanic45
Posts: 7
Joined: Sun Nov 21, 2010 1:41 am

Re: Help fixing Q3's dynamic lights

Post by Revanic45 »

I am fairly sure it's possible, Elite force 2 and Jedi Academy had this fixed. I think it's a matter of orientating it onto each individual plane. I just don't really know how to do that here. though if it's really not possible I guess I will look into a 3d texture.
Vic
Posts: 21
Joined: Sun Nov 07, 2010 12:42 am

Re: Help fixing Q3's dynamic lights

Post by Vic »

No, it's not possible.
Revanic45
Posts: 7
Joined: Sun Nov 21, 2010 1:41 am

Re: Help fixing Q3's dynamic lights

Post by Revanic45 »

I don't see how its not possible, the dynamic light is just a projected texture that uses texture coords. In this case those coords are being created in a way that only aligns it properly in either the X, Y, or Z axis. I'm sure theres a way to align it on all 3. Warsow also allows you to turn off 3d texturing and the dynamic lights, whilst they look a little different, they are still aligned.
There is probably a different way I need to handle the texcoords than what I'm doing now, but I know its possible. Jedi academy and elite force 2 did NOT use 3d textures. In fact, jedi academy's dynamic light texture was external and easily editable, which I have done for fun before.
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Help fixing Q3's dynamic lights

Post by mh »

Stop thinking about how to do this on the CPU. The GPU is much better at this kind of thing and does it so much faster and easier. Not everything is software. You use the vertex positions as your texcoords. Translate the texture matrix to the light origin and scale it according to the light radius. Set your texture wrap mode to clamp, use either a 3D texture or a combination of a 2D and 1D texture in 2 texture units; whichever you pick you encode the light falloff into the texture. Or use a shader and you don't even need to bother with textures. Modulate by light colour. Initial light pass in replace mode, subsequent passes over the same surfaces in add mode (or do a prepass clearing everything to black then all light passes in add mode) (for Quake 3 dlights you draw lightmap in pass 1 then add dlights in subsequent passes). Life gets a lot easier if you use a 64-bit or floating point render target instead of the framebuffer, but there is a performance hit. Of course it's possible - this is completely standard attenuation map stuff, it was old 10 years ago.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
Post Reply