Search Unity

Is This Possible or A Thing? - Shader with deferred texture loading

Discussion in 'Shaders' started by MastermindInteractive, Jul 21, 2016.

  1. MastermindInteractive

    MastermindInteractive

    Joined:
    Jun 13, 2014
    Posts:
    89
    Let me start by saying I'm completely ignorant to what is possible with shaders so this may already be a thing or shouldn't be a thing.

    I want to know if I can have a shader that uses a solid color as the albedo and an actual texture that doesn't load by default but does load / unload into memory based on your proximity to the material.

    So for instance, if you have a red brick building at a distance it would only render the albedo color and not load the brick textures (albedo, normals, height, etc) into memory until you get within a certain distance to the material.

    I realize that this isn't fully thought out because it doesn't consider mipmaps or the fact that you may have several instances of the same material, but I'm just wondering if it is possible.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    No.

    Shaders are very limited in what they can do. They take input data on one end (a mesh, usually some textures, a few matrices and other numbers) and spit out a color at a pixel on the other. Shaders have no ability to make permanent changes to any of the data going into it, and certainly can't decide if a texture should be in memory or not. All of those choices need to have been made long before the shader runs. If you run a shader that uses a texture before a texture exist in memory it will still happily draw stuff onto the screen, you just might get a completely black result, or random noise, or a completely different texture in its place.
     
    Last edited: Jul 21, 2016
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    You could look into amplify texture or similar streaming for texture data.
     
  4. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,686
    You ought to be able to fade in / out objects and materials based on distance from the camera with a simple script. That's not a shader solution, but it sounds to me like that's what you're looking for.

    As for the memory management part, you could probably do it with additive levels, with scene loading based on distance.
     
  5. MastermindInteractive

    MastermindInteractive

    Joined:
    Jun 13, 2014
    Posts:
    89
    Thank you for the very helpful responses, everyone.