Global Illumination Script! [DEPRECIATED]

THIS SCRIPT IS OUTDATE GO TO HERE FOR A NEW AND IMPROVED SCRIPT! Thank you : D

So, I have decided to make a open-sourced lighting script that includes…

  • Global Illumination

[EDIT] I almost forgot to say, but this ONLY SUPPORTS sunlight and pointlights

INSERT THIS IN “StarterPlayerScripts” TO WORK FULLY!

BEFORE

AFTER (with extra)

DOWNLOAD HERE:`https://www.roblox.com/library/9853541384/Global-Illumination-Client-Side-Script

I’m working on a new and more optimized version of this script. So don’t use this one, I am working on a new one.

33 Likes

This looks really cool! Keep up the cool ideas.

1 Like

Just for those who were wanting the source code of the script, here it is:

Global Lighting Script:

GLOBAL ILLUMINATION

WARNING! THIS SCRIPT WILL CAUSE LAG IN LARGE TO MEDIUM SIZED GAMES, ONLY USE ON SMALL GAMES, ANYTHING ELSE MAY CAUSE CRASHING OR FREEZING

The "EnabledExtras" Feature adds some extra lighting changing instances to the lighting service
like color correction, bloom, and blur

The "Delay" is how long it will take before the lighting will fully update



local rayDirection = game.Lighting:GetSunDirection()
local rayLength = 125
if script.Configuration.EnabledExtra.Value == true then
	if game.Lighting:FindFirstChild("LuminBloom") then
		local bloom = game.Lighting:FindFirstChild("LuminBloom")
		bloom.Enabled = true
		bloom.Name = "LuminBloom"
		bloom.Threshold = 0.8
		bloom.Size = 56
		bloom.Intensity = 0.2
	else
		local bloom = Instance.new("BloomEffect",game.Lighting)
		bloom.Enabled = true
		bloom.Name = "LuminBloom"
		bloom.Threshold = 0.8
		bloom.Size = 56
		bloom.Intensity = 0.2
	end
	if game.Lighting:FindFirstChild("LuminColor") then
		local cc = game.Lighting:FindFirstChild("LuminColor")
		cc.Enabled = true
		cc.Name = "LuminColor"
		cc.Brightness = 0.2
		cc.Contrast = 0.2
		cc.Saturation = 0.2
	else
		local cc = Instance.new("ColorCorrectionEffect",game.Lighting)
		cc.Enabled = true
		cc.Name = "LuminColor"
		cc.Brightness = 0.2
		cc.Contrast = 0.2
		cc.Saturation = 0.2
	end
	if game.Lighting:FindFirstChild("Luminblur") then
		local blur = game.Lighting:FindFirstChild("Luminblur")
		blur.Enabled = true
		blur.Name = "Luminblur"
		blur.Size = 2
	else
		local blur = Instance.new("BlurEffect",game.Lighting)
		blur.Enabled = true
		blur.Name = "Luminblur"
		blur.Size = 2
	end
end
game.Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(function()
	rayDirection = game.Lighting:GetSunDirection()
end)

if not game.Workspace:FindFirstChild("Center") then
	local cen = Instance.new("Part")
	cen.Position = Vector3.new(0,0,0)
	cen.Transparency = 1
	cen.Anchored = true
	cen.Size = Vector3.new(0.1,0.1,0.1)
	cen.CanCollide = false
	cen.CanQuery = false
	cen.CanTouch = false
	cen.Name = "Center"
	cen.Parent = game.Workspace
end


local timer = 0
local timermax = script.Configuration.Delay.Value
game:GetService("RunService").Heartbeat:Connect(function(dt)
	timer += dt
	if timer >= timermax then
		timer = 0
		for i, v in pairs(game.Workspace:GetDescendants()) do
			if not v:FindFirstChild("Lum") then
				if v:IsA("PointLight") then
					local range = v.Range
					local part = v:FindFirstAncestorOfClass("Part")
					for _, checking in pairs(game.Workspace:GetDescendants()) do
						if checking:IsA("Part") or checking:IsA("UnionOperation") or checking:IsA("MeshPart") or checking:IsA("Truss") or checking:IsA("WedgePart") or checking:IsA("CornerWedgePart")  then
							if checking.Transparency < 0.75 and (checking.Position-part.Position).Magnitude <= range then
								local par = {}
								for _, is in pairs(game.Workspace:GetDescendants()) do
									if is:IsA("Part") or is:IsA("UnionOperation") or is:IsA("MeshPart") or is:IsA("Truss") or is:IsA("WedgePart") or is:IsA("CornerWedgePart") then
										if is.Transparency >= 0.75 or is.CastShadow == false then
											table.insert(par,is)
										end
									end
								end
								local params = RaycastParams.new(par)
								params.FilterType = Enum.RaycastFilterType.Blacklist
								local ray = game.Workspace:Raycast(part.Position,(checking.Position-part.Position)*range,params)
								if ray then
									if (ray.Position-part.Position).Magnitude <= range and ray.Instance == checking then
										local at = Instance.new("Attachment")
										local lu = Instance.new("PointLight")
										local ch = Instance.new("ObjectValue")
										ch.Name = "Lum"
										ch.Parent = lu
										lu.Parent = at
										lu.Range = (((range/2 * ((checking.Size.Y+checking.Size.X+checking.Size.Z)/6))*(v.Brightness*(range/50))))
										if ray.Instance:FindFirstAncestorOfClass("Model") then
											if ray.Instance:FindFirstAncestorOfClass("Model"):FindFirstChild("Humanoid") then
												lu.Brightness = v.Brightness/15
											else
												lu.Brightness = v.Brightness/5
											end
										else
											lu.Brightness = v.Brightness/5
										end
										lu.Color = ray.Instance.Color
										lu.Shadows = true
										at.WorldPosition = ray.Position
										at.Parent = game.Workspace:FindFirstChild("Center")
										local pos = ray.Position
										spawn(function()
											wait(timermax/2)
											local ray1 = game.Workspace:Raycast(part.Position,(checking.Position-part.Position)*range,params)
											if ray1 and at and pos ~= ray1.Position then
												pos = ray1.Position
												game:GetService('TweenService'):Create(at,TweenInfo.new(timermax/2,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),{WorldPosition = ray1.Position}):Play()
												game:GetService('TweenService'):Create(lu,TweenInfo.new(timermax/2,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),{Range = (((range/2 * ((checking.Size.Y+checking.Size.X+checking.Size.Z)/6))*(v.Brightness*(range/50))))}):Play()
											end
											wait(timermax/2)
											local ray2 = game.Workspace:Raycast(part.Position,(checking.Position-part.Position)*range,params)
											if ray2 and at and pos ~= ray2.Position then
												pos = ray2.Position
												game:GetService('TweenService'):Create(at,TweenInfo.new(timermax/2,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),{WorldPosition = ray2.Position}):Play()
												game:GetService('TweenService'):Create(lu,TweenInfo.new(timermax/2,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),{Range = (((range/2 * ((checking.Size.Y+checking.Size.X+checking.Size.Z)/6))*(v.Brightness*(range/50))))}):Play()
											end
										end)
									end
								end
							end

						end
					end	
				elseif v:IsA("Part") or v:IsA("UnionOperation") or v:IsA("MeshPart") or v:IsA("Truss") or v:IsA("WedgePart") or v:IsA("CornerWedgePart") then
					if v.Transparency < 0.75 then
						local par = {}
						for _, is in pairs(game.Workspace:GetDescendants()) do
							if is:IsA("Part") or is:IsA("UnionOperation") or is:IsA("MeshPart") or is:IsA("Truss") or is:IsA("WedgePart") or is:IsA("CornerWedgePart") then
								if is.Transparency >= 0.75 or is.CastShadow == false then
									table.insert(par,is)
								end
							end
						end
						local params = RaycastParams.new(par)
						params.FilterType = Enum.RaycastFilterType.Blacklist
						local corners = require(script.PositionModule).GetCorners(v)
						local isbounce = false
						for _, corner in pairs(corners) do
							if isbounce == false then
								local ray = game.Workspace:Raycast(corner + rayDirection * rayLength,(corner - (corner + rayDirection * rayLength))*rayLength*2,params)
								if ray then
									if ray.Instance == v then
										isbounce = true
										local at = Instance.new("Attachment")
										local lu = Instance.new("PointLight")
										local ch = Instance.new("ObjectValue")
										ch.Name = "Lum"
										ch.Parent = lu
										lu.Parent = at
										lu.Range = (v.Size.X+v.Size.Y+v.Size.Z)/1.5
										if ray.Instance:FindFirstAncestorOfClass("Model") then
											if ray.Instance:FindFirstAncestorOfClass("Model"):FindFirstChild("Humanoid") then
												lu.Brightness = 0.1
											else
												lu.Brightness = 0.2
											end
										else
											lu.Brightness = 0.2
										end
										lu.Color = ray.Instance.Color
										lu.Shadows = true
										at.WorldPosition = ray.Position
										at.Parent = game.Workspace:FindFirstChild("Center")
										local pos = ray.Position
										spawn(function()
											wait(timermax/2)
											local ray1 = game.Workspace:Raycast(corner + rayDirection * rayLength,(corner - (corner + rayDirection * rayLength))*rayLength*2,params)
											if ray1 and at and pos ~= ray1.Position then
												pos = ray1.Position
												game:GetService('TweenService'):Create(at,TweenInfo.new(timermax/2,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),{WorldPosition = ray1.Position}):Play()
											end
											wait(timermax/2)
											local ray2 = game.Workspace:Raycast(corner + rayDirection * rayLength,(corner - (corner + rayDirection * rayLength))*rayLength*2,params)
											if ray2 and at and pos ~= ray2.Position then
												pos = ray2.Position
												game:GetService('TweenService'):Create(at,TweenInfo.new(timermax/2,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut),{WorldPosition = ray2.Position}):Play()
											end	
										end)
									end
								end
							end
						end
					end
				end
			elseif v:FindFirstChild("Lum") then
				v:FindFirstAncestorOfClass("Attachment"):Destroy()
			end
		end
	end
end)

PositionModule:

local module = {}

module.GetCorners = function(part)
	local cf = part.CFrame
	local size = part.Size

	local corners = {}
	
	local frontFaceCenter = (cf + cf.LookVector * size.Z/2)
	local backFaceCenter = (cf - cf.LookVector * size.Z/2)
	
	-- edges
	local topFrontEdgeCenter = frontFaceCenter + frontFaceCenter.UpVector * size.Y/2
	local bottomFrontEdgeCenter = frontFaceCenter - frontFaceCenter.UpVector * size.Y/2
	local topBackEdgeCenter = backFaceCenter + backFaceCenter.UpVector * size.Y/2
	local bottomBackEdgeCenter = backFaceCenter - backFaceCenter.UpVector * size.Y/2
	
	-- center
	corners.center = part.Position
	
	-- corners
	corners.topFrontRight = (topFrontEdgeCenter + topFrontEdgeCenter.RightVector * size.X/2.5).Position
	corners.topFrontLeft = (topFrontEdgeCenter - topFrontEdgeCenter.RightVector * size.X/2.5).Position

	corners.topBackRight = (topBackEdgeCenter + topBackEdgeCenter.RightVector * size.X/2.5).Position
	corners.topBackLeft = (topBackEdgeCenter - topBackEdgeCenter.RightVector * size.X/2.5).Position
	
	return corners
end

return module
``
7 Likes

I wonder if there could be a way to run it on the client, so that users could customize it for themselves, and maybe speed it up.

4 Likes

Fun fact, it was originally made on a local script. It should be easy to convert if you understand how it is made.

2 Likes

Having issues with it, game doesn’t load at all/takes hours & runs at 0.8 fps.

2 Likes

I forgot to mention, but it doesn’t work well with larger to medium sized games.
(EDIT) But I did say it in the script

2 Likes

I read the script, I’m just using it on a baseplate.

2 Likes

Maybe I might make a client-side version of it that has a render distance to it.
(EDIT) Did you change the delay?

2 Likes

If it doesn’t work still then I might make what I said.

2 Likes

What’s the delay meant to be?

characters

2 Likes

The delay is just the delay before the bounce lighting is replaced.

2 Likes

Yeah, if I make the delay 10, it just waits 10 then freezes.

2 Likes

You said it is just on a baseplate right?

2 Likes

Correct

aaaaaaaaaaaaaaaaaaaaaaa

2 Likes

It seems to be working for me. I will try to make a more optimized client-side version.

5 Likes

I added another link, just a reminder to disable “CheckCorners” and to lower “RenderDistance” for more optimization!

3 Likes

UPDATE! I have improved how the script works and also added a new setting called “EnabledTweening” This exists to improve performance, And I also disabled shadows on light that has been created by the script to remove the light flashing bug.

4 Likes

Would it be ok if you gave a tutorial to set up the client-side version? I tried setting it up, but it just made everything ugly, and broke.

2 Likes

First of all, the script comes with a small tutorial inside at the top of the script, and to make sure your games lighting doesn’t change disable the “EnabledExtra” value in the configuration. And remember, global illumination makes it so then light bounces off of surfaces, like ue5. I hope this helped you understand the script.
(EDIT) Before I forget this is designed for future ligthing.

3 Likes