[V1.1] Realistic Dynamic Lighting | Open Sourced

VERSION 1.1 IS HERE!

What’s new?

  • 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.

Links
.rbxl file:
Dynamic Lighting.rbxl (61.3 KB)
Marketplace link

Showcase
Game link: (4) Isla Natura [Showcase] - Roblox
Note: Type ;time X to change the clocktime (X is for a number between 0 and 24)



Benchmarks

If you have any questions then feel free to message me

61 Likes

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.

Hope to hear back soon!

6 Likes

This is incredible! Are you taking suggestions? I have some ideas that I think would allow this to have potentially more helpful features. :slight_smile:

Aside from that, thank you for this resource and your contribution to the forum! :pray:

2 Likes

Sure, I got you!

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):

With the system installed:
Clocktime: 07 (Sunrise lighting)

Clocktime: 19 (Sunset lighting)

Clocktime: 22 (Night lighting)

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.

5 Likes

Thank you! Yes, I’m taking suggestions. Feel free to DM me or reply to this post if you want to suggest anything. :slight_smile:

2 Likes

It looks good.

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

1 Like

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.

2 Likes

i’d go for linear interpolation instead of tweening. for example, what if player stops and/or reverses time?

2 Likes

[Update] Added Version 1.1, the new changes are in the post.

1 Like

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.

1 Like

i’ve shortened it down if anyone’s interested :slight_smile:

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)
1 Like

How can my game look like: https://devforum-uploads.s3.dualstack.us-east-2.amazonaws.com/uploads/optimized/5X/0/3/c/e/03cef49d9540f39cb9bc1ba6e7907ce4dd767198_2_1035x552.jpeg

For me it looks nothing like it when I use your dynamic lighting file.

1 Like

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.

1 Like

added tweening for smoother transition

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

Your game isn’t open sourced by the way, I tried to see how you did your lighting settings, but to no avail, no access.

2 Likes