精選文章

SmallBurger Asset Home

  SmallBurger

2025年5月12日 星期一

Integration and Application of DrawMeshInstancedIndirect

People who have experience with GPU-driven rendering should be familiar with using ComputeShader for GPU culling and then invoking DrawMeshInstancedIndirect for rendering. This entire process bypasses the CPU. Colin Leung provides an excellent example here:People who have experience with GPU-driven rendering should be familiar with using ComputeShader for GPU culling and then invoking DrawMeshInstancedIndirect for rendering. This entire process bypasses the CPU. Colin Leung provides an excellent example here:

UnityURP-MobileDrawMeshInstancedIndirectExample

In the example of InstancedIndirectGrass.shader, we found the usage of StructuredBuffer, and the relevant definition is as follows:

StructuredBuffer<float3> _AllInstancesTransformBuffer;
StructuredBuffer<uint> _VisibleInstanceOnlyTransformIDBuffer;

However, currently, the hardware of many mobile platforms does not support the use of StructuredBuffer in the Vertex Shader, especially on Mali’s GLES platform. Additionally, for some hardware that does have support, there are performance issues. We can determine hardware support through SystemInfo.maxComputeBufferInputsVertex. This is also one of the reasons why ComputeShader is less commonly used for rendering a large number of objects on mobile platforms.

Furthermore, the creation of grass transform data in the example is a significant challenge. The common practice is to use separate Instance Transform data for storage, which can lead to substantial memory issues.

The GPUPlantPainter plugin addresses this issue by utilizing a ResultTexture approach, storing the GPU culling results in a RenderTexture. Then, it references this texture in the Vertex Shader for rendering. Since accessing textures in the Vertex Shader is a fundamental capability, this significantly enhances cross-platform consistency.

Furthermore, the GPUPlantPainter plugin addresses the issue of massive memory usage by employing Template Transforms (sharing the same Transform matrix data) and a filter weight map (allowing artists to directly paint on it) for filtering. This approach significantly reduces memory usage and improves loading speed.


Additionally, the GPUPlantPainter plugin utilizes real-time projection of height maps for editing, followed by storage. This achieves the purpose of allowing grass to adhere to objects, and storing it aids in reducing the performance cost of rendering height map in real-time.



If you are interested in this plugin, you can find it here:

沒有留言:

張貼留言