How to make circles on the screen from the sun?

Hello developers! Today I saw one interesting thing at one of the demonstrations, namely these circles or what is it…

I really don’t know what to call it but it looks beautiful. Could you help me achieve this effect?

It’s not very similar to the built-in Sun Rays effect.

5 Likes

Under lighting, you can add an effect called “SunRaysEffect.” You can tweak the variables to make it look different, too.

1 Like

I think this is an additional module or scripts, because Sun Rays does not have such settings.

2 Likes

Hey there! That’s a lens flare effect. You are correct in that this is not a built-in feature, but more in line with additional scripts.

If I remember right, the lens flare effects I’ve seen before on Roblox were created using BillboardGui’s or Beams, either can have a similar end result.

Sorry I don’t have anything to provide that can give you this effect or more info on it. I just know it’s 1000% possible :slight_smile: Good luck on it!

1 Like

What demonstration?, who made it? Can you ask that person?

1 Like

I know for sure that this video uses these glares from the sun. This person’s name is Aerophagia.

thanks for the answer! I think someone has already done this, but if I don’t find it, I’ll try to do it myself.

I found something similar but it’s not exactly what’s in the picture. Forum

I did end up finding the old leans flare effect I originally tinkered around with, credits to @Maximum_ADHD!

It does use beams as I mentioned, and seems to be more first-person oriented, has some choppiness to it in third-person.

------------------------------------------------------------------------------------------------------------------------
-- @CloneTrooper1019, 2018 <3
-- Lens Flare Effect
-- A remake of Roblox's 2007 Lens Flare
------------------------------------------------------------------------------------------------------------------------
-- Configuration
------------------------------------------------------------------------------------------------------------------------

-- Classic Style
local TweenService = game:GetService("TweenService")

local FadeInfo = TweenInfo.new(0.3,Enum.EasingStyle.Sine,Enum.EasingDirection.Out)
local LENS_FLARE_CONFIGURATION = 
	{	
		Scale = 1/3;
		--Texture = "rbxasset://textures/whiteCircle.png";
		--Texture = "rbxassetid://3052949762";
		Texture = "rbxassetid://3428619365";
		Transparency = 0.7;
	}

-- 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 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 };
	}

local ActiveTweens = {} :: {Tween}

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

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

local currentCamera = workspace.CurrentCamera
local lensFlareNode = currentCamera: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 = currentCamera
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 = currentCamera.CFrame.Position + (currentCamera.CFrame.LookVector*2)
	local direction = origin + (sunDir * 900000)
	local ignore = {game.Players.LocalPlayer.Character, currentCamera}
	local params = RaycastParams.new()
	params.FilterDescendantsInstances = ignore
	params.FilterType = Enum.RaycastFilterType.Exclude
	params.IgnoreWater = false
	
	local occluded = false
	
	while task.wait() do
		local result = workspace:Raycast(origin,direction,params)
		if result and result.Instance:IsA("BasePart") then
			local t = result.Instance.Transparency + result.Instance.LocalTransparencyModifier
			if t <= 0 then
				occluded = true
				break
			else
				table.insert(ignore,result.Instance)
			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

	local transparency = Instance.new("NumberValue", beam)
	transparency.Name = "Transparency"
	transparency.Value = beam.Transparency.Keypoints[1].Value
	transparency:GetPropertyChangedSignal("Value"):Connect(function()
		beam.Transparency = NumberSequence.new(transparency.Value)
	end)
	
	return beam
end

local function updateLensFlare()
	local vpSize = currentCamera.ViewportSize
	local sunDir = Lighting:GetSunDirection()
	local sunWrldSpace = sunDir * 10e6
	local sunScrnSpace,inView = as_Vector2(currentCamera:WorldToViewportPoint(sunWrldSpace))
	local sunScrnSpaceInv = currentCamera.ViewportSize - sunScrnSpace
	local enabled = (inView and not isSunOccluded(sunDir))
	
	for i,lense in ipairs(LENSES) do
		local beam : Beam = lense.Beam or createLenseBeam(lense,i)
		
		local transparencyValue : NumberValue = beam:FindFirstChild("Transparency")
		if transparencyValue then
			if ActiveTweens[beam] then ActiveTweens[beam]:Pause() ActiveTweens[beam] = nil end
			ActiveTweens[beam] = TweenService:Create(transparencyValue, TweenInfo.new(0.075,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),{Value = (enabled and 0.7 or 1)}):Play()
		end
		
		if enabled then
			beam.Enabled = enabled
			
			local radius = lense.Radius * LENS_FLARE_CONFIGURATION.Scale
			local lenseSP = sunScrnSpaceInv:lerp(sunScrnSpace,lense.Distance)
			local lenseWP = currentCamera: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)
		else
			if ActiveTweens[beam] and ActiveTweens[beam].PlaybackState == Enum.PlaybackState.Completed then
				beam.Enabled = enabled
			end
		end
	end
end

RunService:BindToRenderStep("UpdateLensFlare",201,updateLensFlare)

------------------------------------------------------------------------------------------------------------------------

I did add a fade for transparency so it’s not as 2007 looking lol it’s not a bad take on lens flare overall though.

1 Like

oh thank you! I also talked to the creator of the place where there is such an effect and he told me how to do it. As soon as I test this model, I will tell you about it!

The creator of this game told me about this model that he used in this game. Link to Twitter and Model.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.