Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Creating skybox textures programatically

Discussion in 'General Graphics' started by jackmott, Jul 17, 2015.

  1. jackmott

    jackmott

    Joined:
    Jan 5, 2014
    Posts:
    167
    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?
     
  2. ethans

    ethans

    Joined:
    Mar 3, 2015
    Posts:
    11
    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 http://www.nutty.ca/?p=381

    SpaceScape, nebula and star generator http://alexcpeterson.com/spacescape/
     
    Last edited: Jul 17, 2015
  3. CPXTom

    CPXTom

    Joined:
    Apr 24, 2010
    Posts:
    113
  4. jackmott

    jackmott

    Joined:
    Jan 5, 2014
    Posts:
    167
    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.
     
  5. jackmott

    jackmott

    Joined:
    Jan 5, 2014
    Posts:
    167
    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
     
    CPXTom likes this.