mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 14:16:48 +01:00
fix(render): EU07M review of #537: no whole vertices kept for the bounds, the compact variant checked by CI and given up when it fails
- The bounding radius, offset() and MaxY() read the positions of a chunk alone (Positions(), geometry_bank::positions()): on Vulkan the compact streams are no longer decoded into basic_vertex and kept for the life of the bank as every model loads, so the host memory of EU07M models stays below that of E3D. What still needs whole vertices (the editor, the picking, the export) decodes them on first use as before. - A COMPACT_VERTEX variant which doesn't compile is told once in the log and the banks of EU07M models go back to basic_vertex (compact_layout_failed()), those built already when they are drawn next, instead of the models being left out for the session. - The shader validator compiles the vk14 shaders which have COMPACT_VERTEX with it, alone and with MODEL_DRAWS, as the renderer makes the variants.
This commit is contained in:
+23
-9
@@ -1486,9 +1486,10 @@ void TSubModel::create_geometry(std::size_t &Indexoffset, std::size_t &Vertexoff
|
||||
// since we're comparing squared radii, we need to square it back for correct results
|
||||
m_boundingradius *= m_boundingradius;
|
||||
auto const submodeloffset{offset(std::numeric_limits<float>::max())};
|
||||
for (auto const &vertex : GfxRenderer->Vertices(m_geometry.handle))
|
||||
// the positions alone: the vertices of an EU07M model on Vulkan would be made and kept whole for it
|
||||
for (auto const &position : GfxRenderer->Positions(m_geometry.handle))
|
||||
{
|
||||
squaredradius = glm::length2(submodeloffset + vertex.position);
|
||||
squaredradius = glm::length2(submodeloffset + position);
|
||||
if (squaredradius > m_boundingradius)
|
||||
{
|
||||
m_boundingradius = squaredradius;
|
||||
@@ -1612,9 +1613,9 @@ float TSubModel::MaxY(float4x4 const &m)
|
||||
if (m_geometry.handle != null_handle)
|
||||
{
|
||||
|
||||
for (auto const &vertex : GfxRenderer->Vertices(m_geometry.handle))
|
||||
for (auto const &position : GfxRenderer->Positions(m_geometry.handle))
|
||||
{
|
||||
maxy = std::max(maxy, m[0][1] * vertex.position.x + m[1][1] * vertex.position.y + m[2][1] * vertex.position.z + m[3][1]);
|
||||
maxy = std::max(maxy, m[0][1] * position.x + m[1][1] * position.y + m[2][1] * position.z + m[3][1]);
|
||||
}
|
||||
}
|
||||
else if (false == Vertices.empty())
|
||||
@@ -1756,17 +1757,30 @@ glm::vec3 TSubModel::offset(float const Geometrytestoffsetthreshold) const
|
||||
// offset of zero generally means the submodel has optimized identity matrix
|
||||
// for such cases we resort to an estimate from submodel geometry
|
||||
// TODO: do proper bounding area calculation for submodel when loading mesh and grab the centre point from it here
|
||||
auto const &vertices{(m_geometry.handle != null_handle ? GfxRenderer->Vertices(m_geometry.handle) : Vertices)};
|
||||
if (false == vertices.empty())
|
||||
// the positions alone: the vertices of an EU07M model on Vulkan would be made and kept whole for them
|
||||
gfx::position_array positions;
|
||||
if (m_geometry.handle != null_handle)
|
||||
{
|
||||
positions = GfxRenderer->Positions(m_geometry.handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
positions.reserve(Vertices.size());
|
||||
for (auto const &vertex : Vertices)
|
||||
{
|
||||
positions.push_back(vertex.position);
|
||||
}
|
||||
}
|
||||
if (false == positions.empty())
|
||||
{
|
||||
// transformation matrix for the submodel can still contain rotation and/or scaling,
|
||||
// so we pass the vertex positions through it rather than just grab them directly
|
||||
offset = glm::vec3();
|
||||
auto const vertexfactor{1.f / vertices.size()};
|
||||
auto const vertexfactor{1.f / positions.size()};
|
||||
auto const transformationmatrix{glm::make_mat4(parentmatrix.readArray())};
|
||||
for (auto const &vertex : vertices)
|
||||
for (auto const &position : positions)
|
||||
{
|
||||
offset += glm::vec3{transformationmatrix * glm::vec4{vertex.position, 1}} * vertexfactor;
|
||||
offset += glm::vec3{transformationmatrix * glm::vec4{position, 1}} * vertexfactor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user