DGL
https://delphigl.com/forum/

VBSP 19(HL2) - Lightmaps
https://delphigl.com/forum/viewtopic.php?f=19&t=4530
Seite 1 von 1

Autor:  Stucuk [ Fr Sep 02, 2005 10:09 ]
Betreff des Beitrags:  VBSP 19(HL2) - Lightmaps

Im having problems loading lightmaps... or converting the data.

Bild
Bild

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:
  1. for x := 0 to NumFaces-1 do
  2. begin
  3. If Faces[x].LightOffset < 0 then
  4. begin
  5. Lightmaps[x].TextureId := 0;
  6. continue;
  7. end;
  8.  
  9. Seek(f, Header.lumps[VBSP_LUMP_LIGHTMAPS].fileofs + Faces[x].LightOffset);
  10.  
  11. SetLength(ALightmap[0],(Faces[x].LightmapTextureSizeInLuxels[0]+1) * (Faces[x].LightmapTextureSizeInLuxels[1]+1));
  12.  
  13. BlockRead(F,ALightmap[0][0],(Faces[x].LightmapTextureSizeInLuxels[0]+1) * (Faces[x].LightmapTextureSizeInLuxels[1]+1)*SizeOf(TColorRGBExp32));
  14.  
  15. SetLength(Lightmaps[x].Data[0],(Faces[x].LightmapTextureSizeInLuxels[0]+1) * (Faces[x].LightmapTextureSizeInLuxels[1]+1));
  16.  
  17. for y := 0 to (Faces[x].LightmapTextureSizeInLuxels[0]+1) * (Faces[x].LightmapTextureSizeInLuxels[1]+1)-1 do
  18. begin
  19. Temp := Power(2,ALightmap[0][y].Exponent);
  20. Lightmaps[x].Data[0][y] := SetVector(ALightmap[0][y].r*Temp,ALightmap[0][y].g*Temp,ALightmap[0][y].b*Temp);
  21. end;
  22. //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));
  23.  
  24. CreateLightmapTexture(Lightmaps[x].TextureId,Lightmaps[x],(Faces[x].LightmapTextureSizeInLuxels[0]),(Faces[x].LightmapTextureSizeInLuxels[1]));
  25. WorkOutPercentage(TotalPer,x,CurrentPer,Percentage,Step);
  26. end;
  27.  
  28.  
  29. Procedure TVBSPMap.CreateLightmapTexture(var texture:GLUINT; pImageBits:TVBSPLightmap; width,height:integer);
  30. begin
  31.   // Generate a texture with the associative texture ID stored in the array
  32.   glGenTextures(1, @texture);
  33.   // This sets the alignment requirements for the start of each pixel row in memory.
  34.   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  35.   // Bind the texture to the texture arrays index and init the texture
  36.   glBindTexture(GL_TEXTURE_2D, texture);
  37.   // Change the lightmap gamma values by our desired gamma
  38.  // ChangeGammaLightmap(pImageBits, width,height, Engine.Map.Gamma);
  39.  
  40.   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  41.  
  42.   //Assign the mip map levels
  43.   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  44.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
  45.  
  46.   // Build Mipmaps (builds different versions of the picture for distances - looks better)
  47.   gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, width, height, GL_RGB, GL_FLOAT, @pImageBits.data[0][0].X);
  48.  
  49. end;
  50.  


Each colour is stored in the following

Code:
  1.  
  2. struct ColorRGBExp32
  3. {
  4.     byte r, g, b;
  5.     signed char exponent;
  6. };
  7.  


Zitat:
Standard RGB format can be obtained from this by multiplying each colour component by 2^(exponent).


Code:
  1. Temp := Power(2,ALightmap[0][y].Exponent);
  2. 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

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/