This commit is contained in:
2023-03-02 12:39:08 +01:00
commit ec2fe87ec9
75 changed files with 5431 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
// Each #kernel tells which function to compile; you can have many kernels
#pragma kernel Noise
#include "Noises/SimplexNoise.compute"
RWStructuredBuffer<float4> points;
int numPointsPerAxis;
int octaves;
float frequency;
float persistence;
float amplitude;
float4 offset;
int indexFromCoord(int x, int y, int z) {
return z * numPointsPerAxis * numPointsPerAxis + y * numPointsPerAxis + x;
}
[numthreads(8,8,8)]
void Noise (int3 id : SV_DispatchThreadID)
{
if (id.x >= numPointsPerAxis || id.y >= numPointsPerAxis || id.z >= numPointsPerAxis) {
return;
}
float maxAmp = 0;
float noise = 0;
for(int i = 0; i < octaves; i++)
{
float3 new_id = (id + offset.xyz)* frequency;
noise += snoise(new_id) * amplitude;
maxAmp += amplitude;
amplitude *= persistence;
frequency *= 2;
}
noise /= maxAmp;
int index = indexFromCoord(id.x,id.y,id.z);
points[index] = float4(id, noise);
}