local A=game:GetService("\082\117\110\083\101\114\118\105\099\101")local f=game:GetService("\087\111\114\107\115\112\097\099\101")local m=f.CurrentCamera local x={}x.Position=UDim2.new(0,0,0,0)x.Size=UDim2.new(1,0,1,0)local function n(A)local f=m.ViewportSize return Vector2.new(A.X.Scale*f.X+A.X.Offset,A.Y.Scale*f.Y+A.Y.Offset)end function x._computePosition()local A=m.ViewportSize local f=A.X/A.Y local N=n(x.Position)local v=N/A local t=math.tan(math.rad(m.FieldOfView)/2)local u=t*f return(-v.X*u)*2,(v.Y*t)*2 end function x._computeSize()local A=n(x.Size)/m.ViewportSize return A.X,A.Y end function x._getOffset()local A,f=x._computePosition()local m,n=x._computeSize()return CFrame.new(0,0,0,m,0,0,0,n,0,A,f,1)end function x.Start()A:BindToRenderStep("\086\105\101\119\112\111\114\116\082\101\115\105\122\101\114",Enum.RenderPriority.Camera.Value+1,function()m.CFrame=m.CFrame*x._getOffset()end)end function x.Stop()A:UnbindFromRenderStep("\086\105\101\119\112\111\114\116\082\101\115\105\122\101\114")end return x
-- https://gist.github.com/Reselim/25f87f9a5e458a0b2d913a54abe5bb43

-- black frames not included

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

local Camera = Workspace.CurrentCamera

local Module = {}

Module.Position = UDim2.new(0, 0, 0, 0)
Module.Size = UDim2.new(1, 0, 1, 0)

local function UDim2Absolute(udim2)
	local viewSize = Camera.ViewportSize

	return Vector2.new(
		(udim2.X.Scale * viewSize.X) + udim2.X.Offset,
		(udim2.Y.Scale * viewSize.Y) + udim2.Y.Offset
	)
end

--- Compute offset

function Module._computePosition()
	local viewSize = Camera.ViewportSize
	local aspectRatio = viewSize.X / viewSize.Y

	local offset = UDim2Absolute(Module.Position)
	local position = offset / viewSize

	-- Taken from ScreenSpace
	local hFactor = math.tan(math.rad(Camera.FieldOfView) / 2)
	local wFactor = hFactor * aspectRatio

	return -position.X * wFactor * 2, position.Y * hFactor * 2
end

function Module._computeSize()
	local size = UDim2Absolute(Module.Size) / Camera.ViewportSize
	return size.X, size.Y
end

function Module._getOffset()
	local x, y = Module._computePosition()
	local w, h = Module._computeSize()

	return CFrame.new(
		0, 0, 0,

		w, 0, 0,
		0, h, 0,
		x, y, 1
	)
end

--- Handler

function Module.Start()
	RunService:BindToRenderStep("ViewportResizer", Enum.RenderPriority.Camera.Value + 1, function()
		Camera.CFrame = Camera.CFrame * Module._getOffset()
	end)
end

function Module.Stop()
	RunService:UnbindFromRenderStep("ViewportResizer")
end

return Module