docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class DetailUtility

    Functions for manipulating terrain details

    Inheritance
    object
    DetailUtility
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEditor.TerrainTools
    Assembly: Unity.TerrainTools.Editor.dll
    Syntax
    public static class DetailUtility

    Methods

    GetDensityMapTexture(TerrainData, int)

    Gets a TerrainData's detailLayer as a Texture2D

    Declaration
    public static Texture2D GetDensityMapTexture(TerrainData tData, int detailLayer = 0)
    Parameters
    Type Name Description
    TerrainData tData

    A TerrainData object.

    int detailLayer

    The detail layer to use.

    Returns
    Type Description
    Texture2D

    Texture2D representing the grayscale values of the detail masks.

    LoadDensityMap(Terrain, string, int)

    Loads a saved density map for terrain from folder into detail layer detailLayer

    Declaration
    public static bool LoadDensityMap(Terrain terrain, string folderName, int detailLayer)
    Parameters
    Type Name Description
    Terrain terrain

    A Terrain object.

    string folderName

    String folder path.

    int detailLayer

    Integer detail layer.

    Returns
    Type Description
    bool

    True if the expected texture asset exists and can be applied, or false otherwise.

    LoadDensityMap(Terrain, DefaultAsset, int)

    Loads a saved density map for terrain from folder into detail layer detailLayer

    Declaration
    public static bool LoadDensityMap(Terrain terrain, DefaultAsset folder, int detailLayer)
    Parameters
    Type Name Description
    Terrain terrain

    A Terrain object.

    DefaultAsset folder

    DefaultAsset or string folder path.

    int detailLayer

    Integer detail layer.

    Returns
    Type Description
    bool

    True if the expected texture asset exists and can be applied, or false otherwise.

    LoadDensityMaps(Terrain, string)

    Given a text path of an asset folder to search, finds the detail maps corresponding to terrain and loads them into the corresponding detail channels of terrain.

    Declaration
    public static void LoadDensityMaps(Terrain terrain, string folderName)
    Parameters
    Type Name Description
    Terrain terrain

    A Terrain object.

    string folderName

    An Asset folder containing textures.

    LoadDensityMaps(Terrain, DefaultAsset)

    Given a DefaultAsset folder to seach, finds the density maps corresponding to terrain and loads them into the corresponding detail channels of terrain.

    Declaration
    public static void LoadDensityMaps(Terrain terrain, DefaultAsset folder)
    Parameters
    Type Name Description
    Terrain terrain

    A Terrain object.

    DefaultAsset folder

    A DefaultAsset corresponding to Asset folder containing textures.

    SaveAllDensityMaps(Terrain, string)

    Save a detail density map for every prototype in the supplied terrain to folder

    Declaration
    public static void SaveAllDensityMaps(Terrain terrain, string folderName)
    Parameters
    Type Name Description
    Terrain terrain

    A terrain object to save.

    string folderName

    String path to the asset folder.

    SaveAllDensityMaps(Terrain, DefaultAsset)

    Save a detail density map for every prototype in the supplied terrain to folder

    Declaration
    public static void SaveAllDensityMaps(Terrain terrain, DefaultAsset folder)
    Parameters
    Type Name Description
    Terrain terrain

    A terrain object to save.

    DefaultAsset folder

    An asset folder to receive saved assets.

    SaveDensityMap(Terrain, DefaultAsset, int)

    Saves a Texture2D representing the detail density in terrain to the asset folder folder

    Declaration
    public static void SaveDensityMap(Terrain terrain, DefaultAsset folder, int detailLayer)
    Parameters
    Type Name Description
    Terrain terrain

    A terrain object to save.

    DefaultAsset folder

    An asset folder to receive saved assets.

    int detailLayer

    The detail layer to save.

    SetDensityMap(TerrainData, Material, int)

    Use the supplied material to generate a detail layer map for the supplied TerrainData The material will be blitted to an 8-bit R8 RenderTarget of the same resolution as the TerrainData's detail layers. The material will be given references to the TerrainData's splatmap textures (referenced as "_Control0" and "_Control1" if present), and the heightmap (referenced as "_Height"). If instanced rendering is enabled, the material will also be given a reference to the TerrainData's normal map ("_Normal"). Existing detail arrays will be passed to the material as RenderTextures (referenced as "_Density#" where # is the detail layer number. The material can use or ignore these inputs as desired.

    Declaration
    public static void SetDensityMap(TerrainData tData, Material densityMaterial, int detailLayer = 0)
    Parameters
    Type Name Description
    TerrainData tData

    (this) Target TerrainData.

    Material densityMaterial

    A material to blit.

    int detailLayer

    The detail index of the details to scatter.

    SetDensityMap(TerrainData, RenderTexture, int)

    Sets a TerrainData's detail layer using the supplied RenderTextures This executes synchronously

    Declaration
    public static void SetDensityMap(TerrainData tData, RenderTexture rTexture, int detailLayer = 0)
    Parameters
    Type Name Description
    TerrainData tData

    The TerrainData to populate.

    RenderTexture rTexture

    An R8 format RenderTexture.

    int detailLayer

    The detail layer to populate.

    SetDensityMap(TerrainData, in Texture2D, int, bool)

    Populates a TerrainData's detail layer using the red channel of the supplied texture as a density map. Bright texels translate to more detail instances, dark texels translate to fewer or none. By default, the texture will be resampled to the correct size for the TerrainData's detail array. If the optional allowResample parameter is passed as false, the method will throw an ArgumentException if the texture and detail resolutions don't match. This method will accept any Texture2D as an input, but for best results use a texture which is not saved with gamma or color correction.

    Declaration
    public static void SetDensityMap(TerrainData tData, in Texture2D texture, int detailLayer = 0, bool allowResample = true)
    Parameters
    Type Name Description
    TerrainData tData

    The TerrainData to populate.

    Texture2D texture

    A Texture2D.

    int detailLayer

    The detail layer to populate.

    bool allowResample

    If true, resample the texture to fit the detail array. If false, accept only textures of the same dimensions as the detail array.

    Exceptions
    Type Condition
    ArgumentException

    Thrown if allowResample is false and the texture resolution does not match the detail array resolution.

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)