Jump to content


Need some help with generating lightmaps


5 replies to this topic

#1 Borf

    New Member

  • Members
  • Pip
  • 1 posts

Posted 26 September 2005 - 02:27 PM

Hi,

I'm working on a small 3d engine, and I'm planning on using lightmaps for static lighting. I'm at the point where I have to generate the lightmaps now, but for some reason I can't get the texel-world-coordinates right.

the triangle I'm rendering a map for is (v1,v2,v3) where v1,v2,v3 are vectors

the UVs for the lightmap are (0,0), (1,0) and (1,1)

to start with, I'm using 1 static light at (0,0,0), and I'm using the following code to generate the maps
		cVector3 edge1 = v3 - v1;
		cVector3 edge2 = v2 - v1;
		cVector3 edge3 = v3 - v2;

		for(int x = 0; x < LIGHTMAPSIZE; x++)
		{
			for(int y = 0; y < LIGHTMAPSIZE; y++)
			{
				float mx = (float)x / (float)LIGHTMAPSIZE;
				float my = (float)y / (float)LIGHTMAPSIZE;

				cVector3 pos3d = v1 + (edge2*mx)+(edge3*my);
				
				float dist = 255-max(pos3d.Magnitude(), 255);

				map[x][y][0] = dist;
				map[x][y][1] = dist;
				map[x][y][2] = dist;
			}
		}



the problem is that pos3d doesn't contain the proper world-coordinates, which means the lighting isn't calculated properly as well. When I use (pos3d.x%256) as color, it does appear as a gradient on 1 triangle, but when I have 2 triangles next to eachother the gradients do not match

#2 roel

    Senior Member

  • Members
  • PipPipPipPip
  • 697 posts

Posted 26 September 2005 - 02:39 PM

just a quick guess: try:

cVector3 pos3d = v1 + (edge2*mx)+(edge1*my);

or something. some intuitive explanation: on top of the code you create two vectors that create a span (edge1 and edge2), and they are both relative to v1. in the calculation for pos3d you use v1 as base and scale in the directions of the edges, so you should use only the edges relative to v1, and that is not edge3. this explanation sucks, sorry. good luck.

#3 kusma

    Valued Member

  • Members
  • PipPipPip
  • 163 posts

Posted 27 September 2005 - 12:32 AM

i'm not meaning to be an ass and ruin your fun here, but is there a really good reason why you don't offload shadowmap-calculations to the content creation tools like 3dsmax? giving your artists more freedom and contro is a GoodThing™...

#4 roel

    Senior Member

  • Members
  • PipPipPipPip
  • 697 posts

Posted 27 September 2005 - 07:51 AM

I made a lightmapper too, its quite interesting and challenging. I guess that's a good reason.

#5 Ed Mack

    Senior Member

  • Members
  • PipPipPipPip
  • 1239 posts

Posted 27 September 2005 - 04:46 PM

I enjoyed the learning curve, and real-time lightmapping is interesting. See http://www.frustum.org for gpu-based realtime lightmapping (or so I remember)

#6 roel

    Senior Member

  • Members
  • PipPipPipPip
  • 697 posts

Posted 27 September 2005 - 07:22 PM

Ed Mack said:

I enjoyed the learning curve, and real-time lightmapping is interesting. See http://www.frustum.org for gpu-based realtime lightmapping (or so I remember)

If I'm correct, these two things are totally different actually (I guess that you mean shadow mapping). Confusing names though.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users