Cut 5d-2: ParticlePool + OmniLight3D[4], CameraJuiceState, Hud hit-markers & vignette, unified SimEvent drain

This commit is contained in:
Meta Vens 2026-12-05 10:14:54 +01:00
commit 323c02cf8d
12 changed files with 2294 additions and 320 deletions

View file

@ -30,12 +30,17 @@ public partial class SionMapRenderer : Node3D
public required MeshInstance3D Instance;
}
private const int GroundTintGridSize = 128;
private static readonly Color NeutralAlpineDustTint = new(0.56f, 0.53f, 0.46f, 1.0f);
private readonly List<MeshInstance3D> _terrainChunks = new(36);
private readonly List<BuildingTileEntry> _buildingTiles = new(36);
private readonly Dictionary<string, StandardMaterial3D> _sharedBuildingMaterials = new(StringComparer.Ordinal);
private string? _builtForDir;
private ShaderMaterial? _terrainMat;
private ImageTexture? _surfaceTex;
private Color[]? _groundTintGrid;
private float _groundTintSizeM;
public bool IsBuilt { get; private set; }
public int TerrainChunkCount => _terrainChunks.Count;
@ -132,6 +137,26 @@ public partial class SionMapRenderer : Node3D
{
throw new InvalidOperationException($"Failed to decode Sion terrain surface texture: {surfPath}");
}
// Downsample CPU copy once for zero-readback terrain-tinted dust & impact plumes
var tintImg = (Image)img.Duplicate();
tintImg.Resize(GroundTintGridSize, GroundTintGridSize, Image.Interpolation.Bilinear);
var grid = new Color[GroundTintGridSize * GroundTintGridSize];
for (int y = 0; y < GroundTintGridSize; y++)
{
for (int x = 0; x < GroundTintGridSize; x++)
{
Color c = tintImg.GetPixel(x, y);
grid[y * GroundTintGridSize + x] = new Color(
Math.Clamp(c.R + 0.11f, 0.20f, 0.90f),
Math.Clamp(c.G + 0.11f, 0.20f, 0.88f),
Math.Clamp(c.B + 0.10f, 0.18f, 0.84f),
1.0f);
}
}
_groundTintGrid = grid;
_groundTintSizeM = sion.Metadata.SizeMeters;
img.GenerateMipmaps();
_surfaceTex = ImageTexture.CreateFromImage(img);
@ -476,6 +501,39 @@ public partial class SionMapRenderer : Node3D
return (defaultKey, defMat);
}
public Color SampleGroundTint(float worldX, float worldZ)
{
Color[]? grid = _groundTintGrid;
float sizeM = _groundTintSizeM;
if (grid is null || sizeM <= 1f || !float.IsFinite(worldX) || !float.IsFinite(worldZ))
{
return NeutralAlpineDustTint;
}
float half = sizeM * 0.5f;
float u = (worldX + half) / sizeM;
float v = (worldZ + half) / sizeM;
if (u < 0f || u > 1f || v < 0f || v > 1f)
{
return NeutralAlpineDustTint;
}
float fx = u * (GroundTintGridSize - 1);
float fy = v * (GroundTintGridSize - 1);
int x0 = Math.Clamp((int)MathF.Floor(fx), 0, GroundTintGridSize - 1);
int y0 = Math.Clamp((int)MathF.Floor(fy), 0, GroundTintGridSize - 1);
int x1 = Math.Min(x0 + 1, GroundTintGridSize - 1);
int y1 = Math.Min(y0 + 1, GroundTintGridSize - 1);
float tx = fx - x0;
float ty = fy - y0;
Color c00 = grid[y0 * GroundTintGridSize + x0];
Color c10 = grid[y0 * GroundTintGridSize + x1];
Color c01 = grid[y1 * GroundTintGridSize + x0];
Color c11 = grid[y1 * GroundTintGridSize + x1];
return c00.Lerp(c10, tx).Lerp(c01.Lerp(c11, tx), ty);
}
private void ClearBuilt()
{
for (int i = 0; i < _terrainChunks.Count; i++)
@ -493,6 +551,8 @@ public partial class SionMapRenderer : Node3D
_sharedBuildingMaterials.Clear();
_terrainMat = null;
_surfaceTex = null;
_groundTintGrid = null;
_groundTintSizeM = 0f;
_builtForDir = null;
IsBuilt = false;
ActiveLod1TileCount = 0;