Creating skybox textures programatically

I’ve got 3d coordinates for a bunch of stars, and I want to turn that into a skybox. So I need to programatically create the 6 skybox textures. At a high level I think I need to draw a line from the origin, through each star, to a point on whichever face of the skybox ‘cube’ it hits. Then draw on that portion of the skybox texture.

Anyone have any code or know of asset store libraries that do this?

There’s two main ways I would do this.

-Build your skybox scene with Unity and call Camera.RenderToCubemap

-Manually generate the pixels of each cubemap face and use CubeMap.SetPixels

Also here’s the first two results from google’ing “skybox generator”

SkyGen, an in browser sky box generator SkyGen WebGL Tool | Nutty Software

SpaceScape, nebula and star generator Spacescape – Alex Peterson

Is this a skybox that will be used for a space scene? If so I suggest using: Spacescape – Alex Peterson It’s free and very easy to use.

Thanks for the tips guys. These star coordinates will be dynamic, depending on where you are in the galaxy, so using a 3rd party tool to generate the skybox textures won’t work. I need to do it in code. So, manually generate the pixels of each cubemap face is what I am after, just need pointers on the math to do that.

Got it working, not sure if it is the most efficient method, but it goes pretty quick.

Basically create a ray from the origin through each star coordiate.
Create 6 planes (front, back, left,right,up,down)
See which plane the ray intersects
Use that intersection point to compute the texture coordinate

1 Like