fix: backlight not applied to entities
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "window/Window.hpp"
|
||||
#include "voxels/Chunks.hpp"
|
||||
#include "lighting/Lightmap.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
@@ -49,14 +50,19 @@ static glm::mat4 extract_rotation(glm::mat4 matrix) {
|
||||
return glm::toMat3(rotation);
|
||||
}
|
||||
|
||||
ModelBatch::ModelBatch(size_t capacity, Assets* assets, Chunks* chunks)
|
||||
: buffer(std::make_unique<float[]>(capacity * VERTEX_SIZE)),
|
||||
capacity(capacity),
|
||||
index(0),
|
||||
mesh(std::make_unique<Mesh>(buffer.get(), 0, attrs)),
|
||||
assets(assets),
|
||||
chunks(chunks)
|
||||
{
|
||||
ModelBatch::ModelBatch(
|
||||
size_t capacity,
|
||||
Assets* assets,
|
||||
Chunks* chunks,
|
||||
const EngineSettings* settings
|
||||
)
|
||||
: buffer(std::make_unique<float[]>(capacity * VERTEX_SIZE)),
|
||||
capacity(capacity),
|
||||
index(0),
|
||||
mesh(std::make_unique<Mesh>(buffer.get(), 0, attrs)),
|
||||
assets(assets),
|
||||
chunks(chunks),
|
||||
settings(settings) {
|
||||
const ubyte pixels[] = {
|
||||
255, 255, 255, 255,
|
||||
};
|
||||
@@ -68,18 +74,19 @@ ModelBatch::~ModelBatch() = default;
|
||||
|
||||
void ModelBatch::draw(const model::Mesh& mesh, const glm::mat4& matrix,
|
||||
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);
|
||||
light_t light = chunks->getLight(
|
||||
std::floor(gpos.x),
|
||||
std::floor(std::min(CHUNK_H-1.0f, gpos.y)),
|
||||
std::floor(gpos.z));
|
||||
|
||||
glm::vec4 lights (
|
||||
Lightmap::extract(light, 0) / 15.0f,
|
||||
Lightmap::extract(light, 1) / 15.0f,
|
||||
Lightmap::extract(light, 2) / 15.0f,
|
||||
Lightmap::extract(light, 3) / 15.0f
|
||||
light_t minIntensity = backlight ? 1 : 0;
|
||||
glm::vec4 lights(
|
||||
glm::max(Lightmap::extract(light, 0), minIntensity) / 15.0f,
|
||||
glm::max(Lightmap::extract(light, 1), minIntensity) / 15.0f,
|
||||
glm::max(Lightmap::extract(light, 2), minIntensity) / 15.0f,
|
||||
glm::max(Lightmap::extract(light, 3), minIntensity) / 15.0f
|
||||
);
|
||||
setTexture(mesh.texture, varTextures);
|
||||
size_t vcount = mesh.vertices.size();
|
||||
@@ -115,8 +122,16 @@ void ModelBatch::render() {
|
||||
return a.mesh->texture < b.mesh->texture;
|
||||
}
|
||||
);
|
||||
bool backlight = settings->graphics.backlight.get();
|
||||
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();
|
||||
entries.clear();
|
||||
|
||||
Reference in New Issue
Block a user