mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-09 04:51:49 +00:00
fix entities shading
This commit is contained in:
parent
07d39d2742
commit
7a98f0c411
7 changed files with 58 additions and 41 deletions
|
|
@ -18,13 +18,15 @@ struct MainBatchVertex {
|
|||
glm::vec3 position;
|
||||
glm::vec2 uv;
|
||||
glm::vec3 tint;
|
||||
std::array<uint8_t,4> color;
|
||||
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::UNSIGNED_BYTE, true, 4},
|
||||
{VertexAttribute::Type::UNSIGNED_BYTE, true, 4},
|
||||
{{}, 0}};
|
||||
};
|
||||
|
||||
|
|
@ -61,7 +63,8 @@ public:
|
|||
const glm::vec3& pos,
|
||||
const glm::vec2& uv,
|
||||
const glm::vec4& light,
|
||||
const glm::vec3& tint
|
||||
const glm::vec3& tint,
|
||||
const glm::vec3& normal
|
||||
) {
|
||||
MainBatchVertex* buffer = this->buffer.get();
|
||||
buffer[index].position = pos;
|
||||
|
|
@ -72,6 +75,10 @@ public:
|
|||
buffer[index].color[1] = static_cast<uint8_t>(light.g * 255);
|
||||
buffer[index].color[2] = static_cast<uint8_t>(light.b * 255);
|
||||
buffer[index].color[3] = static_cast<uint8_t>(light.a * 255);
|
||||
|
||||
buffer[index].normal[0] = static_cast<uint8_t>(normal.x * 128 + 127);
|
||||
buffer[index].normal[1] = static_cast<uint8_t>(normal.y * 128 + 127);
|
||||
buffer[index].normal[2] = static_cast<uint8_t>(normal.z * 128 + 127);
|
||||
index++;
|
||||
}
|
||||
|
||||
|
|
@ -89,38 +96,44 @@ public:
|
|||
pos - right * size.x * 0.5f - up * size.y * 0.5f,
|
||||
{subregion.u1, subregion.v1},
|
||||
light,
|
||||
tint
|
||||
tint,
|
||||
glm::cross(up, right)
|
||||
);
|
||||
vertex(
|
||||
pos + right * size.x * 0.5f - up * size.y * 0.5f,
|
||||
{subregion.u2, subregion.v1},
|
||||
light,
|
||||
tint
|
||||
tint,
|
||||
glm::cross(up, right)
|
||||
);
|
||||
vertex(
|
||||
pos + right * size.x * 0.5f + up * size.y * 0.5f,
|
||||
{subregion.u2, subregion.v2},
|
||||
light,
|
||||
tint
|
||||
tint,
|
||||
glm::cross(up, right)
|
||||
);
|
||||
|
||||
vertex(
|
||||
pos - right * size.x * 0.5f - up * size.y * 0.5f,
|
||||
{subregion.u1, subregion.v1},
|
||||
light,
|
||||
tint
|
||||
tint,
|
||||
glm::cross(up, right)
|
||||
);
|
||||
vertex(
|
||||
pos + right * size.x * 0.5f + up * size.y * 0.5f,
|
||||
{subregion.u2, subregion.v2},
|
||||
light,
|
||||
tint
|
||||
tint,
|
||||
glm::cross(up, right)
|
||||
);
|
||||
vertex(
|
||||
pos - right * size.x * 0.5f + up * size.y * 0.5f,
|
||||
{subregion.u1, subregion.v2},
|
||||
light,
|
||||
tint
|
||||
tint,
|
||||
glm::cross(up, right)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue