GPU Instanced Grass in Unity
For the original post, please go to https://www.yuque.com/qwerasdwww/dfy5xd
Part 6: Use Command Buffer to change the rendering order
Right now there is some glitching when we rotate the camera fast.
It is becasue we get the depth texture and generate hi-z inside OnPostRender(), which happens when the camera finishes render the scene. We can see the mesh is drawn before the depth mipmap is drawn, so we cannnot get the Hi-Z of current frame.
With command buffer, we can adjust the rendering order.
We can get the depth texture, generate Hi-Z mipmap, then draw the grass.
We duplicate the C# script grass.cs and rename the class to be GrassWithCommandBuffer.
We declare three command buffers, and add them.
We comment out the OnPostRender() because we want to get the depth texture before the grass is drawn. We also don't need to dispatch the compute shader inside Update() since we are gonna do that together in OnPostRender( ).
No comments:
Post a Comment