Skip to content

Commit 7b8bd50

Browse files
committed
[Renderer] block model
1 parent 2694d77 commit 7b8bd50

4 files changed

Lines changed: 14 additions & 11 deletions

File tree

include/openminecraft/renderer/common/wrap/om_renderer_voxel.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class OMVoxelCompiler
271271
std::function<void(OMVoxel)>, std::function<void(OMVoxelComplex)>) -> void;
272272

273273
OMVoxelHandler *handler = new OMVoxelHandlerDummy();
274-
std::function<uint32_t(uint32_t)> converter;
274+
std::function<uint32_t(uint32_t, uint64_t, uint64_t, uint64_t, int, int, int)> converter;
275275

276276
private:
277277
log::OMLogger logger;
@@ -327,7 +327,7 @@ class OMVoxelManager
327327
public:
328328
OMVoxelManager(OMRenderer *renderer, OMRendererTexture *, OMRendererTexture *,
329329
std::shared_ptr<world::OMChunkManager<16>>, std::function<void()>, OMVoxelHandler *,
330-
std::function<uint32_t(uint32_t)>);
330+
std::function<uint32_t(uint32_t, uint64_t, uint64_t, uint64_t, int, int, int)>);
331331
~OMVoxelManager();
332332

333333
auto submit(OMRendererTask *, OMRendererTempTarget *) -> OMRendererTask *;
@@ -350,7 +350,7 @@ class OMVoxelManager
350350
log::OMLogger logger;
351351
OMVoxelCompiler compiler;
352352

353-
std::function<uint32_t(uint32_t)> converter;
353+
std::function<uint32_t(uint32_t, uint64_t, uint64_t, uint64_t, int, int, int)> converter;
354354
std::shared_ptr<world::OMChunkManager<16>> chunkManager;
355355
OMVoxelLayer<OMVoxel> *voxelLayer, *voxelTranslucentLayer;
356356
OMVoxelLayer<OMVoxelComplex> *voxelComplexLayer, *voxelTranslucentComplexLayer;

src/openminecraft-core/renderer/common/wrap/om_renderer_voxel_compiler.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include "openminecraft/renderer/common/wrap/om_renderer_voxel.hpp"
33
#include <array>
44
#include <cstdint>
5-
#include <iostream>
65
#include <tuple>
76

87
namespace openminecraft::renderer::common::wrap
@@ -130,9 +129,10 @@ auto OMVoxelCompiler::existSoild(const world::OMChunk<16> &chunk,
130129
{
131130
if (x < 0 || y < 0 || z < 0 || x > 15 || y > 15 || z > 15)
132131
return handler->querySoild(
133-
converter(externalAccessor(glm::ivec3(x, y, z), chunk.chunkx, chunk.chunky, chunk.chunkz)));
132+
converter(externalAccessor(glm::ivec3(x, y, z), chunk.chunkx, chunk.chunky, chunk.chunkz), chunk.chunkx,
133+
chunk.chunky, chunk.chunkz, x, y, z));
134134

135-
return handler->querySoild(converter(chunk.fetch(x, y, z)));
135+
return handler->querySoild(converter(chunk.fetch(x, y, z), chunk.chunkx, chunk.chunky, chunk.chunkz, x, y, z));
136136
}
137137

138138
auto OMVoxelCompiler::queryBlockstate(const world::OMChunk<16> &chunk,
@@ -166,7 +166,7 @@ auto OMVoxelCompiler::computeAO(const world::OMChunk<16> &chunk,
166166
glm::mix(currentAabb.offset, currentAabb.offset + currentAabb.size, glm::vec3(pos.x, pos.y, pos.z)) -
167167
(glm::vec3(dx, dy, dz) * 16.0f);
168168

169-
auto occ = handler->queryOcclusionShape(converter(tgbs));
169+
auto occ = handler->queryOcclusionShape(converter(tgbs, chunk.chunkx, chunk.chunky, chunk.chunkz, x, y, z));
170170
if (occ.contains(currentPos))
171171
{
172172
return 1;
@@ -288,7 +288,7 @@ auto OMVoxelCompiler::compile(const world::OMChunk<16> &chunk,
288288
{
289289
for (const auto &v : chunk)
290290
{
291-
auto bsid = converter(v.second);
291+
auto bsid = converter(v.second, chunk.chunkx, chunk.chunky, chunk.chunkz, v.first.x, v.first.y, v.first.z);
292292
if (handler->queryNumParts(bsid) == 0)
293293
{
294294
continue;

src/openminecraft-core/renderer/common/wrap/om_renderer_voxel_manager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ namespace openminecraft::renderer::common::wrap
2424
uint64_t cx = 0, cy = 0, cz = 0;
2525
OMVoxelManager::OMVoxelManager(OMRenderer *renderer, OMRendererTexture *tex, OMRendererTexture *texSec,
2626
std::shared_ptr<world::OMChunkManager<16>> man, std::function<void()> rec,
27-
OMVoxelHandler *handler, std::function<uint32_t(uint32_t)> converter)
27+
OMVoxelHandler *handler,
28+
std::function<uint32_t(uint32_t, uint64_t, uint64_t, uint64_t, int, int, int)> converter)
2829
: logger("OMVoxelManager", this)
2930
{
3031
this->rec = rec;

src/openminecraft/renderer/worldrenderer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ OMWorldRenderer::OMWorldRenderer(OMRenderer *renderer, std::shared_ptr<basics::O
8282
voxelManager = new wrap::OMVoxelManager(
8383
renderer, textureAtlas->texture, textureAtlas->textureSecondary, chunkManager, [&]() { record(); },
8484
this->voxelHandler,
85-
[&](uint32_t v) -> uint32_t {
85+
[&](uint32_t v, uint64_t cx, uint64_t cy, uint64_t cz, int x, int y, int z) -> uint32_t {
8686
const auto &reg = data::block::blockstateRegistry.idToRegistry[v];
87-
return blockstateResolver->fetchModel(reg.block, reg.state);
87+
uint64_t h = (cx * 16 + x) * 341873128712L + (cy * 16 + y) * 132897987541L + cz * 16 + z + 1L;
88+
h ^= h >> 16;
89+
return blockstateResolver->fetchModel(reg.block, reg.state, h);
8890
});
8991

9092
voxelManager->pipeline->bindInput(0, cameraBuffer);

0 commit comments

Comments
 (0)