Browse Source

Add golden ratio hash constant and update usages

- Add GoldenRatioHash constant to render_constants.h
- Update terrain_renderer.cpp to use GoldenRatioHash
- Update arrow_vfx_renderer.cpp to use GoldenRatioHash
- Update archer_renderer.cpp to use GoldenRatioHash

Co-authored-by: djeada <[email protected]>
copilot-swe-agent[bot] 1 month ago
parent
commit
7ed558e972

+ 1 - 1
render/entity/archer_renderer.cpp

@@ -528,7 +528,7 @@ private:
              v.palette.leather, nullptr, 1.0F);
 
     float const j = (hash01(seed) - 0.5F) * 0.04F;
-    float const k = (hash01(seed ^ 0x9E3779B9U) - 0.5F) * 0.04F;
+    float const k = (hash01(seed ^ HashXorShift::GoldenRatioHash) - 0.5F) * 0.04F;
 
     QVector3D const a1 = qTop + QVector3D(0.00F + j, 0.08F, 0.00F + k);
     out.mesh(getUnitCylinder(), cylinderBetween(ctx.model, qTop, a1, 0.010F),

+ 1 - 1
render/entity/arrow_vfx_renderer.cpp

@@ -298,7 +298,7 @@ static inline void drawQuiver(const DrawContext &p, ISubmitter &out,
            C.leather, nullptr, 1.0F);
 
   float j = (hash01(seed) - 0.5F) * 0.04F;
-  float k = (hash01(seed ^ 0x9E3779B9u) - 0.5F) * 0.04F;
+  float k = (hash01(seed ^ HashXorShift::GoldenRatioHash) - 0.5F) * 0.04F;
 
   QVector3D a1 = qTop + QVector3D(0.00F + j, 0.08F, 0.00F + k);
   out.mesh(getUnitCylinder(), cylinderBetween(p.model, qTop, a1, 0.010F),

+ 1 - 0
render/gl/render_constants.h

@@ -86,4 +86,5 @@ namespace Render::GL::HashXorShift {
 inline constexpr int Shift5 = 5;
 inline constexpr int Shift13 = 13;
 inline constexpr int Shift17 = 17;
+inline constexpr uint32_t GoldenRatioHash = 0x9E3779B9U;
 } // namespace Render::GL::HashXorShift

+ 2 - 1
render/ground/terrain_renderer.cpp

@@ -31,6 +31,7 @@ namespace {
 using std::uint32_t;
 using namespace Render::GL::BitShift;
 using namespace Render::GL::Geometry;
+using namespace Render::GL::HashXorShift;
 using namespace Render::Ground;
 
 const QMatrix4x4 k_identity_matrix;
@@ -346,7 +347,7 @@ void TerrainRenderer::buildMeshes() {
       SectionData sections[3];
 
       uint32_t const chunk_seed = hashCoords(chunk_x, chunk_z, m_noiseSeed);
-      uint32_t const variant_seed = chunk_seed ^ 0x9e3779b9U;
+      uint32_t const variant_seed = chunk_seed ^ GoldenRatioHash;
       float const rotation_step =
           static_cast<float>((variant_seed >> 5) & 3) * 90.0F;
       bool const flip = ((variant_seed >> 7) & 1U) != 0U;