Merge branch 'MihailRis:main' into main

This commit is contained in:
Astazium 2026-09-20 12:36:56 +03:00 • committed by GitHub
commit 2c3c217fef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
71 changed files with 3978 additions and 786 deletions

View file

@ -161,7 +161,7 @@ void BlockWrapsRenderer::draw(const DrawContext& pctx) {
u64id_t BlockWrapsRenderer::add(
const glm::ivec3& position,
const std::string& texture,
const glm::vec3& tint,
const glm::vec4& tint,
float emission
) {
u64id_t id = nextWrapper++;

View file

@ -20,7 +20,7 @@ class DrawContext;
struct BlockWrapper {
glm::ivec3 position;
std::array<std::string, 6> textureFaces {};
std::array<glm::vec3, 6> tints {};
std::array<glm::vec4, 6> tints {};
float emission = 0.0f;
// --- render cache ---
@ -56,7 +56,7 @@ public:
u64id_t add(
const glm::ivec3& position,
const std::string& texture,
const glm::vec3& tint,
const glm::vec4& tint,
float emission
);

View file

@ -357,20 +357,30 @@ void BlocksRenderer::blockCustomModel(
const auto& vcoord = vertex.coord - 0.5f;
glm::vec4 aoColor {1.0f, 1.0f, 1.0f, 1.0f};
if (shading && ao) {
if (shading) {
const float eps = 0.05f;
auto p = coord + vcoord.x * X + vcoord.y * Y + vcoord.z * Z +
r * 0.5f + t * 0.5f + n * eps;
auto p1 = p + n * eps;
auto p2 = p + n * 0.5f;
aoColor = pickSoftLight(p1.x, p1.y, p1.z, glm::ivec3(r), glm::ivec3(t));
if (!block.lightPassing) {
aoColor = glm::max(
aoColor,
pickSoftLight(
p2.x, p2.y, p2.z, glm::ivec3(r), glm::ivec3(t)
)
);
r * 0.5f + t * 0.5f + n * eps;
if (ao) {
auto p1 = p + n * eps;
auto p2 = p + n * 0.5f;
aoColor = pickSoftLight(p1.x, p1.y, p1.z, glm::ivec3(r), glm::ivec3(t));
if (!block.lightPassing) {
aoColor = glm::max(
aoColor,
pickSoftLight(
p2.x, p2.y, p2.z, glm::ivec3(r), glm::ivec3(t)
)
);
}
} else {
aoColor = pickLight(glm::floor(p + 0.5f) + 0.5f);
if (!block.lightPassing) {
aoColor = glm::max(
aoColor,
pickLight(glm::floor(p + n + 0.5f) + 0.5f)
);
}
}
}
this->vertex(

View file

@ -30,6 +30,7 @@ void HandsRenderer::render(const Camera& camera) {
assets,
modelBatch,
skeleton,
ModelLightingMode::SOLID,
glm::mat3(1.0f),
glm::vec3(),
glm::vec3(1.0f)

View file

@ -82,12 +82,75 @@ inline glm::vec4 do_tint(float value) {
return {value, value, value, 1.0f};
}
void MainBatch::quad(
const glm::vec3& pos,
const glm::vec3& right,
const glm::vec3& up,
const glm::vec3& normal,
const glm::vec2& size,
const glm::vec4& light,
const glm::vec4& tint,
const UVRegion& subregion,
float emission
) {
prepare(6);
vertex(
pos - right * size.x * 0.5f - up * size.y * 0.5f,
{subregion.u1, subregion.v1},
light,
tint,
normal,
emission
);
vertex(
pos + right * size.x * 0.5f - up * size.y * 0.5f,
{subregion.u2, subregion.v1},
light,
tint,
normal,
emission
);
vertex(
pos + right * size.x * 0.5f + up * size.y * 0.5f,
{subregion.u2, subregion.v2},
light,
tint,
normal,
emission
);
vertex(
pos - right * size.x * 0.5f - up * size.y * 0.5f,
{subregion.u1, subregion.v1},
light,
tint,
normal,
emission
);
vertex(
pos + right * size.x * 0.5f + up * size.y * 0.5f,
{subregion.u2, subregion.v2},
light,
tint,
normal,
emission
);
vertex(
pos - right * size.x * 0.5f + up * size.y * 0.5f,
{subregion.u1, subregion.v2},
light,
tint,
normal,
emission
);
}
void MainBatch::cube(
const glm::vec3& coord,
const glm::vec3& size,
const UVRegion(&texfaces)[6],
const glm::vec4& lights,
const glm::vec3 tints[],
const glm::vec4 tints[],
float emission,
uint8_t cullingBits
) {

View file

@ -17,30 +17,20 @@ class Chunks;
struct MainBatchVertex {
glm::vec3 position;
glm::vec2 uv;
glm::vec3 tint;
glm::vec4 tint;
std::array<uint8_t, 4> color;
std::array<uint8_t, 4> normal;
static constexpr VertexAttribute ATTRIBUTES[] = {
{VertexAttribute::Type::FLOAT, false, 3},
{VertexAttribute::Type::FLOAT, false, 2},
{VertexAttribute::Type::FLOAT, false, 3},
{VertexAttribute::Type::FLOAT, false, 4},
{VertexAttribute::Type::UNSIGNED_BYTE, true, 4},
{VertexAttribute::Type::UNSIGNED_BYTE, true, 4},
{{}, 0}};
};
class MainBatch {
std::unique_ptr<MainBatchVertex[]> const buffer;
size_t const capacity;
size_t index;
UVRegion region {0.0f, 0.0f, 1.0f, 1.0f};
std::unique_ptr<Mesh<MainBatchVertex>> mesh;
std::unique_ptr<Texture> blank;
const Texture* texture = nullptr;
public:
/// xyz, uv, color, compressed lights
@ -63,7 +53,7 @@ public:
const glm::vec3& pos,
const glm::vec2& uv,
const glm::vec4& light,
const glm::vec3& tint,
const glm::vec4& tint,
const glm::vec3& normal,
float emission
) {
@ -84,76 +74,36 @@ public:
index++;
}
inline void quad(
void quad(
const glm::vec3& pos,
const glm::vec3& right,
const glm::vec3& up,
const glm::vec3& normal,
const glm::vec2& size,
const glm::vec4& light,
const glm::vec3& tint,
const glm::vec4& tint,
const UVRegion& subregion,
float emission = 0.0f
) {
prepare(6);
vertex(
pos - right * size.x * 0.5f - up * size.y * 0.5f,
{subregion.u1, subregion.v1},
light,
tint,
normal,
emission
);
vertex(
pos + right * size.x * 0.5f - up * size.y * 0.5f,
{subregion.u2, subregion.v1},
light,
tint,
normal,
emission
);
vertex(
pos + right * size.x * 0.5f + up * size.y * 0.5f,
{subregion.u2, subregion.v2},
light,
tint,
normal,
emission
);
vertex(
pos - right * size.x * 0.5f - up * size.y * 0.5f,
{subregion.u1, subregion.v1},
light,
tint,
normal,
emission
);
vertex(
pos + right * size.x * 0.5f + up * size.y * 0.5f,
{subregion.u2, subregion.v2},
light,
tint,
normal,
emission
);
vertex(
pos - right * size.x * 0.5f + up * size.y * 0.5f,
{subregion.u1, subregion.v2},
light,
tint,
normal,
emission
);
}
);
void cube(
const glm::vec3& coord,
const glm::vec3& size,
const UVRegion(&texfaces)[6],
const glm::vec4& lights,
const glm::vec3 tints[],
const glm::vec4 tints[],
float emission,
uint8_t cullingBits = 0xFF
);
private:
std::unique_ptr<MainBatchVertex[]> const buffer;
size_t const capacity;
size_t index;
UVRegion region {0.0f, 0.0f, 1.0f, 1.0f};
std::unique_ptr<Mesh<MainBatchVertex>> mesh;
std::unique_ptr<Texture> blank;
const Texture* texture = nullptr;
};

View file

@ -61,8 +61,8 @@ void ModelBatch::draw(
const model::Mesh& mesh,
const glm::mat4& matrix,
const glm::mat3& rotation,
glm::vec3 tint,
const texture_names_map* varTextures,
const glm::vec4& tint,
const TextureNamesMap* varTextures,
bool backlight
) {
setTexture(mesh.texture, varTextures);
@ -72,7 +72,7 @@ void ModelBatch::draw(
glm::vec4 lights(1, 1, 1, 0);
if (mesh.shading) {
glm::vec3 gpos = matrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
gpos += lightsOffset;
gpos += lightsOffset + localLightsOffset;
lights = MainBatch::sampleLight(gpos, chunks, backlight);
}
for (size_t i = 0; i < vcount / 3; i++) {
@ -97,14 +97,21 @@ void ModelBatch::draw(
}
}
void ModelBatch::draw(glm::mat4 matrix,
glm::vec3 tint,
const model::Model* model,
const texture_names_map* varTextures) {
void ModelBatch::draw(
const glm::mat4& matrix,
const glm::vec4& tint,
const glm::vec3& lightSampleOffset,
const model::Model* model,
const TextureNamesMap* varTextures
) {
for (const auto& mesh : model->meshes) {
entries.push_back({
matrix, extract_rotation(matrix), tint, &mesh, varTextures
});
entries.push_back(DrawEntry {
matrix,
extract_rotation(matrix),
tint,
lightSampleOffset,
&mesh,
varTextures});
}
}
@ -116,6 +123,7 @@ void ModelBatch::render() {
);
bool backlight = settings.graphics.backlight.get();
for (auto& entry : entries) {
localLightsOffset = entry.lightSampleOffset;
draw(
*entry.mesh,
entry.matrix,
@ -124,6 +132,7 @@ void ModelBatch::render() {
entry.varTextures,
backlight
);
localLightsOffset = {};
}
batch->flush();
entries.clear();
@ -134,7 +143,7 @@ void ModelBatch::setLightsOffset(const glm::vec3& offset) {
}
void ModelBatch::setTexture(const std::string& name,
const texture_names_map* varTextures) {
const TextureNamesMap* varTextures) {
if (varTextures && !name.empty() && name.at(0) == '$') {
const auto& found = varTextures->find(name);
if (found == varTextures->end()) {

View file

@ -18,37 +18,9 @@ namespace model {
struct Model;
}
using texture_names_map = std::unordered_map<std::string, std::string>;
using TextureNamesMap = std::unordered_map<std::string, std::string>;
class ModelBatch {
const Assets& assets;
const Chunks& chunks;
const EngineSettings& settings;
glm::vec3 lightsOffset {};
static inline glm::vec3 SUN_VECTOR {0.411934f, 0.863868f, -0.279161f};
std::unique_ptr<MainBatch> batch;
void draw(const model::Mesh& mesh,
const glm::mat4& matrix,
const glm::mat3& rotation,
glm::vec3 tint,
const texture_names_map* varTextures,
bool backlight);
void setTexture(const std::string& name,
const texture_names_map* varTextures);
struct DrawEntry {
glm::mat4 matrix;
glm::mat3 rotation;
glm::vec3 tint;
const model::Mesh* mesh;
const texture_names_map* varTextures;
};
std::vector<DrawEntry> entries;
public:
ModelBatch(
size_t capacity,
@ -58,11 +30,47 @@ public:
);
~ModelBatch();
void draw(glm::mat4 matrix,
glm::vec3 tint,
const model::Model* model,
const texture_names_map* varTextures);
void draw(
const glm::mat4& matrix,
const glm::vec4& tint,
const glm::vec3& lightSampleOffset,
const model::Model* model,
const TextureNamesMap* varTextures
);
void render();
void setLightsOffset(const glm::vec3& offset);
private:
const Assets& assets;
const Chunks& chunks;
const EngineSettings& settings;
glm::vec3 lightsOffset {};
glm::vec3 localLightsOffset {};
static inline glm::vec3 SUN_VECTOR {0.411934f, 0.863868f, -0.279161f};
std::unique_ptr<MainBatch> batch;
void draw(
const model::Mesh& mesh,
const glm::mat4& matrix,
const glm::mat3& rotation,
const glm::vec4& tint,
const TextureNamesMap* varTextures,
bool backlight
);
void setTexture(const std::string& name,
const TextureNamesMap* varTextures);
struct DrawEntry {
glm::mat4 matrix;
glm::mat3 rotation;
glm::vec4 tint;
glm::vec3 lightSampleOffset;
const model::Mesh* mesh;
const TextureNamesMap* varTextures;
};
std::vector<DrawEntry> entries;
};

View file

@ -160,7 +160,7 @@ void ParticlesRenderer::renderParticle(
-camera.front,
preset.size * scale,
light,
glm::vec3(1.0f),
glm::vec4(1.0f),
particle.region,
preset.lighting ? 0.0f : 1.0f
);

View file

@ -151,7 +151,7 @@ void PrecipitationRenderer::render(
glm::cross(glm::vec3(0, 1, 0), face.right),
FACE_SIZE,
light_at(chunks, pos.x, y, pos.z),
glm::vec3(1.0f),
glm::vec4(1.0f),
calc_uv(pos, face.right, timer, weather)
);
}