Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MMWare · Apr 16 at 07:46 PM · procedural meshcompute shadereditor scripting

Is it possible to render geometry in a ComputeBuffer outside play mode?

Hi guys, I've been playing around with procedurally generated terrain recently and have now decided that I can't be bothered to press play every time I want to see my mesh, so I made some basic editor GUI-elements to allow for more convenient mesh generation. On the CPU, that worked quite well, but of course having to wait a minute for the base mesh to be calculated is not exactly streamlining the whole process. So I moved to ComputeShaders for mesh creation, following a tutorial I found online. By following it, I have succeeded in getting a button to fill a ComputeBuffer with verteces consisting each of a position and a uv-coordinate.

Now there are a few problems: The tutorial uses a call to Graphics.DrawProceduralIndirect from Update, which I have gotten to work in the past, but now I would like to continually draw the geometry without the game playing - is that possible? Calling DrawProceduralIndirect once did nothing, as far as I could tell. Furthermore, my console is flooded with warnings telling me that I need to release my ComputeBuffers, because if I don't, the garbage collector will. This is an issue, because I do not want to release these buffers - I want to continuously render their contents, after all.

One possible solution I can think of is sending all triangles to the CPU, throwing them into a mesh and finally using a built-in mesh renderer to display them. I would prefer not to have to resort to this approach, however, since 1) I'm not sure that would be a staggering increase in performance and 2) I would like to write custom shaders for displacement and the like later on, so it would be much more intuitive to leave the geometry on the GPU.

Here are the exerpts of my code I think relevant:

 public class TerrainRenderer : MonoBehaviour
 {
     [SerializeField] private Material terrainMat;
     private ComputeBuffer meshBuffer;
     private ComputeBuffer indirectDrawArgs;
     private bool buffersInitialized;
 
     private void DrawTerrain()
     {
         Bounds bounds = new Bounds(transform.position, transform.lossyScale);
         Graphics.DrawProceduralIndirect(terrainMat, bounds, MeshTopology.Triangles, indirectDrawArgs);
     }
 
     public void ReleaseBuffers()
     {
         meshBuffer.Release();
         indirectDrawArgs.Release();
         buffersInitialized = false;
     }
 
     public void UpdateBuffers(ComputeBuffer mesh, ComputeBuffer drawArgs)
     {
         if (buffersInitialized) ReleaseBuffers();
         meshBuffer = mesh;
         indirectDrawArgs = drawArgs;
         buffersInitialized = true;
         DrawTerrain();
     }
 }
 
 // From class TerrainGenerator
 public void GenerateMeshOnGPU()
     {
         // This method fills both the meshBuffer and the drawArgs buffer appropriately. 
         GetComponent<MeshGenerator>().CreateMeshOnGPU(subdivisions, scale, out ComputeBuffer meshBuffer, out ComputeBuffer drawArgs);
         targetRenderer.UpdateBuffers(meshBuffer, drawArgs); // targetRenderer is a reference to an instance of TerrainRenderer
     }

My question, then, is this: Is what I have described even possible? If so, could you point me to a resource on this topic? Thanks in advance!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

142 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make grass on a mesh on a m1 mac? 0 Answers

Sharing Compute Buffers between multiple Compute Shader instances 0 Answers

Custom Inspector and ExposedRefreces 1 Answer

Possible to set 'Scene Gizmo' position in custom 'Scene View Window'? 0 Answers

Can I receive values from Compute Shader? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges