From 6f9bad05572c7ec394f8bae7da2cf93c0c50ce7e Mon Sep 17 00:00:00 2001 From: MihailRis Date: Tue, 5 Nov 2024 01:51:37 +0300 Subject: [PATCH] fix block models generation --- res/shaders/entity.glslf | 2 +- src/graphics/render/ModelBatch.cpp | 21 +++++++++++++++------ src/graphics/render/ModelsGenerator.cpp | 9 +++++++-- src/graphics/render/ParticlesRenderer.cpp | 2 +- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/res/shaders/entity.glslf b/res/shaders/entity.glslf index b332c02f..5da4142c 100644 --- a/res/shaders/entity.glslf +++ b/res/shaders/entity.glslf @@ -16,7 +16,7 @@ void main() { float depth = (a_distance/256.0); float alpha = a_color.a * tex_color.a; // anyway it's any alpha-test alternative required - if (alpha < 0.9f) + if (alpha < 0.5f) discard; f_color = mix(a_color * tex_color, vec4(fogColor,1.0), min(1.0, pow(depth*u_fogFactor, u_fogCurve))); diff --git a/src/graphics/render/ModelBatch.cpp b/src/graphics/render/ModelBatch.cpp index e222b349..42ceb921 100644 --- a/src/graphics/render/ModelBatch.cpp +++ b/src/graphics/render/ModelBatch.cpp @@ -63,19 +63,28 @@ void ModelBatch::draw(const model::Mesh& mesh, const glm::mat4& matrix, const glm::mat3& rotation, glm::vec3 tint, const texture_names_map* varTextures, bool backlight) { - glm::vec3 gpos = matrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f); - gpos += lightsOffset; - glm::vec4 lights = MainBatch::sampleLight(gpos, *chunks, backlight); + + setTexture(mesh.texture, varTextures); size_t vcount = mesh.vertices.size(); const auto& vertexData = mesh.vertices.data(); + + glm::vec4 lights(1, 1, 1, 0); + if (mesh.lighting) { + glm::vec3 gpos = matrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f); + gpos += lightsOffset; + lights = MainBatch::sampleLight(gpos, *chunks, backlight); + } for (size_t i = 0; i < vcount / 3; i++) { batch->prepare(3); for (size_t j = 0; j < 3; j++) { const auto vert = vertexData[i * 3 + j]; - auto norm = rotation * vert.normal; - float d = glm::dot(norm, SUN_VECTOR); - d = 0.8f + d * 0.2f; + float d = 1.0f; + if (mesh.lighting) { + auto norm = rotation * vert.normal; + d = glm::dot(norm, SUN_VECTOR); + d = 0.8f + d * 0.2f; + } batch->vertex(matrix * glm::vec4(vert.coord, 1.0f), vert.uv, lights*d, tint); } } diff --git a/src/graphics/render/ModelsGenerator.cpp b/src/graphics/render/ModelsGenerator.cpp index 07bf7b0d..705cabd3 100644 --- a/src/graphics/render/ModelsGenerator.cpp +++ b/src/graphics/render/ModelsGenerator.cpp @@ -63,7 +63,7 @@ model::Model ModelsGenerator::generate( for (size_t i = 0; i < blockDef.modelBoxes.size(); i++) { auto& mesh = model.addMesh("blocks:" + blockDef.modelTextures[i * 6]); - mesh.lighting = !def.rt.emissive; + mesh.lighting = !blockDef.shadeless; const UVRegion (&boxtexfaces)[6] = { get_region_for(blockDef.modelTextures[i * 6], assets), get_region_for(blockDef.modelTextures[i * 6 + 1], assets), @@ -86,7 +86,7 @@ model::Model ModelsGenerator::generate( blockDef.modelTextures[blockDef.modelBoxes.size() * 6 + i]; auto& mesh = model.addMesh(texture); - mesh.lighting = !def.rt.emissive; + mesh.lighting = !blockDef.shadeless; auto reg = get_region_for(texture, assets); mesh.vertices.push_back( @@ -108,8 +108,13 @@ model::Model ModelsGenerator::generate( {points[i * 4 + 0] - poff, glm::vec2(reg.u1, reg.v2), norm} ); } + for (auto& mesh : model.meshes) { + mesh.scale(glm::vec3(0.3f)); + } + return model; } for (auto& mesh : model.meshes) { + mesh.lighting = !blockDef.shadeless; switch (blockDef.model) { case BlockModel::aabb: { glm::vec3 size = blockDef.hitboxes.at(0).size(); diff --git a/src/graphics/render/ParticlesRenderer.cpp b/src/graphics/render/ParticlesRenderer.cpp index d377773e..0e030dbc 100644 --- a/src/graphics/render/ParticlesRenderer.cpp +++ b/src/graphics/render/ParticlesRenderer.cpp @@ -92,7 +92,7 @@ void ParticlesRenderer::renderParticles(const Camera& camera, float delta) { batch->quad( particle.position, right, - up, + preset.globalUpVector ? glm::vec3(0, 1, 0) : up, preset.size, light, glm::vec3(1.0f),