decrease memory usage by storing chunk colours as 8bit (at the cost of slower mesh generation)

This commit is contained in:
a dinosaur 2024-09-09 02:34:04 +10:00
parent 53e1f9cc7e
commit d4b1377238
4 changed files with 6 additions and 6 deletions

View File

@ -123,7 +123,7 @@ public struct Chunk: Hashable {
public enum BlockType: Hashable {
case air
case solid(_ color: Color<Float>)
case solid(_ color: Color<UInt8>)
}
public struct Block: Hashable {

View File

@ -13,7 +13,7 @@ struct ChunkMeshBuilder {
.init(
position: SIMD3(position) + $0.position,
normal: $0.normal,
color: SIMD4(color),
color: SIMD4(Color<Float>(color).linear),
texCoord: $0.texCoord)
})
indices.append(contentsOf: sideIndices.map { orig + $0 })

View File

@ -32,9 +32,9 @@ struct StandardWorldGenerator: WorldGenerator {
if self.ravineMask.get(position * SIMD3(1, 0.441, 1)) >= 0.8 &&
abs(self.ravineNoise.get(position * SIMD3(1, 0.6, 1))) <= 0.1 { return .air }
#endif
return .solid(.init(
return .solid(Color<UInt8>(.init(
hue: Float(180 + self.colorNoise.get(position) * 180),
saturation: 0.47, value: 0.9).linear)
saturation: 0.47, value: 0.9)))
}
let chunkOrigin = chunkID.getPosition()

View File

@ -19,11 +19,11 @@ struct TerrorTowerGenerator: WorldGenerator {
let gradient = simd_length(fpos.xz) / 14.0
let value = self.noise1.get(fpos) - 0.25
return if gradient + value < threshold {
.solid(.init(
.solid(Color<UInt8>(.init(
hue: ((fpos.x * 0.5 + fpos.y) / 30.0) * 360.0,
saturation: 0.2 + noise2.get(fpos) * 0.2,
value: 0.75 + noise2.get(SIMD4(fpos, 1) * 0.25)
).linear)
)))
} else {
.air
}