Search Unity

Generate 360 cubemap, save with compression?

Discussion in 'Editor & General Support' started by Jelmer123, Oct 2, 2019.

  1. Jelmer123

    Jelmer123

    Joined:
    Feb 11, 2019
    Posts:
    243
    Hi all

    I'm captuing a 360 picture of my scene, to use as a skybox in a loading screen (this is a webGL project), and adapted from https://medium.com/acrossthegalaxy/making-skyboxes-directly-in-unity-7250fe90c632
    Code:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3.  
    4. public class SkyboxCamera : MonoBehaviour
    5. {
    6.  
    7. #if UNITY_EDITOR
    8.     const int TEXTURE_SIZE = 1024;
    9.     void Update()
    10.     {
    11.         if (Input.anyKey)
    12.         {
    13.             Capture();
    14.         }
    15.     }
    16.     void Capture()
    17.     {
    18.         Debug.Log("Going to render cubemap");
    19.         Cubemap cubemap = new Cubemap(TEXTURE_SIZE, TextureFormat.RGB24, false);
    20.         cubemap.name = "Skybox";
    21.         Camera camera = GetComponent<Camera>();
    22.         camera.RenderToCubemap(cubemap);
    23.         EditorUtility.CompressCubemapTexture(cubemap, TextureFormat.DXT5, 0);
    24.          AssetDatabase.CreateAsset(
    25.           cubemap,
    26.           "Assets/Materials/Sky/Skybox.cubemap"
    27.         );
    28.         Debug.Log("CUBEMAP RENDERED AND SAVED!");
    29.     }
    30. #endif
    31. }
    The problem is that the cubemap hardly supports compression and thus is quite large. 6MB for a 1024 cubemap.
    One of the few compressions that I found worked was DXT5, which is funny because cubemap is supposed to not support any compression.
    How would I save it as a modern skybox with compression? I don't need HDR or anything fancy :)