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.

# Lightmap calculation / drawing

Started by illuzion, Jul 31 2001 11:17 PM

2 replies to this topic

Sponsor:

###
#2
Anonymous Poster_Anonymous Poster_*
Guests - Reputation:

Posted 31 July 2001 - 11:58 PM

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.

###
#3
Members - Reputation: **122**

Posted 01 August 2001 - 11:12 PM

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.

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.