Jarvis, Optimise my shit

This commit is contained in:
Halbear 2026-09-25 23:37:22 +01:00
parent d1abde919d
commit 9424b29d0a
50 changed files with 1469 additions and 1232 deletions

View file

@ -2,7 +2,9 @@
layout(local_size_x = 4, local_size_y = 4, local_size_z = 4) in;
const int CHUNK_SIZE = 16;
const int CHUNK_AREA = CHUNK_SIZE * CHUNK_SIZE;
const int SCRATCH_SIZE = CHUNK_SIZE + 2;
const int SCRATCH_AREA = SCRATCH_SIZE * SCRATCH_SIZE;
const int SCRATCH_VOXEL_COUNT = SCRATCH_SIZE * SCRATCH_SIZE * SCRATCH_SIZE;
const int STRUCTURE_CELL_SIZE = 16;
const int REPLACE_AIR_ONLY = 1;
const int REPLACE_FOLIAGE = 2;
@ -14,7 +16,6 @@ layout(push_constant) uniform ChunkInfo {
int slot;
uint faceOffset;
uint voxelTypeCount;
uint indirectCommandIndex;
uint biomeCount;
uint structureCount;
uint worldSeed;
@ -453,35 +454,44 @@ StructureVoxelResult getStructureVoxelAt(ivec3 worldPos, uint biome) {
ivec3 baseCell = getStructureCell3D(worldPos, spacing);
for (int ox = -1; ox <= 1; ox++) {
for (int oz = -1; oz <= 1; oz++) {
ivec3 cell = baseCell + ivec3(ox, 0, oz);
for (int oy = -1; oy <= 1; oy++) {
for (int oz = -1; oz <= 1; oz++) {
ivec3 cell = baseCell + ivec3(ox, oy, oz);
uint seed = hash31(cell + ivec3(0, int(structureId) * 97, 0)) ^ worldSeed;
uint seed = hash31(cell + ivec3(0, int(structureId) * 97, 0)) ^ worldSeed;
if (!cellSpawnsStructure(seed, s)) {
continue;
}
if (!cellSpawnsStructure(seed, s)) {
continue;
}
ivec2 anchorXZ = getStructureAnchorXZ(cell.xz, seed, s.spawnSpacing);
ivec2 anchorXZ = getStructureAnchorXZ(cell.xz, seed, s.spawnSpacing);
int referenceY = cell.y * 75;
float anchorHeight = getSurfaceHeight(anchorXZ.x, anchorXZ.y, referenceY);
int anchorY = int(floor(anchorHeight)) + 1;
// Match getStructureBlock's uncentered footprint before sampling terrain.
ivec2 localXZ = worldPos.xz - anchorXZ;
if (localXZ.x < 0 || localXZ.x >= int(s.sizeX) ||
localXZ.y < 0 || localXZ.y >= int(s.sizeZ)) {
continue;
}
ivec3 origin = ivec3(anchorXZ.x, anchorY, anchorXZ.y);
int referenceY = cell.y * 75;
float anchorHeight = getSurfaceHeight(int(anchorXZ.x - s.sizeX/2), int(anchorXZ.y - s.sizeZ/2), referenceY);
int anchorY = int(floor(anchorHeight)) + 1;
if (!isValidStructureAnchor(origin, structureId, biome)) {
continue;
}
ivec3 origin = ivec3(anchorXZ.x, anchorY, anchorXZ.y);
ivec3 local = worldPos - origin;
if (!isValidStructureAnchor(origin, structureId, biome)) {
continue;
}
uint block = getStructureBlock(structureId, local);
ivec3 local = worldPos - origin;
if (block != 0u) {
result.block = block;
result.flags = s.flags;
return result;
uint block = getStructureBlock(structureId, local);
if (block != 0u) {
result.block = block;
result.flags = s.flags;
return result;
}
}
}
}
@ -491,10 +501,13 @@ StructureVoxelResult getStructureVoxelAt(ivec3 worldPos, uint biome) {
}
void main() {
ivec3 localPos = ivec3(gl_GlobalInvocationID.xyz);
if (any(greaterThanEqual(gl_GlobalInvocationID.xyz, uvec3(SCRATCH_SIZE)))) {
return;
}
ivec3 localPos = ivec3(gl_GlobalInvocationID.xyz) - ivec3(1);
ivec3 worldPos = chunkPos * CHUNK_SIZE + localPos;
uint biome = GetBiome(vec3(worldPos.z, worldPos.y, worldPos.x) * 0.05, biomeCount);
uint biome = GetBiome(vec3(worldPos.z, worldPos.y, worldPos.x) * 0.005, biomeCount);
Biome currentBiome = BiomeReg.biomes[biome];
float YZone = floor(worldPos.y/150.0)*150.0;
@ -577,6 +590,7 @@ void main() {
}
}
uint index = uint((localPos.x * CHUNK_AREA) + (localPos.y * CHUNK_SIZE) + localPos.z);
uint index = uint(slot * SCRATCH_VOXEL_COUNT + (localPos.x + 1) * SCRATCH_AREA +
(localPos.y + 1) * SCRATCH_SIZE + localPos.z + 1);
voxels[index] = voxelType;
}