summaryrefslogtreecommitdiff
path: root/game/scenary
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2026-03-04 03:12:26 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2026-03-04 03:12:26 +0000
commit5273a03417b0bb1b1f9f0baabee22466c8ea440c (patch)
treeef13d3639f54bd62db95dccfa34c54e30e2f9f74 /game/scenary
parentCalculate an appropriate billboardSize and useMeshClipDist (diff)
downloadilt-5273a03417b0bb1b1f9f0baabee22466c8ea440c.tar.bz2
ilt-5273a03417b0bb1b1f9f0baabee22466c8ea440c.tar.xz
ilt-5273a03417b0bb1b1f9f0baabee22466c8ea440c.zip
Update stencils and billboards less often
No need to update these every frame when little of nothing has changed. Instead, track the angle previously rendered and updated only when the new angle has diverged sufficiently from this. Larger updates update more frequently.
Diffstat (limited to 'game/scenary')
-rw-r--r--game/scenary/foliage.cpp15
-rw-r--r--game/scenary/foliage.h2
2 files changed, 12 insertions, 5 deletions
diff --git a/game/scenary/foliage.cpp b/game/scenary/foliage.cpp
index 680d902..0981ffc 100644
--- a/game/scenary/foliage.cpp
+++ b/game/scenary/foliage.cpp
@@ -9,8 +9,9 @@
static_assert(std::is_constructible_v<Foliage>);
constexpr float OBJECT_BILLBOARD_DIVISOR = 64;
+constexpr float BILLBOARD_ANGLE_TOLERANCE = 250.F; // Radians per mm size
constexpr float ASSUMED_VIEWPORT = 1440;
-constexpr float OVER_SAMPLE_MULTIPLIER = 4; // Use mesh until billboard 1/4 of rendered size
+constexpr float OVER_SAMPLE_MULTIPLIER = 2; // Use mesh until billboard 1/2 of rendered size
namespace {
GLsizei
@@ -51,18 +52,22 @@ Foliage::postLoad()
}
void
-Foliage::updateStencil(const ShadowStenciller & ss) const
+Foliage::updateStencil(const ShadowStenciller & shadowStenciller) const
{
- if (instancePartitions.second.second != instancePartitions.second.first) {
- ss.renderStencil(shadowStencil, *bodyMesh, texture);
+ if (instancePartitions.second.second != instancePartitions.second.first
+ && glm::distance(shadowStenciller.getLightDirection(), shadowStencilDir)
+ > BILLBOARD_ANGLE_TOLERANCE / bodyMesh->getDimensions().size) {
+ shadowStenciller.renderStencil(shadowStencil, *bodyMesh, texture);
}
}
void
Foliage::updateBillboard(const BillboardPainter & bbp) const
{
- if (instancePartitions.first != instancePartitions.second.first) {
+ if (instancePartitions.first != instancePartitions.second.first
+ && std::abs(bbp.getAngle() - billboardAngle) > BILLBOARD_ANGLE_TOLERANCE / bodyMesh->getDimensions().size) {
bbp.renderBillBoard(billboard, *bodyMesh, texture);
+ billboardAngle = bbp.getAngle();
}
}
diff --git a/game/scenary/foliage.h b/game/scenary/foliage.h
index c457404..3d73573 100644
--- a/game/scenary/foliage.h
+++ b/game/scenary/foliage.h
@@ -37,7 +37,9 @@ protected:
void postLoad() override;
GLsizei billboardSize {};
RelativeDistance useMeshClipDist {};
+ mutable Direction2D shadowStencilDir {std::numeric_limits<Direction2D::value_type>::infinity()};
glTexture shadowStencil;
+ mutable Angle billboardAngle = std::numeric_limits<Angle>::infinity();
glTextures<3> billboard;
private: