Im having problems loading lightmaps... or converting the data.
As u can see from the pics the lightmaps unity makes (there is no colours or anything applyed other than a lightmap) are screwed.
Code: for x := 0 to NumFaces-1 do begin If Faces[x].LightOffset < 0 then begin Lightmaps[x].TextureId := 0; continue; end; Seek(f, Header.lumps[VBSP_LUMP_LIGHTMAPS].fileofs + Faces[x].LightOffset); SetLength(ALightmap[0],(Faces[x].LightmapTextureSizeInLuxels[0]+1) * (Faces[x].LightmapTextureSizeInLuxels[1]+1)); BlockRead(F,ALightmap[0][0],(Faces[x].LightmapTextureSizeInLuxels[0]+1) * (Faces[x].LightmapTextureSizeInLuxels[1]+1)*SizeOf(TColorRGBExp32)); SetLength(Lightmaps[x].Data[0],(Faces[x].LightmapTextureSizeInLuxels[0]+1) * (Faces[x].LightmapTextureSizeInLuxels[1]+1)); for y := 0 to (Faces[x].LightmapTextureSizeInLuxels[0]+1) * (Faces[x].LightmapTextureSizeInLuxels[1]+1)-1 do begin Temp := Power(2,ALightmap[0][y].Exponent); Lightmaps[x].Data[0][y] := SetVector(ALightmap[0][y].r*Temp,ALightmap[0][y].g*Temp,ALightmap[0][y].b*Temp); end; //Lightmaps[x].Data[0][y] := SetVector(Power(ALightmap[0][y].r,ALightmap[0][y].Exponent),Power(ALightmap[0][y].g,ALightmap[0][y].Exponent),Power(ALightmap[0][y].b,ALightmap[0][y].Exponent)); CreateLightmapTexture(Lightmaps[x].TextureId,Lightmaps[x],(Faces[x].LightmapTextureSizeInLuxels[0]),(Faces[x].LightmapTextureSizeInLuxels[1])); WorkOutPercentage(TotalPer,x,CurrentPer,Percentage,Step); end; Procedure TVBSPMap.CreateLightmapTexture(var texture:GLUINT; pImageBits:TVBSPLightmap; width,height:integer); begin // Generate a texture with the associative texture ID stored in the array glGenTextures(1, @texture); // This sets the alignment requirements for the start of each pixel row in memory. glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Bind the texture to the texture arrays index and init the texture glBindTexture(GL_TEXTURE_2D, texture); // Change the lightmap gamma values by our desired gamma // ChangeGammaLightmap(pImageBits, width,height, Engine.Map.Gamma); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); //Assign the mip map levels glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // Build Mipmaps (builds different versions of the picture for distances - looks better) gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, width, height, GL_RGB, GL_FLOAT, @pImageBits.data[0][0].X); end;
Each colour is stored in the following
Code: struct ColorRGBExp32 { byte r, g, b; signed char exponent; };
Zitat: Standard RGB format can be obtained from this by multiplying each colour component by 2^(exponent).
Code: Temp := Power(2,ALightmap[0][y].Exponent); Lightmaps[x].Data[0][y] := SetVector(ALightmap[0][y].r*Temp,ALightmap[0][y].g*Temp,ALightmap[0][y].b*Temp);
Im assuming the Power function acts like ^ in maths.
Currently im only loading one out of a possible 4 "styles" (each face can have what i guess to be 4 different lightmaps effecting it) but even if some have more styles, the colours im getting are a tad off for other styles to be the cause.
The offset seems to be correctly done
Zitat: Each face gives a byte offset into the lighting lump in its lightofs member (if no lighting information is used for this face e.g. faces with skybox, nodraw and invisible textures, lightofs is -1.) There are (number of lightstyles)*(number of luxels) lightmap samples for each face, where each sample is a 4-byte ColorRGBExp32 structure
|