Render all lightmap layers
This commit is contained in:
parent
3307cdc8a9
commit
d7b8ee35f4
|
@ -118,45 +118,29 @@ public class WorldRep : IChunk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly Vector4[] AsRgba(uint layer)
|
public readonly Vector4 GetPixel(uint layer, uint x, uint y)
|
||||||
{
|
{
|
||||||
if (layer >= Pixels.GetLength(0))
|
if (layer >= Pixels.GetLength(0) || x >= Pixels.GetLength(2) || y >= Pixels.GetLength(1))
|
||||||
{
|
{
|
||||||
|
return Vector4.Zero;
|
||||||
return System.Array.Empty<Vector4>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var height = Pixels.GetLength(1);
|
switch (Pixels.GetLength(3))
|
||||||
var width = Pixels.GetLength(2);
|
|
||||||
var bpp = Pixels.GetLength(3);
|
|
||||||
var colours = new Vector4[height * width];
|
|
||||||
for (var y = 0; y < height; y++)
|
|
||||||
{
|
|
||||||
for (var x = 0; x < width; x++)
|
|
||||||
{
|
|
||||||
var idx = x + y * width;
|
|
||||||
|
|
||||||
switch (bpp)
|
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
var raw1 = Pixels[layer, y, x, 0];
|
var raw1 = Pixels[layer, y, x, 0];
|
||||||
colours[idx] = new Vector4(raw1, raw1, raw1, 255) / 255.0f;
|
return new Vector4(raw1, raw1, raw1, 255) / 255.0f;
|
||||||
break;
|
|
||||||
case 2:
|
case 2:
|
||||||
var raw2 = Pixels[layer, y, x, 0] + (Pixels[layer, y, x, 1] << 8);
|
var raw2 = Pixels[layer, y, x, 0] + (Pixels[layer, y, x, 1] << 8);
|
||||||
colours[idx] = new Vector4(raw2 & 31, (raw2 >> 5) & 31, (raw2 >> 10) & 31, 32) / 32.0f;
|
return new Vector4(raw2 & 31, (raw2 >> 5) & 31, (raw2 >> 10) & 31, 32) / 32.0f;
|
||||||
break;
|
|
||||||
case 4:
|
case 4:
|
||||||
colours[idx] = new Vector4(Pixels[layer, y, x, 0], Pixels[layer, y, x, 1], Pixels[layer, y, x, 2], Pixels[layer, y, x, 3]) / 255.0f;
|
return new Vector4(Pixels[layer, y, x, 0], Pixels[layer, y, x, 1], Pixels[layer, y, x, 2], Pixels[layer, y, x, 3]) / 255.0f;
|
||||||
break;
|
default:
|
||||||
|
return Vector4.Zero;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return colours;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte VertexCount { get; set; }
|
public byte VertexCount { get; set; }
|
||||||
public byte PolyCount { get; set; }
|
public byte PolyCount { get; set; }
|
||||||
public byte RenderPolyCount { get; set; }
|
public byte RenderPolyCount { get; set; }
|
||||||
|
|
|
@ -137,15 +137,20 @@ public partial class Mission : Node3D
|
||||||
// Build lightmap
|
// Build lightmap
|
||||||
var lightmap = cell.Lightmaps[rect.Id];
|
var lightmap = cell.Lightmaps[rect.Id];
|
||||||
// TODO: Handle animlight layers
|
// TODO: Handle animlight layers
|
||||||
var colours = lightmap.AsRgba(0);
|
var layers = (uint)lightmap.Pixels.GetLength(0);
|
||||||
var height = lightmap.Pixels.GetLength(1);
|
var height = (uint)lightmap.Pixels.GetLength(1);
|
||||||
var width = lightmap.Pixels.GetLength(2);
|
var width = (uint)lightmap.Pixels.GetLength(2);
|
||||||
for (var y = 0; y < height; y++)
|
for (uint y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
for (var x = 0; x < width; x++)
|
for (uint x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
var rawColour = colours[x + y * width];
|
var rawColour = System.Numerics.Vector4.Zero;
|
||||||
image.SetPixel((int)rect.X + x, (int)rect.Y + y, new Color(rawColour.X, rawColour.Y, rawColour.Z, rawColour.W));
|
for (uint l = 0; l < layers; l++)
|
||||||
|
{
|
||||||
|
rawColour += lightmap.GetPixel(l, x, y);
|
||||||
|
}
|
||||||
|
var colour = new Color(MathF.Min(rawColour.X, 1.0f), MathF.Min(rawColour.Y, 1.0f), MathF.Min(rawColour.Z, 1.0f), MathF.Min(rawColour.W, 1.0f));
|
||||||
|
image.SetPixel((int)(rect.X + x), (int)(rect.Y + y), colour);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue