- Home /
Which mesh is used for Unity's skybox?
I've read that Unity uses special geometry for its skybox. From looking at the stats window in an empty scene, that special mesh uses about 1.7k tris and 5k vertices. From modifying skybox shaders, it appears the skybox mesh uses 3d uvs (where uvw map to each vertex' position xyz in a range of -1...1).
Is there any way to get a copy of the skybox mesh or extract it and store it as an asset?
Answer by JonPQ · May 04, 2020 at 06:57 PM
I doubt unity would spend 5k vertices for its skybox... can you link to the article you found please ?
A typical skybox... is 6 vertices.... a box. with 6 mapped textures for top,bot,l,r,f,b also known as a cubemap material. You assign cube-maps to the lighting / sky settings.
If you want to make your own custom geometry for a sky box... you can just make a cube with inverted normals (pointing inward) and set its layer on a camera that renders first, user that camera's position as it's position also. There isn't too much point in adding lots of geometry, as they don't move relative the the camera... so there are no perspective or parallax effects. ( hence why you only need a box geometry)
The only reason I can think of... is if you wanted to build vertex painted sky for a specific look... in which case... you could do the custom camera / layering trick mentioned above. but you'd have to build it in an art tool, something like max or maya.
Here is Unity's skybox in an empty scene in RenderDoc. The stats window shows 5k verts and 3 batches. Switch the clear mode to solid color and the verts are down to 8 and batches down to 2.
I can only guess why the skybox mesh is built the way it is, but I think Unity hasn't been doing cubic skyboxes since moving to PBR.
The specific reason I want to access this mesh is that I'm building my own renderer in Unity, can't rely on the builtin skybox system, but want to mimic it as close as possible.
ahh. i'm in 2019.1 currently. its still using skybox. I tried one of my pc and one mobile project. I disabled it to test... and scene vertex count didn't really change at all. seems like you can set it to cubemap in settings. Thats what I'm using. I'm not using HDRP though... so maybe its using more vertices there. The mesh 'might' also be built on the fly.... compute shader, if so you can't copy their mesh. Wouldn't any sphere work just as well?
I just tested with various different skyboxes and found that the geometry/vertex count is actually dependent on which skybox shader you're using. If the skybox material uses the "Skybox/6 Sided" shader, Unity indeed uses a cube to draw its skybox. For any of the other built-in shaders (Cubemap, Procedural, Panoramic), it uses the sphere from my renderdoc screenshot. This is on built-in render pipeline, not HDRP.
I think the reason why they use a more finely tesselated geometry is that it allows them to shift more of the heavy math to the vertex shader. That could be an explanation why the sphere from my screenshot has most of the tesselation around the equator (and it follows that a regular sphere would not perform as well). Could also be that since shader interpolators are interpolated linearly between vertices, any skybox shader more complex than a simple 6 sided map would introduce some warping if Unity were to render it with a simple cube (but that's my speculation, haven't looked into it).
I'm using a regular sphere right now, but again, I'd rather mimic what Unity is doing to stay compatible with their built-in shaders.
Your answer
Follow this Question
Related Questions
how exactly to I add a "sky" to my terrain? 1 Answer
Dynamic Skybox 2 Answers
Skybox problem, it's like cubed, clamp not working 1 Answer
Why don't shader LODs work on skybox? 0 Answers
How make dynamic skybox with animated particles system 0 Answers