fix block models generation

This commit is contained in:
MihailRis 2024-11-05 01:51:37 +03:00
parent 87663e597b
commit 6f9bad0557
4 changed files with 24 additions and 10 deletions

View File

@ -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)));

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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),