Init
This commit is contained in:
43
Assets/Script/Compute/Noise.compute
Normal file
43
Assets/Script/Compute/Noise.compute
Normal 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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user