   Overlapping Problem when generating UV cords for a lightmap
  So I’m trying to generate a single lightmap texture for an entire polygonal scene, but first I must generate the texture coords for my polygons of course. I’ve already implemented this into my little demo, but I’m having a problem with overlapping (which I will explain in a second) . I’ve read a bunch of articles on how to generate the uv coords, and I’m pretty sure I understand it all, its just a few simple steps:1)Using the polygon’s normals (an absolute version of the normal) , find which axis they are primarily facing, and project them into 2d space2)Find the minimum and maximum UV coords for your entire scene. because the range of your polygon’s texture coords might be way out of range of the lightmap texture, subtract the mimumum UV coord from all your uv coords.3)Find the difference between minimum and maximum UV coord. Now divide all your texture coords by that difference so all your tex coords are in a 0.0f to 1.0f range4)I should be done calculating the texture coords for my lightmap.But here’s my problem, Lets say I have a polygon and it’s normal is ( 1, 0, 0 ) so we would use the Y and Z from the polygon’s position to copy into it’s UVs, so in that case the polygon’s verticies X is ignored when figuring out its texture coords. With one polygon for one lightmap that works just fine, but lets say I have 2 polygons in one lightmap, and they both fall in the same place in 3d space except the X is different (think of a box, the front and back of it would be mapped to the place on the texture)Does anyone Know what I mean or what I can do to fix multiple polygons texture coords getting mapped to the same place?If you care to see how I’m doing this, you can see my code:   unsigned int i, j;MapObjectT* obj;MapFaceT* pFace;// GENERATE THE UVSfor( i = 0; i < uNumObjects; i++ ){obj = &pObjectArray[i];for( j = 0; j < obj->uNumVerts; j++ ){pFace = &obj->pFaceArray[j/3];if( pFace->vAbsNormal.x >= pFace->vAbsNormal.y && pFace->vAbsNormal.x >= pFace->vAbsNormal.z ){obj->pLightMapArray[ j ].x = obj->pVertexArray[ j ].z;obj->pLightMapArray[ j ].y = -obj->pVertexArray[ j ].y;}// Does the polygon primarily face along the Y-axis?else if( pFace->vAbsNormal.y >= pFace->vAbsNormal.x && pFace->vAbsNormal.y >= pFace->vAbsNormal.z ){obj->pLightMapArray[ j ].x = obj->pVertexArray[ j ].x;obj->pLightMapArray[ j ].y = -obj->pVertexArray[ j ].z;}// The polygon primarily face along the Z-axiselse{obj->pLightMapArray[ j ].x = obj->pVertexArray[ j ].x;obj->pLightMapArray[ j ].y = -obj->pVertexArray[ j ].y;}}}// FIND THE MIN AND MAX UVSVec2 minUV = pObjectArray[0].pLightMapArray[0];Vec2 maxUV = pObjectArray[0].pLightMapArray[0];for( i = 0; i < uNumObjects; i++ ){obj = &pObjectArray[i];for( j = 0; j < obj->uNumVerts; j++ ){if( obj->pLightMapArray[j].x < minUV.x )minUV.x = obj->pLightMapArray[j].x;if( obj->pLightMapArray[j].y < minUV.y )minUV.y = obj->pLightMapArray[j].y;if( obj->pLightMapArray[j].x > maxUV.x )maxUV.x = obj->pLightMapArray[j].x;if( obj->pLightMapArray[j].y > minUV.y )maxUV.y = obj->pLightMapArray[j].y;}}// MAKE THE UVS FIT ON A ( 0.0f to 1.0f ) rangeVec2 uvDiff = { 0.99f / (maxUV.x-minUV.x), 0.99f / (maxUV.y-minUV.y) };for( i = 0; i < uNumObjects; i++ ){obj = &pObjectArray[i];for( j = 0; j < obj->uNumVerts; j++ ){obj->pLightMapArray[j].x -= minUV.x;obj->pLightMapArray[j].y -= minUV.y;obj->pLightMapArray[j].x *= uvDiff.x;obj->pLightMapArray[j].y *= uvDiff.y;}}
  You might get more replies if you put this in the Graphics Programming forum instead. ;  Oh, thanks bro :-) 