Search Unity

Games GPU Computed Grass Renderer

Discussion in 'Works In Progress - Archive' started by MaxWitsch, Oct 31, 2017.

  1. MaxWitsch

    MaxWitsch

    Joined:
    Jul 6, 2015
    Posts:
    114
    Hello everyone,

    After a endless fight with unity's terrain system i decided to approach the basics of compute shading so i could build my own renderer.

    After a couple of days i have to say that im very impressed of the possibilities you can achieve with this fully GPU computed Workflows.

    I want to show you my current WIP.
    All grass billboards are computed at runtime via a compute shader.
    The compute shader fills a AppendStructuredBuffer with thousands of 4x4 matrices.
    Also the compute shader gets some height normal color and splat information which i could not bake at runtime.

    Fortunately Unity has implementet the DrawMeshInstancedIndirect Method which allows me to beam the buffer directly to the instance shader of the grasses. :)

    Compute Smiley.PNG
    This was my first try. I tried to debug the computed Buffer-data with Gizmos.
    Mask.PNG
    I tried to add a bit of noise and combine the computed data with an GPU instance Shader.
    View Distance.PNG
    After a while of experimenting i created a Cell structure to Compute them as parts and cull them.
    test.PNG test2.PNG
    A "Height" and "Normal" map of course so i don't need to stay flat. ^^
     
    one_one, Arkade, antoripa and 2 others like this.
  2. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Looks good. You can easy add the frustrum planes to the compute shader and do per item frustum culling in a compute shader pass. Will save you the extra GPU time on partial visible cells
     
  3. MaxWitsch

    MaxWitsch

    Joined:
    Jul 6, 2015
    Posts:
    114
    And now the results of one week

    hope you like it :)

    size Random.PNG coloration4.PNG Stones.jpeg Stones2.jpeg wide.jpeg
     
  4. MaxWitsch

    MaxWitsch

    Joined:
    Jul 6, 2015
    Posts:
    114
    Multi terrain support and Debug view ^^
    debugger.PNG multiterrain.PNG
     
    antoripa likes this.
  5. MaxWitsch

    MaxWitsch

    Joined:
    Jul 6, 2015
    Posts:
    114
    The Problem is that i do not update the Compute buffer every frame, but just once it is in View Distance.
    But i will test this, thanks a lot! :)
     
  6. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    You keep your buffer and just process this every time to a visible buffer that you render with drawMeshInstanced Indirect. I will send you a link to a video where I do this.
     
    Arkade and antoripa like this.
  7. MaxWitsch

    MaxWitsch

    Joined:
    Jul 6, 2015
    Posts:
    114
    Awesome!
    Maybe one Day i can help you with something ;)
     
    antoripa likes this.
  8. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Grass is looking good :)
     
  9. MaxWitsch

    MaxWitsch

    Joined:
    Jul 6, 2015
    Posts:
    114
    here is a short clip.

    sorry for the bad quality.
    Runs on a 560GTX.

    12.4 ms on CPU
    1.1 ms on GPU

    It looks like i have to improve the Memory Alloc. :(
     
    antoripa likes this.
  10. Pode

    Pode

    Joined:
    Nov 13, 2013
    Posts:
    145
    @moxi : what is the target level of your shader ? Would it run on a mobile platform (if that's the only thing displayed onscreen) ?
     
    MaxWitsch likes this.
  11. MaxWitsch

    MaxWitsch

    Joined:
    Jul 6, 2015
    Posts:
    114
    Well, i have not tested jet.
    But i'm pretty sure it does since you don't need that much bandwidth between the GPU and the CPU as with conventional techniques. As long the Device supports the Vulkan or Metal or OpenGL ES 3.1.

    But please do not get me wrong.
    Because I don't have plans to Distribute it on the store, since i don't want to compete my work with Mr. Johansen who create wonders with Vegetation Studio.
    I pretty sure VS performs way better.

    I would say: Testing Time!!!!! :D
     
    Last edited: Oct 31, 2017
  12. MaxWitsch

    MaxWitsch

    Joined:
    Jul 6, 2015
    Posts:
    114
    As you can see if i fixed the memory Problem :D
    prov.PNG prov2.PNG
     
  13. MaxWitsch

    MaxWitsch

    Joined:
    Jul 6, 2015
    Posts:
    114
    sbeauty1.PNG sbeauty2.PNG sbeauty3.PNG sbeauty4.PNG sbeauty5.PNG

    Some soothing pics at the end of the day :)
     
    MarkusGod likes this.
  14. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Shader model 5.0 since you use compute shaders.
     
    MaxWitsch likes this.
  15. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,487
    Errmmm, will we ever be able to give this a go ourselves ? :) Did you say multiterrain support, can you point this in aeras?
     
    Sparking02 likes this.