-- custom_sc.lua (整合总控版) -- 包含: -- 1) 分段 Chromatic + Vignette + Zoom(FOV) -- 2) BPM=210 四分音 Bloom+Chromatic 脉冲 -- 3) SceneControl: my_flash (UI 短脉冲) -- ========================================================= -- [A] 配置区 -- ========================================================= -- A1) 分段 Chromatic + Vignette + Zoom local SEGMENTS_CA_VIG_ZOOM = { {21714, 25714}, {26285, 30285}, {30857, 34857}, {35428, 38857}, } local SEG_FADE_IN = 140 local SEG_FADE_OUT = 140 local CA_MAX_INTENSITY_SEG = 0.20 local VIG_MAX_INTENSITY_SEG = 0.06 local VIG_SMOOTHNESS = 0.90 local VIG_ROUNDNESS = 1.00 local ZOOM_FOV_DELTA = 1.0 -- A2) Bloom + Chromatic 脉冲(BPM210 四分音) local BPM = 210 local BEAT = 60000 / BPM local PULSE_RANGES = { {40000, 49142}, {53714, 56000}, {124571, 134857}, {135071, 135071}, {135285, 135285}, {135428, 135428}, {135642, 135642}, {135857, 135857}, {136000, 136000}, {136285, 136285}, {136428, 136428}, {136571, 136571}, {136642, 136642}, {136714, 136714}, {136857, 136857}, {137000, 137000}, {137142, 137142}, {137285, 137285}, {137428, 137428}, {137571, 137571}, {137714, 137714}, {137785, 137785}, {137857, 137857}, {137928, 137928}, {138000, 138000}, {138142, 138142}, {138285, 138285}, {138428, 138428}, {138571, 138571}, {138642, 138642}, {138714, 138714}, {138785, 138785}, {138857, 138857}, {139000, 139000}, {139142, 139142}, {139214, 139214}, {139285, 139285}, {139357, 139357}, {139428, 139428}, {138428, 138428}, {138428, 138428}, } local PULSE_DURATION = 700 local BLOOM_PEAK = 0.06 local CHROMA_PEAK = 0.11 local BLOOM_THRESHOLD = 1.0 local BLOOM_SOFTKNEE = 0.5 local BLOOM_RADIUS = 4.0 local BLOOM_ANTIFLICKER = true -- A3) my_flash(UI 脉冲) local FLASH_DURATION = 240 -- ========================================================= -- [B] 状态区 -- ========================================================= local inited = false local pp = nil local baseFov = nil -- 脉冲状态 local pulseTimings = {} local nextPulseIndex = 1 local pulseStart = -1 local lastTiming = -2147483648 -- my_flash 状态 local flashStart = -1 -- 可扩展更新函数列表(后续你可 append) local ExtraUpdateHooks = {} -- ========================================================= -- [C] 工具函数 -- ========================================================= local function clamp01(x) if x < 0 then return 0 end if x > 1 then return 1 end return x end local function ease01(x) return EaseManager.Evaluate(Ease.InOutSine, clamp01(x)) end local function segmentAlpha(t, s, e, fadeIn, fadeOut) if t < s or t > e then return 0 end local fin = clamp01((t - s) / fadeIn) local fout = clamp01((e - t) / fadeOut) return ease01(math.min(fin, fout)) end local function totalSegmentAlphaAt(timing, segments, fadeIn, fadeOut) local a = 0 for i = 1, #segments do local s = segments[i][1] local e = segments[i][2] local sa = segmentAlpha(timing, s, e, fadeIn, fadeOut) if sa > a then a = sa end end return a end local function buildPulseTimings() pulseTimings = {} for i = 1, #PULSE_RANGES do local s = PULSE_RANGES[i][1] local e = PULSE_RANGES[i][2] local t = s while t <= e do pulseTimings[#pulseTimings + 1] = math.floor(t + 0.5) t = t + BEAT end end end local function findNextPulseIndexByTiming(timing) for i = 1, #pulseTimings do if pulseTimings[i] > timing then return i end end return #pulseTimings + 1 end -- 给你后续扩展用:可把新效果更新函数注册进来 function RegisterExtraUpdate(fn) ExtraUpdateHooks[#ExtraUpdateHooks + 1] = fn end -- ========================================================= -- [D] 初始化 -- ========================================================= local function initAll() if inited then return end pp = Data.CreatePostProcessingProfile() pp:Use() -- 统一启用并置零,避免反复开关带来的状态问题 pp.Bloom.Enabled = true pp.Bloom.Intensity = 0 pp.Bloom.Threshold = BLOOM_THRESHOLD pp.Bloom.SoftKnee = BLOOM_SOFTKNEE pp.Bloom.Radius = BLOOM_RADIUS pp.Bloom.AntiFlicker = BLOOM_ANTIFLICKER pp.ChromaticAberration.Enabled = true pp.ChromaticAberration.Intensity = 0 pp.Vignette.Enabled = true pp.Vignette.Intensity = 0 pp.Vignette.Mode = VignetteMode.Classic pp.Vignette.Center = Data.Vec2(0.5, 0.5) pp.Vignette.Color = Data.Color(0, 0, 0, 1) pp.Vignette.Smoothness = VIG_SMOOTHNESS pp.Vignette.Roundness = VIG_ROUNDNESS pp.Vignette.Rounded = true baseFov = Camera.FieldOfView buildPulseTimings() nextPulseIndex = 1 pulseStart = -1 lastTiming = -2147483648 inited = true end -- ========================================================= -- [E] SceneControl 注册 -- ========================================================= SceneControl.Register("my_flash", function(sc) flashStart = sc.Timing -- Toast.Show("Triggered my_flash at " .. tostring(sc.Timing)) end) -- ========================================================= -- [F] 主更新 -- ========================================================= function UpdateAtTiming(timing) initAll() -- 回放/重开时处理(时间倒退) if timing < lastTiming then nextPulseIndex = findNextPulseIndexByTiming(timing) pulseStart = -1 -- my_flash 不强制恢复,让它自然等待下一次触发 end -- ----------------------------- -- F1) 分段 CA + Vignette + Zoom -- ----------------------------- local segAlpha = totalSegmentAlphaAt( timing, SEGMENTS_CA_VIG_ZOOM, SEG_FADE_IN, SEG_FADE_OUT ) local chromaSeg = CA_MAX_INTENSITY_SEG * segAlpha local vig = VIG_MAX_INTENSITY_SEG * segAlpha local fovOffset = ZOOM_FOV_DELTA * segAlpha -- ----------------------------- -- F2) 四分音脉冲 Bloom + CA -- ----------------------------- while nextPulseIndex <= #pulseTimings and timing >= pulseTimings[nextPulseIndex] do pulseStart = pulseTimings[nextPulseIndex] nextPulseIndex = nextPulseIndex + 1 end local bloomPulse = 0 local chromaPulse = 0 if pulseStart >= 0 then local p = clamp01((timing - pulseStart) / PULSE_DURATION) if p < 1 then local k = 1 - EaseManager.Evaluate(Ease.OutCubic, p) bloomPulse = BLOOM_PEAK * k chromaPulse = CHROMA_PEAK * k end end -- ----------------------------- -- F3) my_flash UI 脉冲 -- ----------------------------- if flashStart >= 0 then local p = clamp01((timing - flashStart) / FLASH_DURATION) local k = 1 - EaseManager.Evaluate(Ease.OutQuad, p) UI.SetUILeftOpacity(1 - 0.5 * k) UI.SetUIRightOpacity(1 - 0.5 * k) UI.SetComboOpacity(1 - 0.7 * k) if p >= 1 then UI.SetUILeftOpacity(1) UI.SetUIRightOpacity(1) UI.SetComboOpacity(1) flashStart = -1 end end -- ----------------------------- -- F4) 合成并写入后处理 -- ----------------------------- local finalBloom = bloomPulse local finalChroma = clamp01(chromaSeg + chromaPulse) local finalVig = vig -- F4.5) 139571-140571: ramp in, then hold (no exit) do local s = 139571 local e = 140571 local caFrom = 0.11 local blFrom = 0.06 local caTo = 1.00 local blTo = 0.70 if timing >= s and timing <= e then local p = clamp01((timing - s) / (e - s)) local k = EaseManager.Evaluate(Ease.InOutSine, p) local caHold = caFrom + (caTo - caFrom) * k local blHold = blFrom + (blTo - blFrom) * k finalChroma = math.max(finalChroma, caHold) finalBloom = math.max(finalBloom, blHold) elseif timing > e then finalChroma = math.max(finalChroma, caTo) finalBloom = math.max(finalBloom, blTo) end end -- F4.6) 144857-145142: fade out CA + Bloom to 0, then keep 0 do local s2 = 140571 local e2 = 145142 if timing >= s2 and timing <= e2 then local p2 = clamp01((timing - s2) / (e2 - s2)) local k2 = EaseManager.Evaluate(Ease.InOutSine, p2) -- 0 -> 1 finalChroma = finalChroma * (1 - k2) finalBloom = finalBloom * (1 - k2) elseif timing > e2 then finalChroma = 0 finalBloom = 0 end end pp.Bloom.Intensity = finalBloom pp.ChromaticAberration.Intensity = finalChroma pp.Vignette.Intensity = finalVig -- 轻微放大(FOV缩小) if baseFov ~= nil then Camera.FieldOfView = baseFov - fovOffset end -- ----------------------------- -- F5) 执行扩展更新钩子(你后面 append 用) -- ----------------------------- for i = 1, #ExtraUpdateHooks do ExtraUpdateHooks[i](timing) end lastTiming = timing end RegisterExtraUpdate(function(timing) if pp == nil then return end local s = 49142 local e = 49714 local function clamp01(x) if x < 0 then return 0 end if x > 1 then return 1 end return x end if timing >= s and timing < e then local p = clamp01((timing - s) / (e - s)) local k = EaseManager.Evaluate(Ease.OutSine, p) -- 0 -> 1 -- 渐黑 pp.Vignette.Enabled = true local targetVig = 0.20 * k if pp.Vignette.Intensity < targetVig then pp.Vignette.Intensity = targetVig end -- 压 Bloom pp.Bloom.Intensity = pp.Bloom.Intensity * (1 - 0.95 * k) -- 加强 CA(关键改动) pp.ChromaticAberration.Enabled = true local targetCA = 0.60 * k -- 想更猛可改 0.30~0.35 if pp.ChromaticAberration.Intensity < targetCA then pp.ChromaticAberration.Intensity = targetCA end end end) RegisterExtraUpdate(function(timing) local s = 58285 local fadeInStart = 74285 local fadeInEnd = 76571 local fadeOutDur = 2600 -- 你可改成 300/800 local function clamp01(x) if x < 0 then return 0 end if x > 1 then return 1 end return x end local function ease(x) return EaseManager.Evaluate(Ease.InOutSine, clamp01(x)) end local a = 1 if timing < s then a = 1 elseif timing < s + fadeOutDur then local p = (timing - s) / fadeOutDur a = 1 - ease(p) -- fade out: 1 -> 0 elseif timing < fadeInStart then a = 0 elseif timing <= fadeInEnd then local p = (timing - fadeInStart) / (fadeInEnd - fadeInStart) a = ease(p) -- fade in: 0 -> 1 else a = 1 end UI.SetUILeftOpacity(a) UI.SetUIRightOpacity(a) UI.SetComboOpacity(a) pcall(function() UI.SetHPBarOpacity(a) end) pcall(function() UI.SetHpBarOpacity(a) end) pcall(function() UI.SetHealthBarOpacity(a) end) pcall(function() UI.SetScoreOpacity(a) end) pcall(function() UI.SetScoreBarOpacity(a) end) pcall(function() UI.SetPauseButtonOpacity(a) end) pcall(function() UI.SetPauseOpacity(a) end) end) -- ========================================================= -- [G] 扩展区域(以后你直接 append 在下面) -- 用法示例: -- RegisterExtraUpdate(function(timing) -- -- 你的新效果逻辑 -- end) -- =========================================================