formatting changes in voxel generation shader

This commit is contained in:
Harrison Corlett 2026-09-18 08:55:43 +01:00
parent 0074bf1d1f
commit 95a27cfd50
2 changed files with 40 additions and 26 deletions

View file

@ -101,22 +101,24 @@ bool isCave(vec3 worldPos) {
void main() {
ivec3 localPos = ivec3(gl_GlobalInvocationID.xyz);
ivec3 worldPos = chunkPos * CHUNK_SIZE + localPos;
float YZone = floor(worldPos.y/150.0)*150.0;
float islandheight = valueNoise(vec2(worldPos.x + YZone * 2, worldPos.z + YZone * 2) * 0.005) * 100 + valueNoise(vec2(worldPos.x + YZone * 2, worldPos.z + YZone * 2) * 0.1) * 20 + valueNoise(vec2(worldPos.x + YZone * 2, worldPos.z + YZone * 2) * 0.1) * 5+ valueNoise(vec2(worldPos.x + YZone * 2, worldPos.z + YZone * 2)) * 0.5 - 15 + YZone;
float height = valueNoise(vec2(worldPos.x + YZone * 2, worldPos.z + YZone * 2) * 0.005) * 100 + valueNoise(vec2(worldPos.x + YZone * 2, worldPos.z + YZone * 2) * 0.01) * 10 + valueNoise(vec2(worldPos.x + YZone * 2, worldPos.z + YZone * 2) * 0.1) * 5+ valueNoise(vec2(worldPos.x + YZone * 2, worldPos.z + YZone * 2)) * 0.5 + YZone;
float SurfaceHeight = valueNoise(vec2(worldPos.x + YZone * 2, worldPos.z + YZone * 2) * 0.005) * 100 +
valueNoise(vec2(worldPos.x + YZone * 2, worldPos.z + YZone * 2) * 0.01) * 10 +
valueNoise(vec2(worldPos.x + YZone * 2, worldPos.z + YZone * 2) * 0.1) * 5 +
valueNoise(vec2(worldPos.x + YZone * 2, worldPos.z + YZone * 2)) * 0.5 + YZone;
float IslandUnderneathHeight = valueNoise(vec2(worldPos.x + YZone * 2, worldPos.z + YZone * 2) * 0.005) * 100 +
valueNoise(vec2(worldPos.x + YZone * 2, worldPos.z + YZone * 2) * 0.1) * 20 +
valueNoise(vec2(worldPos.x + YZone * 2, worldPos.z + YZone * 2) * 0.1) * 5 +
valueNoise(vec2(worldPos.x + YZone * 2, worldPos.z + YZone * 2)) * 0.5 - 15 + YZone;
float YZone2 = floor(worldPos.y/75.0)*75.0;
float islandheight2 = valueNoise(vec2(worldPos.x - YZone2 * 2, worldPos.z -YZone2 * 2) * 0.005) * 60 + valueNoise(vec2(worldPos.x + YZone2 * 2, worldPos.z + YZone2 * 2) * 0.1) * 20 + valueNoise(vec2(worldPos.x + YZone2 * 2, worldPos.z + YZone2 * 2) * 0.1) * 10+ valueNoise(vec2(worldPos.x + YZone2 * 2, worldPos.z + YZone2 * 2)) * 0.5 - 5 + YZone2;
float height2 = valueNoise(vec2(worldPos.x + YZone2 * 2, worldPos.z + YZone2 * 2) * 0.005) * 50 + valueNoise(vec2(worldPos.x + YZone2 * 2, worldPos.z + YZone2 * 2) * 0.01) * 10 + valueNoise(vec2(worldPos.x + YZone2 * 2, worldPos.z + YZone2 * 2) * 0.1) * 5+ valueNoise(vec2(worldPos.x + YZone2 * 2, worldPos.z + YZone2 * 2)) * 0.5 + YZone2;
float grassNoise = valueNoise(vec2(worldPos.z + YZone * 2, worldPos.x + YZone * 2));
//float height2 = valueNoise(vec2(-worldPos.x, -worldPos.z) * 0.005) * 100 + valueNoise(vec2(-worldPos.x, -worldPos.z) * 0.01) * 10 + valueNoise(vec2(-worldPos.x, -worldPos.z) * 0.1) * 5+ valueNoise(vec2(-worldPos.x, -worldPos.z)) * 0.5 + 100;
//float islandheight2 = 100 + valueNoise(vec2(-worldPos.z, -worldPos.x) * 0.005) * 100 + valueNoise(vec2(-worldPos.x, -worldPos.z) * 0.1) * 20 + valueNoise(vec2(worldPos.x, worldPos.z) * 0.1) * 5+ valueNoise(vec2(worldPos.x, worldPos.z)) * 0.5 - 5;
//height = clamp(height, 4.0, 28.0);
uint voxelType = 0u;
if (float(worldPos.y) <= height && float(worldPos.y) >= islandheight) {
float depthBelowSurface = height - float(worldPos.y);
if (float(worldPos.y) <= SurfaceHeight && float(worldPos.y) >= IslandUnderneathHeight) {
float depthBelowSurface = SurfaceHeight - float(worldPos.y);
if (depthBelowSurface < 0.5) {
if(grassNoise < 0.65) voxelType = 4u; // Grass foliage
else voxelType = 0u;
@ -128,22 +130,34 @@ void main() {
voxelType = 3u; // Stone
}
}
else if (float(worldPos.y) <= height2 && float(worldPos.y) >= islandheight2) {
float depthBelowSurface = height2 - float(worldPos.y);
else{
float YZone2 = floor(worldPos.y/75.0)*75.0;
float IslandUnderneathHeight2 = valueNoise(vec2(worldPos.x - YZone2 * 2, worldPos.z -YZone2 * 2) * 0.005) * 60 +
valueNoise(vec2(worldPos.x + YZone2 * 2, worldPos.z + YZone2 * 2) * 0.1) * 20 +
valueNoise(vec2(worldPos.x + YZone2 * 2, worldPos.z + YZone2 * 2) * 0.1) * 10+
valueNoise(vec2(worldPos.x + YZone2 * 2, worldPos.z + YZone2 * 2)) * 0.5 - 5 + YZone2;
float height2 = valueNoise(vec2(worldPos.x + YZone2 * 2, worldPos.z + YZone2 * 2) * 0.005) * 50 +
valueNoise(vec2(worldPos.x + YZone2 * 2, worldPos.z + YZone2 * 2) * 0.01) * 10 +
valueNoise(vec2(worldPos.x + YZone2 * 2, worldPos.z + YZone2 * 2) * 0.1) * 5+
valueNoise(vec2(worldPos.x + YZone2 * 2, worldPos.z + YZone2 * 2)) * 0.5 + YZone2;
if (depthBelowSurface < 0.5) {
if(grassNoise < 0.65) voxelType = 4u; // Grass foliage
else voxelType = 0u;
}else if (depthBelowSurface < 1.5) {
voxelType = 1u; // Grass
} else if (depthBelowSurface < 6.0) {
voxelType = 2u; // Dirt(also stone rn)
} else {
voxelType = 3u; // Stone
if (float(worldPos.y) <= height2 && float(worldPos.y) >= IslandUnderneathHeight2) {
float depthBelowSurface = height2 - float(worldPos.y);
if (depthBelowSurface < 0.5) {
if (grassNoise < 0.65) voxelType = 4u; // Grass foliage
else voxelType = 0u;
} else if (depthBelowSurface < 1.5) {
voxelType = 1u; // Grass
} else if (depthBelowSurface < 6.0) {
voxelType = 2u; // Dirt(also stone rn)
} else {
voxelType = 3u; // Stone
}
}
}
if (voxelType != 0u) {
if (voxelType != 0u) {
if (isCave(vec3(worldPos*0.05))) {
voxelType = 0u;
}

View file

@ -681,11 +681,11 @@ public class GameCore implements GameLogic {
Vector3f CamRot = cam.GetRotation();
Vector3i ChunkPos = new Vector3i((int)Math.floor(CamPos.x/ (float) VoxelChunkGenerator.CHUNK_SIZE),(int)Math.floor(CamPos.y/ (float)VoxelChunkGenerator.CHUNK_SIZE),(int)Math.floor(CamPos.z/ (float)VoxelChunkGenerator.CHUNK_SIZE));
if(ChunkPos.x != VoxelWorldManager.LastPosition.x || ChunkPos.y != VoxelWorldManager.LastPosition.y || ChunkPos.z != VoxelWorldManager.LastPosition.z || CamRot.x != LastCamRotation.x || CamRot.y != LastCamRotation.y || CamRot.z != LastCamRotation.z) {
VoxelWorldManager.UnloadFarChunks(ChunkPos, 20,cam.GetViewMatrix(),projection.GetProjectionMatrix());
VoxelWorldManager.GenerateChunks(ChunkPos, new Vector3i(20,8,20),cam.GetViewMatrix(),projection.GetProjectionMatrix());
VoxelWorldManager.UnloadFarChunks(ChunkPos, 12,cam.GetViewMatrix(),projection.GetProjectionMatrix());
VoxelWorldManager.GenerateChunks(ChunkPos, new Vector3i(12,8,12),cam.GetViewMatrix(),projection.GetProjectionMatrix());
} else {
VoxelWorldManager.UnloadFarChunks(ChunkPos, 64,cam.GetViewMatrix(),projection.GetProjectionMatrix());
VoxelWorldManager.GenerateChunks(ChunkPos, new Vector3i(32,12,32),cam.GetViewMatrix(),projection.GetProjectionMatrix());
VoxelWorldManager.UnloadFarChunks(ChunkPos, 24,cam.GetViewMatrix(),projection.GetProjectionMatrix());
VoxelWorldManager.GenerateChunks(ChunkPos, new Vector3i(24,12,24),cam.GetViewMatrix(),projection.GetProjectionMatrix());
}
LastCamRotation.set(CamRot);
if(PrimaryRuntime.IsServer){