Sign in to follow this  
Surp

Generate Lightmaps

Recommended Posts

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 : [url="http://www.flipcode.com/archives/Lightmaps_Static_Shadowmaps.shtml"]Lightmaps[/url]
if someone could help me with the steps explained in the tutorial i would be really thankful.

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

[b]*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.[/b]
- 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?

[b]*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).
[/b]- This i got working i think.

[b]*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.
[/b]- Texture plane origin?

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

[b]*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). [/b]
- ?? Texture coordinates??

Thanks!

Share this post


Link to post
Share on other sites
[quote name='Surp' timestamp='1313616456' post='4850478']
[b]*1 Determine the primary axis plane based on the absolute value of the normal for this surface. [/b]
- I guess i can just check wich axis is the largest?
[/quote]
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.

[quote name='Surp' timestamp='1313616456' post='4850478']
[b]*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.[/b]
- 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?
[/quote]
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)

[quote name='Surp' timestamp='1313616456' post='4850478']
[b]*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.
[/b]- Texture plane origin?

[b]*4 Determine the u and v lengths (max-min) [/b]
- If i just had the min and max hmm?
[/quote]
The answer to these came from the 2D projections from #2

[quote name='Surp' timestamp='1313616456' post='4850478']
[b]*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). [/b]
- ?? Texture coordinates??
[/quote]
The projected coordinate from #2 gets scaled and biased in #4 to give you your texture coordinate.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote name='Surp' timestamp='1313783176' post='4851354']
Does anyone know of any example code for generating lightmaps?

Thanks!
[/quote]

IIRC there's a fairly complete example in [i]Core Techniques and Algorithms in Game Programming.[/i][i] [/i]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this