Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

illuzion

Lightmap calculation / drawing

This topic is 6197 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is another question about lightmaps. Not how to use them (I know, multi-texturing...) but how to calulate and draw the actual bitmap used. I have the following information: - an array of triangles, each withx y and z coords, and uniques texture u and v coordinates - an array of (omni) lights, each with a rgb color and an xyz position coordinate. I want to calculate the amount of light (rgb values) for each triangle (I suppose; would at each vertex be better? How would you do that though?) I suppose I have to calulate the normals for each triangle, and then find the angle between those / the light. How do I do this? (Please explain clearly, or link to a site that explains it clearly, preferably with code examples). Once I have a value for each triangle, I want to draw this to a bitmap. I suppose I could just draw a flat shape, but that would result in flat-shaded triangles in-game, wouldn''t it? So how do I go about blending between the triangles? Does anyone have a code snippet for drawing triangles with a different colour at each vertex? Or should I draw them flat, and then use a blur function? (Now I need to know code for a blur... and how do you calulate how much blur to use?) Sorry this is such a long post, and asks such a lot... I''m fairly new to OpenGL, and I''ve never used lightmaps before. TIA, Illuzion.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
quote:
Original post by illuzion

I have the following information:
- an array of triangles, each withx y and z coords, and uniques texture u and v coordinates
- an array of (omni) lights, each with a rgb color and an xyz position coordinate.

I want to calculate the amount of light (rgb values) for each triangle (I suppose; would at each vertex be better? How would you do that though?)


Radiosity lighting seems to be good method for you. See
http://www.delphi3d.net/articles/viewarticle.php?article=radiosity.htm
for introduction to radiosity.

quote:

I suppose I have to calulate the normals for each triangle, and then find the angle between those / the light. How do I do this? (Please explain clearly, or link to a site that explains it clearly, preferably with code examples).


You can calculate normal for a triangle by taking normalized vectors parallel to two edges of the triangle and performing cross product between them, resulting in the third, normal vector of the triangle. It goes something like this (p0, p1 and p2 are the points (vectors) forming your triangle):

Vector v0 = p0-p1;
Vector v1 = p1-p2;
Normalize(v0);
Normalize(v1);
Vector vn = CrossProduct(v0, v1);

Calculating angle between normal vector of a triangle and direction vector of light involves taking dot product between these two vectors.

quote:

Once I have a value for each triangle, I want to draw this to a bitmap. I suppose I could just draw a flat shape, but that would result in flat-shaded triangles in-game, wouldn''t it?
So how do I go about blending between the triangles? Does anyone have a code snippet for drawing triangles with a different colour at each vertex? Or should I draw them flat, and then use a blur function? (Now I need to know code for a blur... and how do you calulate how much blur to use?)


This is where patches come in play. See the link above.

Share this post


Link to post
Share on other sites
ok, thanks. That''s very useful, thankyou.

Just a couple of questions, though:

Shadows. I suppose to calulate those, I need to implement a simple raycaster. How?
(yes, I could look on the net, and I have, but you people probably have the best (and simple!) links that are difficult to find...)
I''ve been thinking (wow). I suppose you could calculate the equation for the triangle''s plane (how, the only explanations I''ve seen I don''t really understand), and then somehow see if the normal (extended, cast as a ray) for a triangle passes through the plane... within the bounds of the triangle. Sound good?

The other thing is blurring. Do you know a good blur algorithm? These should be easy to find on the ent, but I''ve been wondering about the difference between ''normal'' blurs and gaussian blurs. What is the difference?

thanks. illuzion.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!