Static lightmap creation and using lightmap UVs


(G0-Gerbil) #1
  1. Is there a way of forcing lightmap face allocation onto the actual lightmaps to remain constant between compiles? [EDIT] Appears q3map2 has -nocollapse parameter, which along with grouping shaders to use a specific lightmap may or may not do what I want here. [/EDIT]

  2. Is there a way of assigning lightmap coordinates to a texture layer while specifying a custom texture map? [EDIT] tcgen lightmap to the rescue. Will have to test to see how fast / slow it is though. [/EDIT]

I’ll explain a bit more in depth.
The idea is to have two sets of lightmaps for a level or shader. Then with a shader be able to blend between them at runtime creating entirely different fading lights (eg night to day).
Psuedo shader code!

myshader/amazingeffect
{
{
map $lightmap
}
{
uselightmapUVs
map myshader/lightmapversion2
alphagen somethingthatfades
blendfunc blend
}
{
map standardshader
blendfunc multiply
}
}

Hopefully you can see where I’m going. The normal lightmap goes first, and the second lightmap (my specified texture) goes second, but naturally it needs to use the generated lightmap UV coordinates to match.
Then the standard texture comes last (unlike most shaders, but it’s the only way I could think of easily getting the two lightmaps to blend).

The idea is I create two versions of my map that differ only in lighting. I compile them both, using one set of lightmaps as the default, and using the second set as the ones to fade between. This requires both compiles to output the same face / lightmap allocation. While in theory this is easy to do, I think q3map2 does lots of nice optimisations like collapsing very similar lightmaps, which of course would differ between the two compiles since the lighting would be different.

Then, assuming part 1 above is possible (maybe a new q3map2 switch -nolightmapcollapse or something, if it’s not in there already!), the second part comes into play - getting at the darned lightmap UVs but being able to specify my own texture map for the layer.

Perhaps some q3map2 tcgen $lightmap or something?

I reckon it it should be simple to code in (hurrah, I’m guessing Ydnar’s workload again, bet he loves it when people do that!) if it can’t be done already, and it could provide for some rather stunning effects!

If people still aren’t clear what I’m going on about, I can knock up a quick working demo using a purely terrain map (since the lightmap output on that is guaranteed to remain the same and it’ll be easy enough for me to fudge the lightmap UV coordinate thingy with a standard coordinate generator function.


(nUllSkillZ) #2

Isn’t there an example map by ydnar where the seasons of the year change during time?

Edit:

The map is from Rgoer.
And I’ve found only a newssite with a non working link to the map at level-designer.de so far (some pictures but text is german):
http://www.level-designer.de/index.php?option=content&task=view&id=1702


(G0-Gerbil) #3

If there is I wanna see :smiley:


(nUllSkillZ) #4

Please take a look at [edit].


(G0-Gerbil) #5

Thanks for that mullSkilZ.
Just done an edit of my own, since it seems q3map2 already supports a -nocollapse switch for the lighting phase.
A quick test should see if this does what I want it do. If so, half my ‘requirements’ sorted, one to go :slight_smile:


(G0-Gerbil) #6

Well, from the screenshots it’s possible to guess he’s just doing the fading in and out of several texture layers for each shader. Basically a 4 layer version of the 2 layer effect I want to acheive with the lightmaps. Can’t verify that without having the source, but can’t find a place to download it from so speculation is all I have unless Mr Rgoer wishes to find a new host location for it :slight_smile:


(G0-Gerbil) #7

Darn, looks like it may not be possible without a mod.
I’d assumed map $lightmap was a compile-time option to specify using lightmap image and UVs, but it looks like it’s actually the game engine that reads it in.

Each vertex in a BSP has both it’s texture and lightmap UVs in it, so the data is raring to go, but possibly there’s no way to force the game engine to use lightmap UVs with a different texture. I’d like to think I’m wrong, if anyone feels like proving / disproving this. Maybe 2 map lines in the shader layer or something mumbles gibberish hopefully and keeps looking


(obsidian) #8

rgoer’s map only faded between texture layers, the lightmap was not modified.

It’s possible to do something like this with lightstyles, have 2 sun pointlights with alternating phases fade in and out. The frame rate results would be horrendous, of course. Someone had a beta map of an entire level doing this but with only 1 lightsource and even that seemed to be a large frame rate hog.

If you only want a small portion of your map doing this, say the shadow of a single object, you could use 2 _decal entities with a painted shadow texture.


(G0-Gerbil) #9

If the above is true, I’d then have to have the entire map twice - the only way around it I can think of is to have the shaders just deal with the lightmap stage and I manually hack their texture UVs to match the lightmap UVs. Then have a second brush face for each with just the normal texture and polygon offset.
Talk about a hack - would probably be stupidly painful unless I wrote a program that created both required copies of the brushes from a source .MAP.

Ouch, it’s making my head spin :slight_smile:


(chavo_one) #10

It’s called “A Year In About 3½ Minutes”.

rgoer’s homepage (for screenshots)
zip file


(G0-Gerbil) #11

BTW is it fair to say that q3map2 makes EVERY normal drawable face (IE not a patch nor a billboard / sprite) are stored in the BSP as type 3, mesh, and never as type 1 (polygon)?
I can now imagine a q3map2 specific tag in a shader that means ALL non-lightmap layers get to use the lightmap UVs (you’d just dupe the lightmap UV into the texture UV storage).

Is there any per-layer q3map2 function that stores precalculated modified texture UVs?
TCMOD is calculated at runtime based on the texture UV, but I’m not sure if the q3map_ivector (or whatever they are called, memory fails me right now!) manages to store the modified UVs, or simply allows them to be calculated and cached at map start (which I think is what wolfwings has said in the past regarding them).


(G0-Gerbil) #12

Ooh some new posts :slight_smile:

Obsidian - I had the feeling lightstyles aren’t the way to go. While I’m not familiar with their usage, I’ve never seen a demonstration of them that would allow what I want. Of course, that may simply be because I’ve not seen much of them. How exactly do they work regarding the swapping or blending of 1 lightmap to another?

Chavo One - to the rescue again - although I think the map works how I suspected, it’ll still be nice to see :slight_smile: - boo Q3 only - time to read the shader file. Never as exciting…


(G0-Gerbil) #13

BTW am reading up on lightstyles now and grabbing some sample source maps in case it’s exactly what I want - don’t want to look any stupider than I have to!

Edit:

Seems it might be what I’m after - I noticed the ‘custom’ $lightmap4 etc bits in ydnar’s shaders. Only thing is the map is RTCW hence the lightmaps are internal - I want to see how they work. Has anyone got an ET map using lightstyles they can point me too?


(G0-Gerbil) #14

I noticed in a shader layer you can use tcgen lightmap.
Seems like that’s all I need for now, although I’ve no idea how fast or slow it is.
Time to go try it out.

Thanks for the people who’ve helped me in this thread even if it seems like a long-winded rambling by myself (because it is!) - when an idea pops into my head I don’t like to let it go until it’s either had it’s full run-around, or it’s been squashed in the way only stupid ideas can be :smiley: