Fix incorrect anim light map layering
This commit is contained in:
parent
0a41d78cac
commit
c162a5028d
|
@ -152,6 +152,7 @@ public class WorldRep : IChunk
|
||||||
|
|
||||||
public class Lightmap
|
public class Lightmap
|
||||||
{
|
{
|
||||||
|
private readonly bool[] _litLayers;
|
||||||
public List<byte[]> Pixels { get; set; }
|
public List<byte[]> Pixels { get; set; }
|
||||||
|
|
||||||
public int Layers;
|
public int Layers;
|
||||||
|
@ -163,10 +164,12 @@ public class WorldRep : IChunk
|
||||||
{
|
{
|
||||||
var layers = 1 + BitOperations.PopCount(bitmask);
|
var layers = 1 + BitOperations.PopCount(bitmask);
|
||||||
var length = bytesPerPixel * width * height;
|
var length = bytesPerPixel * width * height;
|
||||||
|
_litLayers = new bool[33];
|
||||||
Pixels = new List<byte[]>();
|
Pixels = new List<byte[]>();
|
||||||
for (var i = 0; i < layers; i++)
|
for (var i = 0; i < layers; i++)
|
||||||
{
|
{
|
||||||
Pixels.Add(reader.ReadBytes(length));
|
Pixels.Add(reader.ReadBytes(length));
|
||||||
|
_litLayers[i] = true;
|
||||||
}
|
}
|
||||||
Layers = layers;
|
Layers = layers;
|
||||||
Width = width;
|
Width = width;
|
||||||
|
@ -246,6 +249,8 @@ public class WorldRep : IChunk
|
||||||
pLayer[idx + 1] = (byte)Math.Clamp(pLayer[idx + 1] + g, 0, 255);
|
pLayer[idx + 1] = (byte)Math.Clamp(pLayer[idx + 1] + g, 0, 255);
|
||||||
pLayer[idx + 2] = (byte)Math.Clamp(pLayer[idx + 2] + b, 0, 255);
|
pLayer[idx + 2] = (byte)Math.Clamp(pLayer[idx + 2] + b, 0, 255);
|
||||||
pLayer[idx + 3] = 255;
|
pLayer[idx + 3] = 255;
|
||||||
|
|
||||||
|
_litLayers[layer] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddLight(int layer, int x, int y, Vector3 color, float strength, bool hdr)
|
public void AddLight(int layer, int x, int y, Vector3 color, float strength, bool hdr)
|
||||||
|
@ -271,9 +276,18 @@ public class WorldRep : IChunk
|
||||||
|
|
||||||
public void Reset(Vector3 ambientLight, bool hdr)
|
public void Reset(Vector3 ambientLight, bool hdr)
|
||||||
{
|
{
|
||||||
Layers = 0;
|
Layers = 33;
|
||||||
Pixels.Clear();
|
Pixels.Clear();
|
||||||
AddLayer();
|
var bytesPerLayer = Width * Height * Bpp;
|
||||||
|
for (var i = 0; i < Layers; i++)
|
||||||
|
{
|
||||||
|
Pixels.Add(new byte[bytesPerLayer]);
|
||||||
|
for (var j = 0; j < bytesPerLayer; j++)
|
||||||
|
{
|
||||||
|
Pixels[i][j] = 0;
|
||||||
|
}
|
||||||
|
_litLayers[i] = false;
|
||||||
|
}
|
||||||
|
|
||||||
for (var y = 0; y < Height; y++)
|
for (var y = 0; y < Height; y++)
|
||||||
{
|
{
|
||||||
|
@ -284,22 +298,14 @@ public class WorldRep : IChunk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddLayer()
|
|
||||||
{
|
|
||||||
var bytesPerLayer = Width * Height * Bpp;
|
|
||||||
Pixels.Add(new byte[bytesPerLayer]);
|
|
||||||
for (var j = 0; j < bytesPerLayer; j++)
|
|
||||||
{
|
|
||||||
Pixels[Layers][j] = 0;
|
|
||||||
}
|
|
||||||
Layers++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Write(BinaryWriter writer)
|
public void Write(BinaryWriter writer)
|
||||||
{
|
{
|
||||||
foreach (var layer in Pixels)
|
for (var i = 0; i < Layers; i++)
|
||||||
{
|
{
|
||||||
writer.Write(layer);
|
if (_litLayers[i])
|
||||||
|
{
|
||||||
|
writer.Write(Pixels[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -445,13 +445,6 @@ class Program
|
||||||
foreach (var light in lights)
|
foreach (var light in lights)
|
||||||
{
|
{
|
||||||
var layer = 0;
|
var layer = 0;
|
||||||
if (light.anim)
|
|
||||||
{
|
|
||||||
// Because we're building the AnimLightBitmask in this loop we
|
|
||||||
// know there aren't any layers set above us. So the target layer
|
|
||||||
// is just the number of set bits + 1.
|
|
||||||
layer = BitOperations.PopCount(info.AnimLightBitmask) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if plane normal is facing towards the light
|
// Check if plane normal is facing towards the light
|
||||||
// If it's not then we're never going to be (directly) lit by this
|
// If it's not then we're never going to be (directly) lit by this
|
||||||
|
@ -535,11 +528,7 @@ class Program
|
||||||
cell.AnimLights.Add((ushort)light.lightTableIndex);
|
cell.AnimLights.Add((ushort)light.lightTableIndex);
|
||||||
}
|
}
|
||||||
info.AnimLightBitmask |= 1u << paletteIdx;
|
info.AnimLightBitmask |= 1u << paletteIdx;
|
||||||
|
layer = paletteIdx + 1;
|
||||||
if (layer >= lightmap.Layers)
|
|
||||||
{
|
|
||||||
lightmap.AddLayer();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
var strength = CalculateLightStrengthAtPoint(light, pos, plane);
|
var strength = CalculateLightStrengthAtPoint(light, pos, plane);
|
||||||
lightmap.AddLight(layer, x, y, light.color, strength, hdr);
|
lightmap.AddLight(layer, x, y, light.color, strength, hdr);
|
||||||
|
|
Loading…
Reference in New Issue