I am currently trying to implement marching cubes algorhytm and something goes wrong so it proceedes only one row of desired space.enter image description here zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
c# code:
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
public class NoiseGenerator : MonoBehaviour
{
[Range(0,1)] public float ISO;
ComputeBuffer _weightsBuffer;
public ComputeShader NoiseShader;
[SerializeField] float noiseScale = 0.08f;
[SerializeField] float amplitude = 200;
[SerializeField] float frequency = 0.004f;
[SerializeField] int octaves = 6;
[SerializeField, Range(0f, 1f)] float groundPercent = 0.2f;
private void Awake() {
CreateBuffers();
}
private void OnDestroy() {
ReleaseBuffers();
}
public float[] GetNoise() {
float[] noiseValues =
new float[GridMetrics.PointsPerChunk * GridMetrics.PointsPerChunk * GridMetrics.PointsPerChunk];
NoiseShader.SetBuffer(0, "_Weights", _weightsBuffer);
//NoiseShader.SetInts("ChunkId",chunkId);
NoiseShader.SetInt("_ChunkSize", GridMetrics.PointsPerChunk);
NoiseShader.SetFloat("_NoiseScale", noiseScale);
NoiseShader.SetFloat("_Amplitude", amplitude);
NoiseShader.SetFloat("_Frequency", frequency);
NoiseShader.SetInt("_Octaves", octaves);
NoiseShader.SetFloat("_GroundPercent", groundPercent);
NoiseShader.Dispatch(
0, GridMetrics.PointsPerChunk / GridMetrics.NumThreads, GridMetrics.PointsPerChunk / GridMetrics.NumThreads, GridMetrics.PointsPerChunk / GridMetrics.NumThreads
);
_weightsBuffer.GetData(noiseValues);
return noiseValues;
}
void CreateBuffers() {
_weightsBuffer = new ComputeBuffer(
GridMetrics.PointsPerChunk * GridMetrics.PointsPerChunk * GridMetrics.PointsPerChunk, sizeof(float)
);
}
void ReleaseBuffers() {
_weightsBuffer.Release();
}
}
hlsl code(some variables are defined in the includes)
#pragma kernel GenerateNoise
#include "Includes\FastNoiseLite.compute"
#include "Includes\MetricsCompute.compute"
RWStructuredBuffer<float> _Weights;
float _NoiseScale;
float _Amplitude;
float _Frequency;
int _Octaves;
float _GroundPercent;
[numthreads(numThreads, numThreads, numThreads)]
void GenerateNoise(uint3 id : SV_DispatchThreadID)
{
int3 huh = id;
fnl_state noise = fnlCreateState();
noise.noise_type = FNL_NOISE_VALUE_CUBIC;
noise.fractal_type = FNL_FRACTAL_RIDGED;
noise.frequency = _Frequency;
noise.octaves = _Octaves;
float3 pos = id * _NoiseScale;
float ground = -pos.y + (_GroundPercent * ChunkSize);
float n = ground + fnlGetNoise3D(noise, pos.x, pos.y, pos.z) * _Amplitude;
_Weights[indexFromCoord(huh.x, huh.y, huh.z)] = 1;
}
it worked just fine and i havent changed anything but it broke