As the title suggests, this is a small module for creating 3D skyboxes that react to time of day, resolution and FOV changes using ViewportFrames. I created this module as none of the alternatives present here contained these features.
This module is perfect for rendering very distant objects, such as planets and landscapes, as you can fake millions of kilometers by decreasing the camera’s movement speed.
If you wish to change a property, you’ll have to do so through the provided methods as there are no metamethods to handle direct property change.
There are a few internal properties/methods, but they aren’t shown here as they serve no use for the user.
<type> PropertyName[DefaultValue]: Description. <boolean> IsAlive [true]: Is set to false when the skybox is destroyed. <boolean> IsActive [false]: Whether the skybox is currently visible. <number> WorldScale : Camera's movement speed multiplier. Smaller value = bigger skybox. <Vector3> CameraOrigin [(0,0,0)]: Camera's origin point. <string> LightSource ["Cycle"]: Which light source to follow. "Cycle" switches between the Sun and the Moon, "Moon" locks it to the Moon and "Sun" to the Sun. <Color3> AmbientColorDay [(128,128,128)]: Sunlight's ambient color. <Color3> AmbientColorNight [(35,35,35)]: Moonlight's ambient color. <Color3> LightColorDay [(128,128,128)]: Sunlight's color. <Color3> LightColorNight [(35,35,35)]: Moonlight's color. <ViewportFrame> ViewportFrame <Camera> Camera
(<void>) SetWorldScale (<number> WorldScale) (<void>) SetCameraOrigin (<Vector3> CameraOrigin) (<void>) SetViewportFrameZIndex (<number> ZIndex) (<void>) SetLightSource (<string> LightSource) (<void>) SetAmbientColorDay (<Color3> AmbientColorDay) (<void>) SetAmbientColorNight (<Color3> AmbientColorNight) (<void>) SetLightColorDay (<Color3> LightColorDay) (<void>) SetLightColorNight (<Color3> LightColorNight) (<void>) SetActive (<boolean> IsActive): Sets whether the skybox is visible. (<void>) Destroy (<void>): Destroys all instances linked to this skybox and deactivates it.
Quick setup guide
You have to require the module, create a new skybox, parent something to the skybox’s ViewportFrame and activate it. You may also want to change the CameraOrigin and WorldScale properties to ensure the correct scale and camera offset for your skybox.
The module has to be required from a LocalScript as it will error otherwise.
local Skybox3D = require(script.Skybox3D) local sky = Skybox3D.new() sky:SetWorldScale(0.1) sky:SetCameraOrigin(Vector3.new(0,10,0) script.Model.Parent = sky.ViewportFrame sky:SetActive(true)
(Ignore the fact that Jupiter is inside an atmosphere)
A place file as an example of how to use it:
skybox.rbxl (32.4 KB)
Please report any bugs you encounter and leave suggestions. I made this during midnight in a few hours, so there was little time left for troubleshooting.
:SetViewportFrameZIndex(<number>ZIndex)method and removed the one active skybox only limit. This allows for multiple skyboxes for different ranges, like a skybox for distant planets and a skybox for the current atmosphere.
LightSourceproperty as well as a
:SetLightSource(<string> LightSource)method. You can use this to lock the light direction and ambient color to only follow the Sun or the Moon. The default “Cycle” value retains the previous behavior.
Noticed that the billboard doesn’t scale correctly when CFrame based FOV is used to go above 120, so I added that (check this link for more details). I’m planning a code cleanup in the near future.
Code cleanup complete. Some bugs may occur as it required almost a complete rewrite of certain parts.
Converted the module to use types. There is a type error since :Clone() returns an “Instance”, while “ViewportFrame” is expected. But the code works and this issue will be fixed by Roblox as development of Luau continues.