Загрузка данных


local Lighting = game:GetService("Lighting")

-- ================= НАСТРОЙКИ =================
local Settings = {
	AutoCycle = true,       -- автоматическая смена дня и ночи
	DayLengthMinutes = 10,  -- сколько минут длится сутки в игре
	StartClock = 14,        -- стартовое время (0-24)
}
-- =============================================

local function getOrCreate(class, name)
	local obj = Lighting:FindFirstChild(name)
	if not obj then
		obj = Instance.new(class)
		obj.Name = name
		obj.Parent = Lighting
	end
	return obj
end

local atmosphere = getOrCreate("Atmosphere", "WorldAtmosphere")
local bloom = getOrCreate("BloomEffect", "WorldBloom")
local sunRays = getOrCreate("SunRaysEffect", "WorldSunRays")
local color = getOrCreate("ColorCorrectionEffect", "WorldColor")
local dof = getOrCreate("DepthOfFieldEffect", "WorldDOF")

Lighting.GlobalShadows = true
Lighting.EnvironmentDiffuseScale = 1
Lighting.EnvironmentSpecularScale = 1
Lighting.ShadowSoftness = 0.3

bloom.Intensity = 0.4
bloom.Size = 30
bloom.Threshold = 1.6

dof.FarIntensity = 0.15
dof.FocusDistance = 60
dof.InFocusRadius = 50
dof.NearIntensity = 0

atmosphere.Offset = 0.25

local function lerp(a, b, t)
	return a + (b - a) * t
end

local function update()
	local t = Lighting.ClockTime
	-- освещённость: 0 ночью, 1 днём
	local day = math.clamp(math.sin((t - 6) / 12 * math.pi) * 1.4, 0, 1)
	-- близость к восходу или закату
	local edge = math.clamp(1 - math.abs(day - 0.3) * 3, 0, 1)

	Lighting.Brightness = lerp(0.3, 3, day)
	Lighting.ExposureCompensation = lerp(0.4, 0, day)
	Lighting.OutdoorAmbient = Color3.fromRGB(lerp(25, 120, day), lerp(30, 125, day), lerp(55, 135, day))

	atmosphere.Density = lerp(0.45, 0.32, day)
	atmosphere.Haze = lerp(0.8, 1.8, edge)
	atmosphere.Color = Color3.fromRGB(lerp(60, 199, day), lerp(70, 190, day), lerp(110, 200, day))
	atmosphere.Decay = Color3.fromRGB(lerp(40, 106, day), lerp(40, 112, day), lerp(70, 125, day))

	sunRays.Intensity = 0.05 + day * 0.15
	color.Contrast = 0.08
	color.Saturation = lerp(-0.1, 0.15, day)
	color.TintColor = Color3.new(1, lerp(0.97, 0.9, edge), lerp(1, 0.8, edge))
end

Lighting.ClockTime = Settings.StartClock
update()

task.spawn(function()
	local step = 0.25
	local perStep = 24 / (Settings.DayLengthMinutes * 60) * step
	while true do
		task.wait(step)
		if Settings.AutoCycle then
			Lighting.ClockTime = (Lighting.ClockTime + perStep) % 24
		end
		update()
	end
end)