mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-20 15:04:58 +01:00
Optimise raytracing and buffer building
This commit is contained in:
@@ -15,6 +15,8 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "utilities/Globals.h"
|
||||
#include "utilities/Timer.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace gfx
|
||||
{
|
||||
|
||||
@@ -246,6 +248,7 @@ bool grass_field::prepare(glm::dvec3 const &Camera, std::function<bool(scene::bo
|
||||
draw.share = share;
|
||||
draw.dry = dry;
|
||||
draw.first = m_tiledraws.size();
|
||||
draw.nearest = distance;
|
||||
m_chunkdraws.push_back(draw);
|
||||
}
|
||||
// fewer segments further away
|
||||
@@ -258,11 +261,20 @@ bool grass_field::prepare(glm::dvec3 const &Camera, std::function<bool(scene::bo
|
||||
draw.part = glm::vec4{fill, static_cast<float>(segments), seedx, seedz};
|
||||
draw.count = count;
|
||||
draw.segments = segments;
|
||||
draw.distance = distance;
|
||||
m_tiledraws.push_back(draw);
|
||||
++m_chunkdraws.back().count;
|
||||
m_chunkdraws.back().nearest = std::min(m_chunkdraws.back().nearest, distance);
|
||||
m_triangles += static_cast<std::size_t>(count) * (segments * 2 - 1);
|
||||
}
|
||||
}
|
||||
// from the nearest: the blades in front are drawn first, and those they hide fail the depth test before they're shaded
|
||||
for (auto const &chunk : m_chunkdraws)
|
||||
{
|
||||
auto const first{m_tiledraws.begin() + static_cast<std::ptrdiff_t>(chunk.first)};
|
||||
std::ranges::sort(first, first + static_cast<std::ptrdiff_t>(chunk.count), {}, &tile_draw::distance);
|
||||
}
|
||||
std::ranges::sort(m_chunkdraws, {}, &chunk_draw::nearest);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ class grass_field
|
||||
glm::vec4 share{0.f};
|
||||
std::size_t first{0}; // tiles drawn, in tile_draws()
|
||||
std::size_t count{0};
|
||||
float nearest{0.f}; // distance to the nearest of its tiles; the chunks are drawn from the nearest one
|
||||
};
|
||||
// a tile drawn: Count instances of a strip of 2 * Segments + 1 vertices
|
||||
struct tile_draw
|
||||
@@ -71,6 +72,7 @@ class grass_field
|
||||
glm::vec4 part{0.f}; // grass_part
|
||||
int count{0};
|
||||
int segments{0};
|
||||
float distance{0.f}; // to the box of the tile; the tiles of a chunk are drawn from the nearest one
|
||||
};
|
||||
// the draws of the grass seen from Camera: false when there is nothing to draw (grass off, no chunks or kinds), the draws of
|
||||
// the last call are left then. Visible: whether the bounds of a tile are seen
|
||||
|
||||
Reference in New Issue
Block a user