Logo Test 2019
  • Tile Composer
      • Back
      • Documentation
          • Back
          • Introduction
          • Documentation: Tile Collections
          • Documentation: Tile
          • Documentation: Tile Composer
          • Documentation: Solvers
          • Documentation: Helpful Tools
          • Tutorial: Empty Tiles
          • Tutorial: Connectors
          • Tutorial: Neighbors from mesh
          • Tutorial: Neighbor matrix editing
          • Combining Workflows
          • Tutorial: Multiple Tile Composer Passes
          • Custom Grid Types
  • DirectX 11 Grass Shader
      • Back
      • Documentation
          • Back
          • General Overview
          • Grass Painter
          • Interaction System
          • CPU Fallback
          • Grass Texture Atlas Templates
          • Performance Optimization
          • Improve Visuals
          • Virtual Reality
          • Using URP and HDRP
          • Upgrade to version 2
  • Contact

Documentation

  • General Overview
  • Grass Painter
  • Interaction System
  • CPU Fallback
  • Grass Texture Atlas Templates
  • Performance Optimization
  • Improve Visuals
  • Virtual Reality
  • Using URP and HDRP
  • Upgrade to version 2

Table of Contents

  • General Information
  • How-To: Set up the grass in your scene
    • Create a grass material
    • Render the grass on your custom mesh or Unity terrain
  • Components
    • Nature Mesh Filter
    • Grass Renderer
  • Material Settings
    • Shader Versions
    • Shader Variants
      • Grass Modes
      • Grass Lighting
      • Level of Detail Interpolation
      • Object / World Space Modes
      • Other Shader Variants
    • Shader Settings
      • Performance Settings
      • Visual Settings
      • Wind settings
      • Base Textures
      • Grass types
DirectX 11 Grass Shader > Documentation > General Overview

General Information

This part of the documentation will walk though the parts of the asset that are necessary to include grass in your project.

This documentation is meant as a general overview for the concepts used in the shader, if you want to know what a specific setting does, look at its tooltip for more information.

For feature requests, documentation problems, bugs, or other reasons you can contact me via our support email ( support@stixgames.com), or though the contact form.

How-To: Set up the grass in your scene

Create a grass material

  1. In the project window, navigate to the folder where you want to create your grass material.
  2. Right click > Create > Material
  3. Select the shader: Stix Games / Grass or Stix Games / Grass Forward Only

You can only change the selected shader when selecting the material directly, not in the grass editor. This will likely be fixed in future versions.

Render the grass on your custom mesh or Unity terrain

  1. Select your floor object. This can be a custom mesh or a Unity terrain, the process is the same. Make sure you have selected the object with the Mesh Filter or Terrain component.
  2. Add Component: Stix Games > General > Nature Mesh Filter
  3. Add Component: Stix Games > General > Grass Renderer
  4. Select your grass material in the Grass Renderers Material Field
  5. Configure all settings to your liking

Components

Nature Mesh Filter

The Nature Mesh Filter is the bridge between the regular Mesh Filter or Unity Terrain, the Grass Renderer, and the Grass Fallback Renderer. It also supports preprocessing the mesh, so deformed meshes with irregular polygon sizes can automatically be processed, so the blades of grass appear smooth and without artifacts.

The mesh normalization should only be enabled when necessary and you should try to use as little polygons as possible, to improve performance.

The Nature Mesh Filter works with regular meshes and Unity terrain, you can treat them exactly the same, the filter will take care of the conversion.

Grass Renderer

The grass renderer takes the processed mesh from the Nature Mesh Filter and renders your grass material.

It can also be used to automatically set the floor color and texture for your material, you should be careful not to use the same material with multiple renderers in this case, or they might interfere with each other.

The grass material could also be used like a regular material, however you would have to duplicate the floor object for this, which adds structural clutter. You would also lose the ability of mesh normalization and grass fallback, so it is recommended that you always use the Nature Mesh Filter and Grass Renderer components. If your project was made with pre 2.0 versions of the shader you can still use the old workflow, however I would recommend migrating to the new system for the same reasons.

Material Settings

This section will walk though the material settings, which includes most visual and performance related options of the asset.

Shader Versions

  • Stix Games / Grass: The regular grass shader with all its features
  • Stix Games / Grass Forward Only: Like the regular grass, but deferred shading is disabled. Use this to enable all lighting features in deferred rendering. Be aware that this might cause performance loss.

Shader Variants

Shader variants make it possible to change the shader code from within the editor, which allows for very different behaviour, without having to use costly branching in the shader itself. Changing one of these settings causes the editor to recompile the shader and can increase the build time immensely.

With shader variants it is possible to have one large shader that is very customizable, without sacrificing any performance. More info about shader variant can be found in the Unity documentation.

If you are using more than one very complex shader, Unity might encounter errors because there are too many shader keywords. It can also cause extreme compile times, as Unity is trying to compile all combinations of shader variants. More about these in the Performance Optimization section.

Grass Modes

Grass Types

This setting is the most important for the visual appearence of the grass material. It can also have a high performance impact. In short: "Simple" is the cheapest and "4 Textures" is the most expensive shader version.

  • Simple Grass: In this mode the shader generates simple, textureless blades of grass. This mode is ideal for large areas with high view distance and fits perfectly into stylized games.
  • 1 - 4 textures: This mode allows you to have up to 4 different textures. You can set their density either by using absolute values, textures, or vertex colors, each channel controls one grass type.

Density Mode

The density modes can be used to add variation, so the grass is not equally distributed over your mesh, and to set areas for different grass types. You could for example have a field of wheat right next to a field of grass with occasional patches of grass using a single material.

You should never use the density modes to reduce the density of the whole material, for example having a density value of 0.5. This would cost performance, without any benefit. Instead, change the target density setting.

  • Texture density: In this mode the shader uses a grass density lookup texture. This is perfect if you want to have control over small details in the grass. This mode requires UV coordinates on your mesh. You can use the grass painter to directly change the density texture.
  • Vertex density: Use the vertex color to set grass densities. This mode is perfect for procedurally generated content, or if you don't need small details and want to save performance.
  • Value Based density: If this option is checked, you can set the grass density directly via a shader variable. Use this option if you want to have a large field with uniform densities.

Randomize grass orientation

This setting randomizes the direction each blade of grass is looking at, instead of being oriented towards the camera, like a billboard. This can be used to create a more realistic style and reduce visual problems in VR. When using deferred rendering this setting is mandatory. When using this setting, subsurface scattering can be used to improve the visual quality of your grass.

This setting is performance costly, each blade of grass has to render a front and back side, instead of only once.

Randomize orientation Randomize orientation
Orient towards camera Orient towards camera
↔

The difference is fairly subtle, however the grass oriented towards the camera fakes the lighting calculations, which is not possible in deferred rendering. Note that the randomized grass in this screenshot uses a high subsurface scattering value, so the lighting is comparable.

Grass Lighting

The grass lighting dropdown can be used to change how grass reacts to light sources and the environment. They can have performance impact. These settings are not available in deferred rendering, as all lighting will be handled by the shared deferred rendering shader.

Lighting Mode

  • Unlit: If you are going for a very stylized look, or just don’t want to waste unnecessary performance you can completely ignore the lighting and just output the unaffected color of the grass.
  • Unshaded: The grass will be colored by lights, but it will ignore the light angle, so no matter how the grass moves or how a light rotates, it will always have the same color. The grass will still be affected by shadows. The unshaded mode is ideal for art styles with clear color schemes and uniform colors, that are still affected by lights and shadows.
  • Inverted Specular PBR: When using Unity's PBR rendering the specular highlights are visible in the opposite direction of the sun. While this may be realistic and can be observed in nature, however having the specular lighting in the same direction as the sun can look beautiful and fit perfectly with certain art styles. The inverted specular option switches the direction where the specular highlights can be seen. For this, a modified version of Unity's PBR lighting is used, which could result in slightly higher performance costs.
  • Default PBR: This lighting mode uses the default Unity PBR.
  • Unlit
  • Unshaded
  • Inverted PBR
  • Default PBR

Ignore specular global illumination

Showing the reflection of the skybox or environment can make the grass appear more lifelike, but it can also cause strange looking lighting effects. Activate this setting to ignore all global specular lighting.

Lighting normal mode

This setting allows you to change the normal used for lighting calulations. You can use it to make the grass smooth into your floor object.

The normal is a very important part of lighting calculations. Basically it tells the renderer the forward direction of your mesh. When it is changed, the renderer will handle your objects as if they had a different orientation, even if the mesh itself doesn't change.

  • Regular normal: Uses the normal of the blades of grass / billboards.
  • Hybrid normal: In this mode the diffuse calculations are done with the floor normal, but the specular lighting is done with the billboard normal. This results in grass that smooths into the floor without giving up the detailed specular highlights. However, the grass doesn't perfectly fit with the floor lighting. This mode is also more performance costly than the other two modes, as two different normals have to be used for lighting.

    This mode doesn't work in deferred rendering, it will fall back to surface normal mode instead.

  • Surface normal: Uses the normal of the floor mesh. This mode perfectly matches the floor lighting, the grass should blend into the floor perfectly.

For the hybrid and surface normal mode, you should set the floor color parameter to be exactly the same as your floor material. Especially for the surface normal mode, you should probably also copy the specular color and smoothness values, to create an exact match in the lighting calculations.

  • Regular normal
  • Hybrid normal
  • Surface normal

Note that these screenshots don't have exactly the same material settings. The floor color, grass color, specular color, and smoothness values have been changed to still look good with the other settings.

Level of Detail Interpolation

With these option you can enable or disable different types of smoothing between tessellation (density) levels. They are purely visual and should only have a minor effect on performance. They can however have a significant impact on how smoothly the different levels of detail blend into each other. For a smooth result you should enable at least one of these settings.

Object / World Space Modes

These settings can be used to change how the grass interprets the mesh it is rendered on. With "Object Space Mode" you can have grass that is on a moving platform and "Follow Surface Normal" can be used to create grass around a sphere.

Other Shader Variants

These are general settings that change the visuals of the shader, like improving how the grass looks like when directly viewed from above, if you want to use the wind setting in the shader or set it manually though the density system, and most importantly if the material uses texture atlases.

Use texture atlas

When this setting is enabled, each grass type will be interpreted as texture atlas. You can set the amount of columns (width) and rows (height) individually for each grass type. The shader will randomly select one of the possible textures for each blade of grass.

This setting is probably the most powerful way of creating variation and making your material more visually appealing. You could for example create a material with 2 grass types and add various stylized blades of grass in one and different stylized flowers, or use photography-based textures to create a realistic field of grain. The amount of blades of grass per atlas is not restricted, except for the texture size limit by Unity.

You can use the texture atlas creation tool to input individual blades of grass and generate a finished texture atlas. See how to use this tool in TODO.

Shader Settings

The following settings do not cause a recompile of the shader, unlike shader variants, however they can still have an extreme performance impact, especially the settings in the Performance Settings section. Otherwise, they define the visual appearance of the material, starting with global settings, but also the settings for each individual grass type.

Performance Settings

Density Settings

The 4 density settings are the single most important settings with regards to performance and visual appearance.

  • Target Density: This setting represents the maximum density of your grass. You should use the highest value where the material still looks good, in order to improve performance.
  • Density Falloff Start: The distance after which grass density will start to decrease. Everything between the camera and this distance will have exactly the Target Density.
  • Density Falloff Scale: Scales the falloff speed linearly. A higher value causes the density to decrease more quickly.
  • Density Falloff Power: Scales the falloff speed non-linearly. A higher value increases the speed at which density increases.

The density falloff scales like this: \((s d)^p\), where \(s\) is the scale, \(d\) is the distance from the falloff start, and \(p\) is the falloff power.

Don't use Target Density like an arbitrary slider. It should represent a specific maximum density. You should use a mesh with sufficient polygon density (or use mesh normalization on the mesh filter) and select a value that represents the density you want for your scene. When you follow this rule, you will prevent artifacts, make the material more predictable, and improve your visual appearance.

  • Target Density
  • Falloff Start
  • Falloff Scale
  • Falloff Power
High Target Density High Target Density
Low Target Density Low Target Density
↔
High Falloff Start High Falloff Start
Low Falloff Start Low Falloff Start
↔
Low Falloff Scale Low Falloff Scale
High Falloff Scale High Falloff Scale
↔
Low Falloff Power Low Falloff Power
High Falloff Power High Falloff Power
↔

LOD Settings

These settings change how many polygons are used per blade of grass. This can be used to improve performance.

Fade Settings

These settings define at which distance the grass starts to fade into the ground. All blades of grass further away than Grass Fade End will not be rendered at all, which improves performance.

Visual Settings

Visual settings have minor to no performance impact. They primarily influence the appearance of your material.

Grass Floor Color

These settings can be used to blend the grass into the floor. The mesh filter can automatically set both materials, however this requires a unique material per mesh, or the different mesh filters will interfere with each other.

Wind settings

Changes the global wind. If you want to have wind areas, or dynamic wind, you should disable global wind and use the interaction system instead.

Base Textures

Textures that influence the grass material over the whole mesh, they can change the color, height, base displacement (for example for crop circles, although using the interaction system instead would be recommended), and grass density.

Grass types

These settings define the look of each grass type. Check the tooltips for more information on each setting. Most of them are either obvious, like main texture, height, and width, or are equivalent to Unity's PBR materials, like color, specular color and smoothness.

Softness

The softness setting defines how easy it is to interact with the grass type. A low softness will make the grass stiff and for example sway less in the wind.

Subsurface Scattering

Subsurface scattering is available when the setting Randomize grass orientation is used, however it is not possible when using deferred rendering. Grass that is oriented towards the camera calculates the grass normal as if it was always rotated towards the sun, this results in a beautiful stylized look, however it is not realistic and can't be used in deferred rendering, where the same normal is used for all lighting calculations. With randomized grass orientation the grass has a front and back side, which can result in a very dark appearance. In reality the grass is still lit, by light that refracts through the grass itself. The subsurface scattering setting is a very simple approximation of this, with almost no performance cost.

With Subsurface Scattering With Subsurface Scattering
No Subsurface Scattering No Subsurface Scattering
↔

The right picture has subsurface scattering of about 0.3, which is low enough so the front and back sides are still differently bright. You can use this to fit the grass perfectly to your art style.

Texture atlas settings

The texture atlas settings are only available when Use texture atlas is enabled in the Other Shader Variants setting. They tell the shader how many rows and columns are used for this texture type.


If you think something is missing from this documentation page, or would like to give us feedback, please contact us through the contact form.
Logo Test 2019
© StixGames 2015 - 2023
All rights reserved.
The entered information could not be validated.
You will receive a mail to confirm your registration.

Impressum