Home

Awesome

Terrain Layer Sampler for Unity

Scripting functionality to efficiently read terrain layer weights in realtime.

Image

Motivations

The painted strength of a terrain layer is stored in a channel of an RGBA splatmap texture. Reading this back using Texture2D.GetPixel is too slow for realtime uses.

Instead this script can pre-bake this information into a ScriptableObject, and provides an API for sampling the data at any given world-space position. The weight/strength for each terrain layer is returned as an array.

Example use cases

Adding it to a project

via Package Manager:

via Git:

via browser

Usage instructions

A TerrainLayerData asset will automatically be created, and will be saved on the component with the scene. You can however choose to use a ScriptableObject that is saved on disk. In order to do so, right-click in the Project window and choose Create/TerrainLayerData and assign it. The context menu on the component has a "Bake" option.

Scripting Workflow