fix custom model lighting

This commit is contained in:
MihailRis 2024-11-09 23:54:19 +03:00
parent 983e516fb4
commit a333cadfca

View File

@ -292,23 +292,29 @@ void BlocksRenderer::blockCustomModel(
overflow = true; overflow = true;
return; return;
} }
int i = 0; for (int triangle = 0; triangle < mesh.vertices.size() / 3; triangle++) {
for (const auto& vertex : mesh.vertices) { auto r = mesh.vertices[triangle * 3 + (triangle % 2) * 2].coord -
auto n = mesh.vertices[triangle * 3 + 1].coord;
vertex.normal.x * X + vertex.normal.y * Y + vertex.normal.z * Z; r = glm::normalize(r);
float d = glm::dot(glm::normalize(n), SUN_VECTOR);
d = 0.8f + d * 0.2f; for (int i = 0; i < 3; i++) {
const auto& vcoord = vertex.coord - 0.5f; const auto& vertex = mesh.vertices[triangle * 3 + i];
vertexAO( auto n = vertex.normal.x * X + vertex.normal.y * Y +
coord + vcoord.x * X + vcoord.y * Y + vcoord.z * Z, vertex.normal.z * Z;
vertex.uv.x, float d = glm::dot(n, SUN_VECTOR);
vertex.uv.y, d = 0.8f + d * 0.2f;
glm::vec4(1, 1, 1, 1), const auto& vcoord = vertex.coord - 0.5f;
glm::vec3(1, 0, 0), vertexAO(
glm::vec3(0, 1, 0), coord + vcoord.x * X + vcoord.y * Y + vcoord.z * Z,
n vertex.uv.x,
); vertex.uv.y,
indexBuffer[indexSize++] = indexOffset++; glm::vec4(d, d, d, d),
glm::cross(r, n),
r,
n
);
indexBuffer[indexSize++] = indexOffset++;
}
} }
} }
} }