Compare commits
	
		
			No commits in common. "940c78e1cfc76124d11edfe8fb0639db013dacd4" and "1d32b3ef7b7212841dd8a17c95f0e464aa546822" have entirely different histories.
		
	
	
		
			940c78e1cf
			...
			1d32b3ef7b
		
	
		|  | @ -332,7 +332,7 @@ public class WorldRep : IChunk | |||
|         public LightmapInfo[] LightList { get; set; } | ||||
|         public Lightmap[] Lightmaps { get; set; } | ||||
|         public int LightIndexCount { get; set; } | ||||
|         public List<ushort> LightIndices { get; set; } | ||||
|         public ushort[] LightIndices { get; set; } | ||||
| 
 | ||||
|         public Cell(BinaryReader reader, int bpp) | ||||
|         { | ||||
|  | @ -392,10 +392,10 @@ public class WorldRep : IChunk | |||
|                 Lightmaps[i] = new Lightmap(reader, info.Width, info.Height, info.AnimLightBitmask, bpp); | ||||
|             } | ||||
|             LightIndexCount = reader.ReadInt32(); | ||||
|             LightIndices = new List<ushort>(LightIndexCount); | ||||
|             LightIndices = new ushort[LightIndexCount]; | ||||
|             for (var i = 0; i < LightIndexCount; i++) | ||||
|             { | ||||
|                 LightIndices.Add(reader.ReadUInt16()); | ||||
|                 LightIndices[i] = reader.ReadUInt16(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|  |  | |||
|  | @ -49,12 +49,6 @@ public static class MathUtils | |||
|         return d2 < r2; | ||||
|     } | ||||
| 
 | ||||
|     public static bool Intersects(Sphere sphere, Sphere other) | ||||
|     { | ||||
|         var rsum = sphere.Radius + other.Radius; | ||||
|         return (sphere.Position - other.Position).Length() <= rsum; | ||||
|     } | ||||
| 
 | ||||
|     public static float DistanceFromPlane(Plane plane, Vector3 point) | ||||
|     { | ||||
|         return Math.Abs(Vector3.Dot(plane.Normal, point) + plane.D) / plane.Normal.Length(); | ||||
|  |  | |||
|  | @ -22,9 +22,9 @@ class Program | |||
|         public float spotlightInnerAngle; | ||||
|         public float spotlightOuterAngle; | ||||
| 
 | ||||
|         public int objId; | ||||
|         public int lightTableIndex; | ||||
|         public bool anim; | ||||
|         public int animObjId; | ||||
|         public int animLightTableIndex; | ||||
|     } | ||||
| 
 | ||||
|     static void Main(string[] args) | ||||
|  | @ -36,10 +36,9 @@ class Program | |||
|         var campaignName = "JAYRUDE_Tests"; | ||||
|         var missionName = "lm_test.cow"; | ||||
| 
 | ||||
|         // campaignName = "JAYRUDE_1MIL_Mages"; | ||||
|         // campaignName = "TDP20AC_a_burrick_in_a_room"; | ||||
|         // campaignName = "AtdV"; | ||||
|         // missionName = "miss20.mis"; | ||||
|         campaignName = "AtdV"; | ||||
|         missionName = "miss20.mis"; | ||||
| 
 | ||||
|         // Setup extract path | ||||
|         var tmpDir = Directory.CreateTempSubdirectory("KCLightmapper"); | ||||
|  | @ -144,10 +143,10 @@ class Program | |||
|         foreach (var (lightIdx, animCellMaps) in map) | ||||
|         { | ||||
|             // Get the appropriate property!! | ||||
|             var light = lights.Find((l) => l.anim && l.lightTableIndex == lightIdx); | ||||
|             var light = lights.Find((l) => l.anim && l.animLightTableIndex == lightIdx); | ||||
|             foreach (var prop in animLightChunk.properties) | ||||
|             { | ||||
|                 if (prop.objectId == light.objId) | ||||
|                 if (prop.objectId == light.animObjId) | ||||
|                 { | ||||
|                     prop.LightTableLightIndex = lightIdx; | ||||
|                     prop.LightTableMapIndex = (ushort)worldRep.LightingTable.AnimMapCount; | ||||
|  | @ -196,7 +195,6 @@ class Program | |||
|                     color = HsbToRgb(sz.Y, sz.Z, Math.Min(sz.X, 255.0f)), | ||||
|                     radius = float.MaxValue, | ||||
|                     r2 = float.MaxValue, | ||||
|                     lightTableIndex = worldRep.LightingTable.LightCount, | ||||
|                 }; | ||||
| 
 | ||||
|                 lights.Add(light); | ||||
|  | @ -274,7 +272,6 @@ class Program | |||
|                         spotlightDir = baseLight.spotlightDir, | ||||
|                         spotlightInnerAngle = baseLight.spotlightInnerAngle, | ||||
|                         spotlightOuterAngle = baseLight.spotlightOuterAngle, | ||||
|                         lightTableIndex = worldRep.LightingTable.LightCount, | ||||
|                     }; | ||||
| 
 | ||||
|                     if (propLight.Radius == 0) | ||||
|  | @ -312,8 +309,8 @@ class Program | |||
|                         spotlightInnerAngle = baseLight.spotlightInnerAngle, | ||||
|                         spotlightOuterAngle = baseLight.spotlightOuterAngle, | ||||
|                         anim = true, | ||||
|                         objId = id, | ||||
|                         lightTableIndex = propAnimLight.LightTableLightIndex, | ||||
|                         animObjId = id, | ||||
|                         animLightTableIndex = propAnimLight.LightTableLightIndex, | ||||
|                     }; | ||||
|                     if (propAnimLight.Radius == 0) | ||||
|                     { | ||||
|  | @ -414,41 +411,6 @@ class Program | |||
|     { | ||||
|         var hdr = wr.DataHeader.LightmapFormat == 2; | ||||
| 
 | ||||
|         // We set up light indices in a separate loop because the actual lighting | ||||
|         // phase takes a lot of shortcuts that we don't want | ||||
|         Parallel.ForEach(wr.Cells, cell => | ||||
|         { | ||||
|             cell.LightIndexCount = 0; | ||||
|             cell.LightIndices.Clear(); | ||||
| 
 | ||||
|             // The OG lightmapper uses the cell traversal to work out all the cells that | ||||
|             // are actually visited. We're a lot more coarse and just say if a cell is | ||||
|             // in range then we potentially affect the lighting in the cell and add it  | ||||
|             // to the list. Cells already contain their sphere bounds so we just use | ||||
|             // that for now, but a tighter AABB is another option. | ||||
|             var cellSphere = new MathUtils.Sphere(cell.SphereCenter, cell.SphereRadius); | ||||
|             foreach (var light in lights) | ||||
|             { | ||||
|                 // If the light had radius 0 (represented here with max float) then we | ||||
|                 // always add it to the list | ||||
|                 // TODO: Neaten this up | ||||
|                 if (light.radius == float.MaxValue) | ||||
|                 { | ||||
|                     cell.LightIndexCount++; | ||||
|                     cell.LightIndices.Add((ushort)light.lightTableIndex); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     var lightSphere = new MathUtils.Sphere(light.position, light.radius); | ||||
|                     if (MathUtils.Intersects(cellSphere, lightSphere)) | ||||
|                     { | ||||
|                         cell.LightIndexCount++; | ||||
|                         cell.LightIndices.Add((ushort)light.lightTableIndex); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|         Parallel.ForEach(wr.Cells, cell => | ||||
|         { | ||||
|             // Reset cell AnimLight palette | ||||
|  | @ -587,12 +549,12 @@ class Program | |||
|                                 if (light.anim) | ||||
|                                 { | ||||
|                                     // TODO: Don't recalculate this for every point lol | ||||
|                                     var paletteIdx = cell.AnimLights.IndexOf((ushort)light.lightTableIndex); | ||||
|                                     var paletteIdx = cell.AnimLights.IndexOf((ushort)light.animLightTableIndex); | ||||
|                                     if (paletteIdx == -1) | ||||
|                                     { | ||||
|                                         paletteIdx = cell.AnimLightCount; | ||||
|                                         cell.AnimLightCount++; | ||||
|                                         cell.AnimLights.Add((ushort)light.lightTableIndex); | ||||
|                                         cell.AnimLights.Add((ushort)light.animLightTableIndex); | ||||
|                                     } | ||||
|                                     info.AnimLightBitmask |= 1u << paletteIdx; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue