Search Unity

Question How to preload texture mipmap for runtime-instantiated renderer object?

Discussion in 'General Graphics' started by Kichang-Kim, Aug 24, 2021.

  1. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
    Hi. I enabled Texture Streaming and found that runtime instantiated MeshRenderer makes pop in effect.

    It seems that Streaming Controller (https://docs.unity3d.com/ScriptReference/StreamingController.html) only has Preload() method for specific camera, not individual renderers.

    Is there any method for preloading mipmap for single Renderer (especially, before enabling it)?

    Thanks.
     
  2. lyndon_unity

    lyndon_unity

    Unity Technologies

    Joined:
    Nov 2, 2017
    Posts:
    66
    Currently there isn't preloading control at the renderer level, and for the system to calculate the desired mip levels the renderer would need to be enabled (and thus added to the texture streaming manager).

    One potential solution is to set forceRenderingOff on the renderer you runtime instance. Then each frame check if the renderers textures are all loaded, before clearing this flag. (Note if the renderer is not enabled it will not be in the list to calculate the texture mip levels, hence the suggestion of the 'forceRenderingOff' flag rather than 'enabled')

    To check all the renderers textures are all loaded, check the loadedMipmapLevel against desiredMipmapLevel.
    You may need to loop over the renderers materials to find all related textures (unless you have this information already available), for performance you'd want to cache this texture list so you don't search for it each time.


    Another alternative is to calculate the mip level manually following the example in GetUVDistributionMetric and use the requestedMipMapLevel to force it to load for each of the textures associated with the renderer.