Giter Site home page Giter Site logo

terraingrassshader's Introduction

Real-time Terrain Grass Shader

Image

This package includes a Unity terrain shader that generates grass on different textures in Real-time. (Tested with 5.6) It was created in the course of a Bachelor's thesis at the HCI research group at the Hamburg University. References

Main Feature

Grass is generated on the GPU in real-time and distributed depending on the ID of the ground textures. Painting terrain textures immediately updates the grass for direct visual feedback. The shader utilizes the "Deferred Rendering" path support cheap lighting and shadows. It also supports up to 10 sperical colliders (e.g. for the player character to bend the grass where he walks).

IMAGE ALT TEXT

Installation

Import the .unitypackage into your project. Either open one of the two demo scenes or follow the instructions.

Instructions on how to use the terrain grass shader:

Setup:

  1. Make sure rendering path is set to Deferred and color space is linear.
  2. Create a terrain object and add at least one texture.
  3. Go the terrain settings -> Choose the "Custom" option under "Material" and add the "Grass Shader Deferred" Material in the "Custom Material" slot.

Configuration: To configure the shader, select the "Grass Shader Deferred" material found in "Terrain Shader/Shader". The four foldout menus "Options for Terrain texture #" are used to configure the grass for the first four terrain textures of the terrain object. Select the texture of the grass you want to draw. Configure the height, width and the dry/healthy colors to your content. Finally the "Enabled" checkbox activates this grass. The grass is now rendered on the terrain depending on the strength of the corresponding terrain texture.

  • Noise Texture: Specify a noise texture for varying height and color.
  • Smoothness: Increase reflectivity of the grass (0 is recommended).
  • UpDown: Move grass into the ground in the case that bottom of texture and the ground do not meet up.
  • Grass Density: Change the amount of grass rendered.
  • 3 Sprites: Enables highest LOD with 3 interlacing sprites
  • 1 Sprite: Enables lowest LOD with 1 sprite (else 2 sprites are used; better for an elevated view).
  • Enable wind: Enable waving movement of the grass.
  • Wind Direction: 0-360° denotes direction of wind movement.
  • Max Distance: Maximum drawing distance of grass.
  • LOD2 Distance: Distance where to switch to second LOD.
  • Transition Size: Size of the transition area between the LODs (larger values cost more performance but smoothen the transition).
  • Cast Shadows: Enables grass to cast shadows (Very high overhead).
  • Shadow Thickness: Makes cast shadows more distinctive. (Also use the shadow strength of the casting light!)
  • Shadow LOD Distance: Distance up to which the grass casts shadows.
  • HDR On: Enable this when using HDR.

You can add the "Terrain Shader/Shader/GrassCollider.cs" script to the player character model (or any other object) to make the grass bend in a circle around it. When the script is added to the model, "Radius" specifies the maximum radius where grass is bent. The "Material" slot of the script needs to be filled with the "Grass Shader Deferred" material.


Performance Hints: If more performance is needed you can try to do the following adjustments:

  • Reduce any LOD distances
  • Disable Shadow Casting
  • Reduce density
  • Change lowest LOD to 1 Sprite

Other:

  • The included texture is best used for rather flat terrains (or as long as the grass terrain is flat). For grass on hills a wedge \ / texture is more suitable.
  • If you blend two terrain textures the grass assigned to each texture blends depending on the strengths of each texture.

License

MIT License

Copyright (c) [2017] [Sebastian Rings]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

terraingrassshader's People

Contributors

acrosicious avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

unitycoder

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.