Search Unity

Efficiently creating large geometry on GPU using Compute Shaders

Discussion in 'Shaders' started by maxzoech, Mar 19, 2017.

  1. maxzoech

    maxzoech

    Joined:
    Dec 23, 2013
    Posts:
    23
    Hi everyone!
    Does somebody of you has experience with creating procedural geometry on the GPU? I am trying to generate terrain and want to avoid the CPU bottleneck by generating the geometry in a compute shader. But I'm curious about this given that Geometry Shaders seem to be very slow and aren't recommended for large sets of geometry.
     
    ModLunar likes this.
  2. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    I'm not sure how long it'll be till I get to it, but I've been wondering the same thing myself for a while now and I'd love to do it sometime. If I find out, I'll definitely share with you some sample code and explain it if I can!

    I've been making a voxel terrain (but smoothed so it doesn't look like Minecraft) and I was having problems generating the whole mesh in one go on the CPU. But what I was able to do was divide the thing into many chunks, where each chunk is 1 Mesh with 1 MeshFilter and 1 MeshRenderer, so that way each chunk has a completely separate List<Vector3> for its verts, List<int> for the tris, etc., and they can each operate completely independently of one another in parallel.

    I tried multithreading the generation of 1 Mesh, and that came out disastrous haha.