local E={Scale=.125;Texture="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\119\104\105\116\101\067\105\114\099\108\101\046\112\110\103";Transparency=.9}local z={{Color=Color3.fromRGB(200,255,200);Radius=1.0;Distance=.0};{Color=Color3.fromRGB(0,255,0),Radius=.5;Distance=.2};{Color=Color3.fromRGB(255,0,0);Radius=.3,Distance=.225},{Color=Color3.fromRGB(255,170,0);Radius=1.5;Distance=.25},{Color=Color3.fromRGB(255,170,0);Radius=3.0;Distance=.25};{Color=Color3.fromRGB(0,255,0),Radius=.5,Distance=.3};{Color=Color3.fromRGB(0,255,0),Radius=.2;Distance=.6};{Color=Color3.fromRGB(0,255,0),Radius=.4,Distance=.65},{Color=Color3.fromRGB(255,0,0);Radius=.2;Distance=.78};{Color=Color3.fromRGB(0,255,0);Radius=.25;Distance=.9},{Color=Color3.fromRGB(63,63,63);Radius=.15;Distance=1.2},{Color=Color3.fromRGB(63,63,63),Radius=.15;Distance=1.5}}local a=game:GetService("\082\117\110\083\101\114\118\105\099\101")local L=game:GetService("\076\105\103\104\116\105\110\103")local Y=workspace.CurrentCamera local m=Y:FindFirstChild("\076\101\110\115\070\108\097\114\101\078\111\100\101")if m then m:ClearAllChildren()else m=Instance.new("\080\097\114\116")m.Name="\076\101\110\115\070\108\097\114\101\078\111\100\101"m.Transparency=1 m.Anchored=true m.CanCollide=false m.Locked=true m.Parent=Y end local function s(E,...)return Vector2.new(E.X,E.Y),...end local function U(E)local z=Y.CFrame.p+Y.CFrame.lookVector*2 local a={}local L=false while true do local Y=RaycastParams.new()Y.FilterDescendantsInstances=a local m=workspace:Raycast(z,z+E*10000000.0,Y)if m then local E=m.Instance local z=E.Transparency+E.LocalTransparencyModifier if z<=0 then L=true break else table.insert(a,E)end else break end end return L end local function K(z,a)local L=z.Radius*E.Scale local Y=Instance.new("\065\116\116\097\099\104\109\101\110\116")Y.Name=a.."\095\065\048"Y.Parent=m z.A0=Y local s=Instance.new("\065\116\116\097\099\104\109\101\110\116")s.Name=a.."\095\065\049"s.Parent=m z.A1=s local U=Instance.new("\066\101\097\109")U.Name=a U.Color=ColorSequence.new(z.Color)U.Width0=L U.Width1=L U.TextureSpeed=0 U.LightEmission=1 U.Texture=E.Texture U.Attachment0=Y U.Attachment1=s U.Transparency=NumberSequence.new(E.Transparency)U.Parent=m z.Beam=U return U end local function q()local a=L:GetSunDirection()local m=a*10000000.0 local q,k=s(Y:WorldToViewportPoint(m))local l=Y.ViewportSize-q local A=k and not U(a)for z,L in ipairs(z)do local m=L.Beam or K(L,z)m.Enabled=A if A then local z=L.Radius*E.Scale local m=l:lerp(q,L.Distance)local s=(Y:ViewportPointToRay(m.X,m.Y,1)).Origin local U=CFrame.new(s,s-a)L.A0.CFrame=U*CFrame.new(-z/2,0,0)L.A1.CFrame=U*CFrame.new(z/2,0,0)end end end a:BindToRenderStep("\085\112\100\097\116\101\076\101\110\115\070\108\097\114\101",201,q)
------------------------------------------------------------------------------------------------------------------------
-- @CloneTrooper1019, 2018 <3
-- Lens Flare Effect
-- A remake of Roblox's 2007 Lens Flare
------------------------------------------------------------------------------------------------------------------------
-- Configuration
------------------------------------------------------------------------------------------------------------------------

-- Classic Style

local LENS_FLARE_CONFIGURATION =
{
	Scale = 1 / 8;
	Texture = "rbxasset://textures/whiteCircle.png";
	Transparency = 0.9;
}

-- Modern Style

--local LENS_FLARE_CONFIGURATION =
--{
--	Scale = 1/3;
--	Texture = "rbxasset://textures/shadowblurmask.png";
--	Transparency = 0.7;
--}

------------------------------------------------------------------------------------------------------------------------
-- Lenses
------------------------------------------------------------------------------------------------------------------------
--[[
	The LENSES array is used to control the individual lenses of the effect.

	* Color		- The color of the lense.
	* Radius	- An arbitrary scaling factor for each lense.
	* Distance	- A value between 0 and 1 indicating the position of the lense on the screen.
				  ( A value of 0.5 will always be at the center of the screen )
				  ( A value of 1.0 will be directly on top of the sun )
				  ( A value of 0.0 will be on the opposite end of the screen )

--]]

local LENSES =
{
	{
		Color = Color3.fromRGB(200, 255, 200),
		Radius = 1.00,
		Distance = 0.000
	};
	{
		Color = Color3.fromRGB(  0, 255,   0),
		Radius = 0.50,
		Distance = 0.200
	};
	{
		Color = Color3.fromRGB(255,   0,   0),
		Radius = 0.30,
		Distance = 0.225
	};
	{
		Color = Color3.fromRGB(255, 170,   0),
		Radius = 1.50,
		Distance = 0.250
	};
	{
		Color = Color3.fromRGB(255, 170,   0),
		Radius = 3.00,
		Distance = 0.250
	};
	{
		Color = Color3.fromRGB(  0, 255,   0),
		Radius = 0.50,
		Distance = 0.300
	};
	{
		Color = Color3.fromRGB(  0, 255,   0),
		Radius = 0.20,
		Distance = 0.600
	};
	{
		Color = Color3.fromRGB(  0, 255,   0),
		Radius = 0.40,
		Distance = 0.650
	};
	{
		Color = Color3.fromRGB(255,   0,   0),
		Radius = 0.20,
		Distance = 0.780
	};
	{
		Color = Color3.fromRGB(  0, 255,   0),
		Radius = 0.25,
		Distance = 0.900
	};
	{
		Color = Color3.fromRGB( 63,  63,  63),
		Radius = 0.15,
		Distance = 1.200
	};
	{
		Color = Color3.fromRGB( 63,  63,  63),
		Radius = 0.15,
		Distance = 1.500
	};
}

------------------------------------------------------------------------------------------------------------------------
-- Constants
------------------------------------------------------------------------------------------------------------------------

local RunService = game:GetService("RunService")
local Lighting = game:GetService("Lighting")

local c = workspace.CurrentCamera
local lensFlareNode = c:FindFirstChild("LensFlareNode")
if lensFlareNode then
	lensFlareNode:ClearAllChildren()
else
	lensFlareNode = Instance.new("Part")
	lensFlareNode.Name = "LensFlareNode"
	lensFlareNode.Transparency = 1
	lensFlareNode.Anchored = true
	lensFlareNode.CanCollide = false
	lensFlareNode.Locked = true
	lensFlareNode.Parent = c
end

	-----------------------------------------------------------------------------------------------------------------------
	-- Main
	-----------------------------------------------------------------------------------------------------------------------

local function as_Vector2(v3, ...)
	-- Roblox likes to kill my OCD.
	return Vector2.new(v3.X, v3.Y), ...
end

local function isSunOccluded(sunDir)
	local origin = c.CFrame.p + (c.CFrame.lookVector * 2)
	local ignore = {}
	local occluded = false
	while true do
		local params = RaycastParams.new()
		params.FilterDescendantsInstances = ignore
		local hit = workspace:Raycast(origin, origin + (sunDir * 10e6), params)
		if hit then
			local inst = hit.Instance
			local t = inst.Transparency + inst.LocalTransparencyModifier
			if t <= 0 then
				occluded = true
				break
			else
				table.insert(ignore, inst)
			end
		else
			break
		end
	end
	return occluded
end

local function createLenseBeam(lense, id)
	local radius = lense.Radius * LENS_FLARE_CONFIGURATION.Scale
	local a0 = Instance.new("Attachment")
	a0.Name = id .. "_A0"
	a0.Parent = lensFlareNode
	lense.A0 = a0

	local a1 = Instance.new("Attachment")
	a1.Name = id .. "_A1"
	a1.Parent = lensFlareNode
	lense.A1 = a1

	local beam = Instance.new("Beam")
	beam.Name = id
	beam.Color = ColorSequence.new(lense.Color)
	beam.Width0 = radius
	beam.Width1 = radius
	beam.TextureSpeed = 0
	beam.LightEmission = 1
	beam.Texture = LENS_FLARE_CONFIGURATION.Texture
	beam.Attachment0 = a0
	beam.Attachment1 = a1
	beam.Transparency = NumberSequence.new(LENS_FLARE_CONFIGURATION.Transparency)
	beam.Parent = lensFlareNode
	lense.Beam = beam
	return beam
end

local function updateLensFlare()
	local sunDir = Lighting:GetSunDirection()
	local sunWrldSpace = sunDir * 10e6
	local sunScrnSpace, inView = as_Vector2(c:WorldToViewportPoint(sunWrldSpace))
	local sunScrnSpaceInv = c.ViewportSize - sunScrnSpace
	local enabled = (inView and not isSunOccluded(sunDir))

	for i, lense in ipairs(LENSES) do
		local beam = lense.Beam or createLenseBeam(lense, i)
		beam.Enabled = enabled
		if enabled then
			local radius = lense.Radius * LENS_FLARE_CONFIGURATION.Scale
			local lenseSP = sunScrnSpaceInv:lerp(sunScrnSpace, lense.Distance)
			local lenseWP = c:ViewportPointToRay(lenseSP.X, lenseSP.Y, 1).Origin
			local lenseCF = CFrame.new(lenseWP, lenseWP - sunDir)
			lense.A0.CFrame = lenseCF * CFrame.new(-radius / 2, 0, 0)
			lense.A1.CFrame = lenseCF * CFrame.new(radius / 2, 0, 0)
		end
	end
end
RunService:BindToRenderStep("UpdateLensFlare", 201, updateLensFlare)
