Thread: [Algorithms] Lightmap Terrain
Brought to you by:
vexxed72
From: <sro...@te...> - 2000-08-24 19:50:29
|
Hi! I trying to find how to generate a lightmap/illumination/shadow on a terrain. Do you know some good tutorial/code/links talking about that? I want something to generate a lightmap on a (1025x1025 terrain). A good generation if possible like compute the the light from a point. I want generate the lightmap just before the use of the terrain and i dont want something that i need to pre-calculate and put the result on a file or something like. Thanks, Corrosif |
From: Klaus H. <k_h...@os...> - 2000-08-25 00:34:41
|
Sylvain, :) > Hi! > > I trying to find how to generate a lightmap/illumination/shadow on a > terrain. > Do you know some good tutorial/code/links talking about that? Unfortunately, no, I don't know of any such papers and good code is also very rare (I wasn't able to find any good code, yet). The only useful related paper I know of is "Grid Tracing: Fast Ray Tracing for Height Fields", by famous Mr. F. Kenton Musgrave. The paper does, however, not explain how to light a surface, it only describes a fast algorithm to trace a ray and intersect it with a height field. It is useful for many things. Shadow feelers are a nice example. If you want to know, if a point on the height field surface lies in shadow, then you can cast a ray from that point to the light source, and then use the algorithm to trace the ray, and test wheter it intersects with the height field (or any other object) before it reaches the light source. If there is an intersection then the point lies in shadow, and you decrease the intensity at that point. > I want something to generate a lightmap on a (1025x1025 terrain). A good > generation > if possible like compute the the light from a point. A simple, but not perfect, way to calculate the light at a point on the height field is to use the dot product: [1] Calculate the unit vertex normal, N, at the point, P, you want to illuminate [2] Calculate the unit direction vector, L, that points from point P towards the point light source (or pre-calculate the single unit direction vector for a directional light source). [3] If the dot product I = L _dot_ N is smaller or equal to 0, then angle between N and L is >= 90 degree, and the light source has no effect on point P. If I is greater than 0, then the angle between L and N is smaller than 90 degree, and you can use I to illuminate the point: point.r = material.r * I * lightSource.r; point.g = material.g * I * lightSource.g; point.b = material.b * I * lightSource.b; Note, that I actually is the cosine of the angle between the two *unit* vectors, L and N. In general: U _dot_ V = |U| * |V| * cos(angle(U, V)) where, U and V are two vectors, and angle(U, V) is the angle between the two vectors U, and V. If U and V are both unit vectors, then: U _dot_ V = 1 * 1 * cos(angle(U, V)) <=> U _dot_ V = cos(angle(U, V)) So, if in the above example, N and L are not unit vectors, then you need to compute I as follows: I = (L _dot_ N) / ( |L| * |N|) Here's a small performance tip w.r.t. point light sources (and spot lights). If you use a point light source, then you need to re-compute L all the time, because L depends on the point P. However, normalizing L all the time is really expensive, and it is a waste of performance to normalize L, if the light has no effect at the point P (the angle between N and L is greater than 90°). You can speed this up as follows: L = compute NON-normalized vector L I = L _dot_ N; if (I <= 0) then return; /light has no effect*/ I /= |L|; point.r = material.r * I * lightSource.r; point.g = material.g * I * lightSource.g; point.b = material.b * I * lightSource.b; > I want generate the lightmap > just before the use of the terrain and i dont want something that i need to > pre-calculate and put the result on a file or something like. Not sure what you mean here... HTH, Niki |
From: Akbar A. <sye...@ea...> - 2000-08-25 01:34:29
|
what algo did q3 use to light it's textures? peace, akbar A. -----Original Message----- From: gda...@li... [mailto:gda...@li...]On Behalf Of Klaus Hartmann Sent: Thursday, August 24, 2000 5:30 PM To: gda...@li... Subject: Re: [Algorithms] Lightmap Terrain Sylvain, :) > Hi! > > I trying to find how to generate a lightmap/illumination/shadow on a > terrain. > Do you know some good tutorial/code/links talking about that? Unfortunately, no, I don't know of any such papers and good code is also very rare (I wasn't able to find any good code, yet). The only useful related paper I know of is "Grid Tracing: Fast Ray Tracing for Height Fields", by famous Mr. F. Kenton Musgrave. The paper does, however, not explain how to light a surface, it only describes a fast algorithm to trace a ray and intersect it with a height field. It is useful for many things. Shadow feelers are a nice example. If you want to know, if a point on the height field surface lies in shadow, then you can cast a ray from that point to the light source, and then use the algorithm to trace the ray, and test wheter it intersects with the height field (or any other object) before it reaches the light source. If there is an intersection then the point lies in shadow, and you decrease the intensity at that point. > I want something to generate a lightmap on a (1025x1025 terrain). A good > generation > if possible like compute the the light from a point. A simple, but not perfect, way to calculate the light at a point on the height field is to use the dot product: [1] Calculate the unit vertex normal, N, at the point, P, you want to illuminate [2] Calculate the unit direction vector, L, that points from point P towards the point light source (or pre-calculate the single unit direction vector for a directional light source). [3] If the dot product I = L _dot_ N is smaller or equal to 0, then angle between N and L is >= 90 degree, and the light source has no effect on point P. If I is greater than 0, then the angle between L and N is smaller than 90 degree, and you can use I to illuminate the point: point.r = material.r * I * lightSource.r; point.g = material.g * I * lightSource.g; point.b = material.b * I * lightSource.b; Note, that I actually is the cosine of the angle between the two *unit* vectors, L and N. In general: U _dot_ V = |U| * |V| * cos(angle(U, V)) where, U and V are two vectors, and angle(U, V) is the angle between the two vectors U, and V. If U and V are both unit vectors, then: U _dot_ V = 1 * 1 * cos(angle(U, V)) <=> U _dot_ V = cos(angle(U, V)) So, if in the above example, N and L are not unit vectors, then you need to compute I as follows: I = (L _dot_ N) / ( |L| * |N|) Here's a small performance tip w.r.t. point light sources (and spot lights). If you use a point light source, then you need to re-compute L all the time, because L depends on the point P. However, normalizing L all the time is really expensive, and it is a waste of performance to normalize L, if the light has no effect at the point P (the angle between N and L is greater than 90°). You can speed this up as follows: L = compute NON-normalized vector L I = L _dot_ N; if (I <= 0) then return; /light has no effect*/ I /= |L|; point.r = material.r * I * lightSource.r; point.g = material.g * I * lightSource.g; point.b = material.b * I * lightSource.b; > I want generate the lightmap > just before the use of the terrain and i dont want something that i need to > pre-calculate and put the result on a file or something like. Not sure what you mean here... HTH, Niki _______________________________________________ GDAlgorithms-list mailing list GDA...@li... http://lists.sourceforge.net/mailman/listinfo/gdalgorithms-list |
From: Leigh M. <lei...@ro...> - 2000-08-25 13:28:07
|
I have seen people reply with many good ideas on this lightmap thing so I am guessing that many people are going with lightmaps for terrain. I am wondering if these people have a fixed position for the main light source such as a sun. I am currently using vertex lighting as it was very quick to get going and it looks good even with a LOD algorithm. Are lightmaps being generated as the sun moves? Do the lightmaps light static objects also? I was also worried of loosing a multi-texture to lighting when I could use it for noise or something else. What about DOT3, does anyone have an idea how fast it would be? Leigh ----- Original Message ----- From: <sro...@te...> To: <gda...@li...> Sent: Thursday, August 24, 2000 3:54 PM Subject: [Algorithms] Lightmap Terrain > Hi! > > I trying to find how to generate a lightmap/illumination/shadow on a > terrain. > Do you know some good tutorial/code/links talking about that? > > I want something to generate a lightmap on a (1025x1025 terrain). A good > generation > if possible like compute the the light from a point. I want generate the > lightmap > just before the use of the terrain and i dont want something that i need to > pre-calculate and put the result on a file or something like. > > Thanks, > Corrosif > > _______________________________________________ > GDAlgorithms-list mailing list > GDA...@li... > http://lists.sourceforge.net/mailman/listinfo/gdalgorithms-list > |