Added an option to choose between making the system run on the client or server (by default it now runs on the client)
The properties now tween instead of instantly changing
Introduction
Hello everyone! Having realistic lighting can greatly impact the quality of your game, realistic lighting can help players immerse themselves better with the world you are building. While having good lighting is important for realistic games, having dynamic lighting that changes depending on the time of day would boost realism in your game by a lot!
This is why I decided to open source my simple dynamic lighting system, which changes the atmosphere & lighting settings depending on the time of day in your game.
Looks really good and can save an indie developer like me some time! Big question is how is it performance wise?
Could you provide some sort of benchmark or video comparing the difference of using it and using the default lighting features by roblox?
Its one thing having a game look good but having it run poorly for most players which is why I ask.
I added the system to an empty baseplate and tested it on roblox. Here’s the benchmark for the game without the system (basically just the default empty baseplate):
I hope this helps. Currently I’m using the system in a W.I.P game I’m making and I haven’t noticed an impact on the game’s performance from this system.
I do ask that when you have gotten to a decent portion of the game being built for what you’re building could you supply the same tests again just to confirm its consistent as the screen shots say?
I say this assuming the game has not much too at the moment and being pretty much a baseplate. Hopefully you understand
The system you made is really nice and as you mentioned you are taking suggestions up above, I’ll suggest a few things:
Making it client side.
Instead of just jumping from phases, tween them for smoother transition.
Hello. I would love to have a Moon Phases feature implemented into this module. It would greatly benefit my game and make the module feel even more realistic.
local lightingPresets = {
Sunrise = { module = require(modules.LightingPresets.Sunrise), Active = false },
Day = { module = require(modules.LightingPresets.Day), Active = false },
MorningGoldenHour = { module = require(modules.LightingPresets.MorningGoldenHour), Active = false },
AfternoonGoldenHour = { module = require(modules.LightingPresets.AfternoonGoldenHour), Active = false },
Night = { module = require(modules.LightingPresets.Night), Active = false },
Sunset = { module = require(modules.LightingPresets.Sunset), Active = false },
Twilight = { module = require(modules.LightingPresets.Twilight), Active = false }
}
local timeRanges = {
{Start = 6, Finish = 8, Period = "Sunrise"},
{Start = 8.01, Finish = 17, Period = "Day"},
{Start = 17.01, Finish = 18, Period = "AfternoonGoldenHour"},
{Start = 18.01, Finish = 18.15, Period = "Sunset"},
{Start = 18.16, Finish = 21, Period = "Twilight"},
{Start = 21.01, Finish = 5.99, Period = "Night"}
}
function tweenProperty(instance: Instance, propertyName: string, propertyValue: any)
local tweenInfo = TweenInfo.new(1)
local tween = tweenService:Create(instance, tweenInfo, {[propertyName] = propertyValue})
tween:Play()
debris:AddItem(tween, tweenInfo.Time)
end
function setLightingSettings(config: ModuleScript)
for objectName, objectTable in pairs(config) do
for propertyName, property in pairs(objectTable) do
local instance
if objectName == "Lighting" then
instance = lighting
elseif objectName == "Clouds" then
instance = workspace:FindFirstChild("Terrain").Clouds
elseif objectName ~= nil and propertyName ~= nil then
instance = lighting:FindFirstChild(objectName)
end
if instance then
tweenProperty(instance, propertyName, property)
end
end
end
end
function resetPeriod()
for period, data in pairs(lightingPresets) do
data.Active = false
end
end
lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
local time = lighting.ClockTime
for _, range in ipairs(timeRanges) do
if (time >= range.Start and time <= range.Finish) or (range.Start > range.Finish and (time >= range.Start or time <= range.Finish)) then
local period = range.Period
if not lightingPresets[period].Active then
resetPeriod()
lightingPresets[period].Active = true
setLightingSettings(lightingPresets[period].module)
end
end
end
end)
Hello, sorry for the late reply. I’ve provided a link to the game which you sent a screenshot of in the post. The game is open sourced, so feel free to copy the lighting settings from it into your game, and of coruse into the module scripts so it works.
local Lighting = game:GetService("Lighting")
local TweenService = game:GetService("TweenService")
local LightingModules = {
Sunrise = require(script.Parent:WaitForChild("Lighting Presets"):WaitForChild("Sunrise")),
Day = require(script.Parent:WaitForChild("Lighting Presets"):WaitForChild("Day")),
AfternoonGoldenHour = require(script.Parent:WaitForChild("Lighting Presets"):WaitForChild("AfternoonGoldenHour")),
Sunset = require(script.Parent:WaitForChild("Lighting Presets"):WaitForChild("Sunset")),
Twilight = require(script.Parent:WaitForChild("Lighting Presets"):WaitForChild("Twilight")),
Night = require(script.Parent:WaitForChild("Lighting Presets"):WaitForChild("Night")),
}
local CurrentTimePeriod = nil
local TweenSettings = TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local function ApplyLightingSettings(preset)
for property, value in pairs(preset.Lighting or {}) do
local tween = TweenService:Create(Lighting, TweenSettings, { [property] = value })
tween:Play()
end
local function ApplyEffectSettings(effectClass, settings)
local effect = Lighting:FindFirstChildOfClass(effectClass)
if effect then
for property, value in pairs(settings) do
local tween = TweenService:Create(effect, TweenSettings, { [property] = value })
tween:Play()
end
end
end
ApplyEffectSettings("BloomEffect", preset.Bloom or {})
ApplyEffectSettings("BlurEffect", preset.Blur or {})
ApplyEffectSettings("ColorCorrectionEffect", preset.ColorCorrection or {})
ApplyEffectSettings("DepthOfFieldEffect", preset.DepthOfField or {})
ApplyEffectSettings("SunRaysEffect", preset.SunRays or {})
ApplyEffectSettings("Atmosphere", preset.Atmosphere or {})
ApplyEffectSettings("Clouds", preset.Clouds or {})
end
Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
local clock = Lighting.ClockTime
if clock >= 6 and clock <= 8 and CurrentTimePeriod ~= "Sunrise" then
CurrentTimePeriod = "Sunrise"
ApplyLightingSettings(LightingModules.Sunrise)
elseif clock > 8 and clock <= 17 and CurrentTimePeriod ~= "Day" then
CurrentTimePeriod = "Day"
ApplyLightingSettings(LightingModules.Day)
elseif clock > 17 and clock <= 18.5 and CurrentTimePeriod ~= "AfternoonGoldenHour" then
CurrentTimePeriod = "AfternoonGoldenHour"
ApplyLightingSettings(LightingModules.AfternoonGoldenHour)
elseif clock > 18.5 and clock <= 20 and CurrentTimePeriod ~= "Sunset" then
CurrentTimePeriod = "Sunset"
ApplyLightingSettings(LightingModules.Sunset)
elseif clock > 20 and clock <= 23 and CurrentTimePeriod ~= "Twilight" then
CurrentTimePeriod = "Twilight"
ApplyLightingSettings(LightingModules.Twilight)
elseif (clock > 23 or clock <= 6) and CurrentTimePeriod ~= "Night" then
CurrentTimePeriod = "Night"
ApplyLightingSettings(LightingModules.Night)
end
end)
return true