Generate Lightmaps

Started by
4 comments, last by jpd 12 years, 5 months ago
Hi!

I have been trying to generate static lightmaps for a while now but i find it quit hard. I'm trying to follow this article now : Lightmaps
if someone could help me with the steps explained in the tutorial i would be really thankful.

*1 Determine the primary axis plane based on the absolute value of the normal for this surface.
- I guess i can just check wich axis is the largest?

*2 Get the min and max (2D vertices) along that plane. This means to use only the 2 relevant coordinate components for this particular plane. For example if you're using the XY plane, only x and y at the vertices count for this step.
- I dont really know what this means. is min a vector at "0,0" corner and max "1,1" corner if the polygon would start at 0,0 and be 1 wide and high?

*Assign the UV vectors (ie, the normalized vectors pointing 'right' and 'down' respectively. You don't have to use 'right' and 'down', but it makes more sense to trace in those directions as you'll see in the loop below).
- This i got working i think.

*3 Determine the texture plane origin (p) from the min. This, and the previous step can be done very simply by getting the 3D points based on your 2D (projected) min/max using the equation of the plane. You have only 1 unknown (the missing vertex component), so solving for it is trivial.
- Texture plane origin?

*4 Determine the u and v lengths (max-min)
- If i just had the min and max hmm?

*5 And finally, determine lightmap coordinates:
(for each vertex) ltu=((pu - minu) / ulen) and ltv=((pv - minv) / vlen)
where pu and pv are the x and y in PLANE space (not world space).

- ?? Texture coordinates??

Thanks!
Advertisement

*1 Determine the primary axis plane based on the absolute value of the normal for this surface.
- I guess i can just check wich axis is the largest?

Pretty much. Though, i don't honestly see a valid reason to use a cardinal axis. If your surface is made of coplanar triangles, then pick any triangle and its normal is the primary axis.


*2 Get the min and max (2D vertices) along that plane. This means to use only the 2 relevant coordinate components for this particular plane. For example if you're using the XY plane, only x and y at the vertices count for this step.
- I dont really know what this means. is min a vector at "0,0" corner and max "1,1" corner if the polygon would start at 0,0 and be 1 wide and high?

Once you have a plane, compute a tangent and bi-tangent for it (perpendicular vectors that run along that plane). The reason people use a cardinal axis as their primary in #1 is so these vectors can just be the other 2 cardinal axis vectors without needing to generate them.
Use those vectors to project a 2d vector (basically, a signed distance from plane, using those directions and the origin. the actual origin doesnt really matter, its just to create a planar projection)


*3 Determine the texture plane origin (p) from the min. This, and the previous step can be done very simply by getting the 3D points based on your 2D (projected) min/max using the equation of the plane. You have only 1 unknown (the missing vertex component), so solving for it is trivial.
- Texture plane origin?

*4 Determine the u and v lengths (max-min)
- If i just had the min and max hmm?

The answer to these came from the 2D projections from #2


*5 And finally, determine lightmap coordinates:
(for each vertex) ltu=((pu - minu) / ulen) and ltv=((pv - minv) / vlen)
where pu and pv are the x and y in PLANE space (not world space).

- ?? Texture coordinates??

The projected coordinate from #2 gets scaled and biased in #4 to give you your texture coordinate.
Thx for the tips, but i'm still having problems.

What's texture plane origin(p) supposed to be?
And pu, pv from *5?

The top plane looks fairly nice but for some reason it gets a bright line at the edges and the coordinates i get from *5 does not match the 2 planes, please help.
Does anyone know of any example code for generating lightmaps?

Thanks!

Does anyone know of any example code for generating lightmaps?

Thanks!


IIRC there's a fairly complete example in Core Techniques and Algorithms in Game Programming.
Hi Surp, I'm having the same issue here creating lightmap, Have you found any new ressources , book, or example you were able to use ? .

This topic is closed to new replies.

Advertisement