Closed eirys closed 12 months ago
CPP code
inline int32_t toChunkPos(float x, float y, float z) noexcept { // TODO: Add render distance in ubo int32_t chunk_address = (int32_t)x / CHUNK_SIZE | ((int32_t)z / CHUNK_SIZE) << 8 | ((int32_t)y / CHUNK_SIZE) << 16; x = (int32_t)x % CHUNK_SIZE; y = (int32_t)y % CHUNK_SIZE; z = (int32_t)z % CHUNK_SIZE; return static_cast<int32_t>(x) | static_cast<int32_t>(y) << 4 | static_cast<int32_t>(z) << 8 | chunk_address << 12; }
HLSL code
// Extract actual vertex position from input float4 extractPos(int input) { // Local position in chunk float3 pos = float3( input & 0xF, (input >> 4) & 0xF, (input >> 8) & 0xF); // Chunk position in world int chunk_x = (input >> 12) & 0xFF; int chunk_z = (input >> 20) & 0xFF; int chunk_y = (input >> 28) & 0xF; return float4( (chunk_x * 16) + pos.x, (chunk_y * 16) + pos.y, (chunk_z * 16) + pos.z, 1.0 ); }
fixed.
CPP code
HLSL code