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
@@ -1,4 +1,4 @@
using Gallop.ImageEffect;
using Gallop.ImageEffect;
using Gallop.RenderPipeline;
using UnityEngine;
@@ -14,6 +14,15 @@ namespace Gallop
public DofDiffusionBloomOverlayParam DofDiffusionBloomOverlayParam => _dofDiffusionBloomOverlayParam;
public bool IsInitialized { get; private set; }
private CameraData _cameraData;
public PostImageEffectFeature.Parameter RenderParameter
{
get
{
if (!IsInitialized) InitializeVolume();
return _cameraData.Parameter;
}
}
// 子系统 A7b:原生 GallopImageEffect.get_ExposureParam(RVA=0x19a97b0) /
// get_ToneCurveParam(RVA=0x19a9930) 的 master7 等价属性。原生 getter 返回
@@ -39,10 +48,16 @@ namespace Gallop
if (adapter != null) adapter.ApplyBloomParameter();
}
private void Awake() { InitializeVolume(); }
protected void Awake() { InitializeVolume(); }
// Retained for existing callers; no spatial Volume is created.
public void InitializeVolume() { IsInitialized = true; }
public virtual void InitializeVolume()
{
if (IsInitialized) return;
if (!TryGetComponent(out _cameraData))
_cameraData = gameObject.AddComponent<CameraData>();
IsInitialized = true;
}
public void ApplyBloomParameter()
{
@@ -50,24 +65,18 @@ namespace Gallop
if (director == null || director.MainRenderCamera == null ||
director.MainRenderCamera.gameObject != gameObject) return;
var parameter = PostImageEffectFeature.RuntimeParameter;
var parameter = RenderParameter;
PostImageEffectFeature.RuntimeParameter = parameter;
parameter.DofDiffuionBloomOverlay.Setup(_dofDiffusionBloomOverlayParam);
if (!UserDofEnabled)
{
parameter.DofDiffuionBloomOverlay.IsEnableDof = false;
parameter.DofDiffuionBloomOverlay.IsEnableOldDof = false;
}
parameter.DofDiffuionBloomOverlay.DecideDrawType(
UserDofEnabled && _dofDiffusionBloomOverlayParam.IsEnableDof);
_cameraData.UpdateImageEffectParameter();
parameter.TargetCamera = director.MainRenderCamera;
// 子系统 A7b:原生 CameraData.UpdateImageEffectParameter(RVA=0x1a0da30)
// 末尾 jmp Parameter.DecideDrawType,把 GallopImageEffect 的参数块
//(DOF + Exposure + ToneCurve…)统一交给渲染侧。master7 的
// PostImageEffectFeature.Parameter 还没有 Exposure/ToneCurve 的
// pass 消费字段,因此先挂在运行时参数对象上供后续
// ExposurePass/ToneCurvePass(原生 RVA=0x1a22e10/0x1a527d0)接入,
// 数据已随时间轴逐帧刷新,不会比原生缺帧。
// Exposure and tone curves publish into the same camera-owned render state.
parameter.ExposureParam.Setup(ExposureParam);
parameter.ToneCurveParam.Setup(ToneCurveParam);
}
@@ -0,0 +1,15 @@
namespace Gallop
{
// Serialized Live camera subtype. The base image effect is also used outside Live.
public class LiveImageEffect : GallopImageEffect
{
public override void InitializeVolume()
{
if (IsInitialized) return;
base.InitializeVolume();
// Actual game Initialize RVA 0x7395c80 calls the base initializer,
// then writes render Parameter+0x1b=true (0x7395ced). Not source Setup.
RenderParameter.DofDiffuionBloomOverlay.IsEnableDofAutoDisable = true;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 428adbfbca84b7e49a12cc841c2928b3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
@@ -331,7 +331,7 @@ namespace Gallop.Live.Cutt
public event HdrBloomUpdateInfoDelegate OnUpdateHdrBloom;
public event Action<PostEffectUpdateInfo_BloomDiffusion> OnUpdatePostEffect_BloomDiffusion;
public event Action<LiveTimelineKeyPostEffectDOFData> OnUpdatePostEffect_Dof;
public event Action<LiveTimelineKeyPostEffectDOFData, Vector3?> OnUpdatePostEffect_Dof;
public bool HasDofCameraLookAt { get; private set; }
public Vector3 DofCameraLookAt { get; private set; }
public Camera DofTrackCamera { get; private set; }
@@ -395,6 +395,7 @@ namespace Gallop.Live.Cutt
public event Action RecordUma;
public Dictionary<string, GameObject> StageObjectMap = new Dictionary<string, GameObject>();
public Dictionary<string, StageObjectUnit> StageObjectUnitMap = new Dictionary<string, StageObjectUnit>();
public float currentLiveTime
{
@@ -553,16 +554,18 @@ namespace Gallop.Live.Cutt
public void InitCharaMotionSequence(int[] motionSequence)
{
//Create Animation
foreach (var obj in Director.instance.charaObjs)
var director = Director.instance;
// Native InitCharaMotionSequence retains an entry for each physical slot.
foreach (var obj in director.charaObjs)
{
var container = obj.GetComponentInChildren<UmaContainer>();
if (container)
var container = obj != null ? obj.GetComponentInChildren<UmaContainer>() : null;
Animation animation = null;
if (container != null)
{
EnsureMicMotionTransforms(container.transform);
var animation = container.gameObject.AddComponent<Animation>();
Director.instance.charaAnims.Add(animation);
animation = container.gameObject.AddComponent<Animation>();
}
director.charaAnims.Add(animation);
}
//Get KeyArray
@@ -578,14 +581,14 @@ namespace Gallop.Live.Cutt
if (Director.instance.liveMode == 1)
{
//Set Motion
int CharaPositionMax = Director.instance.allowCount;
int CharaPositionMax = Mathf.Max(0, Mathf.Min(director.allowCount,
Mathf.Min(director.charaObjs.Count, motionSequence != null ? motionSequence.Length : 0)));
_motionSequenceArray = new LiveTimelineMotionSequence[CharaPositionMax];
for (int i = 0; i < CharaPositionMax; i++)
{
Debug.Log(i);
_motionSequenceArray[i] = new LiveTimelineMotionSequence();
_motionSequenceArray[i].Initialize(Director.instance.charaObjs[i], i, motionSequence[i], this);
}
@@ -597,7 +600,10 @@ namespace Gallop.Live.Cutt
foreach (var motion in UmaViewerMain.Instance.AbMotions.Where(a => a.Name.StartsWith($"3d/motion/live/body/son{Director.instance.live.MusicId}") && Path.GetFileName(a.Name).Split('_').Length == 4))
{
AssetBundle motionAB = UmaAssetManager.LoadAssetBundle(motion);
AnimationClip motionAnim = motionAB.LoadAsset<AnimationClip>(Path.GetFileName(motion.Name).Split('.')[0]);
AnimationClip motionAnim = motionAB != null
? motionAB.LoadAsset<AnimationClip>(Path.GetFileName(motion.Name).Split('.')[0]) : null;
if (motionAnim == null)
Debug.LogError("[LiveTimelineControl] Basic motion clip load failed: " + motion.Name);
if (Gallop.Live.LiveRuntimeDiagnostics.Enabled)
Gallop.Live.LiveRuntimeDiagnostics.RecordAssetLoad(motion.Name, "LoadAsset", typeof(AnimationClip),
new UnityEngine.Object[] { motionAnim }, motionAnim, Path.GetFileName(motion.Name).Split('.')[0]);
@@ -605,7 +611,8 @@ namespace Gallop.Live.Cutt
}
//Set Motion
int CharaPositionMax = Director.instance.allowCount;
int CharaPositionMax = Mathf.Max(0, Mathf.Min(director.allowCount,
Mathf.Min(director.charaObjs.Count, Mathf.Min(director.charaAnims.Count, Anims.Count))));
_motionSequenceArray = new LiveTimelineMotionSequence[CharaPositionMax];
@@ -613,7 +620,7 @@ namespace Gallop.Live.Cutt
for (int i = 0; i < CharaPositionMax; i++)
{
_motionSequenceArray[i] = new LiveTimelineMotionSequence();
_motionSequenceArray[i].Initialize(Director.instance.charaObjs[i], i, motionSequence[i], this, Anims);
_motionSequenceArray[i].Initialize(director.charaObjs[i], i, i, this, Anims);
}
}
@@ -1585,26 +1592,15 @@ namespace Gallop.Live.Cutt
LiveTimelineKeyCameraPositionData liveTimelineKeyCameraPositionData = curKey as LiveTimelineKeyCameraPositionData;
camera.camera.nearClipPlane = liveTimelineKeyCameraPositionData.nearClip;
camera.camera.farClipPlane = liveTimelineKeyCameraPositionData.farClip;
// Native AlterUpdate_CameraPos (0x1acd38c..0x1acd3f4) preserves unflagged state.
if (((int)liveTimelineKeyCameraPositionData.attribute & 0x20000) != 0)
camera.camera.cullingMask = liveTimelineKeyCameraPositionData.GetCullingMask();
if (((int)liveTimelineKeyCameraPositionData.attribute & 0x40000) != 0)
camera.camera.backgroundColor = liveTimelineKeyCameraPositionData.BgColor;
if (CalculateCameraPos(out var pos, sheet, curKey, nextKey, currentFrame))
{
camera.cacheTransform.position = pos;
// TODO 锟斤拷锟斤拷锟矫的伙拷锟斤拷CGSS锟斤拷layer枚锟劫o拷要锟斤拷锟斤拷锟芥换
/*
int num = liveTimelineKeyCameraPositionData.GetCullingMask();
if (num == 0)
{
num = LiveTimelineKeyCameraPositionData.GetDefaultCullingMask();
}
camera.camera.cullingMask = num;
if (OnUpdateCameraPos != null)
{
CameraPosUpdateInfo updateInfo = default(CameraPosUpdateInfo);
updateInfo.outlineZOffset = liveTimelineKeyCameraPositionData.outlineZOffset;
updateInfo.characterLODMask = (int)liveTimelineKeyCameraPositionData.characterLODMask;
OnUpdateCameraPos(ref updateInfo);
}
*/
}
}
@@ -2440,7 +2436,7 @@ namespace Gallop.Live.Cutt
private void AlterUpdate_MobControl(LiveTimelineWorkSheet sheet, float currentFrame)
{
AlterUpdate_MobCyalumeControl(
sheet != null ? sheet.mobControlList : null,
sheet != null ? sheet.MobControlKeys : null,
currentFrame,
OnUpdateMobControl);
}
@@ -2448,7 +2444,7 @@ namespace Gallop.Live.Cutt
private void AlterUpdate_CyalumeControl(LiveTimelineWorkSheet sheet, float currentFrame)
{
AlterUpdate_MobCyalumeControl(
sheet != null ? sheet.cyalumeControlList : null,
sheet != null ? sheet.CyalumeControlKeys : null,
currentFrame,
OnUpdateCyalumeControl);
}
@@ -2465,10 +2461,10 @@ namespace Gallop.Live.Cutt
for (int i = 0; i < count; i++)
{
var controlData = dataList[i];
if (controlData == null || controlData.keys == null)
if (controlData == null || controlData.Keys == null || (uint)controlData.GroupIndex >= 11u)
continue;
var keys = controlData.keys;
var keys = controlData.Keys;
if (keys.Count <= 0)
continue;
if (keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable))
@@ -2485,22 +2481,22 @@ namespace Gallop.Live.Cutt
MobCyalumeUpdateInfo info = default;
info.data = controlData;
info.unk0 = (uint)keys.unk48 < 11u ? keys.unk48 : i;
info.unk0 = controlData.GroupIndex;
info.currentFrame = currentFrame;
info.currentLiveTime = currentLiveTime;
if (next != null && next.interpolateType != 0)
{
float t = CalculateInterpolationValue(current, next, currentFrame);
info.position = Vector3.Lerp(current.position, next.position, t);
info.position = Vector3.Lerp(current.Position, next.Position, t);
info.rotation = Quaternion.Lerp(current.GetRotation(), next.GetRotation(), t);
info.scale = Vector3.Lerp(current.scale, next.scale, t);
info.scale = Vector3.Lerp(current.Scale, next.Scale, t);
}
else
{
info.position = current.position;
info.position = current.Position;
info.rotation = current.GetRotation();
info.scale = current.scale;
info.scale = current.Scale;
}
callback.Invoke(ref info);
@@ -2975,7 +2971,8 @@ namespace Gallop.Live.Cutt
continue;
}
if (StageObjectMap == null || !StageObjectMap.ContainsKey(objectEntry.name))
if ((StageObjectMap == null || !StageObjectMap.ContainsKey(objectEntry.name)) &&
(StageObjectUnitMap == null || !StageObjectUnitMap.ContainsKey(objectEntry.name)))
continue;
FindTimelineKey(out var curKey, out var nextKey, keys, currentFrame);
@@ -3207,6 +3204,27 @@ namespace Gallop.Live.Cutt
}
}
private Vector3? ResolveDofWorldFocus(LiveTimelineKeyPostEffectDOFData key)
{
if (((int)key.attribute & (1 << 16)) != 0)
return HasDofCameraLookAt ? DofCameraLookAt : (Vector3?)null;
bool valid = key.charactor == 0;
for (int i = 0; !valid && i < liveCharactorLocators.Length && i < liveCharaPositionMax; ++i)
valid = (key.charactor & (1 << i)) != 0 && liveCharactorLocators[i] != null;
return valid ? GetPositionWithCharacters(key.FocusCharacters, LiveCameraCharaParts.Face,
Vector3.zero, Vector3.zero) : (Vector3?)null;
}
private Vector3? SetupDofWorldFocus(LiveTimelineKeyPostEffectDOFData current,
LiveTimelineKeyPostEffectDOFData next, float progress)
{
var start = ResolveDofWorldFocus(current);
if (ReferenceEquals(current, next)) return start;
var end = ResolveDofWorldFocus(next);
return start.HasValue && end.HasValue
? Vector3.LerpUnclamped(start.Value, end.Value, progress) : (Vector3?)null;
}
private void AlterUpdate_PostEffect_Dof(LiveTimelineWorkSheet sheet, int frame)
{
DofTrackCamera = GetCamera(sheet.targetCameraIndex)?.camera;
@@ -3214,32 +3232,32 @@ namespace Gallop.Live.Cutt
if (keys == null || keys.HasAttribute(LiveTimelineKeyDataListAttr.Disable) ||
!keys.EnablePlayModeTimeline(_playMode))
{
OnUpdatePostEffect_Dof?.Invoke(null);
OnUpdatePostEffect_Dof?.Invoke(null, null);
return;
}
FindTimelineKey(out var currentBase, out var nextBase, keys, frame);
var current = currentBase as LiveTimelineKeyPostEffectDOFData;
var next = nextBase as LiveTimelineKeyPostEffectDOFData;
if (current == null) { OnUpdatePostEffect_Dof?.Invoke(null); return; }
if (current == null) { OnUpdatePostEffect_Dof?.Invoke(null, null); return; }
float t = next != null && next.IsInterpolateKey()
? CalculateInterpolationValue(current, next, frame) : 0f;
if (next == null) next = current;
if (next == null || !next.IsInterpolateKey()) next = current;
var sample = _dofSample;
sample.frame = current.frame;
sample.attribute = current.attribute;
sample.charactor = current.charactor;
sample.dofBlurType = current.dofBlurType;
sample.dofQuality = current.dofQuality;
sample.forcalSize = Mathf.Lerp(current.forcalSize, next.forcalSize, t);
sample.blurSpread = Mathf.Lerp(current.blurSpread, next.blurSpread, t);
sample.dofForegroundSize = Mathf.Lerp(current.dofForegroundSize, next.dofForegroundSize, t);
sample.dofFocalPoint = Mathf.Lerp(current.dofFocalPoint, next.dofFocalPoint, t);
sample.dofSmoothness = Mathf.Lerp(current.dofSmoothness, next.dofSmoothness, t);
sample.BallBlurPowerFactor = Mathf.Lerp(current.BallBlurPowerFactor, next.BallBlurPowerFactor, t);
sample.BallBlurBrightnessThreshhold = Mathf.Lerp(current.BallBlurBrightnessThreshhold, next.BallBlurBrightnessThreshhold, t);
sample.BallBlurBrightnessIntensity = Mathf.Lerp(current.BallBlurBrightnessIntensity, next.BallBlurBrightnessIntensity, t);
sample.BallBlurSpread = Mathf.Lerp(current.BallBlurSpread, next.BallBlurSpread, t);
OnUpdatePostEffect_Dof?.Invoke(sample);
sample.forcalSize = LerpWithoutClamp(current.forcalSize, next.forcalSize, t);
sample.blurSpread = LerpWithoutClamp(current.blurSpread, next.blurSpread, t);
sample.dofForegroundSize = LerpWithoutClamp(current.dofForegroundSize, next.dofForegroundSize, t);
sample.dofFocalPoint = LerpWithoutClamp(current.dofFocalPoint, next.dofFocalPoint, t);
sample.dofSmoothness = LerpWithoutClamp(current.dofSmoothness, next.dofSmoothness, t);
sample.BallBlurPowerFactor = LerpWithoutClamp(current.BallBlurPowerFactor, next.BallBlurPowerFactor, t);
sample.BallBlurBrightnessThreshhold = LerpWithoutClamp(current.BallBlurBrightnessThreshhold, next.BallBlurBrightnessThreshhold, t);
sample.BallBlurBrightnessIntensity = LerpWithoutClamp(current.BallBlurBrightnessIntensity, next.BallBlurBrightnessIntensity, t);
sample.BallBlurSpread = LerpWithoutClamp(current.BallBlurSpread, next.BallBlurSpread, t);
OnUpdatePostEffect_Dof?.Invoke(sample, SetupDofWorldFocus(current, next, t));
}
private void AlterUpdate_PostEffect_BloomDiffusion( LiveTimelineWorkSheet sheet, int currentFrame)
@@ -225,6 +225,9 @@ namespace Gallop.Live.Cutt
public float maxForcalSize;
public bool isUseMirrorScanMotionDictionary;
public bool isUseGameSettingToParticle;
public bool IsChangedCharaLayerOnlyMirrorRendering;
public bool IsRenderMirrorObjectOnlyOnBaseCamera;
public bool UseDepthOnlyCube;
public LiveTimelineStageObjectsSettings stageObjectsSettings;
public LiveTimelineDebugSettings debugSettings;
}
@@ -10,9 +10,9 @@ namespace Gallop.Live.Cutt
{
get{return LiveTimelineKeyDataType.CyalumeControl;}
}
public Vector3 position;
public Vector3 angle;
public Vector3 scale = Vector3.one;
public Vector3 Position;
public Vector3 Angle;
public Vector3 Scale = Vector3.one;
[NonSerialized]
private Quaternion _rotationCache = Quaternion.identity;
@@ -24,7 +24,7 @@ namespace Gallop.Live.Cutt
{
if (!_hasRotationCache)
{
_rotationCache = Quaternion.Euler(angle);
_rotationCache = Quaternion.Euler(Angle);
_hasRotationCache = true;
}
@@ -35,13 +35,13 @@ namespace Gallop.Live.Cutt
[Serializable]
public class LiveTimelineKeyMobCyalumeControlDataList : LiveTimelineKeyDataListTemplate<LiveTimelineKeyMobCyalumeControlData>
{
public int unk48;
}
[Serializable]
public class LiveTimelineMobCyalumeControlData : ILiveTimelineGroupDataWithName
{
public LiveTimelineKeyMobCyalumeControlDataList keys;
public int GroupIndex;
public LiveTimelineKeyMobCyalumeControlDataList Keys;
}
public delegate void MobCyalumeUpdateInfoDelegate(ref MobCyalumeUpdateInfo updateInfo);
@@ -34,17 +34,11 @@ namespace Gallop.Live.Cutt
/// </summary>
public LiveCharaPositionFlag FocusCharacters => (LiveCharaPositionFlag)charactor;
// High `attribute` bits are per-track flags (same convention as
// LiveTimelineMonitorData). Across the 4427 authored keys only bits 16..19
// appear, in the combinations 0x50000 (3117), 0x70000 (923), 0x60000 (108),
// 0x10000 (106), 0x40000 (77), 0x30000 (72), 0x20000 (22), 0x00000 (1) and
// 0xF0000 (1). Bit 17 covaries with an authored dofFocalPoint: 95.1% of the
// 3301 bit17-clear keys leave it at the 1.0 default, while 88.1% of the 1126
// bit17-set keys carry a real distance. Bit 16 covaries the other way with
// `charactor`: only 1.4% of the 4219 bit16-set keys move it off Center,
// against 56.7% of the 208 bit16-clear keys. The flag names are still
// unknown. Timeline mode tests the inferred bit17=metric / bit16=camera
// target mapping; see docs/LIVE_DOF_TIMELINE_2026-09-06.md for pixel evidence.
// Actual game metadata and SetupDOFUpdateInfo RVA 0x726a610 confirm:
// bit16 ATTR_USE_LOOKAT; bit17 ATTR_USE_FOCAL_POINT;
// bit18 ATTR_ENABLE_DOF; bit19 ATTR_IS_POINT_BALL_BLUR.
// Current-key flags select the mode; both endpoints resolve world focus
// independently before the next key's unclamped interpolation is applied.
}
[Serializable]
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using RootMotion.FinalIK;
@@ -43,56 +44,96 @@ namespace Gallop.Live.Cutt
public void Initialize(Transform target, int targetIndex, int seqDataIndex, LiveTimelineControl timelineControl, List<AnimationClip> animclips = null)
{
if(animclips != null)
{
if (targetIndex < Director.instance.charaAnims.Count)
{
_targetAnim = animclips[targetIndex];
_tempAnim = Director.instance.charaAnims[targetIndex];
_tempAnim.AddClip(_targetAnim, _targetAnim.name);
}
var animations = Director.instance.charaAnims;
if (targetIndex < 0 || targetIndex >= animations.Count || animations[targetIndex] == null)
return;
}
_tempTarget = target;
_targetIndex = targetIndex;
charaIndex = targetIndex;
_tempAnim = animations[targetIndex];
if (animclips != null)
{
if (targetIndex >= animclips.Count) return;
_targetAnim = animclips[targetIndex];
if (_targetAnim != null) _tempAnim.AddClip(_targetAnim, _targetAnim.name);
return;
}
_keyArray = timelineControl._keyArray;
if (seqDataIndex < _keyArray.Length)
if (seqDataIndex < 0 || seqDataIndex >= _keyArray.Length) return;
_currentKey = _keyArray[seqDataIndex];
_sampleIk = _tempAnim.GetComponent<BipedIK>();
if (_sampleIk != null)
{
_currentKey = _keyArray[seqDataIndex];
// SolverManager.Update otherwise restores the bind pose after our manual sample.
_resetIkBeforeSample = _sampleIk.fixTransforms;
if (_resetIkBeforeSample) _sampleIk.fixTransforms = false;
}
if (targetIndex < Director.instance.charaAnims.Count)
{
_tempAnim = Director.instance.charaAnims[targetIndex];
_sampleIk = _tempAnim.GetComponent<BipedIK>();
if (_sampleIk != null)
{
// SolverManager.Update otherwise restores the bind pose after our manual sample.
_resetIkBeforeSample = _sampleIk.fixTransforms;
if (_resetIkBeforeSample) _sampleIk.fixTransforms = false;
}
}
if(_currentKey != null && _tempAnim != null)
if (_currentKey != null)
{
foreach (var key in _currentKey.thisList)
{
if(key.clip != null)
{
_tempAnim.AddClip(key.clip, key.clip.name);
}
}
SetupAnimationClip(key);
}
_tempAnim.wrapMode = WrapMode.Clamp;
_tempAnim.enabled = false;
}
private void SetupAnimationClip(LiveTimelineKeyCharaMotionData key)
{
// Native SetupAnimationClip (0x1af9ed0) ignores unnamed main-motion keys.
if (key == null || string.IsNullOrEmpty(key.motionName)) return;
// Native LoadAnimationClip (0x1ae4780) uses the existing clip triplet first.
if (key.clip == null)
{
key.clip = LoadLiveAnimationClip(key.motionName, key.clip);
key.clip2 = LoadLiveAnimationClip(key.motionName2, key.clip2);
key.clip3 = LoadLiveAnimationClip(key.motionName3, key.clip3);
}
if (key.clip != null) _tempAnim.AddClip(key.clip, key.clip.name);
if (key.clip2 != null) _tempAnim.AddClip(key.clip2, key.clip2.name);
if (key.clip3 != null) _tempAnim.AddClip(key.clip3, key.clip3.name);
}
private static AnimationClip LoadLiveAnimationClip(string motionName, AnimationClip existingClip)
{
if (existingClip != null || string.IsNullOrEmpty(motionName)) return existingClip;
// ResourcePath.GetLiveAnimationClipPath: original body motion, not a substitute action.
string path = "3d/motion/live/body/" + motionName;
var entry = LiveEffectController.FindResourceEntry(path);
if (entry == null)
{
Debug.LogError("[LiveTimelineMotionSequence] Motion resource not found: " + path);
return null;
}
var bundle = UmaAssetManager.LoadAssetBundle(entry);
if (bundle == null)
{
Debug.LogError("[LiveTimelineMotionSequence] Motion bundle load failed: " + path);
return null;
}
string assetName = Path.GetFileNameWithoutExtension(entry.Name);
var clip = bundle.LoadAsset<AnimationClip>(assetName);
if (clip == null)
{
foreach (string asset in bundle.GetAllAssetNames())
{
if (!string.Equals(Path.GetFileNameWithoutExtension(asset), assetName, StringComparison.OrdinalIgnoreCase))
continue;
clip = bundle.LoadAsset<AnimationClip>(asset);
break;
}
}
if (LiveRuntimeDiagnostics.Enabled)
LiveRuntimeDiagnostics.RecordAssetLoad(entry.Name, "LoadAsset", typeof(AnimationClip),
new UnityEngine.Object[] { clip }, clip, assetName);
if (clip == null)
Debug.LogError("[LiveTimelineMotionSequence] Motion clip load failed: " + path + " (" + assetName + ")");
return clip;
}
public void AlterUpdate(float currentTime, LiveTimelineKeyTimescaleDataList timescaleKeys)
{
var director = Director.instance;
@@ -122,6 +163,7 @@ namespace Gallop.Live.Cutt
_curIndex = curKey.index;
LiveTimelineKeyCharaMotionData arg = curKey.key as LiveTimelineKeyCharaMotionData;
if (arg == null || string.IsNullOrEmpty(arg.motionName) || arg.clip == null) return;
AnimationClip anim = arg.clip;
double start;
@@ -172,13 +172,11 @@ namespace Gallop.Live.Cutt
public bool newBezierCalcMethod;
public CullingLayer cullingMask = defCameraCullingLayer;
public float outlineZOffset = 1f;
public CharacterLOD characterLODMask = (CharacterLOD)((uint)outlineLODMask + (uint)shaderLODMask);
protected const CullingLayer defCameraCullingLayer = (CullingLayer)0x7FE;
protected const CharacterLOD outlineLODMask = (CharacterLOD)0x3FF;
@@ -186,92 +184,21 @@ namespace Gallop.Live.Cutt
public int GetCullingMask()
{
return GetCullingMask(cullingMask);
}
protected static int GetCullingMask(CullingLayer layer)
{
int num = 257;
if ((layer & CullingLayer.TransparentFX) != 0)
{
num |= 2;
}
if ((layer & CullingLayer.Background3D_NotReflect) != 0)
{
num |= 0x80000;
}
if ((layer & CullingLayer.Background3d) != 0)
{
num |= 0x100000;
}
if ((layer & CullingLayer.Character3d) != 0)
{
num |= 0x200000;
}
if ((layer & CullingLayer.Character3d_0) != 0)
{
num |= 0x400000;
}
if ((layer & CullingLayer.Character3d_1) != 0)
{
num |= 0x800000;
}
if ((layer & CullingLayer.Character3d_2) != 0)
{
num |= 0x1000000;
}
if ((layer & CullingLayer.Character3d_3) != 0)
{
num |= 0x2000000;
}
if ((layer & CullingLayer.Character3d_4) != 0)
{
num |= 0x4000000;
}
if ((layer & CullingLayer.Character3D_NotReflect) != 0)
{
num |= 0x8000000;
}
if ((layer & CullingLayer.Background3D_Other) != 0)
{
num |= 0x40000;
}
return num;
/*
uint bittest = (uint)layer;
uint result = (uint)LayerMask.GetMask("Default");
if ((bittest & (uint)CullingLayer.TransparentFX) > 0)
result |= (uint)LayerMask.GetMask("TransparentFX");
if ((bittest & (uint)CullingLayer.Background3D_NotReflect) > 0)
result |= (uint)LayerMask.GetMask("background_NotReflect");
if ((bittest & (uint)CullingLayer.Background3d) > 0)
result |= (uint)LayerMask.GetMask("background");
if ((bittest & (uint)CullingLayer.Character3d) > 0)
result |= (uint)LayerMask.GetMask("charas");
if ((bittest & (uint)CullingLayer.Character3d_0) > 0)
result |= (uint)LayerMask.GetMask("chara1");
if ((bittest & (uint)CullingLayer.Character3d_1) > 0)
result |= (uint)LayerMask.GetMask("chara2");
if ((bittest & (uint)CullingLayer.Character3d_2) > 0)
result |= (uint)LayerMask.GetMask("chara3");
if ((bittest & (uint)CullingLayer.Character3d_3) > 0)
result |= (uint)LayerMask.GetMask("chara4");
if ((bittest & (uint)CullingLayer.Character3d_4) > 0)
result |= (uint)LayerMask.GetMask("chara5");
if ((bittest & (uint)CullingLayer.Character3D_NotReflect) > 0)
result |= (uint)LayerMask.GetMask("otherChara");
if ((bittest & (uint)CullingLayer.Background3D_Other) > 0)
result |= (uint)LayerMask.GetMask("background_Other");
return (int)result;
*/
}
public static int GetDefaultCullingMask()
{
return GetCullingMask(defCameraCullingLayer);
// Native GetCullingMask (0x1af50a0) reads cullingLayer, not the legacy CGSS mask.
int mask = 0;
if ((cullingLayer & LiveCameraCullingLayer.TransparentFX) != 0) mask |= 1 << 1;
if ((cullingLayer & LiveCameraCullingLayer.Effect) != 0) mask |= 1 << 11;
if ((cullingLayer & LiveCameraCullingLayer.Background3d_NotReflect) != 0) mask |= 1 << 25;
if ((cullingLayer & LiveCameraCullingLayer.Background3d) != 0) mask |= 1 << 12;
if ((cullingLayer & LiveCameraCullingLayer.Character3d) != 0) mask |= 1 << 13;
if ((cullingLayer & LiveCameraCullingLayer.Character3d_0) != 0) mask |= 1 << 27;
if ((cullingLayer & LiveCameraCullingLayer.Character3d_1) != 0) mask |= 1 << 28;
if ((cullingLayer & LiveCameraCullingLayer.Character3d_NotReflect) != 0) mask |= 1 << 26;
if ((cullingLayer & LiveCameraCullingLayer.NotLayerDefault) == 0)
mask |= GraphicSettings.GetCullingLayer(GraphicSettings.LayerIndex.LayerDefault);
if ((cullingLayer & LiveCameraCullingLayer.NotLayer3d) == 0)
mask |= GraphicSettings.GetCullingLayer(GraphicSettings.LayerIndex.Layer3D);
return mask;
}
public virtual Vector3 GetValue(LiveTimelineControl timelineControl)
@@ -498,8 +425,8 @@ namespace Gallop.Live.Cutt
[SerializeField] public List<LiveTimelineTransformData> transformList;
[SerializeField] public List<LiveTimelineObjectData> objectList;
[SerializeField] public List<LiveTimelineMobCyalumeControlData> mobControlList;
[SerializeField] public List<LiveTimelineMobCyalumeControlData> cyalumeControlList;
[SerializeField] public List<LiveTimelineMobCyalumeControlData> MobControlKeys;
[SerializeField] public List<LiveTimelineMobCyalumeControlData> CyalumeControlKeys;
private void OnEnable()
{
@@ -303,6 +303,7 @@ namespace Gallop.Live.Cyalume
_mobShadowController = mobRoot.AddComponent<MobShadowController>();
_mobShadowController.Initialize(mobRoot);
_mobShadowController.FlushGroupMatrix();
_mobShadowController.SetMobColor(_mobColor);
_mobShadowController.SetAmbientColor(_mobAmbientColor);
@@ -340,8 +341,8 @@ namespace Gallop.Live.Cyalume
if ((uint)info.unk0 < 11u)
return info.unk0;
if (info.data != null && info.data.keys != null && (uint)info.data.keys.unk48 < 11u)
return info.data.keys.unk48;
if (info.data != null && (uint)info.data.GroupIndex < 11u)
return info.data.GroupIndex;
return -1;
}
+120 -97
View File
@@ -19,10 +19,11 @@ namespace Gallop.Live
[SerializeField]
private GameObject[] _cameraNodes;
private Camera[] _cameraObjects;
private GallopImageEffect[] _cameraImageEffects;
private Transform[] _cameraTransforms;
[SerializeField]
private CameraLookAt _cameraLookAt;
private int _activeCameraIndex = 1;
private int _activeCameraIndex = 1;
private readonly int[] kTimelineCameraIndices = new int[3] { 1, 2, 3 };
[SerializeField] private bool _enableMirrorReflection = true;
[SerializeField] private List<MirrorReflection> _mirrorReflections = new List<MirrorReflection>();
@@ -280,9 +281,10 @@ namespace Gallop.Live
}
Builder.LoadAssetPath(stagePath, transform);
_liveTimelineControl.StageObjectMap = _stageController.StageObjectMap;
_liveTimelineControl.StageObjectUnitMap = _stageController.StageObjectUnitMap;
}
@@ -308,7 +310,8 @@ namespace Gallop.Live
charaObjs.Add(newObj.transform);
counter++;
}
};
}
;
//Get live parts info
@@ -397,20 +400,20 @@ namespace Gallop.Live
foreach (var renderer in container.Renderers)
{
renderer.GetPropertyBlock(propertyBlock);
propertyBlock.SetFloat("_RimShadowRate", updateInfo.globalRimShadowRate);
propertyBlock.SetColor("_RimColor", updateInfo.rimColor);
propertyBlock.SetFloat("_RimStep", updateInfo.rimStep);
propertyBlock.SetFloat("_RimFeather", updateInfo.rimFeather);
propertyBlock.SetFloat("_RimSpecRate", updateInfo.rimSpecRate);
propertyBlock.SetFloat("_RimHorizonOffset", updateInfo.RimHorizonOffset);
propertyBlock.SetFloat("_RimVerticalOffset", updateInfo.RimVerticalOffset);
propertyBlock.SetFloat("_RimHorizonOffset2", updateInfo.RimHorizonOffset2);
propertyBlock.SetFloat("_RimVerticalOffset2", updateInfo.RimVerticalOffset2);
propertyBlock.SetColor("_RimColor2", updateInfo.rimColor2);
propertyBlock.SetFloat("_RimStep2", updateInfo.rimStep2);
propertyBlock.SetFloat("_RimFeather2", updateInfo.rimFeather2);
propertyBlock.SetFloat("_RimSpecRate2", updateInfo.rimSpecRate2);
propertyBlock.SetFloat("_RimShadowRate2", updateInfo.globalRimShadowRate2);
propertyBlock.SetFloat("_RimShadowRate", updateInfo.globalRimShadowRate);
propertyBlock.SetColor("_RimColor", updateInfo.rimColor);
propertyBlock.SetFloat("_RimStep", updateInfo.rimStep);
propertyBlock.SetFloat("_RimFeather", updateInfo.rimFeather);
propertyBlock.SetFloat("_RimSpecRate", updateInfo.rimSpecRate);
propertyBlock.SetFloat("_RimHorizonOffset", updateInfo.RimHorizonOffset);
propertyBlock.SetFloat("_RimVerticalOffset", updateInfo.RimVerticalOffset);
propertyBlock.SetFloat("_RimHorizonOffset2", updateInfo.RimHorizonOffset2);
propertyBlock.SetFloat("_RimVerticalOffset2", updateInfo.RimVerticalOffset2);
propertyBlock.SetColor("_RimColor2", updateInfo.rimColor2);
propertyBlock.SetFloat("_RimStep2", updateInfo.rimStep2);
propertyBlock.SetFloat("_RimFeather2", updateInfo.rimFeather2);
propertyBlock.SetFloat("_RimSpecRate2", updateInfo.rimSpecRate2);
propertyBlock.SetFloat("_RimShadowRate2", updateInfo.globalRimShadowRate2);
propertyBlock.SetFloat("_UseOriginalDirectionalLight", 1f);
propertyBlock.SetVector("_OriginalDirectionalLightDir", tmpPos);
renderer.SetPropertyBlock(propertyBlock);
@@ -436,11 +439,11 @@ namespace Gallop.Live
foreach (var renderer in container.Renderers)
{
renderer.GetPropertyBlock(propertyBlock);
propertyBlock.SetColor("_CharaColor", updateInfo.color * updateInfo.colorPower);
propertyBlock.SetColor("_ToonDarkColor", updateInfo.toonDarkColor);
propertyBlock.SetColor("_ToonBrightColor", updateInfo.toonBrightColor);
propertyBlock.SetColor("_OutlineColor", updateInfo.outlineColor);
propertyBlock.SetFloat("_Saturation", updateInfo.Saturation);
propertyBlock.SetColor("_CharaColor", updateInfo.color * updateInfo.colorPower);
propertyBlock.SetColor("_ToonDarkColor", updateInfo.toonDarkColor);
propertyBlock.SetColor("_ToonBrightColor", updateInfo.toonBrightColor);
propertyBlock.SetColor("_OutlineColor", updateInfo.outlineColor);
propertyBlock.SetFloat("_Saturation", updateInfo.Saturation);
renderer.SetPropertyBlock(propertyBlock);
}
}
@@ -527,6 +530,7 @@ namespace Gallop.Live
_stageController != null ? _stageController.transform : null,
flareSetting != null ? flareSetting.lightStandard : 3f,
flareSetting != null ? flareSetting.underLimit : 0f);
_livePropsController.RegisterStageLighting(_stageController, _stageFlares);
foreach (var sheet in _liveTimelineControl.data.worksheetList)
{
if (sheet.bgColor1List != null)
@@ -573,7 +577,7 @@ namespace Gallop.Live
}
UpdateMainCamera();
};
}
public void InitializeCamera()
@@ -595,6 +599,21 @@ namespace Gallop.Live
_cameraTransforms[i] = camera.transform;
}
}
if (_cameraImageEffects == null)
{
_cameraImageEffects = new GallopImageEffect[_cameraObjects.Length];
for (int i = 0; i < _cameraObjects.Length; ++i)
{
var camera = _cameraObjects[i];
if (camera == null) continue;
var effect = camera.GetComponent<GallopImageEffect>();
if (effect == null) effect = camera.gameObject.AddComponent<LiveImageEffect>();
// Actual Director.InitializeCamera dispatches Initialize slot5
// before author enable/bloom state; do not rely on Awake.
effect.InitializeVolume();
_cameraImageEffects[i] = effect;
}
}
}
public void InitializeMultiCamera(LiveTimelineControl control)
@@ -780,6 +799,7 @@ namespace Gallop.Live
parameter.SunShafts = _volumeLightController.SunShafts;
parameter.LightShafts = _volumeLightController.LightShafts;
}
UpdateDofMaxFocalSize();
_lateTimelineAppliedThisFrame = true;
}
@@ -799,7 +819,7 @@ namespace Gallop.Live
if (_syncTime == false)
{
if(liveMusic.sourceList.Count == 0)
if (liveMusic.sourceList.Count == 0)
{
_syncTime = true;
}
@@ -899,7 +919,7 @@ namespace Gallop.Live
{
ApplyTimelineLateUpdate();
}
if (_enableMirrorReflection && _mirrorRenderInLateUpdate)
{
UpdateMirrorReflections();
@@ -998,7 +1018,7 @@ namespace Gallop.Live
public static List<UmaDatabaseEntry> GetLiveAllVoiceEntry(int songid, List<LiveCharacterLoadData> characters)
{
List<UmaDatabaseEntry> entryList = new List <UmaDatabaseEntry>();
List<UmaDatabaseEntry> entryList = new List<UmaDatabaseEntry>();
for (int i = 0; i < characters.Count; i++)
{
if (characters[i].CharaEntry.Name != "")
@@ -1138,10 +1158,11 @@ namespace Gallop.Live
}
private void InitializeMirrorReflections()
{
_stageController?.DestroyMirrorReflections();
_mirrorReflections.Clear();
if (!_enableMirrorReflection)
return;
_mirrorReflections.Clear();
AddMirrorReflections(_mirrorReflections, GetComponentsInChildren<MirrorReflection>(true));
@@ -1164,13 +1185,20 @@ namespace Gallop.Live
if (mainCam == null)
mainCam = Camera.main;
for (int i = 0; i < _mirrorReflections.Count; i++)
if (_stageController != null)
{
var mirror = _mirrorReflections[i];
if (mirror == null) continue;
mirror.Initialize(mainCam, i, false);
mirror.SetupBaseCamera(mainCam, GetMainCameraFovFactor);
_stageController.InitializeMirrorReflections(_mirrorReflections, mainCam,
GetMainCameraFovFactor, _liveTimelineControl, CharaContainerScript);
}
else
{
for (int i = 0; i < _mirrorReflections.Count; i++)
{
var mirror = _mirrorReflections[i];
if (mirror == null) continue;
mirror.Initialize(mainCam, i, false);
mirror.SetupBaseCamera(mainCam, GetMainCameraFovFactor);
}
}
Debug.Log($"[Mirror] Initialized {_mirrorReflections.Count} mirrors.");
@@ -1198,6 +1226,7 @@ namespace Gallop.Live
private void UpdateMirrorReflections()
{
_stageController?.PrepareMirrorCharacters();
if (_mirrorReflections == null || _mirrorReflections.Count == 0)
return;
@@ -1245,14 +1274,39 @@ namespace Gallop.Live
{
_mainGallopImageEffect =
mainCamera.gameObject
.AddComponent<GallopImageEffect>();
.AddComponent<LiveImageEffect>();
}
return _mainGallopImageEffect;
}
private string _lastDofBypassReason;
private void OnUpdatePostEffect_Dof(LiveTimelineKeyPostEffectDOFData key)
private float GetMaxForcalSize()
{
// Actual game RVA 0x71439d0 / AlterLateUpdate 0x713ec50.
// 0x0da24260 is the native 1e-30 fallback; never accumulate sampled sizes.
var data = _liveTimelineControl != null ? _liveTimelineControl.data : null;
return Mathf.Max(1e-30f, data != null ? data.maxForcalSize : 0f);
}
private void UpdateDofMaxFocalSize()
{
float maximum = GetMaxForcalSize();
if (_cameraImageEffects != null)
for (int i = 0; i < _cameraImageEffects.Length; ++i)
if (_cameraImageEffects[i] != null)
{
_cameraImageEffects[i].DofDiffusionBloomOverlayParam.DofMaxFocalSize = maximum;
_cameraImageEffects[i].RenderParameter.DofDiffuionBloomOverlay.DofMaxFocalSize = maximum;
}
if (_multiCameras != null)
for (int i = 0; i < _multiCameras.Length; ++i)
if (_multiCameras[i] != null)
_multiCameras[i].PostEffectParameter.DofDiffuionBloomOverlay.DofMaxFocalSize = maximum;
GetActivePostEffect()?.ApplyBloomParameter();
}
private void OnUpdatePostEffect_Dof(LiveTimelineKeyPostEffectDOFData key, Vector3? worldFocus)
{
var effect = GetActivePostEffect();
if (effect == null) return;
@@ -1271,60 +1325,28 @@ namespace Gallop.Live
bypassReason = "no render camera available for DOF evaluation";
if (key != null && bypassReason == null)
{
// master5's screenshot-tested inference; official flag names remain unknown.
// Actual game SetupDOFUpdateInfo RVA 0x726a610: bit18 enables DOF;
// bit16 selects camera look-at, bit17 a metric focal point.
bool metric = ((int)key.attribute & (1 << 17)) != 0;
bool cameraTarget = ((int)key.attribute & (1 << 16)) != 0;
Vector3 focus = Vector3.zero;
bool valid = metric;
if (!metric && cameraTarget)
{
valid = _liveTimelineControl.HasDofCameraLookAt &&
_liveTimelineControl.DofLookAtCamera == renderCamera;
focus = _liveTimelineControl.DofCameraLookAt;
}
else if (!metric)
{
int count = 0;
var locators = _liveTimelineControl.liveCharactorLocators;
for (int i = 0; i < locators.Length && i < 18; ++i)
if ((key.charactor & (1 << i)) != 0 && locators[i] != null)
{ focus += locators[i].liveCharaHeadPosition; ++count; }
valid = count > 0;
if (valid) focus /= count;
}
// Validate before the backend normalizes depth. In particular, do
// not clamp a behind-camera target to zero and render a full-frame blur.
// [REPORT §10.3-B3/§4.4] 原生 PrepareDofParam 只做 focal01<0→0 的下限夹紧
// (§4.4:只夹下限,无 Clamp01、无 farClipPlane 上限判定)。master7 曾把
// metric 焦距再减 nearClipPlane 且要求 focusDepth<farClipPlane,使
// 0<d<near 的近距焦点与超远焦点被二次关闭 DOF。对齐后只要求焦点在相机
// 前方(>0);相机背后目标仍按下述原注释保持关闭(不还原 focal01=0 全屏模糊)。
Vector3 focus = worldFocus.GetValueOrDefault();
bool valid = metric || worldFocus.HasValue;
// Native PrepareDofParam clamps normalized negative depth, not the
// authored focal point. Missing targets remain a DOF-only bypass.
float focusDepth = metric ? key.dofFocalPoint
: renderCamera.WorldToViewportPoint(focus).z;
valid = valid && !float.IsNaN(focusDepth) && !float.IsInfinity(focusDepth) &&
focusDepth > 0.0001f;
valid = valid && !float.IsNaN(focusDepth) && !float.IsInfinity(focusDepth);
if (!valid) bypassReason = "missing or invalid focus depth";
param.IsEnableDof = valid;
param.DofFocalPosition = focus;
param.DofFocalTransfrom = null;
// [REPORT §10.3-B4/§4.4] 原生 PrepareDofParam(RVA 0x1a20030) 不钳制
// DofFocalPoint 本身,只在后端对归一化 focalDistance01<0 夹 0
// (DofDiffusionBloomOverlayPass.cs:433-434)。删除 master7 自加的
// Max(0.01f)——它把 0~0.01m 的合法近距焦点系统性抬高到 0.01m,
// 近距离特写 DOF 焦点被推远;setter 无隐藏钳制(直接存值)。
param.DofFocalPoint = key.dofFocalPoint;
// Unlike master5's render Parameter, these source-property setters
// select Position/Transform/Point as a side effect. Restore the
// resolved mode LAST, or the default 1m point overwrites look-at
// and character focus before GallopImageEffect copies the state.
param.DofFocalType = metric ? DepthBlurAndBloom.DofFocalType.Point : DepthBlurAndBloom.DofFocalType.Position;
param.DofQualityType = key.dofQuality == 5 ? DepthBlurAndBloom.DofQuality.BackgroundAndForeground : DepthBlurAndBloom.DofQuality.OnlyBackground;
param.DofFocalSize = Mathf.Max(0f, key.forcalSize);
param.DofMaxFocalSize = Mathf.Max(param.DofMaxFocalSize, param.DofFocalSize);
param.DofMaxBlurSpread = Mathf.Max(0f, key.blurSpread);
param.DofForegroundSize = Mathf.Max(0f, key.dofForegroundSize);
param.DofSmoothness = Mathf.Max(0.1f, key.dofSmoothness);
param.DofBlurType = (DepthBlurAndBloom.DofBlur)Mathf.Clamp(key.dofBlurType, 0, 3);
param.IsEnableDof = valid && ((int)key.attribute & (1 << 18)) != 0;
// Source setters select the mode; write only the selected coordinate.
if (metric) param.DofFocalPoint = key.dofFocalPoint;
else param.DofFocalPosition = focus;
param.DofQualityType = (DepthBlurAndBloom.DofQuality)key.dofQuality;
param.DofFocalSize = key.forcalSize;
param.DofMaxFocalSize = GetMaxForcalSize();
param.DofMaxBlurSpread = key.blurSpread;
param.DofForegroundSize = key.dofForegroundSize;
param.DofSmoothness = key.dofSmoothness;
param.DofBlurType = (DepthBlurAndBloom.DofBlur)key.dofBlurType;
param.BallBlurPowerFactor = key.BallBlurPowerFactor;
param.BallBlurBrightnessThreshhold = key.BallBlurBrightnessThreshhold;
param.BallBlurBrightnessIntensity = key.BallBlurBrightnessIntensity;
@@ -1386,18 +1408,18 @@ namespace Gallop.Live
// Distance fog: apply via RenderSettings when isDistance is true.
// Either branch enables scene fog; both false disables it.
bool applyDistanceFog = key.isDistance && !key.isHeight;
bool applyHeightFog = key.isHeight;
bool applyHeightFog = key.isHeight;
RenderSettings.fog = applyDistanceFog || applyHeightFog;
RenderSettings.fog = applyDistanceFog || applyHeightFog;
RenderSettings.fogColor = key.color;
if (applyHeightFog)
{
RenderSettings.fogMode = FogMode.ExponentialSquared;
RenderSettings.fogMode = FogMode.ExponentialSquared;
RenderSettings.fogDensity = key.heightDensity;
// Forward height and fog length as globals so stage shaders can consume them.
float fogLength = Mathf.Max(0.001f, key.end - key.start);
Shader.SetGlobalFloat("_Global_FogHeight", key.height);
Shader.SetGlobalFloat("_Global_FogHeight", key.height);
Shader.SetGlobalFloat("_Global_FogHeightDensity", key.heightDensity);
Shader.SetGlobalVector("_Global_FogLength",
new Vector4(fogLength, fogLength, fogLength, fogLength));
@@ -1408,16 +1430,16 @@ namespace Gallop.Live
switch (key.fogMode)
{
case 1:
RenderSettings.fogMode = FogMode.Linear;
RenderSettings.fogMode = FogMode.Linear;
RenderSettings.fogStartDistance = key.start + key.startDistance;
RenderSettings.fogEndDistance = key.end;
RenderSettings.fogEndDistance = key.end;
break;
case 2:
RenderSettings.fogMode = FogMode.Exponential;
RenderSettings.fogMode = FogMode.Exponential;
RenderSettings.fogDensity = key.expDensity;
break;
default:
RenderSettings.fogMode = FogMode.ExponentialSquared;
RenderSettings.fogMode = FogMode.ExponentialSquared;
RenderSettings.fogDensity = key.expDensity;
break;
}
@@ -1439,7 +1461,7 @@ namespace Gallop.Live
private void OnUpdatePostEffect_BloomDiffusion(PostEffectUpdateInfo_BloomDiffusion updateInfo)
{
GallopImageEffect imageEffect = GetActivePostEffect();
if (imageEffect == null) return;
@@ -1483,9 +1505,9 @@ namespace Gallop.Live
updateInfo.diffusionContrast;
imageEffect.ApplyBloomParameter();
// Debug.Log(
// $"[BloomDirector] activeCameraIndex={_activeCameraIndex}, " +
// $"imageEffect={(imageEffect != null ? imageEffect.name : "null")}");
// Debug.Log(
// $"[BloomDirector] activeCameraIndex={_activeCameraIndex}, " +
// $"imageEffect={(imageEffect != null ? imageEffect.name : "null")}");
}
private void OnUpdateVolumeLight(LiveVolumeLightTimeline.VolumeUpdateInfo info)
{
@@ -1499,6 +1521,7 @@ namespace Gallop.Live
private void OnDestroy()
{
_stageController?.DestroyMirrorReflections();
UnbindTimelineEvents();
_footLightRuntime?.Dispose();
_footLightRuntime = null;
@@ -25,6 +25,9 @@ namespace Gallop.Live
private readonly List<RuntimeProp> instances = new List<RuntimeProp>();
private readonly HashSet<string> warnings = new HashSet<string>(StringComparer.Ordinal);
private bool disposed;
private StageController registeredStage;
private StageBlinkLightDriver registeredBlinkDriver;
private Gallop.RenderPipeline.RecoveredLensFlareController registeredFlares;
// Same predicate used by LiveEffectController. Gated tracks are not silently
// enabled when the Director has not supplied a variation selection.
@@ -72,6 +75,8 @@ namespace Gallop.Live
public bool DefaultPropParent;
public readonly Dictionary<string, Transform> Nodes = new Dictionary<string, Transform>(StringComparer.Ordinal);
public RendererState[] Renderers;
public Props[] StageProps;
public string NameSuffixToken;
public LiveTimelineKeyPropsData Appearance, NextAppearance;
public LiveTimelineKeyPropsAttachData Attachment, NextAttachment;
public float AppearanceRatio, AttachmentRatio;
@@ -139,8 +144,11 @@ namespace Gallop.Live
var instance = Object.Instantiate(prefab, anchor, false);
var runtime = new RuntimeProp
{
CharacterIndex = c, PropsId = id, Setting = setting,
Instance = instance, Anchor = anchor,
CharacterIndex = c,
PropsId = id,
Setting = setting,
Instance = instance,
Anchor = anchor,
Animator = instance.GetComponentInChildren<Animator>(true)
};
CacheNodes(runtime);
@@ -154,9 +162,42 @@ namespace Gallop.Live
{
ResolveDefaultAttachment(prop);
if (prop.DefaultTarget != null) ApplyAttachment(prop);
var character = characters[prop.CharacterIndex];
prop.StageProps = prop.Instance.GetComponentsInChildren<Props>(true);
prop.NameSuffixToken = "_" + prop.CharacterIndex.ToString(CultureInfo.InvariantCulture);
foreach (var component in prop.StageProps)
component.SetScale(character.HeadBone.transform, character.Position, character.BodyScale,
prop.Setting.isInfluenceOfCharaHeight);
// Animation transitions restore the initialized pose, not the prefab's
// unadjusted stand height. Native CreateProps scales once before playback.
CacheNodes(prop);
}
}
// Actual-game Director.CreateProps registers all three stage work arrays
// after creating/scaling props (Komoe RVA 0x7154755..0x71547ea).
internal void RegisterStageLighting(StageController stage,
Gallop.RenderPipeline.RecoveredLensFlareController flares)
{
if (stage == null) return;
registeredStage = stage;
registeredBlinkDriver = stage.GetComponent<StageBlinkLightDriver>();
registeredFlares = flares;
foreach (var prop in instances)
foreach (var component in prop.StageProps)
{
var transforms = component.StageObjectTransformArray;
if (transforms != null)
foreach (var node in transforms)
if (node != null) stage.RegisterObjectTransform(node, prop.NameSuffixToken);
flares?.AddSources(component.transform, prop.NameSuffixToken);
var roots = component.BlinkLightRootObjectArray;
if (roots != null && registeredBlinkDriver != null)
foreach (var root in roots)
if (root != null) registeredBlinkDriver.RegisterRoot(root, prop.NameSuffixToken, flares);
}
}
public static void CollectResourcePaths(LiveTimelinePropsSettings settings,
IList<UmaContainerCharacter> characters, ISet<string> output)
{
@@ -464,6 +505,7 @@ namespace Gallop.Live
ApplyAppearance(prop);
ApplyAttachment(prop);
}
registeredBlinkDriver?.UpdateRegisteredRoots();
}
private void DiagnoseRequestedResource(LiveTimelineKeyPropsData key)
@@ -691,6 +733,19 @@ namespace Gallop.Live
disposed = true;
foreach (var prop in instances)
{
foreach (var component in prop.StageProps)
{
if (component == null) continue;
var transforms = component.StageObjectTransformArray;
if (transforms != null && registeredStage != null)
foreach (var node in transforms)
if (node != null) registeredStage.UnregisterObjectTransform(node, prop.NameSuffixToken);
var roots = component.BlinkLightRootObjectArray;
if (roots != null && registeredBlinkDriver != null)
foreach (var root in roots)
if (root != null) registeredBlinkDriver.UnregisterRoot(root, prop.NameSuffixToken);
registeredFlares?.RemoveSources(component.transform, prop.NameSuffixToken);
}
if (prop.Graph.IsValid()) prop.Graph.Destroy();
// Destroy separately: a prop-to-prop parent may already have been removed.
if (prop.Instance != null) Object.Destroy(prop.Instance);
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
@@ -79,6 +80,8 @@ public class MirrorReflection : MonoBehaviour
private event Action<ScriptableRenderContext, Camera> _endCameraRenderingCallbacks;
private bool _isRenderingNow;
private readonly Stack<int> _mirrorObjectLayers = new Stack<int>(4);
internal Live.StageController LifecycleOwner { get; set; }
private readonly UniversalRenderPipeline.SingleCameraRequest _singleCameraRequest =
new UniversalRenderPipeline.SingleCameraRequest();
@@ -194,6 +197,8 @@ public class MirrorReflection : MonoBehaviour
private void OnDisable()
{
_isEnabled = false;
LifecycleOwner?.RestoreMirrorActorLayers(_mirrorCamera);
RestoreMirrorObjectLayers();
ClearMirrorMaterialBindingOnDisable();
}
@@ -222,6 +227,8 @@ public class MirrorReflection : MonoBehaviour
private void OnDestroy()
{
LifecycleOwner?.ReleaseMirrorReflection(this);
RestoreMirrorObjectLayers();
ReleaseMirrorTexture();
if (_mirrorCamera != null)
@@ -304,6 +311,9 @@ public class MirrorReflection : MonoBehaviour
private void TryAutoInitializeIfPossible()
{
// During live playback StageController is the sole initialization owner.
if (Live.Director.instance != null || GetComponentInParent<Live.StageController>() != null)
return;
EnsureSelfReferences();
if (!EnsureBaseCamera())
@@ -314,6 +324,8 @@ public class MirrorReflection : MonoBehaviour
public void Initialize(Camera baseCamera, int mirrorIndex = -1, bool isUseBaseCameraTextureSize = false)
{
LifecycleOwner?.PrepareMirrorReinitialization(this);
RestoreMirrorObjectLayers();
_isInitialized = false;
EnsureSelfReferences();
@@ -356,6 +368,7 @@ public class MirrorReflection : MonoBehaviour
UpdateMirrorParams();
_isInitialized = true;
LifecycleOwner?.CompleteMirrorReinitialization(this);
Log($"Initialize success. mirrorIndex={_mirrorIndex}, useBaseCameraTextureSize={_isUseBaseCameraTextureSize}");
}
@@ -430,13 +443,32 @@ public class MirrorReflection : MonoBehaviour
public void SetMirrorObjectLayer(int layer)
{
_objectLayer = layer;
gameObject.layer = layer;
if (!_isInitialized || layer < 0)
return;
_objectLayer = gameObject.layer;
_mirrorObjectLayers.Push(_objectLayer);
SetMirrorObjectLayerRecursively(transform, layer);
}
public void ResetMirrorObjectLayer()
{
_objectLayer = gameObject.layer;
if (_mirrorObjectLayers.Count == 0)
return;
_objectLayer = _mirrorObjectLayers.Pop();
SetMirrorObjectLayerRecursively(transform, _objectLayer);
}
internal void RestoreMirrorObjectLayers()
{
while (_mirrorObjectLayers.Count > 0)
ResetMirrorObjectLayer();
}
private static void SetMirrorObjectLayerRecursively(Transform root, int layer)
{
root.gameObject.layer = layer;
for (int i = 0; i < root.childCount; i++)
SetMirrorObjectLayerRecursively(root.GetChild(i), layer);
}
public void SetActive(bool active)
@@ -448,8 +480,11 @@ public class MirrorReflection : MonoBehaviour
public void SetLightMirrorShader(bool isEnable)
{
// �ٷ����������Լҵ� _mirrorCameraData ��д���ء�
// �����ڲ��ùٷ����� RenderPipeline���������ﱣ�ֿ�ʵ�����ӿڼ��ݡ�
// Native RVA 0x19b7f90 writes CameraData.MirrorCasterQuality (0/1).
// GallopRenderer replaces both forward queues with SimpleMirrorCaster
// when quality is 1; renderer slot 1 is installed by LiveRenderSetup.
if (_mirrorCamera != null)
_mirrorCamera.GetUniversalAdditionalCameraData().SetRenderer(isEnable ? 1 : -1);
}
public void SetMirrorVisibleOfficialStyle(bool visible, bool pauseRenderWhenHidden = true)
@@ -911,6 +946,8 @@ public class MirrorReflection : MonoBehaviour
return;
_isRenderingNow = true;
bool oldInvert = GL.invertCulling;
int receiverLayerDepth = _mirrorObjectLayers.Count;
try
{
UpdateRenderTexture();
@@ -924,25 +961,9 @@ public class MirrorReflection : MonoBehaviour
OnPreDraw?.Invoke(this);
_beginCameraRenderingCallbacks?.Invoke(default, _mirrorCamera);
bool oldInvert = GL.invertCulling;
try
{
GL.invertCulling = !oldInvert;
if (!TrySubmitSingleCameraRequest())
_mirrorCamera.Render();
}
finally
{
GL.invertCulling = oldInvert;
if (_mirrorCamera != null)
{
_mirrorCamera.ResetWorldToCameraMatrix();
_mirrorCamera.ResetProjectionMatrix();
_mirrorCamera.ResetCullingMatrix();
}
}
GL.invertCulling = !oldInvert;
if (!TrySubmitSingleCameraRequest())
_mirrorCamera.Render();
}
catch (Exception e)
{
@@ -950,9 +971,57 @@ public class MirrorReflection : MonoBehaviour
}
finally
{
OnPostDraw?.Invoke(this);
_endCameraRenderingCallbacks?.Invoke(default, _mirrorCamera);
_isRenderingNow = false;
try
{
GL.invertCulling = oldInvert;
if (_mirrorCamera != null)
{
_mirrorCamera.ResetWorldToCameraMatrix();
_mirrorCamera.ResetProjectionMatrix();
_mirrorCamera.ResetCullingMatrix();
}
}
finally
{
try
{
OnPostDraw?.Invoke(this);
}
finally
{
try
{
_endCameraRenderingCallbacks?.Invoke(default, _mirrorCamera);
}
finally
{
try
{
LifecycleOwner?.RestoreMirrorActorLayers(_mirrorCamera);
}
finally
{
try
{
// Preserve a parent ordinary-camera scope during a nested mirror draw.
while (_mirrorObjectLayers.Count > receiverLayerDepth)
ResetMirrorObjectLayer();
}
finally
{
try
{
GL.invertCulling = oldInvert;
}
finally
{
_isRenderingNow = false;
}
}
}
}
}
}
}
}
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -269,12 +269,16 @@ namespace Gallop.Live
[SerializeField] private bool _lastLoadSucceeded;
[SerializeField] private int _lastSyncedStageInstanceId;
[SerializeField] private int _lastContextSlotHash;
private bool _hasResolvedContextSlots;
public int LoadedMusicId => _loadedMusicId;
public string LoadedRootPath => _loadedRootPath;
public bool HasTriedLoad => _hasTriedLoad;
public bool LastLoadSucceeded => _lastLoadSucceeded;
public int ContextSlotCount => contextSlots != null ? contextSlots.Count : 0;
// A loaded table may legitimately contain no UVMovie rows. Completion
// is independent of slot availability, so that case is not retried each frame.
public bool HasResolvedContextSlots => _hasResolvedContextSlots;
private void Start()
{
@@ -432,10 +436,12 @@ namespace Gallop.Live
_lastSyncedStageInstanceId = 0;
_lastContextSlotHash = 0;
_hasResolvedContextSlots = false;
}
public bool RebuildContextSlotsFromLiveSettings(LiveTimelineControl timelineControl, int musicId, bool force = false)
{
_hasResolvedContextSlots = false;
string csvText = ResolveLiveSettingsCsvText(musicId);
if (string.IsNullOrWhiteSpace(csvText))
{
@@ -447,6 +453,7 @@ namespace Gallop.Live
List<LiveSettingsUvMovieRow> sourceRows = ParseLiveSettingsUvMovieRows(csvText);
if (sourceRows.Count == 0)
{
_hasResolvedContextSlots = true;
if (verboseLog)
Debug.LogWarning("[MonitorUvMovieProvider] liveSettings csv contains no type=4 UVMovie rows.");
return false;
@@ -502,6 +509,7 @@ namespace Gallop.Live
int slotHash = ComputeSlotHash(resolvedSlots);
if (!force && _lastContextSlotHash == slotHash && contextSlots.Count == resolvedSlots.Count)
{
_hasResolvedContextSlots = true;
if (verboseLog)
Debug.Log($"[MonitorUvMovieProvider] liveSettings slots unchanged: total={resolvedSlots.Count}, musicId={musicId}");
return false;
@@ -510,6 +518,7 @@ namespace Gallop.Live
contextSlots = resolvedSlots;
_lastSyncedStageInstanceId = musicId;
_lastContextSlotHash = slotHash;
_hasResolvedContextSlots = true;
if (verboseLog)
{
@@ -168,7 +168,7 @@ namespace Gallop.Live
// updates these only on flagged keys; CopyFrom must not erase their state.
if (((int)positionKey.attribute & 0x20000) != 0)
{
_timelineCullingMask = GetMonitorCullingMask(positionKey.cullingLayer);
_timelineCullingMask = positionKey.GetCullingMask();
_hasTimelineCullingMask = true;
}
if (((int)positionKey.attribute & 0x40000) != 0)
@@ -241,24 +241,6 @@ namespace Gallop.Live
return _texture.IsCreated() || _texture.Create();
}
private static int GetMonitorCullingMask(LiveCameraCullingLayer layers)
{
// LiveCameraCullingLayer_Helper.GetCullingMask RVA 0x1af2220.
int mask = 0;
if ((layers & LiveCameraCullingLayer.TransparentFX) != 0) mask |= 1 << 1;
if ((layers & LiveCameraCullingLayer.Effect) != 0) mask |= 1 << 11;
if ((layers & LiveCameraCullingLayer.Background3d_NotReflect) != 0) mask |= 1 << 25;
if ((layers & LiveCameraCullingLayer.Background3d) != 0) mask |= 1 << 12;
if ((layers & LiveCameraCullingLayer.Character3d) != 0) mask |= 1 << 13;
if ((layers & LiveCameraCullingLayer.Character3d_0) != 0) mask |= 1 << 27;
if ((layers & LiveCameraCullingLayer.Character3d_1) != 0) mask |= 1 << 28;
if ((layers & LiveCameraCullingLayer.Character3d_NotReflect) != 0) mask |= 1 << 26;
if ((layers & LiveCameraCullingLayer.NotLayerDefault) == 0)
mask |= GraphicSettings.GetCullingLayer(GraphicSettings.LayerIndex.LayerDefault);
if ((layers & LiveCameraCullingLayer.NotLayer3d) == 0)
mask |= GraphicSettings.GetCullingLayer(GraphicSettings.LayerIndex.Layer3D);
return mask;
}
private static bool FindKeys<T>(ILiveTimelineKeyDataList keys, LiveTimelineControl timeline, float frame,
out T current, out T next) where T : LiveTimelineKey
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Reflection;
using Gallop.Live.Cutt;
@@ -31,7 +31,7 @@ namespace Gallop.Live
public string baseColorProperty = "_BaseColor";
public string monitorWidthProperty = "_MonitorWidth";
public string monitorHeightProperty = "_MonitorHeight";
public string crossFadeRateProperty = "_CrossFadeRate";
public string blendFactorProperty = "_BlendFactor";
public string srcBlendModeProperty = "_SrcBlendMode";
public string dstBlendModeProperty = "_DstBlendMode";
public string srcBlendProperty = "_SrcBlend";
@@ -45,6 +45,7 @@ namespace Gallop.Live
public Vector2 baseMainScale;
public Vector2 baseMainOffset;
public bool cameraAppliedThisFrame;
public bool cameraTextureBound;
public string rendererKey;
public string materialKey;
public string rendererCompact;
@@ -82,7 +83,7 @@ namespace Gallop.Live
public float alpha;
public Color colorFade;
public Color baseColor;
public float crossFadeRate;
public float blendFactor;
public float filterTexScale;
public int srcBlendMode;
public int dstBlendMode;
@@ -312,10 +313,11 @@ namespace Gallop.Live
_lastPreparedMusicId = musicId;
bool synced = false;
if (!_providerContextReady || stageChanged || _provider.ContextSlotCount == 0)
if (!_providerContextReady || stageChanged ||
(_provider.ContextSlotCount == 0 && !_provider.HasResolvedContextSlots))
{
synced = _provider.RebuildContextSlotsFromLiveSettings(_ctl, musicId, force: stageChanged || musicChanged);
_providerContextReady = synced || _provider.ContextSlotCount > 0;
_providerContextReady = synced || _provider.ContextSlotCount > 0 || _provider.HasResolvedContextSlots;
}
if (_stage != null)
@@ -685,14 +687,14 @@ namespace Gallop.Live
if (assignMaskTextureToFilterTex && state.hasMainTexture)
state.filterTexture = state.main.maskTexture;
// 保持 _Alpha 为材质原本的值
// 时间轴的监视器数据没有提供专用的透明度字段;
// colorFade 和 BaseColor 会分别传递给对应的着色器参数
state.alpha = 0f;
// Native UpdateMonitor (0x1a93a70) applies these even when neither
// movie slot resolves. An empty slot is not an absent control key:
// ColorFade=(0,0,0,0) must still turn the authored white screen black.
state.alpha = crossFadeRate;
state.colorFade = colorFade;
state.useBaseColor = !IsColorEffectivelyClear(baseColor);
state.baseColor = state.useBaseColor ? baseColor : Color.white;
state.crossFadeRate = crossFadeRate;
state.blendFactor = blendFactor;
state.filterTexScale = filterTexScale;
state.srcBlendMode = curKey.SrcBlendMode;
state.dstBlendMode = curKey.DstBlendMode;
@@ -700,7 +702,7 @@ namespace Gallop.Live
state.renderQueue = curKey.RenderQueueNo;
state.hasRenderQueue = curKey.IsRenderQueue != 0;
return state.hasMainTexture;
return true;
}
private MonitorUvMovieContextSlot ResolvePrimarySlot(
@@ -1043,7 +1045,7 @@ namespace Gallop.Live
for (int i = 0; i < _bindings.Count; i++)
{
MonitorMaterialBinding binding = _bindings[i];
if (!binding.hasAppliedState || !binding.appliedState.useMonitorCamera ||
if (!binding.cameraTextureBound ||
(!force && binding.cameraAppliedThisFrame))
continue;
Material material = binding.material;
@@ -1056,6 +1058,7 @@ namespace Gallop.Live
if (binding.hasUvAdjust)
material.SetVector("_UVAdjust", binding.baseUvAdjust);
}
binding.cameraTextureBound = false;
binding.hasAppliedState = false;
}
}
@@ -1066,7 +1069,11 @@ namespace Gallop.Live
if (material == null)
return;
binding.cameraAppliedThisFrame = state.useMonitorCamera;
// An empty movie slot leaves the current texture untouched, as native
// UpdateMonitorInMovie does. Keep ownership until a real replacement
// arrives, so disabling/rebinding still detaches the capture RT.
binding.cameraAppliedThisFrame = state.useMonitorCamera ||
(!state.hasMainTexture && binding.cameraTextureBound);
if (state.hasMainTexture && HasTextureProperty(material, mainTexProperty))
{
@@ -1079,6 +1086,7 @@ namespace Gallop.Live
material.SetTextureScale(mainTexProperty, state.main.scale);
material.SetTextureOffset(mainTexProperty, state.main.offset);
}
binding.cameraTextureBound = state.useMonitorCamera;
}
if (HasTextureProperty(material, fadeTexProperty))
@@ -1124,7 +1132,11 @@ namespace Gallop.Live
}
}
float appliedAlpha = state.useMonitorCamera ? 0f : binding.baseAlpha;
// Native movie mode maps CrossFadeRate to _Alpha; capture mode does
// not overwrite it. Retain the last value across capture transitions.
float appliedAlpha = state.useMonitorCamera
? (binding.hasAppliedState ? binding.appliedState.alpha : binding.baseAlpha)
: state.alpha;
Color appliedColorFade = state.colorFade;
Color appliedBaseColor = state.useBaseColor ? state.baseColor : binding.baseColor;
@@ -1161,8 +1173,8 @@ namespace Gallop.Live
}
material.SetVector("_UVAdjust", uvAdjust);
}
if (!binding.hasAppliedState || !Approximately(binding.appliedState.crossFadeRate, state.crossFadeRate))
TrySetFloat(material, crossFadeRateProperty, state.crossFadeRate);
if (!binding.hasAppliedState || !Approximately(binding.appliedState.blendFactor, state.blendFactor))
TrySetFloat(material, blendFactorProperty, state.blendFactor);
if (applyBlendModeProperties)
{
@@ -192,6 +192,8 @@ namespace Gallop.Live
RenderCamera.nearClipPlane = current.nearClip;
RenderCamera.farClipPlane = current.farClip;
RenderCamera.fieldOfView = Mathf.LerpUnclamped(current.fov, next.fov, t);
if (((int)current.attribute & 0x40000) != 0)
RenderCamera.backgroundColor = current.BgColor;
}
if (current.maskType == LiveTimelineKeyMultiCameraPositionData.MaskType.Single && transitioning)
{
@@ -0,0 +1,50 @@
using System;
using UnityEngine;
namespace Gallop.Live
{
// Serialized contract from common prop000/001 TypeTrees (assembly: umamusume).
// Height adjustment follows the actual game Props.SetScale (Komoe RVA 0x71daed0).
public sealed class Props : MonoBehaviour
{
[Serializable]
public sealed class AdjustmentData
{
public Transform Transform;
public Vector3 OffsetRange;
public Vector3 TransformRate;
public int TargetNode;
public Vector3 TargetOffset;
public Vector3 TargetPosition { get; internal set; }
}
[SerializeField] private AdjustmentData[] _adjustmentDataArray;
[SerializeField] private bool _isInfluenceOfCharaHeight;
[SerializeField] private GameObject[] _blinkLightRootObjectArray;
[SerializeField] private Transform[] _stageObjectTransformArray;
internal GameObject[] BlinkLightRootObjectArray => _blinkLightRootObjectArray;
internal Transform[] StageObjectTransformArray => _stageObjectTransformArray;
internal void SetScale(Transform headTransform, Transform positionNode, float bodyScale,
bool isInfluenceOfCharaHeight)
{
_isInfluenceOfCharaHeight = isInfluenceOfCharaHeight;
if (_adjustmentDataArray == null || _adjustmentDataArray.Length == 0) return;
// Native Head target: world-space Y difference only. Neither the authored
// local position nor head X/Z participates, and the result is not clamped.
Vector3 targetPosition = new Vector3(0f, headTransform.position.y - positionNode.position.y, 0f);
for (int i = 0; i < _adjustmentDataArray.Length; i++)
{
var adjustment = _adjustmentDataArray[i];
if (adjustment.Transform == null) continue;
adjustment.TargetPosition = targetPosition;
Vector3 position = _isInfluenceOfCharaHeight ? targetPosition / bodyScale : targetPosition;
adjustment.Transform.localPosition = Vector3.Scale(
position + adjustment.TargetOffset - adjustment.OffsetRange, adjustment.TransformRate);
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8ba55f9f4016407da01e39622a086b67
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text.RegularExpressions;
@@ -106,11 +106,11 @@ namespace Gallop.Live
public float powerDiff;
public int loopCountMax;
public float waitTime;
public float waitTime;
public float turnOnTime;
public float turnOffTime;
public float keepTime;
public float intervalTime;
public float intervalTime;
public float loopTime;
public float currentPower;
@@ -161,6 +161,10 @@ namespace Gallop.Live
private readonly Dictionary<string, RootCache> _rootCache = new Dictionary<string, RootCache>(256);
private readonly Dictionary<string, BlinkRootRuntime> _runtime = new Dictionary<string, BlinkRootRuntime>(256);
private readonly Dictionary<string, List<RootCache>> _registeredRoots =
new Dictionary<string, List<RootCache>>(StringComparer.Ordinal);
private Gallop.RenderPipeline.RecoveredLensFlareController _registeredFlares;
private int _registeredUpdateFrame = -1;
private enum IndexMode
{
@@ -200,6 +204,7 @@ namespace Gallop.Live
public bool wantsMpb;
// 官方 RendererData 层
public Gallop.RenderPipeline.CustomLensFlare customLensFlare;
public WashLightController washLightController;
public UnityLensFlareController unityLensFlareController;
public Material material;
@@ -225,6 +230,16 @@ namespace Gallop.Live
private static readonly Regex ReSuffixNumber = new Regex(@"_(\d+)$", RegexOptions.Compiled);
private static readonly Regex ReLastDigits = new Regex(@"(\d+)(?!.*\d)", RegexOptions.Compiled);
private readonly List<Material> _sharedMaterialScratch = new List<Material>(4);
private readonly List<Material> _blendMaterialScratch = new List<Material>(4);
private struct BlendMaterialClassification
{
public Shader shader;
public bool isTarget;
}
private readonly Dictionary<Material, BlendMaterialClassification> _blendMaterialClassification =
new Dictionary<Material, BlendMaterialClassification>();
private void Awake()
{
@@ -238,6 +253,8 @@ namespace Gallop.Live
private void OnDisable()
{
_blendMaterialScratch.Clear();
_blendMaterialClassification.Clear();
Unbind();
}
@@ -275,9 +292,60 @@ namespace Gallop.Live
_groundChosen.Clear();
}
private static bool IsBlinkRootName(string name)
internal void RegisterRoot(GameObject root, string nameSuffixToken,
Gallop.RenderPipeline.RecoveredLensFlareController flares)
{
string name = root.name.Replace("(Clone)", string.Empty) + nameSuffixToken;
_registeredFlares = flares;
if (!_registeredRoots.TryGetValue(name, out var roots))
{
roots = new List<RootCache>();
_registeredRoots.Add(name, roots);
}
string runtimeKey = name + "__U" + root.GetInstanceID();
var cache = GetOrBuildRootCache(runtimeKey, root);
roots.Add(cache);
ApplyRootOffCached(runtimeKey, root);
}
internal void UpdateRegisteredRoots()
{
foreach (var entry in _registeredRoots)
{
if (!_latest.TryGetValue(entry.Key, out var item)) continue;
var info = item.updateInfo;
info.progressTime = Mathf.Max(0f, info.progressTime) * Mathf.Max(0.0001f, localTimeScale);
foreach (var root in entry.Value)
if (root.rootGo != null)
ApplyToRootCached(root.rootName, root.rootGo, info, item.currentLiveTime);
}
_registeredUpdateFrame = Time.frameCount;
}
internal void UnregisterRoot(GameObject root, string nameSuffixToken)
{
string name = root.name.Replace("(Clone)", string.Empty) + nameSuffixToken;
if (!_registeredRoots.TryGetValue(name, out var roots)) return;
for (int i = roots.Count - 1; i >= 0; i--)
{
var cache = roots[i];
if (cache.rootGo != root) continue;
_rootCache.Remove(cache.rootName);
_runtime.Remove(cache.rootName);
_rootBase.Remove(cache.rootName);
roots.RemoveAt(i);
}
if (roots.Count == 0)
{
_registeredRoots.Remove(name);
_latest.Remove(name);
}
}
private bool IsBlinkRootName(string name)
{
if (string.IsNullOrEmpty(name)) return false;
if (_registeredRoots.ContainsKey(NormalizeRuntimeRootName(name))) return true;
if (name.IndexOf("_spotlight3d_controller", StringComparison.OrdinalIgnoreCase) >= 0) return false;
if (name.IndexOf("ledlight", StringComparison.OrdinalIgnoreCase) >= 0) return false;
@@ -435,7 +503,7 @@ namespace Gallop.Live
return false;
}
private void OnBlinkLight(LiveTimelineBlinkLightData data,ref BlinkLightUpdateInfo info,float currentLiveTime)
private void OnBlinkLight(LiveTimelineBlinkLightData data, ref BlinkLightUpdateInfo info, float currentLiveTime)
{
string rootName = (data != null) ? data.name : null;
if (string.IsNullOrEmpty(rootName)) return;
@@ -525,26 +593,37 @@ namespace Gallop.Live
float liveNow = item.currentLiveTime;
if (_stage.StageObjectUnitMap.TryGetValue(rootName, out var unit) &&
unit != null && unit.ChildObjects != null && unit.ChildObjects.Length > 0)
if (_registeredRoots.TryGetValue(rootName, out var registeredRoots))
{
for (int i = 0; i < unit.ChildObjects.Length; i++)
if (_registeredUpdateFrame == Time.frameCount) continue;
for (int i = 0; i < registeredRoots.Count; i++)
{
var childPrefab = unit.ChildObjects[i];
if (childPrefab == null)
continue;
if (_stage.StageObjectMap.TryGetValue(childPrefab.name, out var realGo) && realGo != null)
{
string runtimeKey = rootName + "__U" + i;
ApplyToRootCached(runtimeKey, realGo, updateInfo, liveNow);
}
var root = registeredRoots[i];
if (root.rootGo != null)
ApplyToRootCached(root.rootName, root.rootGo, updateInfo, liveNow);
}
}
else if (_stage.StageObjectMap.TryGetValue(rootName, out var rootGo) && rootGo != null)
{
ApplyToRootCached(rootName, rootGo, updateInfo, liveNow);
}
else
if (_stage.StageObjectUnitMap.TryGetValue(rootName, out var unit) &&
unit != null && unit.ChildObjects != null && unit.ChildObjects.Length > 0)
{
for (int i = 0; i < unit.ChildObjects.Length; i++)
{
var childPrefab = unit.ChildObjects[i];
if (childPrefab == null)
continue;
if (_stage.StageObjectMap.TryGetValue(childPrefab.name, out var realGo) && realGo != null)
{
string runtimeKey = rootName + "__U" + i;
ApplyToRootCached(runtimeKey, realGo, updateInfo, liveNow);
}
}
}
else if (_stage.StageObjectMap.TryGetValue(rootName, out var rootGo) && rootGo != null)
{
ApplyToRootCached(rootName, rootGo, updateInfo, liveNow);
}
}
// Exclusivity must be enforced AFTER the cached timeline update:
@@ -639,6 +718,7 @@ namespace Gallop.Live
var wash = go.GetComponent<WashLightController>();
var flare = go.GetComponent<UnityLensFlareController>();
var customFlare = go.GetComponent<Gallop.RenderPipeline.CustomLensFlare>();
var runtimeMat = r.material;
var mats = r.sharedMaterials;
pendingRenderers.Add(new RendererEntry
@@ -659,6 +739,7 @@ namespace Gallop.Live
washLightController = wash,
unityLensFlareController = flare,
customLensFlare = customFlare,
material = runtimeMat,
isWashLight = false,
isWashLightProjection = false,
@@ -866,7 +947,7 @@ namespace Gallop.Live
return b;
}
private void ApplyToRootCached(string runtimeKey,GameObject rootGo,BlinkLightUpdateInfo updateInfo,float liveNow)
private void ApplyToRootCached(string runtimeKey, GameObject rootGo, BlinkLightUpdateInfo updateInfo, float liveNow)
{
var rc = GetOrBuildRootCache(runtimeKey, rootGo);
if (rc.slotCount <= 0) return;
@@ -970,6 +1051,10 @@ namespace Gallop.Live
}
Color currentColor = new Color(slotColor.x, slotColor.y, slotColor.z, 1f);
// Native Blink.Update writes its power-weighted current color directly
// to the flare, with shader-color reading disabled (Komoe 0x7192856).
if (e.customLensFlare != null)
_registeredFlares?.SetBlinkColor(e.customLensFlare, currentColor * p);
int uvBias = (rc.rootIsUv || e.isUvAlphaMask) ? uvSortingBias : 0;
r.sortingOrder = baseOrder + uvBias + e.stableSlot * stride;
@@ -1281,6 +1366,8 @@ namespace Gallop.Live
{
var e = rc.renderers[i];
var r = e.r;
if (e.customLensFlare != null)
_registeredFlares?.SetBlinkColor(e.customLensFlare, Color.black);
if (r == null)
{
rc.dirty = true;
@@ -1288,7 +1375,7 @@ namespace Gallop.Live
}
EnsureLightBlinkBlendState(r, ref e,(int)fallbackLightBlendMode);
EnsureLightBlinkBlendState(r, ref e, (int)fallbackLightBlendMode);
if (e.wantsMpb)
{
@@ -1336,7 +1423,18 @@ namespace Gallop.Live
{
if (m == null) return false;
string sn = (m.shader != null) ? (m.shader.name ?? "") : "";
Shader shader = m.shader;
if (_blendMaterialClassification.TryGetValue(m, out var cached) && cached.shader == shader)
return cached.isTarget;
bool isTarget = ClassifyBlinkBlendMaterial(m, shader);
_blendMaterialClassification[m] = new BlendMaterialClassification { shader = shader, isTarget = isTarget };
return isTarget;
}
private static bool ClassifyBlinkBlendMaterial(Material m, Shader shader)
{
string sn = shader != null ? (shader.name ?? "") : "";
if (sn.IndexOf("LightBlinkBlend", StringComparison.OrdinalIgnoreCase) >= 0)
return true;
@@ -1401,19 +1499,17 @@ namespace Gallop.Live
int modeId = (int)mode;
// 不要再提前 return。
// 官方 Update 末尾每帧都会 TrySetLightBlendModeMaterialProperty。
// 你这里如果 cache return,材质被 timeline / prefab / 其他脚本改回 One/One 后就不会再修。
// if (e.blendConfigured && e.blendConfiguredMode == modeId)
// return;
// Preserve the native per-frame blend override, including recovery
// after another controller changes the material's blend properties.
var mats = r.materials;
if (mats == null || mats.Length == 0)
r.GetMaterials(_blendMaterialScratch);
var mats = _blendMaterialScratch;
if (mats.Count == 0)
return;
bool touched = false;
for (int i = 0; i < mats.Length; i++)
for (int i = 0; i < mats.Count; i++)
{
var m = mats[i];
if (!IsTargetBlinkBlendMaterial(m))
@@ -4,6 +4,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Rendering;
namespace Gallop.Live
{
@@ -131,7 +132,7 @@ namespace Gallop.Live
[Tooltip("レーザーマテリアル")]
private Material[] _laserMaterials;
private bool _laserSetupDone = false;
private LiveTimelineControl _laserSetupTimelineControl;
private readonly Dictionary<object, int> _laserDataIndexMap =
@@ -177,6 +178,237 @@ namespace Gallop.Live
private readonly Dictionary<int, MirrorReflection> _mirrorByTimelineHash = new Dictionary<int, MirrorReflection>();
private LiveTimelineControl _boundTimelineControl;
private const int MirrorCharacterSlotCount = 20;
private sealed class MirrorCameraTarget
{
internal MirrorReflection Mirror;
internal int BodyMask;
internal int HeadMask;
internal readonly Stack<Camera> ReceiverCameras = new Stack<Camera>(4);
}
private readonly List<MirrorCameraTarget> _mirrorCameraTargets = new List<MirrorCameraTarget>();
private readonly UmaContainerCharacter[] _mirrorBoundCharacters = new UmaContainerCharacter[MirrorCharacterSlotCount];
private IList<UmaContainerCharacter> _mirrorCharacters;
private LiveTimelineData _mirrorTimelineData;
private Camera _activeMirrorRenderingCamera;
private bool _mirrorRenderingCallbacksBound;
internal void InitializeMirrorReflections(IReadOnlyList<MirrorReflection> mirrors, Camera baseCamera,
Func<float> fovFactor, LiveTimelineControl timeline, IList<UmaContainerCharacter> characters)
{
DestroyMirrorReflections();
_mirrorTimelineData = timeline != null ? timeline.data : null;
_mirrorCharacters = characters;
_environmentMirrorTargets.Clear();
_mirrorByTimelineHash.Clear();
for (int i = 0; i < mirrors.Count; i++)
{
var mirror = mirrors[i];
if (mirror == null)
continue;
mirror.Initialize(baseCamera, i, false);
mirror.SetupBaseCamera(baseCamera, fovFactor);
mirror.LifecycleOwner = this;
// Native MirrorCameraTarget construction leaves both actor masks zero.
_mirrorCameraTargets.Add(new MirrorCameraTarget { Mirror = mirror });
RegisterMirrorReflection(mirror);
}
PrepareMirrorCharacters();
BindMirrorRenderingCallbacks();
}
internal void PrepareMirrorCharacters()
{
for (int i = 0; i < MirrorCharacterSlotCount; i++)
{
var character = _mirrorCharacters != null && i < _mirrorCharacters.Count ? _mirrorCharacters[i] : null;
if (_mirrorBoundCharacters[i] == character)
continue;
if (_mirrorBoundCharacters[i] != null)
_mirrorBoundCharacters[i].RestoreMirrorChangedLayers();
_mirrorBoundCharacters[i] = character;
if (character != null)
character.PrepareMirrorLayerCache();
}
}
private void BindMirrorRenderingCallbacks()
{
if (_mirrorRenderingCallbacksBound || !isActiveAndEnabled || _mirrorTimelineData == null ||
!_mirrorTimelineData.IsChangedCharaLayerOnlyMirrorRendering)
return;
_mirrorRenderingCallbacksBound = true;
for (int i = 0; i < _mirrorCameraTargets.Count; i++)
CompleteMirrorReinitialization(_mirrorCameraTargets[i].Mirror);
RenderPipelineManager.beginCameraRendering += OnBeginCameraRendering;
RenderPipelineManager.endCameraRendering += OnEndCameraRendering;
Camera.onPreCull += OnBeginBuiltInCameraRendering;
Camera.onPostRender += OnEndBuiltInCameraRendering;
}
private void UnbindMirrorRenderingCallbacks()
{
if (_mirrorRenderingCallbacksBound)
{
RenderPipelineManager.beginCameraRendering -= OnBeginCameraRendering;
RenderPipelineManager.endCameraRendering -= OnEndCameraRendering;
Camera.onPreCull -= OnBeginBuiltInCameraRendering;
Camera.onPostRender -= OnEndBuiltInCameraRendering;
_mirrorRenderingCallbacksBound = false;
}
for (int i = 0; i < _mirrorCameraTargets.Count; i++)
PrepareMirrorReinitialization(_mirrorCameraTargets[i].Mirror);
RestoreMirrorActorLayers();
}
internal void DestroyMirrorReflections()
{
UnbindMirrorRenderingCallbacks();
for (int i = 0; i < _mirrorCameraTargets.Count; i++)
if (_mirrorCameraTargets[i].Mirror != null)
_mirrorCameraTargets[i].Mirror.LifecycleOwner = null;
_mirrorCameraTargets.Clear();
_mirrorCharacters = null;
_mirrorTimelineData = null;
for (int i = 0; i < MirrorCharacterSlotCount; i++)
_mirrorBoundCharacters[i] = null;
}
internal void PrepareMirrorReinitialization(MirrorReflection mirror)
{
if (mirror == null)
return;
mirror.RemoveBeginCameraRenderingCallback(OnBeginMirrorCameraRendering);
mirror.RemoveEndCameraRenderingCallback(OnEndMirrorCameraRendering);
RestoreMirrorActorLayers(mirror.MirrorCamera);
mirror.RestoreMirrorObjectLayers();
var target = GetMirrorCameraTarget(mirror);
if (target != null)
{
target.BodyMask = 0;
target.HeadMask = 0;
target.ReceiverCameras.Clear();
}
}
internal void CompleteMirrorReinitialization(MirrorReflection mirror)
{
if (!_mirrorRenderingCallbacksBound || mirror == null || !mirror.IsInitialized)
return;
mirror.RemoveBeginCameraRenderingCallback(OnBeginMirrorCameraRendering);
mirror.RemoveEndCameraRenderingCallback(OnEndMirrorCameraRendering);
mirror.AddBeginCameraRenderingCallback(OnBeginMirrorCameraRendering);
mirror.AddEndCameraRenderingCallback(OnEndMirrorCameraRendering);
}
internal void ReleaseMirrorReflection(MirrorReflection mirror)
{
PrepareMirrorReinitialization(mirror);
for (int i = _mirrorCameraTargets.Count - 1; i >= 0; i--)
if (_mirrorCameraTargets[i].Mirror == mirror)
_mirrorCameraTargets.RemoveAt(i);
mirror.LifecycleOwner = null;
}
private MirrorCameraTarget GetMirrorCameraTarget(MirrorReflection mirror)
{
for (int i = 0; i < _mirrorCameraTargets.Count; i++)
if (_mirrorCameraTargets[i].Mirror == mirror)
return _mirrorCameraTargets[i];
return null;
}
private MirrorCameraTarget GetMirrorCameraTarget(Camera camera)
{
for (int i = 0; i < _mirrorCameraTargets.Count; i++)
{
var mirror = _mirrorCameraTargets[i].Mirror;
if (mirror != null && mirror.MirrorCamera == camera)
return _mirrorCameraTargets[i];
}
return null;
}
private void OnBeginMirrorCameraRendering(ScriptableRenderContext context, Camera camera)
{
var target = GetMirrorCameraTarget(camera);
if (target == null)
return;
RestoreMirrorActorLayers();
_activeMirrorRenderingCamera = camera;
int layer = GraphicSettings.GetLayer(GraphicSettings.LayerIndex.LayerCharacter3D_NotReflect);
for (int i = 0; i < MirrorCharacterSlotCount; i++)
if (_mirrorBoundCharacters[i] != null)
_mirrorBoundCharacters[i].SetLayerBeforeMirrorCameraRendering(
(target.BodyMask & (1 << i)) != 0, (target.HeadMask & (1 << i)) != 0, layer);
}
private void OnEndMirrorCameraRendering(ScriptableRenderContext context, Camera camera)
{
RestoreMirrorActorLayers(camera);
}
internal void RestoreMirrorActorLayers(Camera camera)
{
if (_activeMirrorRenderingCamera == camera)
RestoreMirrorActorLayers();
}
private void RestoreMirrorActorLayers()
{
for (int i = 0; i < MirrorCharacterSlotCount; i++)
if (_mirrorBoundCharacters[i] != null)
_mirrorBoundCharacters[i].RestoreMirrorChangedLayers();
_activeMirrorRenderingCamera = null;
}
private void OnBeginCameraRendering(ScriptableRenderContext context, Camera camera)
{
// Mirror cameras already have their own callbacks. Never overwrite a parent receiver scope.
if (!_mirrorRenderingCallbacksBound || GetMirrorCameraTarget(camera) != null)
return;
int layer = GraphicSettings.GetLayer(GraphicSettings.LayerIndex.LayerNO_VISIBLE);
if (layer < 0)
return;
for (int i = 0; i < _mirrorCameraTargets.Count; i++)
{
var target = _mirrorCameraTargets[i];
if (target.Mirror == null || !target.Mirror.IsInitialized || target.Mirror.BaseCamera == camera)
continue;
target.Mirror.SetMirrorObjectLayer(layer);
target.ReceiverCameras.Push(camera);
}
}
private void OnEndCameraRendering(ScriptableRenderContext context, Camera camera)
{
if (GetMirrorCameraTarget(camera) != null)
return;
for (int i = 0; i < _mirrorCameraTargets.Count; i++)
{
var target = _mirrorCameraTargets[i];
if (target.ReceiverCameras.Count == 0 || target.ReceiverCameras.Peek() != camera)
continue;
target.ReceiverCameras.Pop();
if (target.Mirror != null)
target.Mirror.ResetMirrorObjectLayer();
}
}
private void OnBeginBuiltInCameraRendering(Camera camera)
{
if (GraphicsSettings.currentRenderPipeline == null)
OnBeginCameraRendering(default, camera);
}
private void OnEndBuiltInCameraRendering(Camera camera)
{
if (GraphicsSettings.currentRenderPipeline == null)
OnEndCameraRendering(default, camera);
}
private void Awake()
{
_stageColorBlock = new UnityEngine.MaterialPropertyBlock();
@@ -204,6 +436,7 @@ namespace Gallop.Live
Director.instance._stageController = this;
TryBindTimelineCallbacks();
BindMirrorRenderingCallbacks();
}
// Laser 的 AlterUpdate 必须在 LiveTimelineControl 下发本帧 UpdateInfo 之后执行。
@@ -651,7 +884,7 @@ namespace Gallop.Live
return;
}
LaserController controller =_laserControllerArray[index];
LaserController controller = _laserControllerArray[index];
controller?.UpdateInfo(ref updateInfo);
}
@@ -833,7 +1066,7 @@ namespace Gallop.Live
return obj != null ? System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(obj) : 0;
}
}
private void AutoAddDriver(string shortTypeName)
{
Type t = null;
@@ -867,12 +1100,14 @@ namespace Gallop.Live
private void OnDisable()
{
UnbindMirrorRenderingCallbacks();
UnbindTimelineCallbacks(_boundTimelineControl);
_boundTimelineControl = null;
}
private void OnDestroy()
{
DestroyMirrorReflections();
UnbindTimelineCallbacks(_boundTimelineControl);
_boundTimelineControl = null;
}
@@ -1126,6 +1361,16 @@ namespace Gallop.Live
mirror.SetLightMirrorShader(!updateInfo.IsToonMirror);
mirror.MirrorReflectionRate = updateInfo.MirrorReflectionRate;
if (_mirrorRenderingCallbacksBound && updateInfo.EnableMirror)
{
var target = GetMirrorCameraTarget(mirror);
if (target != null)
{
target.BodyMask = (int)updateInfo.TargetChara;
target.HeadMask = (int)(updateInfo.EnableCharaHead ? updateInfo.TargetCharaHead : updateInfo.TargetChara);
}
}
mirror.ResetCullingMask();
if (_mirrorBgLayerMask != 0)
@@ -1169,33 +1414,10 @@ namespace Gallop.Live
foreach (var child in instance.GetComponentsInChildren<Transform>(true))
{
string objectName = child.name.Replace("(Clone)", "");
if (!StageObjectMap.ContainsKey(objectName))
{
if (child.name.IndexOf("light", StringComparison.OrdinalIgnoreCase) >= 0)
child.gameObject.SetActive(true);
StageObjectMap.Add(objectName, child.gameObject);
StageParentMap.Add(objectName, child.parent);
}
int objectHash = FNVHash.Generate(objectName);
if (!_objectsWorkInfoDictionary.TryGetValue(objectHash, out var works))
{
works = new List<StageObjectWorkInfo>();
_objectsWorkInfoDictionary.Add(objectHash, works);
}
works.Add(new StageObjectWorkInfo
{
transform = child,
originalParent = child.parent,
startTransform = new TransformBaseData
{
position = child.localPosition,
rotation = child.localRotation,
scale = child.localScale
},
renderers = child.GetComponents<Renderer>()
});
if (child.name.IndexOf("light", StringComparison.OrdinalIgnoreCase) >= 0 &&
!StageObjectMap.ContainsKey(child.name.Replace("(Clone)", "")))
child.gameObject.SetActive(true);
RegisterObjectTransform(child, string.Empty);
}
}
@@ -1214,6 +1436,67 @@ namespace Gallop.Live
washBeams.Initialize();
}
internal void RegisterObjectTransform(Transform child, string nameSuffixToken)
{
string objectName = child.name.Replace("(Clone)", "") + nameSuffixToken;
if (!StageObjectMap.ContainsKey(objectName))
{
StageObjectMap.Add(objectName, child.gameObject);
StageParentMap.Add(objectName, child.parent);
}
int objectHash = FNVHash.Generate(objectName);
if (!_objectsWorkInfoDictionary.TryGetValue(objectHash, out var works))
{
works = new List<StageObjectWorkInfo>();
_objectsWorkInfoDictionary.Add(objectHash, works);
}
var renderers = child.GetComponents<Renderer>();
for (int i = 0; i < renderers.Length; i++) CacheBgColor1Renderer(renderers[i]);
works.Add(new StageObjectWorkInfo
{
transform = child,
originalParent = child.parent,
startTransform = new TransformBaseData
{
position = child.localPosition,
rotation = child.localRotation,
scale = child.localScale
},
renderers = renderers
});
}
internal void UnregisterObjectTransform(Transform child, string nameSuffixToken)
{
string objectName = child.name.Replace("(Clone)", "") + nameSuffixToken;
int hash = FNVHash.Generate(objectName);
if (!_objectsWorkInfoDictionary.TryGetValue(hash, out var works)) return;
for (int i = works.Count - 1; i >= 0; i--)
{
if (works[i].transform != child) continue;
foreach (var renderer in works[i].renderers)
{
_bgColor1RendererProperties.Remove(renderer);
_ambientColorRenderers.Remove(renderer);
}
works.RemoveAt(i);
}
if (works.Count == 0) _objectsWorkInfoDictionary.Remove(hash);
if (StageObjectMap.TryGetValue(objectName, out var mapped) && mapped == child.gameObject)
{
if (works.Count > 0)
{
StageObjectMap[objectName] = works[0].transform.gameObject;
StageParentMap[objectName] = works[0].originalParent;
}
else
{
StageObjectMap.Remove(objectName);
StageParentMap.Remove(objectName);
}
}
}
private StageObjectUnit FindStageObjectUnit(int hash)
{
if (_stageObjectUnits == null) return null;
@@ -1594,19 +1877,7 @@ namespace Gallop.Live
if (r == null) continue;
_allStageRenderers.Add(r);
IndexRendererSharedMaterials(r);
int stageColorProperties = 0;
bool hasAmbient = false;
var materials = r.sharedMaterials;
for (int m = 0; m < materials.Length; m++)
{
var material = materials[m];
if (material == null) continue;
if (material.HasProperty(BgColor1MulColor0Id)) stageColorProperties |= 1;
if (material.HasProperty(BgColor1ColorPowerId)) stageColorProperties |= 2;
if (material.HasProperty(BgColor1AmbientColorId)) hasAmbient = true;
}
if (stageColorProperties != 0) _bgColor1RendererProperties.Add(r, stageColorProperties);
if (hasAmbient) _ambientColorRenderers.Add(r);
CacheBgColor1Renderer(r);
if (RendererHasAnyBgColorProps(r))
_bgColorAllEligibleRenderers.Add(r);
@@ -1620,6 +1891,23 @@ namespace Gallop.Live
}
}
private void CacheBgColor1Renderer(Renderer r)
{
int stageColorProperties = 0;
bool hasAmbient = false;
var materials = r.sharedMaterials;
for (int m = 0; m < materials.Length; m++)
{
var material = materials[m];
if (material == null) continue;
if (material.HasProperty(BgColor1MulColor0Id)) stageColorProperties |= 1;
if (material.HasProperty(BgColor1ColorPowerId)) stageColorProperties |= 2;
if (material.HasProperty(BgColor1AmbientColorId)) hasAmbient = true;
}
if (stageColorProperties != 0) _bgColor1RendererProperties[r] = stageColorProperties;
if (hasAmbient && !_ambientColorRenderers.Contains(r)) _ambientColorRenderers.Add(r);
}
private void IndexRendererSharedMaterials(Renderer r)
{
var mats = r.sharedMaterials;
@@ -30,6 +30,16 @@ namespace Gallop.RenderPipeline
_parameter = new PostImageEffectFeature.Parameter();
}
public void UpdateImageEffectParameter()
{
// Native RVA 0x1a0da30; recomputed again before each render.
ref var dof = ref Parameter.DofDiffuionBloomOverlay;
dof.IsDisableDofTemporary = dof.IsEnableDofAutoDisable &&
dof.DofFocalSize >= dof.DofMaxFocalSize;
dof.DecideDrawType(dof.IsEnableDof && !dof.IsDisableDofTemporary &&
GallopImageEffect.UserDofEnabled);
}
private void Awake()
{
Initialize(false);
@@ -59,8 +59,8 @@ namespace Gallop.RenderPipeline
set => _enableRendering = value;
}
// Shared live state. Director updates this object from the timeline;
// each camera's CameraData points at the same state before Setup runs.
// Active-camera publication alias, not storage shared by every camera.
// GallopImageEffect / MultiCamera retain their own CameraData parameters.
private static Parameter _runtimeParameter = new Parameter();
public static Parameter RuntimeParameter
@@ -71,6 +71,7 @@ namespace Gallop.RenderPipeline
_runtimeParameter = new Parameter();
return _runtimeParameter;
}
internal set => _runtimeParameter = value;
}
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
@@ -220,12 +221,14 @@ namespace Gallop.RenderPipeline
if (!camera.TryGetComponent(out cameraData))
cameraData = camera.gameObject.AddComponent<CameraData>();
// The recovered feature expects CameraData.Parameter. Keep it
// bound to the timeline-owned object and refresh the active camera
// every frame because CameraSwitcher can replace it.
var cameraParameter = multiCamera != null ? multiCamera.PostEffectParameter : RuntimeParameter;
// Bind this camera's owned state before deciding draw type.
// Live auto-disable must never leak through the active-camera alias.
var imageEffect = camera.GetComponent<GallopImageEffect>();
var cameraParameter = multiCamera != null ? multiCamera.PostEffectParameter
: imageEffect != null ? imageEffect.RenderParameter : RuntimeParameter;
cameraData.Parameter = cameraParameter;
cameraParameter.TargetCamera = camera;
cameraData.UpdateImageEffectParameter();
Parameter parameter = ResolveFeatureParameter(cameraData);
if (parameter == null)
@@ -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;