This commit is contained in:
MihailRis
2024-11-14 09:30:41 +03:00
parent f0b6521c76
commit c4170c07c5
21 changed files with 255 additions and 232 deletions
+33 -34
View File
@@ -18,18 +18,18 @@
#include <glm/ext.hpp>
std::unique_ptr<ImageData> BlocksPreview::draw(
const ContentGfxCache* cache,
Shader* shader,
Framebuffer* fbo,
Batch3D* batch,
const ContentGfxCache& cache,
Shader& shader,
const Framebuffer& fbo,
Batch3D& batch,
const Block& def,
int size
){
Window::clear();
blockid_t id = def.rt.id;
const UVRegion texfaces[6]{cache->getRegion(id, 0), cache->getRegion(id, 1),
cache->getRegion(id, 2), cache->getRegion(id, 3),
cache->getRegion(id, 4), cache->getRegion(id, 5)};
const UVRegion texfaces[6]{cache.getRegion(id, 0), cache.getRegion(id, 1),
cache.getRegion(id, 2), cache.getRegion(id, 3),
cache.getRegion(id, 4), cache.getRegion(id, 5)};
glm::vec3 offset(0.1f, 0.5f, 0.1f);
switch (def.model) {
@@ -37,10 +37,10 @@ std::unique_ptr<ImageData> BlocksPreview::draw(
// something went wrong...
break;
case BlockModel::block:
shader->uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
batch->blockCube(glm::vec3(size * 0.63f), texfaces,
glm::vec4(1.0f), !def.rt.emissive);
batch->flush();
shader.uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
batch.blockCube(glm::vec3(size * 0.63f), texfaces,
glm::vec4(1.0f), !def.rt.emissive);
batch.flush();
break;
case BlockModel::aabb:
{
@@ -49,39 +49,39 @@ std::unique_ptr<ImageData> BlocksPreview::draw(
hitbox = glm::max(hitbox, box.size());
}
offset = glm::vec3(1, 1, 0.0f);
shader->uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
shader.uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
glm::vec3 scaledSize = glm::vec3(size * 0.63f);
batch->cube(
batch.cube(
-hitbox * scaledSize * 0.5f * glm::vec3(1,1,-1),
hitbox * scaledSize,
texfaces, glm::vec4(1.0f),
!def.rt.emissive
);
}
batch->flush();
batch.flush();
break;
case BlockModel::custom:{
glm::vec3 pmul = glm::vec3(size * 0.63f);
glm::vec3 hitbox = glm::vec3(1.0f);
glm::vec3 poff = glm::vec3(0.0f, 0.0f, 1.0f);
offset.y += (1.0f - hitbox).y * 0.5f;
shader->uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
const auto& model = cache->getModel(def.rt.id);
shader.uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
const auto& model = cache.getModel(def.rt.id);
for (const auto& mesh : model.meshes) {
for (const auto& vertex : mesh.vertices) {
float d = glm::dot(glm::normalize(vertex.normal), glm::vec3(0.2, 0.8, 0.4));
d = 0.8f + d * 0.2f;
batch->vertex((vertex.coord - poff)*pmul, vertex.uv, glm::vec4(d, d, d, 1.0f));
batch.vertex((vertex.coord - poff)*pmul, vertex.uv, glm::vec4(d, d, d, 1.0f));
}
batch->flush();
batch.flush();
}
break;
}
case BlockModel::xsprite: {
shader->uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
shader.uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
glm::vec3 right = glm::normalize(glm::vec3(1.f, 0.f, -1.f));
batch->sprite(
batch.sprite(
right*float(size)*0.43f+glm::vec3(0, size*0.4f, 0),
glm::vec3(0.f, 1.f, 0.f),
right,
@@ -89,24 +89,23 @@ std::unique_ptr<ImageData> BlocksPreview::draw(
texfaces[0],
glm::vec4(1.0f)
);
batch->flush();
batch.flush();
break;
}
}
return fbo->getTexture()->readData();
return fbo.getTexture()->readData();
}
std::unique_ptr<Atlas> BlocksPreview::build(
const ContentGfxCache* cache,
Assets* assets,
const Content* content
const ContentGfxCache& cache,
const Assets& assets,
const ContentIndices& indices
) {
auto indices = content->getIndices();
size_t count = indices->blocks.count();
size_t count = indices.blocks.count();
size_t iconSize = ITEM_ICON_SIZE;
auto shader = assets->get<Shader>("ui3d");
auto atlas = assets->get<Atlas>("blocks");
auto& shader = assets.require<Shader>("ui3d");
const auto& atlas = assets.require<Atlas>("blocks");
Viewport viewport(iconSize, iconSize);
DrawContext pctx(nullptr, viewport, nullptr);
@@ -118,8 +117,8 @@ std::unique_ptr<Atlas> BlocksPreview::build(
Batch3D batch(1024);
batch.begin();
shader->use();
shader->uniformMatrix("u_projview",
shader.use();
shader.uniformMatrix("u_projview",
glm::ortho(0.0f, float(iconSize), 0.0f, float(iconSize),
-100.0f, 100.0f) *
glm::lookAt(glm::vec3(0.57735f),
@@ -132,9 +131,9 @@ std::unique_ptr<Atlas> BlocksPreview::build(
fbo.bind();
for (size_t i = 0; i < count; i++) {
auto& def = indices->blocks.require(i);
atlas->getTexture()->bind();
builder.add(def.name, draw(cache, shader, &fbo, &batch, def, iconSize));
auto& def = indices.blocks.require(i);
atlas.getTexture()->bind();
builder.add(def.name, draw(cache, shader, fbo, batch, def, iconSize));
}
fbo.unbind();
+8 -8
View File
@@ -11,23 +11,23 @@ class Atlas;
class Framebuffer;
class Batch3D;
class Block;
class Content;
class ContentIndices;
class Shader;
class ContentGfxCache;
class BlocksPreview {
static std::unique_ptr<ImageData> draw(
const ContentGfxCache* cache,
Shader* shader,
Framebuffer* framebuffer,
Batch3D* batch,
const ContentGfxCache& cache,
Shader& shader,
const Framebuffer& framebuffer,
Batch3D& batch,
const Block& block,
int size
);
public:
static std::unique_ptr<Atlas> build(
const ContentGfxCache* cache,
Assets* assets,
const Content* content
const ContentGfxCache& cache,
const Assets& assets,
const ContentIndices& indices
);
};
+13 -13
View File
@@ -17,9 +17,9 @@ const glm::vec3 BlocksRenderer::SUN_VECTOR (0.411934f, 0.863868f, -0.279161f);
BlocksRenderer::BlocksRenderer(
size_t capacity,
const Content* content,
const ContentGfxCache* cache,
const EngineSettings* settings
const Content& content,
const ContentGfxCache& cache,
const EngineSettings& settings
) : content(content),
vertexBuffer(std::make_unique<float[]>(capacity * VERTEX_SIZE)),
indexBuffer(std::make_unique<int[]>(capacity)),
@@ -34,7 +34,7 @@ BlocksRenderer::BlocksRenderer(
CHUNK_W + voxelBufferPadding*2,
CHUNK_H,
CHUNK_D + voxelBufferPadding*2);
blockDefsCache = content->getIndices()->blocks.getDefs();
blockDefsCache = content.getIndices()->blocks.getDefs();
}
BlocksRenderer::~BlocksRenderer() {
@@ -286,7 +286,7 @@ void BlocksRenderer::blockCustomModel(
Z = orient.axisZ;
}
const auto& model = cache->getModel(block->rt.id);
const auto& model = cache.getModel(block->rt.id);
for (const auto& mesh : model.meshes) {
if (vertexOffset + BlocksRenderer::VERTEX_SIZE * mesh.vertices.size() > capacity) {
overflow = true;
@@ -448,7 +448,7 @@ void BlocksRenderer::render(const voxel* voxels) {
}
beginEnds[def.drawGroup][1] = i;
}
for (const auto drawGroup : *content->drawGroups) {
for (const auto drawGroup : *content.drawGroups) {
int begin = beginEnds[drawGroup][0];
if (begin == 0) {
continue;
@@ -463,12 +463,12 @@ void BlocksRenderer::render(const voxel* voxels) {
continue;
}
const UVRegion texfaces[6] {
cache->getRegion(id, 0),
cache->getRegion(id, 1),
cache->getRegion(id, 2),
cache->getRegion(id, 3),
cache->getRegion(id, 4),
cache->getRegion(id, 5)
cache.getRegion(id, 0),
cache.getRegion(id, 1),
cache.getRegion(id, 2),
cache.getRegion(id, 3),
cache.getRegion(id, 4),
cache.getRegion(id, 5)
};
int x = i % CHUNK_W;
int y = i / (CHUNK_D * CHUNK_W);
@@ -508,7 +508,7 @@ void BlocksRenderer::build(const Chunk* chunk, const Chunks* chunks) {
voxelsBuffer->setPosition(
chunk->x * CHUNK_W - voxelBufferPadding, 0,
chunk->z * CHUNK_D - voxelBufferPadding);
chunks->getVoxels(voxelsBuffer.get(), settings->graphics.backlight.get());
chunks->getVoxels(voxelsBuffer.get(), settings.graphics.backlight.get());
overflow = false;
vertexOffset = 0;
indexOffset = indexSize = 0;
+9 -4
View File
@@ -27,7 +27,7 @@ struct UVRegion;
class BlocksRenderer {
static const glm::vec3 SUN_VECTOR;
static const uint VERTEX_SIZE;
const Content* const content;
const Content& content;
std::unique_ptr<float[]> vertexBuffer;
std::unique_ptr<int[]> indexBuffer;
size_t vertexOffset;
@@ -40,8 +40,8 @@ class BlocksRenderer {
std::unique_ptr<VoxelsVolume> voxelsBuffer;
const Block* const* blockDefsCache;
const ContentGfxCache* const cache;
const EngineSettings* settings;
const ContentGfxCache& cache;
const EngineSettings& settings;
util::PseudoRandom randomizer;
@@ -137,7 +137,12 @@ class BlocksRenderer {
glm::vec4 pickSoftLight(float x, float y, float z, const glm::ivec3& right, const glm::ivec3& up) const;
void render(const voxel* voxels);
public:
BlocksRenderer(size_t capacity, const Content* content, const ContentGfxCache* cache, const EngineSettings* settings);
BlocksRenderer(
size_t capacity,
const Content& content,
const ContentGfxCache& cache,
const EngineSettings& settings
);
virtual ~BlocksRenderer();
void build(const Chunk* chunk, const Chunks* chunks);
+20 -20
View File
@@ -23,20 +23,20 @@ static debug::Logger logger("chunks-render");
size_t ChunksRenderer::visibleChunks = 0;
class RendererWorker : public util::Worker<std::shared_ptr<Chunk>, RendererResult> {
Level* level;
const Level& level;
BlocksRenderer renderer;
public:
RendererWorker(
Level* level,
const ContentGfxCache* cache,
const EngineSettings* settings
const Level& level,
const ContentGfxCache& cache,
const EngineSettings& settings
) : level(level),
renderer(settings->graphics.chunkMaxVertices.get(),
level->content, cache, settings)
renderer(settings.graphics.chunkMaxVertices.get(),
*level.content, cache, settings)
{}
RendererResult operator()(const std::shared_ptr<Chunk>& chunk) override {
renderer.build(chunk.get(), level->chunks.get());
renderer.build(chunk.get(), level.chunks.get());
if (renderer.isCancelled()) {
return RendererResult {
glm::ivec2(chunk->x, chunk->z), true, MeshData()};
@@ -48,29 +48,29 @@ public:
};
ChunksRenderer::ChunksRenderer(
Level* level,
const Level* level,
const Assets& assets,
const Frustum& frustum,
const ContentGfxCache* cache,
const EngineSettings* settings
) : level(level),
const ContentGfxCache& cache,
const EngineSettings& settings
) : level(*level),
assets(assets),
frustum(frustum),
settings(settings),
threadPool(
"chunks-render-pool",
[=](){return std::make_shared<RendererWorker>(level, cache, settings);},
[=](RendererResult& result){
[&](){return std::make_shared<RendererWorker>(*level, cache, settings);},
[&](RendererResult& result){
if (!result.cancelled) {
meshes[result.key] = std::make_shared<Mesh>(result.meshData);
}
inwork.erase(result.key);
}, settings->graphics.chunkMaxRenderers.get())
}, settings.graphics.chunkMaxRenderers.get())
{
threadPool.setStopOnFail(false);
renderer = std::make_unique<BlocksRenderer>(
settings->graphics.chunkMaxVertices.get(),
level->content, cache, settings
settings.graphics.chunkMaxVertices.get(),
*level->content, cache, settings
);
logger.info() << "created " << threadPool.getWorkersCount() << " workers";
}
@@ -81,7 +81,7 @@ ChunksRenderer::~ChunksRenderer() {
std::shared_ptr<Mesh> ChunksRenderer::render(const std::shared_ptr<Chunk>& chunk, bool important) {
chunk->flags.modified = false;
if (important) {
auto mesh = renderer->render(chunk.get(), level->chunks.get());
auto mesh = renderer->render(chunk.get(), level.chunks.get());
meshes[glm::ivec2(chunk->x, chunk->z)] = mesh;
return mesh;
}
@@ -125,7 +125,7 @@ void ChunksRenderer::update() {
bool ChunksRenderer::drawChunk(
size_t index, const Camera& camera, Shader& shader, bool culling
) {
auto chunk = level->chunks->getChunks()[index];
auto chunk = level.chunks->getChunks()[index];
if (chunk == nullptr || !chunk->flags.lighted) {
return false;
}
@@ -161,7 +161,7 @@ bool ChunksRenderer::drawChunk(
void ChunksRenderer::drawChunks(
const Camera& camera, Shader& shader
) {
const auto& chunks = *level->chunks;
const auto& chunks = *level.chunks;
const auto& atlas = assets.require<Atlas>("blocks");
atlas.getTexture()->bind();
@@ -188,7 +188,7 @@ void ChunksRenderer::drawChunks(
}
util::insertion_sort(indices.begin(), indices.end());
bool culling = settings->graphics.frustumCulling.get();
bool culling = settings.graphics.frustumCulling.get();
visibleChunks = 0;
//if (GLEW_ARB_multi_draw_indirect && false) {
+6 -6
View File
@@ -39,15 +39,15 @@ struct RendererResult {
};
class ChunksRenderer {
Level* level;
const Level& level;
const Assets& assets;
const Frustum& frustum;
const EngineSettings* settings;
const EngineSettings& settings;
std::unique_ptr<BlocksRenderer> renderer;
std::unordered_map<glm::ivec2, std::shared_ptr<Mesh>> meshes;
std::unordered_map<glm::ivec2, bool> inwork;
std::vector<ChunksSortEntry> indices;
util::ThreadPool<std::shared_ptr<Chunk>, RendererResult> threadPool;
bool drawChunk(
@@ -55,11 +55,11 @@ class ChunksRenderer {
);
public:
ChunksRenderer(
Level* level,
const Level* level,
const Assets& assets,
const Frustum& frustum,
const ContentGfxCache* cache,
const EngineSettings* settings
const ContentGfxCache& cache,
const EngineSettings& settings
);
virtual ~ChunksRenderer();
+23 -16
View File
@@ -15,6 +15,7 @@
#include <iostream>
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <glm/gtc/constants.hpp>
#ifndef M_PI
#define M_PI 3.141592
@@ -23,7 +24,7 @@
const int STARS_COUNT = 3000;
const int STARS_SEED = 632;
Skybox::Skybox(uint size, Shader* shader)
Skybox::Skybox(uint size, Shader& shader)
: size(size),
shader(shader),
batch3d(std::make_unique<Batch3D>(4096))
@@ -43,14 +44,14 @@ Skybox::Skybox(uint size, Shader* shader)
sprites.push_back(skysprite {
"misc/moon",
M_PI*0.5f,
glm::pi<float>()*0.5f,
4.0f,
false
});
sprites.push_back(skysprite {
"misc/sun",
M_PI*1.5f,
glm::pi<float>()*1.5f,
4.0f,
true
});
@@ -115,13 +116,13 @@ void Skybox::draw(
p_shader->uniformMatrix("u_apply", glm::mat4(1.0f));
batch3d->begin();
float angle = daytime * float(M_PI) * 2.0f;
float angle = daytime * glm::pi<float>() * 2.0f;
float opacity = glm::pow(1.0f-fog, 7.0f);
for (auto& sprite : sprites) {
batch3d->texture(assets.get<Texture>(sprite.texture));
float sangle = daytime * float(M_PI)*2.0 + sprite.phase;
float sangle = daytime * glm::pi<float>()*2.0 + sprite.phase;
float distance = sprite.distance;
glm::vec3 pos(-std::cos(sangle)*distance, std::sin(sangle)*distance, 0);
@@ -152,15 +153,15 @@ void Skybox::refresh(const DrawContext& pctx, float t, float mie, uint quality)
ready = true;
glActiveTexture(GL_TEXTURE1);
cubemap->bind();
shader->use();
t *= M_PI*2.0f;
shader.use();
t *= glm::pi<float>()*2.0f;
lightDir = glm::normalize(glm::vec3(sin(t), -cos(t), 0.0f));
shader->uniform1i("u_quality", quality);
shader->uniform1f("u_mie", mie);
shader->uniform1f("u_fog", mie - 1.0f);
shader->uniform3f("u_lightDir", lightDir);
shader->uniform1f("u_dayTime", dayTime);
shader.uniform1i("u_quality", quality);
shader.uniform1f("u_mie", mie);
shader.uniform1f("u_fog", mie - 1.0f);
shader.uniform3f("u_lightDir", lightDir);
shader.uniform1f("u_dayTime", dayTime);
if (glm::abs(mie-prevMie) + glm::abs(t-prevT) >= 0.01) {
for (uint face = 0; face < 6; face++) {
@@ -206,10 +207,16 @@ void Skybox::refreshFace(uint face, Cubemap* cubemap) {
{0.0f, 0.0f, -1.0f},
{0.0f, 0.0f, 1.0f},
};
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, cubemap->getId(), 0);
shader->uniform3f("u_xaxis", xaxs[face]);
shader->uniform3f("u_yaxis", yaxs[face]);
shader->uniform3f("u_zaxis", zaxs[face]);
glFramebufferTexture2D(
GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
GL_TEXTURE_CUBE_MAP_POSITIVE_X + face,
cubemap->getId(),
0
);
shader.uniform3f("u_xaxis", xaxs[face]);
shader.uniform3f("u_yaxis", yaxs[face]);
shader.uniform3f("u_zaxis", zaxs[face]);
mesh->draw();
}
+2 -2
View File
@@ -27,7 +27,7 @@ struct skysprite {
class Skybox {
std::unique_ptr<Framebuffer> fbo;
uint size;
Shader* shader;
Shader& shader;
bool ready = false;
FastRandom random;
glm::vec3 lightDir;
@@ -46,7 +46,7 @@ class Skybox {
);
void refreshFace(uint face, Cubemap* cubemap);
public:
Skybox(uint size, Shader* shader);
Skybox(uint size, Shader& shader);
~Skybox();
void draw(
+24 -23
View File
@@ -57,38 +57,39 @@ bool WorldRenderer::showChunkBorders = false;
bool WorldRenderer::showEntitiesDebug = false;
WorldRenderer::WorldRenderer(
Engine* engine, LevelFrontend* frontend, Player* player
Engine* engine, LevelFrontend& frontend, Player* player
)
: engine(engine),
level(frontend->getLevel()),
level(frontend.getLevel()),
player(player),
assets(*engine->getAssets()),
frustumCulling(std::make_unique<Frustum>()),
lineBatch(std::make_unique<LineBatch>()),
batch3d(std::make_unique<Batch3D>(BATCH3D_CAPACITY)),
modelBatch(std::make_unique<ModelBatch>(
MODEL_BATCH_CAPACITY, assets, *level->chunks, engine->getSettings()
MODEL_BATCH_CAPACITY, assets, *level.chunks, engine->getSettings()
)),
particles(std::make_unique<ParticlesRenderer>(
assets, *level, &engine->getSettings().graphics
)),
texts(std::make_unique<TextsRenderer>(
*batch3d, assets, *frustumCulling
assets, level, &engine->getSettings().graphics
)),
texts(std::make_unique<TextsRenderer>(*batch3d, assets, *frustumCulling)),
guides(std::make_unique<GuidesRenderer>()),
chunks(std::make_unique<ChunksRenderer>(
level, assets, *frustumCulling, frontend->getContentGfxCache(), &engine->getSettings()
))
{
&level,
assets,
*frustumCulling,
frontend.getContentGfxCache(),
engine->getSettings()
)) {
auto& settings = engine->getSettings();
level->events->listen(
level.events->listen(
EVT_CHUNK_HIDDEN,
[this](lvl_event_type, Chunk* chunk) { chunks->unload(chunk); }
);
auto assets = engine->getAssets();
skybox = std::make_unique<Skybox>(
settings.graphics.skyboxResolution.get(),
assets->get<Shader>("skybox_gen")
assets->require<Shader>("skybox_gen")
);
}
@@ -108,12 +109,12 @@ void WorldRenderer::setupWorldShader(
shader.uniform1f("u_gamma", settings.graphics.gamma.get());
shader.uniform1f("u_fogFactor", fogFactor);
shader.uniform1f("u_fogCurve", settings.graphics.fogCurve.get());
shader.uniform1f("u_dayTime", level->getWorld()->getInfo().daytime);
shader.uniform1f("u_dayTime", level.getWorld()->getInfo().daytime);
shader.uniform2f("u_lightDir", skybox->getLightDir());
shader.uniform3f("u_cameraPos", camera.position);
shader.uniform1i("u_cubemap", 1);
auto indices = level->content->getIndices();
auto indices = level.content->getIndices();
// Light emission when an emissive item is chosen
{
auto inventory = player->getInventory();
@@ -152,15 +153,15 @@ void WorldRenderer::renderLevel(
frustumCulling->update(camera.getProjView());
}
level->entities->render(
level.entities->render(
assets,
*modelBatch,
culling ? frustumCulling.get() : nullptr,
delta,
pause
);
particles->render(camera, delta * !pause);
modelBatch->render();
particles->render(camera, delta * !pause);
auto& shader = assets.require<Shader>("main");
setupWorldShader(shader, camera, settings, fogFactor);
@@ -176,7 +177,7 @@ void WorldRenderer::renderLevel(
void WorldRenderer::renderBlockSelection() {
const auto& selection = player->selection;
auto indices = level->content->getIndices();
auto indices = level.content->getIndices();
blockid_t id = selection.vox.id;
auto& block = indices->blocks.require(id);
const glm::ivec3 pos = player->selection.position;
@@ -214,7 +215,7 @@ void WorldRenderer::renderLines(
if (player->debug && showEntitiesDebug) {
auto ctx = pctx.sub(lineBatch.get());
bool culling = engine->getSettings().graphics.frustumCulling.get();
level->entities->renderDebug(
level.entities->renderDebug(
*lineBatch, culling ? frustumCulling.get() : nullptr, ctx
);
}
@@ -224,7 +225,7 @@ void WorldRenderer::renderHands(
const Camera& camera, float delta
) {
auto& entityShader = assets.require<Shader>("entity");
auto indices = level->content->getIndices();
auto indices = level.content->getIndices();
// get current chosen item
const auto& inventory = player->getInventory();
@@ -292,7 +293,7 @@ void WorldRenderer::draw(
PostProcessing* postProcessing
) {
timer += delta * !pause;
auto world = level->getWorld();
auto world = level.getWorld();
const Viewport& vp = pctx.getViewport();
camera.aspect = vp.getWidth() / static_cast<float>(vp.getHeight());
@@ -346,10 +347,10 @@ void WorldRenderer::renderBlockOverlay(const DrawContext& wctx) {
int x = std::floor(player->currentCamera->position.x);
int y = std::floor(player->currentCamera->position.y);
int z = std::floor(player->currentCamera->position.z);
auto block = level->chunks->get(x, y, z);
auto block = level.chunks->get(x, y, z);
if (block && block->id) {
const auto& def =
level->content->getIndices()->blocks.require(block->id);
level.content->getIndices()->blocks.require(block->id);
if (def.overlayTexture.empty()) {
return;
}
@@ -365,7 +366,7 @@ void WorldRenderer::renderBlockOverlay(const DrawContext& wctx) {
batch3d->begin();
shader.uniformMatrix("u_projview", glm::mat4(1.0f));
shader.uniformMatrix("u_apply", glm::mat4(1.0f));
auto light = level->chunks->getLight(x, y, z);
auto light = level.chunks->getLight(x, y, z);
float s = Lightmap::extract(light, 3) / 15.0f;
glm::vec4 tint(
glm::min(1.0f, Lightmap::extract(light, 0) / 15.0f + s),
+2 -7
View File
@@ -28,16 +28,11 @@ class PostProcessing;
class DrawContext;
class ModelBatch;
class Assets;
class Emitter;
struct EngineSettings;
namespace model {
struct Model;
}
class WorldRenderer {
Engine* engine;
Level* level;
const Level& level;
Player* player;
const Assets& assets;
std::unique_ptr<Frustum> frustumCulling;
@@ -77,7 +72,7 @@ public:
static bool showChunkBorders;
static bool showEntitiesDebug;
WorldRenderer(Engine* engine, LevelFrontend* frontend, Player* player);
WorldRenderer(Engine* engine, LevelFrontend& frontend, Player* player);
~WorldRenderer();
void draw(