mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 22:11:51 +00:00
feat: naive texture-faces support for blockwraps implementation
This commit is contained in:
parent
c6c23c3c53
commit
561fb0fb58
4 changed files with 63 additions and 55 deletions
|
|
@ -25,59 +25,58 @@ BlockWrapsRenderer::BlockWrapsRenderer(
|
||||||
BlockWrapsRenderer::~BlockWrapsRenderer() = default;
|
BlockWrapsRenderer::~BlockWrapsRenderer() = default;
|
||||||
|
|
||||||
void BlockWrapsRenderer::draw(const BlockWrapper& wrapper) {
|
void BlockWrapsRenderer::draw(const BlockWrapper& wrapper) {
|
||||||
auto textureRegion = util::get_texture_region(assets, wrapper.texture, "");
|
|
||||||
|
|
||||||
auto& shader = assets.require<Shader>("entity");
|
auto& shader = assets.require<Shader>("entity");
|
||||||
shader.use();
|
shader.use();
|
||||||
shader.uniform1i("u_alphaClip", false);
|
shader.uniform1i("u_alphaClip", false);
|
||||||
|
|
||||||
const UVRegion& cracksRegion = textureRegion.region;
|
util::TextureRegion texRegions[6] {};
|
||||||
UVRegion regions[6] {
|
UVRegion uvRegions[6] {};
|
||||||
cracksRegion, cracksRegion, cracksRegion,
|
for (int i = 0; i < 6; i++) {
|
||||||
cracksRegion, cracksRegion, cracksRegion
|
auto texRegion = util::get_texture_region(assets, wrapper.textureFaces[i], "");
|
||||||
};
|
texRegions[i] = texRegion;
|
||||||
batch->setTexture(textureRegion.texture);
|
uvRegions[i] = texRegion.region;
|
||||||
|
}
|
||||||
|
batch->setTexture(texRegions[0].texture);
|
||||||
|
|
||||||
const voxel* vox = chunks.get(wrapper.position);
|
const voxel* vox = chunks.get(wrapper.position);
|
||||||
if (vox == nullptr) {
|
if (vox == nullptr || vox->id == BLOCK_VOID) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (vox->id != BLOCK_VOID) {
|
const auto& def = level.content.getIndices()->blocks.require(vox->id);
|
||||||
const auto& def = level.content.getIndices()->blocks.require(vox->id);
|
switch (def.getModel(vox->state.userbits).type) {
|
||||||
switch (def.getModel(vox->state.userbits).type) {
|
case BlockModelType::BLOCK:
|
||||||
case BlockModelType::BLOCK:
|
batch->cube(
|
||||||
batch->cube(
|
glm::vec3(wrapper.position) + glm::vec3(0.5f),
|
||||||
glm::vec3(wrapper.position) + glm::vec3(0.5f),
|
glm::vec3(1.01f),
|
||||||
glm::vec3(1.01f),
|
uvRegions,
|
||||||
regions,
|
glm::vec4(1, 1, 1, 0),
|
||||||
glm::vec4(1,1,1,0),
|
false,
|
||||||
false
|
wrapper.cullingBits
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case BlockModelType::AABB: {
|
case BlockModelType::AABB: {
|
||||||
const auto& aabb =
|
const auto& aabb =
|
||||||
(def.rotatable ? def.rt.hitboxes[vox->state.rotation]
|
(def.rotatable ? def.rt.hitboxes[vox->state.rotation]
|
||||||
: def.hitboxes)
|
: def.hitboxes).at(0);
|
||||||
.at(0);
|
const auto& size = aabb.size();
|
||||||
const auto& size = aabb.size();
|
uvRegions[0].scale(size.z, size.y);
|
||||||
regions[0].scale(size.z, size.y);
|
uvRegions[1].scale(size.z, size.y);
|
||||||
regions[1].scale(size.z, size.y);
|
uvRegions[2].scale(size.x, size.z);
|
||||||
regions[2].scale(size.x, size.z);
|
uvRegions[3].scale(size.x, size.z);
|
||||||
regions[3].scale(size.x, size.z);
|
uvRegions[4].scale(size.x, size.y);
|
||||||
regions[4].scale(size.x, size.y);
|
uvRegions[5].scale(size.x, size.y);
|
||||||
regions[5].scale(size.x, size.y);
|
batch->cube(
|
||||||
batch->cube(
|
glm::vec3(wrapper.position) + aabb.center(),
|
||||||
glm::vec3(wrapper.position) + aabb.center(),
|
size * glm::vec3(1.01f),
|
||||||
size * glm::vec3(1.01f),
|
uvRegions,
|
||||||
regions,
|
glm::vec4(1, 1, 1, 0),
|
||||||
glm::vec4(1,1,1,0),
|
false,
|
||||||
false
|
wrapper.cullingBits
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,9 +92,8 @@ u64id_t BlockWrapsRenderer::add(
|
||||||
const glm::ivec3& position, const std::string& texture
|
const glm::ivec3& position, const std::string& texture
|
||||||
) {
|
) {
|
||||||
u64id_t id = nextWrapper++;
|
u64id_t id = nextWrapper++;
|
||||||
wrappers[id] = std::make_unique<BlockWrapper>(
|
wrappers[id] = std::make_unique<BlockWrapper>(BlockWrapper {
|
||||||
BlockWrapper {position, texture}
|
position, {texture, texture, texture, texture, texture, texture}});
|
||||||
);
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
@ -15,7 +16,8 @@ class DrawContext;
|
||||||
|
|
||||||
struct BlockWrapper {
|
struct BlockWrapper {
|
||||||
glm::ivec3 position;
|
glm::ivec3 position;
|
||||||
std::string texture;
|
std::array<std::string, 6> textureFaces {};
|
||||||
|
uint8_t cullingBits = 0xFF;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BlockWrapsRenderer {
|
class BlockWrapsRenderer {
|
||||||
|
|
|
||||||
|
|
@ -83,50 +83,57 @@ inline glm::vec4 do_tint(float value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainBatch::cube(
|
void MainBatch::cube(
|
||||||
const glm::vec3 &coord,
|
const glm::vec3& coord,
|
||||||
const glm::vec3 &size,
|
const glm::vec3& size,
|
||||||
const UVRegion(&texfaces)[6],
|
const UVRegion(&texfaces)[6],
|
||||||
const glm::vec4 &tint,
|
const glm::vec4& tint,
|
||||||
bool shading
|
bool shading,
|
||||||
|
uint8_t cullingBits
|
||||||
) {
|
) {
|
||||||
const glm::vec3 X(1.0f, 0.0f, 0.0f);
|
const glm::vec3 X(1.0f, 0.0f, 0.0f);
|
||||||
const glm::vec3 Y(0.0f, 1.0f, 0.0f);
|
const glm::vec3 Y(0.0f, 1.0f, 0.0f);
|
||||||
const glm::vec3 Z(0.0f, 0.0f, 1.0f);
|
const glm::vec3 Z(0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
if (cullingBits & 0x20)
|
||||||
quad(
|
quad(
|
||||||
coord + Z * size.z * 0.5f,
|
coord + Z * size.z * 0.5f,
|
||||||
X, Y, Z, glm::vec2(size.x, size.y),
|
X, Y, Z, glm::vec2(size.x, size.y),
|
||||||
(shading ? do_tint(0.8) * tint : tint),
|
(shading ? do_tint(0.8) * tint : tint),
|
||||||
glm::vec3(1.0f), texfaces[5]
|
glm::vec3(1.0f), texfaces[5]
|
||||||
);
|
);
|
||||||
|
if (cullingBits & 0x10)
|
||||||
quad(
|
quad(
|
||||||
coord - Z * size.z * 0.5f,
|
coord - Z * size.z * 0.5f,
|
||||||
-X, Y, -Z, glm::vec2(size.x, size.y),
|
-X, Y, -Z, glm::vec2(size.x, size.y),
|
||||||
(shading ? do_tint(0.9f) * tint : tint),
|
(shading ? do_tint(0.9f) * tint : tint),
|
||||||
glm::vec3(1.0f), texfaces[4]
|
glm::vec3(1.0f), texfaces[4]
|
||||||
);
|
);
|
||||||
|
if (cullingBits & 0x8)
|
||||||
quad(
|
quad(
|
||||||
coord + Y * size.y * 0.5f,
|
coord + Y * size.y * 0.5f,
|
||||||
-X, Z, Y, glm::vec2(size.x, size.z),
|
-X, Z, Y, glm::vec2(size.x, size.z),
|
||||||
(shading ? do_tint(1.0f) * tint : tint),
|
(shading ? do_tint(1.0f) * tint : tint),
|
||||||
glm::vec3(1.0f), texfaces[3]
|
glm::vec3(1.0f), texfaces[3]
|
||||||
);
|
);
|
||||||
|
if (cullingBits & 0x4)
|
||||||
quad(
|
quad(
|
||||||
coord - Y * size.y * 0.5f,
|
coord - Y * size.y * 0.5f,
|
||||||
X, Z, -Y, glm::vec2(size.x, size.z),
|
X, Z, -Y, glm::vec2(size.x, size.z),
|
||||||
(shading ? do_tint(0.7f) * tint : tint),
|
(shading ? do_tint(0.7f) * tint : tint),
|
||||||
glm::vec3(1.0f), texfaces[2]
|
glm::vec3(1.0f), texfaces[2]
|
||||||
);
|
);
|
||||||
|
if (cullingBits & 0x2)
|
||||||
quad(
|
quad(
|
||||||
coord + X * size.x * 0.5f,
|
coord + X * size.x * 0.5f,
|
||||||
-Z, Y, X, glm::vec2(size.z, size.y),
|
-Z, Y, X, glm::vec2(size.z, size.y),
|
||||||
(shading ? do_tint(0.8f) * tint : tint),
|
(shading ? do_tint(0.8f) * tint : tint),
|
||||||
glm::vec3(1.0f), texfaces[1]
|
glm::vec3(1.0f), texfaces[1]
|
||||||
);
|
);
|
||||||
|
if (cullingBits & 0x1)
|
||||||
quad(
|
quad(
|
||||||
coord - X * size.x * 0.5f,
|
coord - X * size.x * 0.5f,
|
||||||
Z, Y, -X, glm::vec2(size.z, size.y),
|
Z, Y, -X, glm::vec2(size.z, size.y),
|
||||||
(shading ? do_tint(0.9f) * tint : tint),
|
(shading ? do_tint(0.9f) * tint : tint),
|
||||||
glm::vec3(1.0f), texfaces[1]
|
glm::vec3(1.0f), texfaces[0]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,7 @@ public:
|
||||||
const glm::vec3& size,
|
const glm::vec3& size,
|
||||||
const UVRegion(&texfaces)[6],
|
const UVRegion(&texfaces)[6],
|
||||||
const glm::vec4& tint,
|
const glm::vec4& tint,
|
||||||
bool shading
|
bool shading,
|
||||||
|
uint8_t cullingBits = 0xFF
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue