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?