A free dynamic 3D skybox module

Introduction

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.

Documentation

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.

Properties

	<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 [1]: 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

Methods

	(<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.

Example:

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)

Videos


(Ignore the fact that Jupiter is inside an atmosphere)

Files

Module itself:
https://www.roblox.com/library/5732671689/
A place file as an example of how to use it:
skybox.rbxl (32.4 KB)

Final note

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.

Updates

  • Added a :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.

  • Added a LightSource property 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.

77 Likes

Wow, its exactly what I needed for! To bad that it dosent has a lot of replys, but I will really use it! So, if I understod it good, I could tween the atmosphere? Ok, I am making a very difficult game, so I will try to say it with other words (if I would say you the real case it would be to difficult):

Lets say you are on a planet (planet earth, the Jupiter inspired me), now you go to the moon. Outside the atmosphere its black, so could you now tween the atmosphere to black without changing the sun position?

But I love this, keep this up!

All this module does is display models parented to the viewport frame on a billboard that constantly gets positioned and scaled in front of your camera. It also controls the light direction and color of the parented models, but not the skybox in any way.

You would have to change properties of the Lighting service as that is what affects the skybox.

1 Like

Ok, I understand, but thank you anyways for trying to help me.

1 Like

This looks awesome! I have a question though, are you able to add different planets or what? Just asking because you displayed Jupiter.

Any model parented to the viewport frame will display.

2 Likes