New: Nature Renderer 2021

Render vast amounts of detailed vegetation on your terrain.

Learn more
This page may not work correctly inside the Unity editor. Open in browser

Streaming

Nature Renderer loads the details for your terrain at runtime while you move around the terrain, only keeping the details within range loaded. This helps to keep memory usage low and performance high.

Streaming is done on a separate background thread and does not block the main thread.

Startup

Streaming starts during the first frame that is rendered and it can take a few frames to fully load all the terrain data and spawn all detail objects. During these first few frames, you'll see missing patches of grass on the terrain, and they'll start popping in one at a time once they are loaded.

It is recommended to keep your loading screen visible during these first few frames to avoid showing these temporarily missing patches of grass to the player.

Use GetPendingBuildTaskCount() to check the build progress. If the pending task count is 0 then all the detail objects finished loading and it is safe to remove the loading screen.

using VisualDesignCafe.Rendering.Nature;

GetComponent<NatureRenderer>().GetPendingBuildTaskCount();

Note

This API is available starting in version 1.5.1

Preload

It is possible to start loading parts of the terrain before spawning or rendering a camera. This is useful during the first startup to start loading the detail objects as soon as the scene is loaded, before spawning and rendering the camera. You can also preload the data if you plan to teleport the player to a different location in your scene.

IEnumerator Preload()
{
    Camera camera = YOUR_CAMERA;
    NatureRenderer natureRenderer = YOUR_NATURE_RENDERER_COMPONENT;

    // The camera is automatically registered when it is first rendered,
    // however, we can register it manually to start streaming immediately.
    natureRenderer.AddCamera( camera  );

    // Force Nature Renderer to start streaming immediately for the 
    // registered cameras.
    natureRenderer.Stream();

    // Wait until Nature Renderer finished loading.
    while( natureRenderer.GetPendingBuildTaskCount() > 0 )
        yield return null;

    // Streaming finished. You can now hide the loading screen.
}

If your camera did not yet spawn in the scene then you can use a temporary dummy camera to preload the data at the specific location where you plan to spawn the camera/player later.

Note

This API is available starting in version 1.5.1

Settings

The distance at which the details are loaded and discarded can be set in the 'streaming' section of the Nature Renderer component. These properties can be kept at the default values in most cases, unless you specifically run into streaming issues.

Stream in Distance

The distance at which to start loading terrain details. This distance is added to the Detail Rendering Distance

Stream out Distance

The distance at which to discard loaded terrain details. This distance is added to the Detail Rendering Distance.

Stream Processor Limit

The number of CPU cores to use for streaming. This number is multiplied by the total number of cores on the device. 

Was this article helpful?
2 out of 4 found this helpful