Search Unity

Question The best way to preload big texture maps in memory in the background

Discussion in 'General Graphics' started by Passeridae, Aug 29, 2020.

  1. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Hi!

    I have a case where I need a number of relatively heavy (~100mb each) 3D Texture maps be ready to be used in shaders at a certain point in the game. And they aren't used anywhere in the scene up to this point. If I begin to load them at the moment when they are already needed it takes ~5 seconds and completely freezes everything for this time period. I guess it's because they're being transferred from an SSD to RAM and GPU Memory. What's the best approach to preload these textures in the background into memory and keep them ready without freezing everything else?

    Thanks!
     
  2. BartPieters

    BartPieters

    Unity Technologies

    Joined:
    Apr 12, 2019
    Posts:
    25
    Hi!

    You could upload your texture slice by slice by using a Texture2D as a staging texture? E.g., create a Texture2D, upload one slice to this Texture2D using SetPixels() or LoadRawTextureData(), and then use CopyTexture() to copy that Texture2D in your Texture3D.