百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
U

Unity-Grass-Instancer

> DevOps
开源

Unity 多种方法用于 GPU 实例化草地 (+ 隐藏/裁剪法线)

333 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

Unity 多种方法用于 GPU 实例化草地 (+ 隐藏/裁剪法线)

Unity Grass Instancer

Contains C# scripts and shaders for GPU instanced grass (or any other mesh)

Made with Unity 2020.3.4f1 and HDRP 10.4.0

Also tested with Unity 2022.3.40f1 and URP 14.0.11 | Unity 6 and URP 17.0.3

Video showcase: https://www.youtube.com/watch?v=4A0QP5x0MOE

Project contains 6 approaches

(Performance increases every step)

  • (old) Plain instanced rendering using DrawMeshInstanced and DrawMeshInstancedIndirect without any optimizations (click here to read more)
  • Frustum culled approach (click here to read more)
  • Frustum culled approach with chunking (click here to read more)
  • Occlusion culled approach with frustum culling and chunking (click here to read more)
  • High performance approach that extends all others (click here to read more)
  • Infinite grass rendering (click here to read more)

Requirements

  • Any render pipeline (only URP and simple HDRP shader provided)
  • A terrain
  • SRP Batcher needs to be disabled
  • Enable GPU instancing on the material

Setup

  • Drag the 3D Model + the scripts of any approach into your project
  • Adjust the 3D model scale factor in the import settings to 100
  • Create a new material and assign the shader
  • Attach the script to an empty game object
    • enable draw gizmos
    • position it at the center of your terrain
    • configure the range so it fits your terrain size

Important settings

Note: some settings don't apply to all approaches.

  • Instances - The amount of grass blades that can be instanced. Works best with powers of 2
  • True instance count - Will be set by the script. Contains the true count of instances since some can be skipped. For example if the terrain is to steep.
  • Visible instance count - Will be set by the script. Contains the amount of instances currently visible and thus being rendered.
  • Scale min and scale max - Used to create a random size for each grass blade
  • Ground layer - The layer of your terrain.
  • Chunk size - The size in meters of a chunk. Works best with powers of 2.
  • Threads chunk render - The amount of thread groups set in the compute shader. Has to match this setting. This also works best with powers of 2.
  • Depth bias - value that will be subtracted from the sampled depth texture. Used to fine tune the culling of occluded chunks.

FAQ

Why can't I see any instances?

This can have numerous reasons.

First be sure to check the requirements and setup sections. Make sure the mesh is scaled correctly.

Adjust the scale factor in the import settings to your needs or use 100 if you are using the provided 3D model.

Your mesh could also be not placed or rotated correctly:

  • rotation adjustments
  • position adjustments

Why are all instances invisible or black?

This may happend, because you're placing the objects with the material by hand. This does not work because the shader needs and instance ID which is only provided by calling DrawMeshInstanced and DrawMeshinstancedIndirect for rendering. Also the _trsBuffer which contains all the data for the instances is only initialized at start and it's needed for rendering.

Another reason could be that the shader is not compatible with your render pipeline. I currently only provide a shader for URP and a shadergraph for HDRP. The HDRP shadergraph only works with Unity 2021.2 or higher since the instance ID node does not exist in earlier versions.

If you have more issues, please open an issue here on Github.

What's next/TODOs

  • New shader for HDRP
  • New shader for default render pipeline
  • Improve the readme files

Resources

  • I got started with this project by this great video about GPU instancing: https://www.youtube.com/watch?v=eyaxqo9JV4w
  • I found a lot of information about grass rendering on Acerola's youtube channel: https://www.youtube.com/c/Acerola_t
    • I'm also using his 3D-Models in my showcase

Glossary (terms I often use)

  • TRS: Transformation, rotation and scale matrix.
  • _trsBuffer: a compute buffer which holds all TRS matrices for the instances and can be accessed like an array inside shaders
  • _argsBuffer: buffer that holds information about what mesh and how many to render for DrawMeshInstancedIndirect
  • batch: a collection of transformation matrices for DrawMeshInstanced

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#frustum-cullinggpugrassinstancing

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类DevOps
定价开源

> 相关工具

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理