HyperBox - A ViewportFrame Wrapper for Stunning Visual Effects

:package: Get ‎v0.3 ‎ ‎ ‎‎ :file_folder: Get Demo ‎‎ ‎ ‎ :video_game: Play Demo


Introduction

Client-sided engine that renders models as a background in a ViewportFrame attached to the player’s camera. Use it to make stunning background effects that native Roblox can’t make. Like non-euclidean backgrounds, make an empty looking map a great look, confuse people etc.


Features

  • Relative camera position (moves with camera relatively using multiplier. Can also be used to lock movement on camera on any axis)
  • Make models gigantic using camera movement to remove the 2048 size limit.
  • Seperate camera effects like FOV (the viewport has its own camera which can be customized seperately than the main camera)
  • Advanced effects like border, always on top, gradient etc.
  • ViewportFrame Masking

Better to show than describe:



More Info

Pros and Cons: Native Roblox

Pros

  • Realistic and Best quality

Cons

  • Size limit
  • Hard to position
  • Lack of effects
Pros and Cons: HyperBox

Pros

  • Axis lock
  • Easy to position and apply
  • Advanced effects
  • Always on top or behind everything (depends on distance for behind)
  • Separate camera effects

Cons

  • Viewport Frame limitations (i.e. no shadows, lighting effects, low quality etc)
  • Magnifying effect using camera position decreases as the multiplier gets lower.
Tutorial

This tutorial walks through installing the module, adding models, wiring simple UI, and tips for performance and debugging.

Installation

  1. Put HyperBox as a ModuleScript in ReplicatedStorage.
  2. Make sure the module’s HyperBackground template (a BillboardGui containing a ViewportFrame) is present under the module as script.HyperBackground so the module can clone it for each player.
  3. Create the models you want to render as backgrounds in workspace (or load them from ReplicatedStorage) — e.g. Rig, Pillers, Ring, Cubes, Fractal. Make sure ther have Persistant streaming mode.

Basic client script (example)

Below is the full example LocalScript that demonstrates this model (in showcase game)


local hyperbox = require(game.ReplicatedStorage.HyperBox)
local player = game.Players.LocalPlayer
local runService = game:GetService("RunService")
local anim = script.Animation
local ui = player.PlayerGui:WaitForChild("ScreenGui").Frame.ScrollingFrame

hyperbox.Initialize() -- Creates necessary objects such as the camera

-- Cloning models, adding them to a table and returning them
local dummy = hyperbox.AddModel(workspace:WaitForChild("Rig"))
local pillers = hyperbox.AddModel(workspace:WaitForChild("Pillers"))
local saturn = hyperbox.AddModel(workspace:WaitForChild("Ring"))
local cubes = hyperbox.AddModel(workspace:WaitForChild("Cubes"))
local fractal = hyperbox.AddModel(workspace:WaitForChild("Fractal"))
local base = workspace.Baseplate

local functions = {}

-- pillers preset
table.insert(functions, function()
    hyperbox.ClearActiveModels() -- clear already visible models
    hyperbox.SetModelActive(pillers, true) -- Make this model visible (parent it to vpf directly)

    hyperbox:ResetSettings() -- Reset settings to default
    hyperbox.Origin = Vector3.zero -- set models origin to zero (when camera moves, it will move as cameraPosition - Origin * Multiplier).
    -- This is to make it look like that the origin is the center of the world which models are positioned around
    hyperbox.Brightness = 10000 -- Make the billboard gui bright (very)
    hyperbox.Multiplier = Vector3.one * 0.0001 -- this will be used whe positioning the camera relative to the main camera
    base.Transparency = 1 -- make baseplate invisible

    hyperbox:UpdateSettings() -- update settings manually
end)

-- (other presets are in the example script from showcase)

-- simple rotation for visual interest
local partsRotation = {}
local fractalRotation = {}

for _, rig in dummy:GetChildren() do
    local hum = rig:FindFirstChildOfClass("Humanoid")
    if hum then
        local track = hum:LoadAnimation(anim)
        track.Looped = true
        track:Play()
    end
end

runService.RenderStepped:Connect(function()
    hyperbox:Render() -- update billboard size, camera cframe etc

    for _, part: BasePart in cubes:GetChildren() do
        if not partsRotation[part] then
            local x = math.random(-50, 50) * 0.01
            local y = math.random(-50, 50) * 0.01
            local z = math.random(-50, 50) * 0.01
            local angle = Vector3.new(math.rad(x), math.rad(y), math.rad(z))
            partsRotation[part] = angle
        end

        local angle = partsRotation[part]
        part.CFrame = part.CFrame * CFrame.Angles(angle.X, angle.Y, angle.Z)
    end

    for _, part: Model in fractal:GetChildren() do
        if not fractalRotation[part] then
            local x = math.random(-50, 50) * 0.01
            local y = math.random(-50, 50) * 0.01
            local z = math.random(-50, 50) * 0.01
            local angle = Vector3.new(math.rad(x), math.rad(y), math.rad(z))
            fractalRotation[part] = angle
        end

        local angle = fractalRotation[part]
        part:PivotTo(part.WorldPivot * CFrame.Angles(angle.X, angle.Y, angle.Z))
    end
end)
How does it work?

It creates a BillboardGui in PlayerGui that is applied to an attachment created inside the camera during initialization. The billboard contains a ViewportFrame and creates a Camera on initialization. It also creates a WorldModel if UseWorldModel is true, like this:

The billboard and viewportframe can be accessed from HyperBox.Components and more UI effects such as UIGradient can be parented inside the viewportframe.

API quick reference
  • hyperbox.Initialize() — initialize
  • hyperbox.AddModel(model: Model, name: string?) -> Model — clones and registers a model. Returns the cloned model.
  • hyperbox.RemoveModel(modelOrName) — remove from registry.
  • hyperbox.GetModels() — returns table of registered models.
  • hyperbox.GetActiveModels() — returns currently active models table.
  • hyperbox.ClearActiveModels() — clears all active models (parents are set to nil)
  • hyperbox.SetModelActive(modelOrName, active: boolean) — set a registered model to active/inactive
  • hyperbox:ResetSettings() — resets module fields to defaults
  • hyperbox:UpdateSettings(settings?) — push current module fields into the actual ViewportFrame & camera (call after mutating settings)
  • hyperbox:Render() — update and place viewport camera; call per-frame (RenderStepped/Heartbeat)
Settings you can tweak
  • Multiplier (Vector3) — multiplies the camera-to-origin vector before placing viewport camera. Small values move the viewport camera very little relative to the main camera; useful for parallax.
  • Distance (number) — StudsOffset for the BillboardGui
  • Brightness, Ambient, LightColor, LightDirection, LightInfluence — lighting controls
  • Transparency, BackgroundTransparency, BackgroundColor, Color — how the ViewportFrame renders
  • FieldOfView and SyncFOV — control viewport camera FOV
  • UseWorldModel — when true, a WorldModel is created inside the ViewportFrame and active models are parented into it.
Default Values
local API = {
	Multiplier = Vector3.one * 0.01,
	Origin = Vector3.zero,
	Distance = -3000,
	Brightness = 1,
	LightInfluence = 0,
	Transparency = 0,
	BackgroundTransparency = 1,
	FieldOfView = 70,
	SyncFOV = true,
	Color = Color3.new(1, 1, 1),
	BackgroundColor = Color3.new(0, 0, 0),
	BorderSize = 0,
	Ambient = Color3.fromRGB(180, 180, 180),
	LightColor = Color3.fromRGB(222, 222, 222),
	LightDirection = Vector3.one * -1,
	AlwaysOnTop = false,
	BorderColor = Color3.new(0, 0, 0),
	UseWorldModel = false,
	Enabled = true
}

Performance

  • Keep active models small (low part counts) — ViewportFrame renders are costly when many parts are visible.
  • Avoid running heavy code inside RenderStepped besides hyperbox:Render() and light transforms. Use Heartbeat if you want slightly relaxed timing or for non-UI scenes.
  • WorldModel with ModelStreamingMode.Persistent is helpful for complex models but can increase memory usage.
  • Disable fog and atmostphere when the Distance is too far.

Troubleshooting

  • HyperBox needs to be initialized first. — you forgot to call hyperbox.Initialize() before SetModelActive/Render.

  • UpdateSettings needs to be called with ':' not '.' — use hyperbox:UpdateSettings() (with colon). The module expects self.

  • Models not appearing or wrong transform — check model pivots and whether the origin is set near the player.

Feedback

Rate
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
0 voters
Will you use this?
  • Yes
  • No
0 voters
61 Likes

This is so cool!

Very underappreciated! The fact you can make models HUGE and have them float in the background is so sick.

I was wondering what is the perfomance of this? And how does HyperBox show these viewportframes? Where are they attached?

2 Likes

Thanks for your feedback!

The module is actually very simple; it just creates a viewport frame inside a billboard GUI that applies to an Attachment created inside the camera. The performance depends on the models that are active. This is the render loop, though:

function API:Render()
	assert(self ~= nil, "Render needs to be called with ':' not '.'")
	assert(initialized, "HyperBox needs to be initialized first.")
	
	if not self.Enabled then
		return		
	end
	
	local origin: Vector3 = self.Origin
	local multiplier: number = self.Multiplier
	local gui: BillboardGui = self.Components.BillboardGui
	local viewport: ViewportFrame = self.Components.Viewport
	local viewCamera: Camera = viewport.CurrentCamera
	
	local distanceFromOrigin: Vector3 = camera.CFrame.Position - origin
	local pos: CFrame = CFrame.new(distanceFromOrigin * multiplier)
	
	gui.Size = UDim2.fromOffset(camera.ViewportSize.X, camera.ViewportSize.Y)
	
	viewCamera.CFrame = pos * camera.CFrame.Rotation
end

It performs just the essential tasks for operation. It doesn’t need to run continuously; invoking it whenever the camera changes is sufficient.

It creates an hierchy like this (the model is directly parented under the vpf if UseWorldModel is false)

This is inside the PlayerGui, not under the attachment, since it doesn’t allow changing the camera’s CFrame.

@Yarik_superpro @A_Mp5 How can I optimize it?

2 Likes

the viewport itself is most likely more expensive than the code (and scales with user graphics quality and hardware anyway)

I wouldremove those local vars that are used less than 3 times. some allocations there aren’t necessary if you pay the oookup cost like once

1 Like

Sadly there isn’t any other way

it’s in a loop so…

you use origin once
you use multiplier once
you use gui once
you use viewcamera once

allocations aren’t free

Oh I thought they helped..
Will fix when I’ll have time.
Heart if I should allocate them outside function, ignore if I should just use self… (I think self is not free either but…)

Edit: also give feedback pls

1 Like

best is outside of the function unless you actually need per-object values, then use self

1 Like

has there been any updates to this or no

Yes

like what

1 Like

someone should make this

2 Likes

tried the neweest version and
to be honest i dont like how the models actually follow your camera


i know this won’t be added but can you add a setting for it to be at 0,0,0

edit: heres some pictures i did with fractal


Sure, I’m gonna make this today
edit:

I mean, I made the background. Too lazy for the platform and ball

They dont follow, the multiplier I used is 100x smaller which makes them move very very slow. If you want to make them not move at all i.e. Make them follow camera, you’ll have to set origin to camera’s CFrame everytime before render.

Wdym


Testing reversed effect for shadows and stuff
I could also make both (make a copy of the workspace, in the workspace, that is smaller and replicates movement and stuff), but that’s much more complex, so unless I get an idea, I can’t make it.

I also gave a direct link to get the module in the beginning of the post.

2 Likes

HyperBox is out on Creator Store!

You can get it here.

2 Likes

Addon

My plugin

when next update

Soon I think

yay

also look at this i made


how big do you think the baseplate is

1 Like