Search Unity

Question Compressing Generated 3D Textures

Discussion in 'General Graphics' started by stebongo, Feb 5, 2024.

  1. stebongo

    stebongo

    Joined:
    Dec 18, 2016
    Posts:
    21
    Hi,

    It is my understanding that BC4 compression of 3D textures is supported, however, while Texture2D has a 'Compress' method, Texture3D does not.

    My 3D texture is generated within a compute shader in Unity written to a RenderTexture, and then written to a Texture3D to be saved as an asset. However, RTs cannot be compressed, and you cannot use Graphics.CopyTexture or directly use the NativeArray to copy it over as the RenderTexture and BC4 format are different.

    I understand I may be able to split the 3D texture into 2D slices and compress each slice to be combined. Is this equivalent to compressing the 3D texture? Is there an easier way?
     
  2. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    669
    Are you doing this at import time or at run-time? Usually textures are compressed at import time, not at run-time. Texture2D.Compress can be called at run-time, but it doesn't compress as well as EditorUtility.CompressTexture.

    There is a thread about run-time texture compression here
    https://forum.unity.com/threads/runtime-texture-compression-using-compute-shader.1031014/
    but as I said, run-time texture compression doesn't give you the best results.

    AFAIK, you should be able to compress each slice individually and then use CopyTexture to copy it to a 3D texture (haven't tried it, though).
     
  3. stebongo

    stebongo

    Joined:
    Dec 18, 2016
    Posts:
    21
    I can do it import time so the execution time of the compression algorithm wouldn't be significant for me. The only reason I note that it is computed is that the texture is in a 3D RenderTexture, therefore, cannot be set to a compressed format on its own.

    In Unity, 3D textures do not seem to have the same compression settings on the asset that 2D textures do.

    I have heard as far as the GPU is concerned, a 3D texture is just a set of 2D slices anyway. My only concern with this sliced texture compression is if any of the compression algorithms do not perform compression independently to depth if that makes sense...
     
  4. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    669
    stebongo likes this.