Merge branch 'model3dview' into update-gfx-pipeline

This commit is contained in:
MihailRis 2025-05-30 21:37:25 +03:00
commit 32bb30ff83
29 changed files with 473 additions and 130 deletions

View file

@ -6,6 +6,11 @@
#include "typedefs.hpp"
#include "maths/UVRegion.hpp"
namespace {
const glm::vec3 SUN_VECTOR(0.528265f, 0.833149f, -0.163704f);
const float DIRECTIONAL_LIGHT_FACTOR = 0.3f;
}
Batch3D::Batch3D(size_t capacity)
: capacity(capacity) {
buffer = std::make_unique<Batch3DVertex[]>(capacity);
@ -29,20 +34,28 @@ void Batch3D::begin(){
}
void Batch3D::vertex(
float x, float y, float z, float u, float v,
float r, float g, float b, float a
float x,
float y,
float z,
float u,
float v,
float r,
float g,
float b,
float a
) {
buffer[index].position = {x, y, z};
buffer[index].uv = {u, v};
buffer[index].uv = {
u * region.getWidth() + region.u1, v * region.getHeight() + region.v1};
buffer[index].color = {r, g, b, a};
index++;
}
void Batch3D::vertex(
glm::vec3 coord, float u, float v,
float r, float g, float b, float a
glm::vec3 coord, float u, float v, float r, float g, float b, float a
) {
buffer[index].position = coord;
buffer[index].uv = {u, v};
buffer[index].uv = {
u * region.getWidth() + region.u1, v * region.getHeight() + region.v1};
buffer[index].color = {r, g, b, a};
index++;
}
@ -52,7 +65,9 @@ void Batch3D::vertex(
float r, float g, float b, float a
) {
buffer[index].position = point;
buffer[index].uv = uvpoint;
buffer[index].uv = {
uvpoint.x * region.getWidth() + region.u1,
uvpoint.y * region.getHeight() + region.v1};
buffer[index].color = {r, g, b, a};
index++;
}
@ -84,14 +99,18 @@ void Batch3D::face(
}
void Batch3D::texture(const Texture* new_texture){
if (currentTexture == new_texture)
if (currentTexture == new_texture) {
return;
}
flush();
currentTexture = new_texture;
if (new_texture == nullptr)
if (new_texture == nullptr) {
blank->bind();
else
region = blank->getUVRegion();
} else {
new_texture->bind();
region = currentTexture->getUVRegion();
}
}
void Batch3D::sprite(
@ -238,6 +257,16 @@ void Batch3D::blockCube(
cube((1.0f - size) * -0.5f, size, texfaces, tint, shading);
}
void Batch3D::setRegion(UVRegion region) {
this->region = region;
}
void Batch3D::vertex(const glm::vec3& pos, const glm::vec2& uv, const glm::vec3& norm) {
float d = glm::dot(glm::normalize(norm), SUN_VECTOR);
d = (1.0f - DIRECTIONAL_LIGHT_FACTOR) + d * DIRECTIONAL_LIGHT_FACTOR;
vertex(pos, uv, glm::vec4(d, d, d, 1.0f));
}
void Batch3D::vertex(
const glm::vec3& coord, const glm::vec2& uv, const glm::vec4& tint
) {