Merge branch 'main' into heightmaps
This commit is contained in:
commit
2ecde94be5
@ -8,6 +8,7 @@
|
|||||||
#include "window/Window.hpp"
|
#include "window/Window.hpp"
|
||||||
#include "voxels/Chunks.hpp"
|
#include "voxels/Chunks.hpp"
|
||||||
#include "lighting/Lightmap.hpp"
|
#include "lighting/Lightmap.hpp"
|
||||||
|
#include "settings.hpp"
|
||||||
|
|
||||||
#define GLM_ENABLE_EXPERIMENTAL
|
#define GLM_ENABLE_EXPERIMENTAL
|
||||||
#include <glm/ext/matrix_transform.hpp>
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
@ -49,14 +50,19 @@ static glm::mat4 extract_rotation(glm::mat4 matrix) {
|
|||||||
return glm::toMat3(rotation);
|
return glm::toMat3(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelBatch::ModelBatch(size_t capacity, Assets* assets, Chunks* chunks)
|
ModelBatch::ModelBatch(
|
||||||
|
size_t capacity,
|
||||||
|
Assets* assets,
|
||||||
|
Chunks* chunks,
|
||||||
|
const EngineSettings* settings
|
||||||
|
)
|
||||||
: buffer(std::make_unique<float[]>(capacity * VERTEX_SIZE)),
|
: buffer(std::make_unique<float[]>(capacity * VERTEX_SIZE)),
|
||||||
capacity(capacity),
|
capacity(capacity),
|
||||||
index(0),
|
index(0),
|
||||||
mesh(std::make_unique<Mesh>(buffer.get(), 0, attrs)),
|
mesh(std::make_unique<Mesh>(buffer.get(), 0, attrs)),
|
||||||
assets(assets),
|
assets(assets),
|
||||||
chunks(chunks)
|
chunks(chunks),
|
||||||
{
|
settings(settings) {
|
||||||
const ubyte pixels[] = {
|
const ubyte pixels[] = {
|
||||||
255, 255, 255, 255,
|
255, 255, 255, 255,
|
||||||
};
|
};
|
||||||
@ -68,18 +74,19 @@ ModelBatch::~ModelBatch() = default;
|
|||||||
|
|
||||||
void ModelBatch::draw(const model::Mesh& mesh, const glm::mat4& matrix,
|
void ModelBatch::draw(const model::Mesh& mesh, const glm::mat4& matrix,
|
||||||
const glm::mat3& rotation, glm::vec3 tint,
|
const glm::mat3& rotation, glm::vec3 tint,
|
||||||
const texture_names_map* varTextures) {
|
const texture_names_map* varTextures,
|
||||||
|
bool backlight) {
|
||||||
glm::vec3 gpos = matrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
glm::vec3 gpos = matrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
light_t light = chunks->getLight(
|
light_t light = chunks->getLight(
|
||||||
std::floor(gpos.x),
|
std::floor(gpos.x),
|
||||||
std::floor(std::min(CHUNK_H-1.0f, gpos.y)),
|
std::floor(std::min(CHUNK_H-1.0f, gpos.y)),
|
||||||
std::floor(gpos.z));
|
std::floor(gpos.z));
|
||||||
|
light_t minIntensity = backlight ? 1 : 0;
|
||||||
glm::vec4 lights (
|
glm::vec4 lights(
|
||||||
Lightmap::extract(light, 0) / 15.0f,
|
glm::max(Lightmap::extract(light, 0), minIntensity) / 15.0f,
|
||||||
Lightmap::extract(light, 1) / 15.0f,
|
glm::max(Lightmap::extract(light, 1), minIntensity) / 15.0f,
|
||||||
Lightmap::extract(light, 2) / 15.0f,
|
glm::max(Lightmap::extract(light, 2), minIntensity) / 15.0f,
|
||||||
Lightmap::extract(light, 3) / 15.0f
|
glm::max(Lightmap::extract(light, 3), minIntensity) / 15.0f
|
||||||
);
|
);
|
||||||
setTexture(mesh.texture, varTextures);
|
setTexture(mesh.texture, varTextures);
|
||||||
size_t vcount = mesh.vertices.size();
|
size_t vcount = mesh.vertices.size();
|
||||||
@ -115,8 +122,16 @@ void ModelBatch::render() {
|
|||||||
return a.mesh->texture < b.mesh->texture;
|
return a.mesh->texture < b.mesh->texture;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
bool backlight = settings->graphics.backlight.get();
|
||||||
for (auto& entry : entries) {
|
for (auto& entry : entries) {
|
||||||
draw(*entry.mesh, entry.matrix, entry.rotation, entry.tint, entry.varTextures);
|
draw(
|
||||||
|
*entry.mesh,
|
||||||
|
entry.matrix,
|
||||||
|
entry.rotation,
|
||||||
|
entry.tint,
|
||||||
|
entry.varTextures,
|
||||||
|
backlight
|
||||||
|
);
|
||||||
}
|
}
|
||||||
flush();
|
flush();
|
||||||
entries.clear();
|
entries.clear();
|
||||||
|
|||||||
@ -12,6 +12,7 @@ class Mesh;
|
|||||||
class Texture;
|
class Texture;
|
||||||
class Chunks;
|
class Chunks;
|
||||||
class Assets;
|
class Assets;
|
||||||
|
struct EngineSettings;
|
||||||
|
|
||||||
namespace model {
|
namespace model {
|
||||||
struct Mesh;
|
struct Mesh;
|
||||||
@ -32,6 +33,7 @@ class ModelBatch {
|
|||||||
Chunks* chunks;
|
Chunks* chunks;
|
||||||
Texture* texture = nullptr;
|
Texture* texture = nullptr;
|
||||||
UVRegion region {0.0f, 0.0f, 1.0f, 1.0f};
|
UVRegion region {0.0f, 0.0f, 1.0f, 1.0f};
|
||||||
|
const EngineSettings* settings;
|
||||||
|
|
||||||
static inline glm::vec3 SUN_VECTOR {0.411934f, 0.863868f, -0.279161f};
|
static inline glm::vec3 SUN_VECTOR {0.411934f, 0.863868f, -0.279161f};
|
||||||
|
|
||||||
@ -65,7 +67,8 @@ class ModelBatch {
|
|||||||
const glm::mat4& matrix,
|
const glm::mat4& matrix,
|
||||||
const glm::mat3& rotation,
|
const glm::mat3& rotation,
|
||||||
glm::vec3 tint,
|
glm::vec3 tint,
|
||||||
const texture_names_map* varTextures);
|
const texture_names_map* varTextures,
|
||||||
|
bool backlight);
|
||||||
void setTexture(const std::string& name,
|
void setTexture(const std::string& name,
|
||||||
const texture_names_map* varTextures);
|
const texture_names_map* varTextures);
|
||||||
void setTexture(Texture* texture);
|
void setTexture(Texture* texture);
|
||||||
@ -80,7 +83,12 @@ class ModelBatch {
|
|||||||
};
|
};
|
||||||
std::vector<DrawEntry> entries;
|
std::vector<DrawEntry> entries;
|
||||||
public:
|
public:
|
||||||
ModelBatch(size_t capacity, Assets* assets, Chunks* chunks);
|
ModelBatch(
|
||||||
|
size_t capacity,
|
||||||
|
Assets* assets,
|
||||||
|
Chunks* chunks,
|
||||||
|
const EngineSettings* settings
|
||||||
|
);
|
||||||
~ModelBatch();
|
~ModelBatch();
|
||||||
|
|
||||||
void draw(glm::mat4 matrix,
|
void draw(glm::mat4 matrix,
|
||||||
|
|||||||
@ -55,7 +55,8 @@ WorldRenderer::WorldRenderer(
|
|||||||
frustumCulling(std::make_unique<Frustum>()),
|
frustumCulling(std::make_unique<Frustum>()),
|
||||||
lineBatch(std::make_unique<LineBatch>()),
|
lineBatch(std::make_unique<LineBatch>()),
|
||||||
modelBatch(std::make_unique<ModelBatch>(
|
modelBatch(std::make_unique<ModelBatch>(
|
||||||
20'000, engine->getAssets(), level->chunks.get()
|
20'000, engine->getAssets(), level->chunks.get(),
|
||||||
|
&engine->getSettings()
|
||||||
)) {
|
)) {
|
||||||
renderer = std::make_unique<ChunksRenderer>(
|
renderer = std::make_unique<ChunksRenderer>(
|
||||||
level, frontend->getContentGfxCache(), &engine->getSettings()
|
level, frontend->getContentGfxCache(), &engine->getSettings()
|
||||||
|
|||||||
@ -64,8 +64,8 @@ struct GraphicsSettings {
|
|||||||
/// @brief Enable chunks frustum culling
|
/// @brief Enable chunks frustum culling
|
||||||
FlagSetting frustumCulling {true};
|
FlagSetting frustumCulling {true};
|
||||||
IntegerSetting skyboxResolution {64 + 32, 64, 128};
|
IntegerSetting skyboxResolution {64 + 32, 64, 128};
|
||||||
IntegerSetting chunkMaxVertices {1'000'000, 0, 4'000'000};
|
IntegerSetting chunkMaxVertices {200'000, 0, 4'000'000};
|
||||||
IntegerSetting chunkMaxRenderers {0, -4, 32};
|
IntegerSetting chunkMaxRenderers {6, -4, 32};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DebugSettings {
|
struct DebugSettings {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user