The tutorial from Erik Roystan Ross is amazing at explaining exactly how to utilize the a geometry shader to generate grass on a model in his tutorial "Grass Shader". The geometry shader can use the vertex as input, so it contains the world position of said vertex, removing the need to create an offset that was needed with GPU Instancing. Geometry shaders were introduced in Direct3D 10 and OpgenGL 3.2, which is a type of shader that can generate points, lines and triangles and are generated after the vertex shader and before the vertices are processed for the fragment shader. You could add support for a height map to tell the grass Material at which height it should be offset, but this would not work when there are two platforms above each other, which both need grass rendered on them (technically it could work, though it would require quite a workaround or several GPU Instancers to make it work). In the example the grass is generated at a certain height, which is not variable. This would fix the problem of generating a great amount of grass while utilizing GPU Instancing, however this solution would not work when taking into account the height of the terrain. Using this method, Colin Leung created a great example of how to combine the Graphics.DrawMeshInstancedIndirect with a generated grass Mesh and a complicated Material to show a large field of grass (10 million instances) with great performance, even supporting bending of the grass when an object runs through the generated grass. The Shader on the Material would be used as a way to render the Mesh on the right position, by getting location data through a ComputeBuffer. One such solution was to use Unity's Graphics.DrawMeshInstanced and Graphics.DrawMeshInstancedIndirect, which renders provided Meshes with a Material that supports GPU Instancing. While researching the topic, I came across the solutions for rendering large amounts of objects without straining the CPU by off-loading most / all of the work to the GPU. There are many games that render tons of grass without the GPU breaking as much as a sweat (Genshin Impact, Breath of the Wild, etc.). A Geometry shader written for Unity's build-in Render Pipeline
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |