Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Feature Request Costume editor to write to terrain Detail Maps?, cant find a texture

Discussion in 'World Building' started by NanushTol, May 14, 2023.

  1. NanushTol

    NanushTol

    Joined:
    Jan 9, 2018
    Posts:
    121
    I'm creating a terrain graph editor to generate levels for my game, and I'm trying to efficiently access and set the detail terrain map, but it seams like there is no access to a texture like with the splat maps (alpha textures) or the height maps.
    I know of
    GetDetailLayer
    and
    SetDetailLayer
    but im looking for a sulotion similer to
    CopyActiveRenderTextureToTexture()
    or the
    DirtyHeightmapRegion()


    would really help as all of the operations in my editor are calculated on the GPU so to transfer data to the CPU and then do a for loop seams a bit in-efficient.

    Any suggetsions?

    upload_2023-5-14_22-53-13.png
     
    wyattt_ likes this.
  2. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    422
    Hi! First of all, just wanna say that graph editor is looking amazing and the output is super clean!

    But now I bring you bad news :(: there's not a texture representation for Terrain details that we manage and use for patch generation or rend. Even our Paint Details tool generates the details map on CPU.

    Given that you have details textures on GPU, you could look into AsyncGPUReadbackRequest of portions of the texture (ie sub-rects of the Terrain tile) over a couple frames. You'll want to associate them with an "edit" so you can throw out out-of-date details data when those callbacks complete. This way you mitigate time spent in a single frame for the readback though the visual feedback will be delayed a little
     
  3. NanushTol

    NanushTol

    Joined:
    Jan 9, 2018
    Posts:
    121
    Thanks for the reply, and also for the compliment :)
    There are some heavy calculations in the erosion sim that take some time anyway so there is a short wait,
    I just wanted to make sure I didn't miss anything.

    From my experimentation I figures that the value in the stored detail maps is the actual count of detail per "texel",
    so if I put for example map[x,y] = 5
    the amount of details in texel x,y will be 5,
    is that correct?

    I also thought about processing this on a compute shader so it can read the texture without passing through the CPU and at the end just spit out a compute buffer with a dataset that matches the detail map
     
  4. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    422
    I believe so. It is a value from 0 to TerrainData.maxDetailScatterPerRes

    Nice. This sounds like a decent idea
     
    NanushTol likes this.