docs.unity3d.com
    Show / Hide Table of Contents

    Class DetailUtility

    Functions for manipulating terrain details

    Inheritance
    Object
    DetailUtility
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: UnityEditor.TerrainTools
    Syntax
    public static class DetailUtility

    Methods

    GetDensityMapTexture(TerrainData, Int32)

    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

    Int32 detailLayer

    the detail layer to use

    Returns
    Type Description
    Texture2D

    Texture2D representing the grayscale values of the detail masks

    LoadDensityMap(Terrain, String, Int32)

    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

    Terrain object

    String folderName

    string folder path

    Int32 detailLayer

    integer detail layer

    Returns
    Type Description
    Boolean

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

    LoadDensityMap(Terrain, DefaultAsset, Int32)

    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

    Terrain object

    DefaultAsset folder

    DefaultAsset or string folder path

    Int32 detailLayer

    integer detail layer

    Returns
    Type Description
    Boolean

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

    LoadDensityMaps(Terrain, String)

    Given a the text path of an asset folder to seach, 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
    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
    DefaultAsset folder

    SaveDensityMap(Terrain, DefaultAsset, Int32)

    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

    Int32 detailLayer

    The detail layer to save

    SetDensityMap(TerrainData, Material, Int32)

    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

    Int32 detailLayer

    the detail index of the details to scatter

    SetDensityMap(TerrainData, RenderTexture, Int32)

    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
    RenderTexture rTexture
    Int32 detailLayer

    SetDensityMap(TerrainData, in Texture2D, Int32, Boolean)

    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.

    Int32 detailLayer

    the detail layer to populate

    Boolean 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

    Back to top
    Copyright © 2023 Unity Technologies
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on Friday, November 3, 2023