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,25 +292,31 @@ 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);
for (int i = 0; i < 3; i++) {
const auto& vertex = mesh.vertices[triangle * 3 + i];
auto n = vertex.normal.x * X + vertex.normal.y * Y +
vertex.normal.z * Z;
float d = glm::dot(n, SUN_VECTOR);
d = 0.8f + d * 0.2f; d = 0.8f + d * 0.2f;
const auto& vcoord = vertex.coord - 0.5f; const auto& vcoord = vertex.coord - 0.5f;
vertexAO( vertexAO(
coord + vcoord.x * X + vcoord.y * Y + vcoord.z * Z, coord + vcoord.x * X + vcoord.y * Y + vcoord.z * Z,
vertex.uv.x, vertex.uv.x,
vertex.uv.y, vertex.uv.y,
glm::vec4(1, 1, 1, 1), glm::vec4(d, d, d, d),
glm::vec3(1, 0, 0), glm::cross(r, n),
glm::vec3(0, 1, 0), r,
n n
); );
indexBuffer[indexSize++] = indexOffset++; indexBuffer[indexSize++] = indexOffset++;
} }
} }
}
} }
/* Fastest solid shaded blocks render method */ /* Fastest solid shaded blocks render method */