• 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 /
  • Help Room /
avatar image
0
Question by ravenpilot83 · Nov 14, 2020 at 04:14 AM · perlin noisecompute shadermarching cubes

Why is my compute shader returning values I explicitly avoided?

CONTEXT: I've been working with the Marching Cubes algorithm to do some terrain generation stuff. The end goal is pretty much a clone of Worms 3D, but right now the first thing I need is some terrain to work with.

I'm fairly new to unity, but not a scrub. I've been hacking apart Sebastian Lague's Marching Cubes coding adventure to make it fit my needs (github). The main things I wanted to salvage from his code was his use of compute shaders to generate some nice noise (perlin I think?) and to perform the marching cube algorithm.

Right now, I'm stuck on the first part. I'm trying to get the points and the noise back from my compute shader. However, points I have EXPLICTLY SAID TO NOT RETURN are being returned somehow, and I'm having a bad time.

Here's the code for the compute shader as it stands right now. There's no noise code here in my noise shader because I have been debugging this for HOURS. I've got a ComputeBuffer to store points and their noise values as Vector4's/float4's. "points" is defined inside Density.compute, and it works in SL's code, so idk what's up.

 #pragma kernel Density
 #include "/Includes/Density.compute"
 #include "/Includes/Noise.compute"
 [numthreads(4, 4, 4)] 
 void Density (int3 id : SV_DispatchThreadID) {
     if (id.x >= 6|| id.y >= 6|| id.z >= 6) 
     {
         return;
     }
     int index = indexFromCoord(id.x,id.y,id.z);
     points[index] = float4(id, 0.5);
 }
 
 

Yet through extensive use of Debug.Log(), I'm finding I'm getting really weird points in the mix, like (0.0, 7.0, 23.0, -6.9).

I'm getting the points out of the compute buffer by the following code:

         Vector4[] noiseVectors = new Vector4[pointsBuffer.count];
         pointsBuffer.GetData(noiseVectors);

and then looping through the array to put it all in a dictionary for future modification. That's how I'm ultimately getting it back and getting it out of Debug.Log().

The last places I can think of problems arising are: - Are my buffers being populated by random stuff from like data already in memory? - Am I not being careful enough when pulling the data out of the ComputeBuffer? - - If so, why does it work for some points and not others? - Is my ComputeBuffer not being properly defined (code not shown, but it's near verbatim from SL's github)

I dunno folks. Any chance y'all could help me out?

also my first time posting a question. any feedback?

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

212 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 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

Surface Nets for Smooth Voxel Terrain 0 Answers

2D world generation with perlin noise is producing regular terrain 0 Answers

Does it impact the performance if I use multible Threadgroups instead of one in a Compute Shader 0 Answers

Question about procedural forest/grass generation 1 Answer

ComputeBuffer low-level access in Direct3D 11 in Unity 5.5.0B3 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges