- Home /
Question by
Slymatt · May 05, 2015 at 08:56 PM ·
proceduralprocedural meshvoxelminecraftprocedural-generation
Creating caves in voxel procedural mesh
Hello, im struggling to implement caves in to my voxel procedural mesh generation. here is the generation code:
public static byte GetTheoreticalByte(Vector3 pos, Vector3 offset0, Vector3 offset1, Vector3 offset2)
{
float clusterValue = CalculateNoiseValue(pos, offset2, 0.02f);
int biomeIndex = Mathf.FloorToInt(clusterValue * World.currentWorld.biomes.Length);
Biome biome = World.currentWorld.biomes[biomeIndex];
float heightBase = biome.minHeight;
float maxHeight = biome.maxHeight;
float heightSwing = maxHeight - heightBase;
float blobValue = CalculateNoiseValue(pos, offset1, 0.05f);
float mountainValue = CalculateNoiseValue(pos, offset0, 0.009f);
mountainValue += biome.mountainPowerBonus;
if (mountainValue < 0) mountainValue = 0;
mountainValue = Mathf.Pow(mountainValue, biome.mountainPower);
byte brick = biome.GetBrick(Mathf.FloorToInt(pos.y), mountainValue, blobValue);
mountainValue *= heightSwing;
mountainValue += heightBase;
mountainValue += (blobValue * 10) - 5f;
if (mountainValue >= pos.y)
return brick;
return 0;
}
public static float CalculateNoiseValue(Vector3 pos, Vector3 offset, float scale)
{
float noiseX = Mathf.Abs((pos.x + offset.x) * scale);
float noiseY = Mathf.Abs((pos.y + offset.y) * scale);
float noiseZ = Mathf.Abs((pos.z + offset.z) * scale);
return Mathf.Max(0, Noise.Generate(noiseX, noiseY, noiseZ));
}
this is just the snippets from the noise creation which is where i think i need to add it but i cant get my head around how to decide if there should or shouldnt be a block here
Comment