Dynamically generated starfield skybox for Unity.
For each 6 faces of the skybox, the script generates stars based on a Perlin noise distribution. The first star is drawn randomly between 10
and 1000
, after that, the next star is drawn between 50
and 1000 * (1 / sample)
where the sample is the current Perlin noise value. If this distance is over, the size of the star is generated (66% red, roughly K-type, 24% white, roughly F-type, 10% blue and twice the size, roughly B-type), and another Perlin noise value is sampled.
On my laptop (i5 7440HQ + GeForce 930MX), each face takes roughly 25-30 ms to generate. I guess this could be made faster with compute shaders, but that falls outside my comfort zone. The heavy part is the two nested while loops that go over the Color[skyboxResolution * skyboxResolution]
array.
- Download the latest release.
- Add the script to your Unity project.
- Attach the script to a Camera that will draw the skybox.
The level of detail, sets the resolution of the skybox texture.
- Low: 128x128
- Medium: 512x512
- High: 1024x1024
- Ultra: 2048x2048
- 4K: 4096x4096
The higher the resolution, the smaller the stars are and slower the generation goes, and vice versa.
A scale factor for the Perlin noise generation.
The Perlin noise will generate a random X and Y origin in the 0
and 1000
range on every Start()
. If you want to set a fixed origin, check this box.
The X origin of the Perlin noise generation.
The Y origin of the Perlin noise generation.