Publish current live selection and graphics source with external keys

This commit is contained in:
0xcjy
2026-10-02 12:07:33 +08:00
parent 737d34db87
commit d6efc31917
56 changed files with 16917 additions and 1788 deletions
@@ -16,16 +16,21 @@ namespace Gallop.RenderPipeline
public Vector3 InitialPosition;
public int NameHash;
public Material Material;
public MeshRenderer Renderer;
public bool HasColorPower, HasMulColor0;
public Color ColorFactor = Color.white;
public float BrightnessFactor = 1f;
public bool AutoBrightness = true;
public bool ScreenFit;
public bool HasBlinkColor;
public Color BlinkColor;
}
private readonly Dictionary<int, List<Target>> _groups = new Dictionary<int, List<Target>>();
private readonly List<Target> _targets = new List<Target>();
private readonly Dictionary<CustomLensFlare, Target> _bySource = new Dictionary<CustomLensFlare, Target>();
private readonly Plane[] _frustumPlanes = new Plane[6];
private readonly MaterialPropertyBlock _lightProperties = new MaterialPropertyBlock();
private readonly float _standard;
private readonly float _under;
private readonly int _colorPowerId;
@@ -38,6 +43,11 @@ namespace Gallop.RenderPipeline
_under = under;
_colorPowerId = ShaderManager.GetPropertyId(ShaderManager.PropertyId._ColorPower);
_mulColor0Id = ShaderManager.GetPropertyId(ShaderManager.PropertyId._MulColor0);
AddSources(root, nameSuffixToken);
}
public void AddSources(Transform root, string nameSuffixToken)
{
if (root == null) return;
foreach (var flare in root.GetComponentsInChildren<CustomLensFlare>(true))
{
@@ -52,10 +62,12 @@ namespace Gallop.RenderPipeline
InitialPosition = sourceTransform.localPosition,
NameHash = FNVHash.Generate(flare.name + nameSuffixToken),
Material = material,
Renderer = renderer,
HasColorPower = material != null && material.HasProperty(_colorPowerId),
HasMulColor0 = material != null && material.HasProperty(_mulColor0Id)
};
_targets.Add(target);
_bySource.Add(flare, target);
if (sourceTransform.parent == null) continue;
// Native strips every literal Clone token from the parent only.
int parentHash = FNVHash.Generate(sourceTransform.parent.name.Replace("(Clone)", string.Empty) + nameSuffixToken);
@@ -68,6 +80,34 @@ namespace Gallop.RenderPipeline
}
}
public void RemoveSources(Transform root, string nameSuffixToken)
{
for (int i = _targets.Count - 1; i >= 0; i--)
{
var target = _targets[i];
if (target.Transform == null || !target.Transform.IsChildOf(root)) continue;
var parent = target.Transform.parent;
if (parent != null)
{
int hash = FNVHash.Generate(parent.name.Replace("(Clone)", string.Empty) + nameSuffixToken);
if (_groups.TryGetValue(hash, out var group))
{
group.Remove(target);
if (group.Count == 0) _groups.Remove(hash);
}
}
_targets.RemoveAt(i);
_bySource.Remove(target.Flare);
}
}
internal void SetBlinkColor(CustomLensFlare flare, Color color)
{
if (flare == null || !_bySource.TryGetValue(flare, out var target)) return;
target.HasBlinkColor = true;
target.BlinkColor = color;
}
public void Apply(ref LensFlareUpdateInfo info)
{
if (_groups.TryGetValue(info.TimelineNameHash, out var group))
@@ -110,8 +150,23 @@ namespace Gallop.RenderPipeline
Color color = target.ColorFactor;
if (target.Material != null)
{
Color materialColor = target.HasMulColor0 ? target.Material.GetColor(_mulColor0Id) : Color.white;
float colorPower = target.HasColorPower ? target.Material.GetFloat(_colorPowerId) : 1f;
// Stage lighting uses property blocks instead of changing the material.
// Read the same first-slot values that the authored source mesh draws.
_lightProperties.Clear();
if (target.Renderer != null)
{
target.Renderer.GetPropertyBlock(_lightProperties, 0);
if (_lightProperties.isEmpty)
target.Renderer.GetPropertyBlock(_lightProperties);
}
Color materialColor = target.HasBlinkColor ? target.BlinkColor : target.HasMulColor0
? _lightProperties.HasColor(_mulColor0Id)
? _lightProperties.GetColor(_mulColor0Id) : target.Material.GetColor(_mulColor0Id)
: Color.white;
float colorPower = target.HasColorPower
? _lightProperties.HasFloat(_colorPowerId)
? _lightProperties.GetFloat(_colorPowerId) : target.Material.GetFloat(_colorPowerId)
: 1f;
color *= materialColor * (colorPower * 2f);
}
bool visibleColor = color.r > 0.000001f || color.g > 0.000001f || color.b > 0.000001f;