New: Nature Shaders

Interaction, Wind, Dynamic Masking, and Better Shading for your vegetation.

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

Material API

Materials that are using Nature Shaders can be easily edited at runtime using the API in this article. The material can be accessed using the NatureMaterial class in the following namespace:

using VisualDesignCafe.Nature;

Edit a Material

To edit a material, create a new NatureMaterial instance for the material. The NatureMaterial class is a wrapper to edit the material, it does not create a copy of the material.

var natureMaterial = new NatureMaterial( material );

After creating the nature material, you can edit the properties directly through the Nature Material class. There is no need to check if a property is supported/enabled for the material, unsupported properties are automatically ignored.

For example, to change the color of the material use the following code:

natureMaterial.Tint =;

After changing the properties, the material needs to be applied and validated to ensure that the correct shader keywords are set.

Note: It is recommended to pass "false" as the parameter to the Validate method when editing the material at runtime. Using "true" will clear the existing settings, which may cause issues at runtime.

natureMaterial.Validate( false );

Manually Checking Material Properties

If, for any reason, you need to check the material properties or keywords without using the NatureMaterial class, then you can do so with the help of the NatureProperties and NatureKeywords classes.

The NatureProperties class contains the names of all material properties. 

For example:

if( material.HasProperty( NatureProperties.Tint ) )
    material.SetColor( NatureProperties.Tint, );

The NatureKeywords class contains all the keywords that are used by Nature Shaders.

For example:

material.EnableKeyword( NatureKeywords.AlphaTest );
Was this article helpful?
0 out of 0 found this helpful