Lightmapping coords wanted

Started by
2 comments, last by BradDaBug 19 years, 7 months ago
I'm working on a level render for Gabriel Knight 3 levels (or rooms, I guess) and so far so good (screeny!) but now the time has come to lightmap the stuff. I've got GK3's lightmap format figured out but I can't figure out how to get the texture coordinates for the lightmaps for each vertex. The BSP format has a field with UV coords and UV scales, then some sort of world scale. The thing is there are more polys than there are these structures, so apparently one lightmap can stretch across multiple polys. Anyone have any idea how to calculate lightmap texture vertex coords using these UV coords and scales?
I like the DARK layout!
Advertisement
Here is an article about lightmapping. You can find a link to coord generation on the bottom of that page.
don't know if it's useful for you.
http://www.flipcode.com/articles/article_lightmapping.shtml#derivation
I saw that article yesterday, but I didn't really give it a good enough look. I'll study it more now. But what I did find interesting was this.

As I was reading it I was thinking "hey! this could be it! I could find the world coords of the two lesser coordinates for each vertex, then divide that by the UV scales in the GK3 BSP file, the add the UV offsets to that and that'd work!" But then I realized it wouldn't. World coordinates of verticies are in the hundreds sometimes but the biggest UV scaling values are in the tens. That wouldn't give me UV coords in the 0..1.0 range. Then I thought maybe the worldsize field could be used for something, but it seems to vary based on polygon size, not position. Tiny polygons, or groups of polygons, have a tiny worldsize but large polygons have a large worldsize.

In that article I linked to it mentioned something about "finding the minimum U and minimum V and subtracting that from the rest." But what's the minimum U and V? (0,0)? Then I thought about finding the "largest" vertex and subtracting it from the rest of the verts in that surface group, then trying to scale and offset. But that seems like a wierd way to do it.

I'll keep working at it. Maybe someday I'll figure it out.
I like the DARK layout!
Bumpity bump bump.

I tried finding the minimum world coordinates of the poly and then subtracting those from all the coordinates of the surface, translating all the verts to (0,0,0). Then I found the extents of the surface in each axis, then divided each vertex by those extents (in other words, I normalized all the verticies to have coordinates between 0 and 1). I then tried to use those coordinates as texture coordinates, and it sort of worked, but not quite. Here's a screenshot of it.

Here's what the surface structure inside the BSP looks like:
struct GBspSurfFile{	DWORD	 Model;								// index into array of model names	char     TexName[kMaxObjectName+1];			// texture name wo/path & extension	float	 UVOffset[2];						// UV offset	float	 UVScale[2];						// UV scale factor	float    WorldSize;							// size of largest world extent	DWORD	 Flags;								// surface flags (see gscene.h)};

Does any of that ring any bells? Any ideas about how this is supposed to work?
I like the DARK layout!

This topic is closed to new replies.

Advertisement