Phases 30-31 (PC, 11-12/10) : rochers visibles, builds separes, densite, demo candidate

Travail local non commite jusqu'ici, sauvegarde avant fusion avec la branche cloud.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cette révision appartient à :
Theo GastineletClaude Opus 5.5 a révisé 2026-10-15 15:09:28 +02:00
1 Parent 84a72fe30c
révision 5cb99fa5f2
10 fichiers modifiés
+1517 -51

Aucun fichier ne correspond à votre recherche

+65 -11
Voir le fichier
@@ -2,6 +2,7 @@
#include <glm/glm.hpp>
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdint>
@@ -21,8 +22,12 @@ const glm::vec3 kLimestone{0.63f, 0.62f, 0.58f};
using Face = std::array<uint32_t, 3>;
using EdgeKey = std::pair<uint32_t, uint32_t>;
// PHASE 30 (Agent B) : `top` = sommet visible de la piece (y > 0, repere du
// mesh). Chaque SOMMET recoit l'ombre de contact a sa hauteur (voir
// rockContactShade) : la couleur est interpolee d'un sommet a l'autre, d'ou un
// degrade du pied assombri vers le haut clair, sans toucher au shader.
void appendFacet(MeshData& mesh, const glm::vec3& a, const glm::vec3& b,
const glm::vec3& c, const glm::vec3& color) {
const glm::vec3& c, const glm::vec3& color, float top) {
const glm::vec3 raw = glm::cross(b - a, c - a);
const float length = glm::length(raw);
if (length < 1e-9f) {
@@ -33,7 +38,7 @@ void appendFacet(MeshData& mesh, const glm::vec3& a, const glm::vec3& b,
for (const glm::vec3& p : { a, b, c }) {
Vertex v{};
v.pos = p;
v.color = color;
v.color = color * rockContactShade(p.y, top);
v.normal = normal;
mesh.vertices.push_back(v);
}
@@ -76,11 +81,36 @@ void unitSphere(int levels, std::vector<glm::vec3>& points, std::vector<Face>& f
}
}
// PHASE 30 (Agent B) : icosaedre sur la sphere unite (20 faces), orientees vers
// l'exterieur. Sert aux cailloux de la pierraille : l'octaedre (8 faces) se lit
// comme une petite pyramide a 10-25 cm, l'octaedre subdivise (32 faces) coutait
// +0,5 ms par image a 361 plaques (mesure entrelacee, RAPPORT Phase 30).
void unitIcosahedron(std::vector<glm::vec3>& points, std::vector<Face>& faces) {
const float t = 1.6180339887f;
points = { { -1, t, 0 }, { 1, t, 0 }, { -1, -t, 0 }, { 1, -t, 0 },
{ 0, -1, t }, { 0, 1, t }, { 0, -1, -t }, { 0, 1, -t },
{ t, 0, -1 }, { t, 0, 1 }, { -t, 0, -1 }, { -t, 0, 1 } };
for (glm::vec3& p : points) {
p = glm::normalize(p);
}
faces = { {0, 11, 5}, {0, 5, 1}, {0, 1, 7}, {0, 7, 10}, {0, 10, 11},
{1, 5, 9}, {5, 11, 4}, {11, 10, 2}, {10, 7, 6}, {7, 1, 8},
{3, 9, 4}, {3, 4, 2}, {3, 2, 6}, {3, 6, 8}, {3, 8, 9},
{4, 9, 5}, {2, 4, 11}, {6, 2, 10}, {8, 6, 7}, {9, 8, 1} };
// Orientation verifiee plutot que supposee : normale sortante (convexe).
for (Face& f : faces) {
const glm::vec3 n = glm::cross(points[f[1]] - points[f[0]], points[f[2]] - points[f[0]]);
if (glm::dot(n, points[f[0]] + points[f[1]] + points[f[2]]) < 0.0f) {
std::swap(f[1], f[2]);
}
}
}
// Un caillou irregulier : sphere bosselee puis TRONQUEE par `cuts` plans
// aleatoires - chaque plan aplatit une calotte et donne une face de fracture
// franche, ce qui distingue un bloc d'eboulis d'un galet roule.
struct RockShape {
int levels = 1;
int levels = 1; // subdivisions de l'octaedre ; < 0 : icosaedre (20 faces)
float bumpMin = 0.78f;
int cuts = 5;
float cutDepth = 0.72f; // distance du plan au centre (sphere unite)
@@ -94,7 +124,11 @@ struct RockShape {
void appendRock(MeshData& mesh, const RockShape& shape) {
std::vector<glm::vec3> points;
std::vector<Face> faces;
unitSphere(shape.levels, points, faces);
if (shape.levels < 0) {
unitIcosahedron(points, faces);
} else {
unitSphere(shape.levels, points, faces);
}
std::mt19937 rng(shape.seed);
std::uniform_real_distribution<float> unit(0.0f, 1.0f);
@@ -123,11 +157,15 @@ void appendRock(MeshData& mesh, const RockShape& shape) {
p.z += shape.offset.y;
p.y += shape.yOffset;
}
float top = 0.0f;
for (const glm::vec3& p : points) {
top = std::max(top, p.y);
}
// Legere variation de teinte par face (patine, lichen) : sans elle un bloc a
// facettes planes a l'air d'un solide de synthese uniforme.
for (const Face& f : faces) {
const float shade = 0.90f + 0.14f * unit(rng);
appendFacet(mesh, points[f[0]], points[f[1]], points[f[2]], shape.color * shade);
appendFacet(mesh, points[f[0]], points[f[1]], points[f[2]], shape.color * shade, top);
}
}
@@ -144,6 +182,11 @@ MeshData boulderMeshData() {
// Hauteur totale 2 x 0,475 = 0,95 : 0,70 visibles, 0,25 enterres.
shape.halfSize = { 0.52f, 0.475f, 0.44f };
shape.yOffset = kRockVisibleHeight - 0.475f;
// PHASE 30 (Agent B) : patine grise, albedo ~0,53 au lieu de 0,63. Le gros
// bloc etait deja 36 % plus sombre que le sol rendu (Weber -0,36, mesure) ;
// on CREUSE cet ecart, on ne l'inverse surtout pas : eclaircir "pour coller
// au calcaire" fondrait le bloc dans un sol rendu tres clair (~224).
shape.color = kLimestone * 0.85f;
shape.seed = 0xB01DE5u;
appendRock(mesh, shape);
return mesh;
@@ -175,15 +218,26 @@ MeshData gravelMeshData() {
// Disque de rayon 0,5, repartition en racine pour ne pas tasser au centre.
const float angle = 6.28318530718f * unit(rng);
const float radius = 0.44f * std::sqrt(unit(rng));
const float size = 0.05f + 0.07f * unit(rng); // demi-largeur 5 a 12 cm
// PHASE 30 (Agent B) : des CAILLOUX et non du gravier. Demi-largeur 5-12 cm
// -> 10-25 cm : a 5-12 cm, enterres a 60 %, il en depassait 2 a 5 cm, soit
// 2 a 3 px a 10 m (mesure, build-phase30gentA\DIAGNOSTIC.md). Meme
// nombre de tirages qu'avant : la disposition des cailloux est conservee.
const float size = 0.10f + 0.15f * unit(rng);
RockShape shape;
shape.levels = 0; // 8 faces : un caillou de quelques cm n'en montre pas plus
shape.bumpMin = 0.65f;
shape.cuts = 2;
// PHASE 30 : icosaedre, 20 faces (etait l'octaedre, 8). A 10-25 cm de
// demi-largeur, l'octaedre se lisait comme une petite PYRAMIDE (vu sur
// capture). L'octaedre subdivise (32 faces) etait plus rond mais coutait
// +0,5 ms de drawFrame a 361 plaques (mesure entrelacee) ; l'icosaedre +
// trois coupes donne un caillou anguleux et trapu pour 20 faces.
shape.levels = -1;
shape.bumpMin = 0.72f;
shape.cuts = 3;
shape.cutDepth = 0.55f;
shape.halfSize = { size, 0.6f * size, 0.8f * size };
// A moitie enterre : 0,4 x hauteur au-dessus du sol.
shape.yOffset = -0.2f * shape.halfSize.y;
// PHASE 30 : centre a +0,1 demi-hauteur (etait -0,2) : ~55 % de la
// hauteur hors sol au lieu de 40 %, le pied reste enfoui de 0,9 demi-
// hauteur (voir le controle de pose sur le DTM reel, RAPPORT Phase 30).
shape.yOffset = 0.1f * shape.halfSize.y;
shape.offset = { radius * std::cos(angle), radius * std::sin(angle) };
shape.color = kLimestone * (0.85f + 0.2f * unit(rng));
shape.seed = 0x9E11u + static_cast<uint32_t>(i) * 7919u;
+19
Voir le fichier
@@ -38,4 +38,23 @@ inline constexpr float kRockVisibleHeight = 0.70f; // bloc et rocher
inline constexpr float kRockBuriedDepth = 0.25f;
inline constexpr float kRockFootprintRadius = 0.50f;
// PHASE 30 (Agent B) : OMBRE DE CONTACT cuite dans la couleur de sommet. Le
// moteur n'a pas d'ombre portee ; sans elle un bloc pose sur un sol clair n'a
// pas de pied et semble colle a plat. Facteur x kRockContactShade au niveau du
// sol (y <= 0), remontant en smoothstep jusqu'a x1 a kRockContactHeight du
// sommet visible de la piece (`top`, repere du mesh). Aucune modification du
// shader : foliage.vert transmet deja la couleur de sommet.
inline constexpr float kRockContactShade = 0.55f;
inline constexpr float kRockContactHeight = 0.40f;
inline float rockContactShade(float y, float top) {
const float h = kRockContactHeight * top;
if (h <= 0.0f) {
return 1.0f;
}
float t = y / h;
t = t < 0.0f ? 0.0f : (t > 1.0f ? 1.0f : t);
const float smooth = t * t * (3.0f - 2.0f * t);
return kRockContactShade + (1.0f - kRockContactShade) * smooth;
}
} // namespace vercora
+187 -27
Voir le fichier
@@ -70,6 +70,21 @@ Rocks::Rocks(const HeightSampler& terrain, const HeightSampler* cover, float ter
params_.gravelDistanceNear > params_.gravelDistanceFar) {
throw std::runtime_error("Rocks : portee proche au-dela de la portee lointaine.");
}
// PHASE 31 : les emplacements de proximite restent EN DECA des portees
// d'origine (sinon ce ne serait plus de la proximite), et le plafond par
// bloc ne peut jamais retirer une instance d'origine.
if (params_.stoneNearDistanceNear > params_.stoneNearDistanceFar ||
params_.gravelNearDistanceNear > params_.gravelNearDistanceFar ||
params_.stoneNearDistanceFar > params_.stoneDistanceNear ||
params_.gravelNearDistanceFar > params_.gravelDistanceNear ||
params_.nearFadeStart <= 0.0f || params_.nearFadeStart >= 1.0f) {
throw std::runtime_error("Rocks : portees de proximite incoherentes.");
}
const auto cells = static_cast<uint32_t>(kBlockCells * kBlockCells);
if (params_.blockInstanceCap < cells * (params_.boulderSlots + params_.stoneSlots) ||
params_.gravelInstanceCap < cells * params_.gravelSlots) {
throw std::runtime_error("Rocks : plafond par bloc sous le maximum des emplacements d'origine.");
}
}
// ---------------------------------------------------------------------------
@@ -174,12 +189,14 @@ float Rocks::streakDensityAt(float worldX, float worldZ) const {
void Rocks::fitBox(Cell& cell, float baseX, float baseZ, float size) const {
float minY = 0.0f, maxY = 0.0f;
bool first = true;
for (const RockInstance& r : cell.rocks) {
const float lo = r.position.y - kRockBuriedDepth * r.scale;
const float hi = r.position.y + (kRockVisibleHeight + 0.3f) * r.scale;
minY = first ? lo : std::min(minY, lo);
maxY = first ? hi : std::max(maxY, hi);
first = false;
for (const std::vector<RockInstance>* list : { &cell.rocks, &cell.nearRocks }) {
for (const RockInstance& r : *list) {
const float lo = r.position.y - kRockBuriedDepth * r.scale;
const float hi = r.position.y + (kRockVisibleHeight + 0.3f) * r.scale;
minY = first ? lo : std::min(minY, lo);
maxY = first ? hi : std::max(maxY, hi);
first = false;
}
}
if (first) {
minY = maxY = terrain_.heightAt(baseX + 0.5f * size, baseZ + 0.5f * size);
@@ -190,8 +207,8 @@ void Rocks::fitBox(Cell& cell, float baseX, float baseZ, float size) const {
}
bool Rocks::makeCandidate(float x, float z, RockKind kind, uint32_t slot, uint32_t slots,
uint32_t hSize, uint32_t hYaw, uint32_t hTint,
RockInstance& out) const {
uint32_t hSize, uint32_t hYaw, uint32_t hTint, float roughness,
RockInstance& out, bool nearSlot) const {
float sizeMin = 0.0f, sizeMax = 0.0f, far = 0.0f, near = 0.0f;
switch (kind) {
case RockKind::Boulder:
@@ -207,16 +224,59 @@ bool Rocks::makeCandidate(float x, float z, RockKind kind, uint32_t slot, uint32
far = params_.gravelDistanceFar; near = params_.gravelDistanceNear;
break;
}
if (nearSlot) {
// PHASE 31 : seule la PORTEE change ; taille, orientation, teinte et
// assise suivent exactement la loi de la classe.
if (kind == RockKind::Gravel) {
far = params_.gravelNearDistanceFar; near = params_.gravelNearDistanceNear;
} else {
far = params_.stoneNearDistanceFar; near = params_.stoneNearDistanceNear;
}
}
out.nearSlot = nearSlot;
const glm::vec2 gradient = walkTerrainGradient(terrain_, x, z, slopeProbe_.params().slopeSampleStep);
out.kind = kind;
out.position = { x, terrain_.heightAt(x, z), z };
// Taille : loi en carre, les petits sujets dominent comme dans un vrai eboulis.
const float s = unitFloat(hSize);
out.scale = sizeMin + (sizeMax - sizeMin) * s * s;
if (kind == RockKind::Stone) {
// PHASE 30 (Agent B) : un rocher moyen grossit avec la rugosite du DTM au
// point (facteur borne, sans tirage : le hachage `hSize` reste le seul
// alea de taille, et rien de ce qui decide la PRESENCE n'est touche).
// Plafond sous collideMinScale : voir RockParams::stoneSizeCap.
out.scale = std::min(out.scale * rockRoughnessScale(roughness, params_), params_.stoneSizeCap);
}
out.yaw = unitFloat(hYaw) * kTwoPi;
out.variation = packRockVariation(unitFloat(hTint), gradient * params_.tiltFollow);
const float t = slots > 1 ? static_cast<float>(slot) / static_cast<float>(slots - 1) : 0.0f;
out.maxDistance = glm::mix(far, near, t);
if (kind == RockKind::Gravel) {
// PHASE 30 (Agent B) : ASSISE de la plaque. Une plaque est un plan RIGIDE
// (incline par le gradient encode, a 85 %) ; le DTM au pas de 1 m, lui,
// se courbe sous un disque de 1 a 2 m. Mesure sur le DTM reel
// (build-phase30gentB\outils erif.cpp) : 3,2 % des cailloux de la
// Phase 29 avaient leur point bas AU-DESSUS du sol, jusqu'a 0,3 m. On
// sonde le sol sur deux anneaux du disque des cailloux et on ENFONCE la
// plaque de l'ecart maximal plan - sol. x et z ne bougent pas ; seul y
// descend, de quelques cm la ou le sol est convexe. Le plus petit caillou
// a deja 0,45 demi-hauteur (>= 0,027 x echelle) enfouie sous le plan,
// apres ses coupes : on ne compense que l'ecart AU-DELA de cette marge
// (kGravelBuriedMargin), sinon on enterrerait aussi tout ce qui depassait.
constexpr float kGravelBuriedMargin = 0.025f;
const glm::vec2 plane = unpackRockGradient(out.variation); // pente reelle du plan
float sink = 0.0f;
for (const float ring : { 0.22f, 0.44f }) {
const float radius = ring * out.scale;
for (int i = 0; i < 8; ++i) {
const float a = static_cast<float>(i) * (kTwoPi / 8.0f);
const float ox = radius * std::cos(a), oz = radius * std::sin(a);
const float planeY = out.position.y + plane.x * ox + plane.y * oz;
sink = std::max(sink, planeY - terrain_.heightAt(x + ox, z + oz));
}
}
out.position.y -= std::max(0.0f, sink - kGravelBuriedMargin * out.scale);
}
return true;
}
@@ -241,14 +301,37 @@ Rocks::Cell Rocks::buildBlockCell(int32_t cx, int32_t cz) const {
const float allowed = streakDensityAt(x, z) * static_cast<float>(kindSlots);
if (static_cast<float>(kindSlot) >= allowed) { continue; }
// 3. Choix du mesh par la rugosite : les blocs ne vont que sur le rugueux.
if (roughnessAt(x, z) < params_.roughBlocks) { continue; }
const float roughness = roughnessAt(x, z);
if (roughness < params_.roughBlocks) { continue; }
RockInstance r;
makeCandidate(x, z, boulder ? RockKind::Boulder : RockKind::Stone, kindSlot,
kindSlots, cellHash(cx, cz, params_.seed, stream + 2u),
cellHash(cx, cz, params_.seed, stream + 3u),
cellHash(cx, cz, params_.seed, stream + 4u), r);
cellHash(cx, cz, params_.seed, stream + 4u), roughness, r);
cell.rocks.push_back(r);
}
// PHASE 31 : emplacements de PROXIMITE, rochers moyens seulement (jamais
// de gros bloc : l'ensemble des blocs solides ne change pas). Memes trois
// filtres, dans le meme ordre ; flux disjoints (>= 6000, les flux
// d'origine s'arretent a 439) et graine distincte pour le rang.
const uint32_t nearSlots = params_.stoneNearSlots;
const uint32_t nearSeed = params_.seed ^ 0x3C6EF372u;
for (uint32_t slot = 0; slot < nearSlots; ++slot) {
const uint32_t stream = slot * 5u + 6000u;
const float x = baseX + unitFloat(cellHash(cx, cz, nearSeed, stream)) * size;
const float z = baseZ + unitFloat(cellHash(cx, cz, nearSeed, stream + 1u)) * size;
if (!maskAt(x, z)) { continue; }
const float allowed = streakDensityAt(x, z) * static_cast<float>(nearSlots);
if (static_cast<float>(slot) >= allowed) { continue; }
const float roughness = roughnessAt(x, z);
if (roughness < params_.roughBlocks) { continue; }
RockInstance r;
makeCandidate(x, z, RockKind::Stone, slot, nearSlots,
cellHash(cx, cz, nearSeed, stream + 2u), cellHash(cx, cz, nearSeed, stream + 3u),
cellHash(cx, cz, nearSeed, stream + 4u), roughness, r, true);
r.rank = cellHash(cx, cz, nearSeed ^ 0xB5297A4Du, stream);
cell.nearRocks.push_back(r);
}
}
fitBox(cell, baseX, baseZ, size);
return cell;
@@ -281,19 +364,59 @@ Rocks::Cell Rocks::buildGravelCell(int32_t cx, int32_t cz) const {
RockInstance r;
makeCandidate(x, z, RockKind::Gravel, slot, params_.gravelSlots,
cellHash(cx, cz, seed, stream + 2u), cellHash(cx, cz, seed, stream + 3u),
cellHash(cx, cz, seed, stream + 4u), r);
cellHash(cx, cz, seed, stream + 4u), 0.0f, r);
cell.rocks.push_back(r);
}
// PHASE 31 : emplacements de PROXIMITE de la pierraille. Meme masque,
// memes trainees, meme decision de rugosite (au centre de la cellule,
// la MEME valeur que ci-dessus : une cellule rugueuse reste aux blocs).
const uint32_t nearSlots = params_.gravelNearSlots;
const uint32_t nearSeed = seed ^ 0x3C6EF372u;
for (uint32_t slot = 0; slot < nearSlots && !(roughKnown && rough); ++slot) {
const uint32_t stream = slot * 5u + 5000u;
const float x = baseX + unitFloat(cellHash(cx, cz, nearSeed, stream)) * size;
const float z = baseZ + unitFloat(cellHash(cx, cz, nearSeed, stream + 1u)) * size;
if (!maskAt(x, z)) { continue; }
const float allowed = streakDensityAt(x, z) * static_cast<float>(nearSlots);
if (static_cast<float>(slot) >= allowed) { continue; }
if (!roughKnown) {
rough = roughnessAt(baseX + 0.5f * size, baseZ + 0.5f * size) >= params_.roughBlocks;
roughKnown = true;
}
if (rough) { break; }
RockInstance r;
makeCandidate(x, z, RockKind::Gravel, slot, nearSlots,
cellHash(cx, cz, nearSeed, stream + 2u), cellHash(cx, cz, nearSeed, stream + 3u),
cellHash(cx, cz, nearSeed, stream + 4u), 0.0f, r, true);
r.rank = cellHash(cx, cz, nearSeed ^ 0xB5297A4Du, stream);
cell.nearRocks.push_back(r);
}
}
fitBox(cell, baseX, baseZ, size);
return cell;
}
namespace {
std::vector<RockInstance> concatenated(const std::vector<RockInstance>& a, const std::vector<RockInstance>& b) {
std::vector<RockInstance> out;
out.reserve(a.size() + b.size());
out.insert(out.end(), a.begin(), a.end());
out.insert(out.end(), b.begin(), b.end());
return out;
}
} // namespace
std::vector<RockInstance> Rocks::blockCellRocks(int32_t cx, int32_t cz) const {
return buildBlockCell(cx, cz).rocks;
const Cell cell = buildBlockCell(cx, cz);
return concatenated(cell.rocks, cell.nearRocks);
}
std::vector<RockInstance> Rocks::gravelCellRocks(int32_t cx, int32_t cz) const {
return buildGravelCell(cx, cz).rocks;
const Cell cell = buildGravelCell(cx, cz);
return concatenated(cell.rocks, cell.nearRocks);
}
std::vector<RockInstance> Rocks::blockRocks(int32_t bx, int32_t bz, bool gravelGrid) const {
const Cell block = buildBlock(bx, bz, gravelGrid);
return concatenated(block.rocks, block.nearRocks);
}
Rocks::Cell Rocks::buildBlock(int32_t bx, int32_t bz, bool gravelGrid) const {
@@ -307,13 +430,38 @@ Rocks::Cell Rocks::buildBlock(int32_t bx, int32_t bz, bool gravelGrid) const {
for (int32_t i = 0; i < kBlockCells; ++i) {
const int32_t cx = bx * kBlockCells + i, cz = bz * kBlockCells + j;
const Cell cell = gravelGrid ? buildGravelCell(cx, cz) : buildBlockCell(cx, cz);
if (cell.rocks.empty()) { continue; }
if (cell.rocks.empty() && cell.nearRocks.empty()) { continue; }
block.boxMin = first ? cell.boxMin : glm::min(block.boxMin, cell.boxMin);
block.boxMax = first ? cell.boxMax : glm::max(block.boxMax, cell.boxMax);
first = false;
block.rocks.insert(block.rocks.end(), cell.rocks.begin(), cell.rocks.end());
block.nearRocks.insert(block.nearRocks.end(), cell.nearRocks.begin(), cell.nearRocks.end());
}
}
// PHASE 31 : PLAFOND d'instances par bloc. Seules les instances de
// proximite sont eclaircies, en gardant les `rank` les plus petits : un
// tirage uniforme (pas un decoupage par cellule ou par emplacement, qui
// ferait des trous ou casserait le LOD), et independant de l'ordre dans
// lequel les blocs sont semes (le bloc est une fonction pure de (bx, bz)).
// Egalites de rang departagees par l'indice : resultat total et
// deterministe. Les instances d'origine ne sont jamais touchees (le
// constructeur garantit cap >= leur maximum).
const uint32_t cap = gravelGrid ? params_.gravelInstanceCap : params_.blockInstanceCap;
const std::size_t room = cap > block.rocks.size() ? cap - block.rocks.size() : 0;
if (block.nearRocks.size() > room) {
std::vector<uint32_t> order(block.nearRocks.size());
for (uint32_t i = 0; i < order.size(); ++i) { order[i] = i; }
std::sort(order.begin(), order.end(), [&](uint32_t a, uint32_t b) {
const uint32_t ra = block.nearRocks[a].rank, rb = block.nearRocks[b].rank;
return ra != rb ? ra < rb : a < b;
});
order.resize(room);
std::sort(order.begin(), order.end());
std::vector<RockInstance> kept;
kept.reserve(room);
for (const uint32_t i : order) { kept.push_back(block.nearRocks[i]); }
block.nearRocks.swap(kept);
}
return block;
}
@@ -346,6 +494,7 @@ void Rocks::gatherGrid(const glm::vec3& eye, const Frustum& frustum, bool gravel
const float cellSize = gravelGrid ? params_.gravelCell : params_.blockCell;
const float reach = gravelGrid ? params_.gravelDistanceFar
: std::max(params_.boulderDistanceFar, params_.stoneDistanceFar);
const float nearReach = gravelGrid ? params_.gravelNearDistanceFar : params_.stoneNearDistanceFar;
const uint32_t budget = gravelGrid ? params_.gravelCellBudget : params_.blockCellBudget;
Cache& cache = gravelGrid ? gravelCache_ : blockCache_;
const float blockSize = static_cast<float>(kBlockCells) * cellSize;
@@ -385,21 +534,32 @@ void Rocks::gatherGrid(const glm::vec3& eye, const Frustum& frustum, bool gravel
found = cache.emplace(CellKey{ bx, bz }, buildBlock(bx, bz, gravelGrid)).first;
}
const Cell& block = found->second;
if (block.rocks.empty() || !frustum.intersectsAABB(block.boxMin, block.boxMax)) {
if ((block.rocks.empty() && block.nearRocks.empty()) ||
!frustum.intersectsAABB(block.boxMin, block.boxMax)) {
continue;
}
for (const RockInstance& r : block.rocks) {
const glm::vec3 d = eye - r.position;
const float d2 = glm::dot(d, d);
if (d2 >= r.maxDistance * r.maxDistance) { continue; }
const float distance = std::sqrt(d2);
InstanceData instance;
instance.position = r.position;
instance.scale = r.scale;
instance.yaw = r.yaw;
instance.variation = r.variation;
instance.fade = 1.0f - ramp(distance, 0.82f * r.maxDistance, r.maxDistance);
outs[static_cast<int>(r.kind)]->push_back(instance);
const auto emit = [&](const std::vector<RockInstance>& list, float fadeStart) {
for (const RockInstance& r : list) {
const glm::vec3 d = eye - r.position;
const float d2 = glm::dot(d, d);
if (d2 >= r.maxDistance * r.maxDistance) { continue; }
const float distance = std::sqrt(d2);
InstanceData instance;
instance.position = r.position;
instance.scale = r.scale;
instance.yaw = r.yaw;
instance.variation = r.variation;
instance.fade = 1.0f - ramp(distance, fadeStart * r.maxDistance, r.maxDistance);
instance.position.y -= rockFadeSink(r.kind, r.scale, instance.fade);
outs[static_cast<int>(r.kind)]->push_back(instance);
}
};
emit(block.rocks, 0.82f);
// PHASE 31 : les emplacements de proximite ne sont meme pas parcourus
// quand le bloc est hors de leur portee (distance horizontale au bloc,
// qui minore la distance 3D) : aucun surcout lointain.
if (!block.nearRocks.empty() && bdx * bdx + bdz * bdz < nearReach * nearReach) {
emit(block.nearRocks, params_.nearFadeStart);
}
}
}
+94 -6
Voir le fichier
@@ -51,8 +51,26 @@ struct RockParams {
float blockCell = 32.0f;
uint32_t boulderSlots = 8; // au plus 8 gros blocs / 1024 m2 (1 / 128 m2)
uint32_t stoneSlots = 20; // au plus 20 rochers moyens / 1024 m2
// Gros blocs : loi de taille de la Phase 29, INCHANGEE en Phase 30. C'est
// elle qui porte la collision (collideMinScale, rayon x echelle) : la garder
// telle quelle garantit une collision identique au bit pres.
float boulderSizeMin = 1.1f, boulderSizeMax = 2.6f; // echelle (m)
float stoneSizeMin = 0.35f, stoneSizeMax = 0.95f;
// PHASE 30 (Agent B) : rochers moyens 0,35-0,95 -> 0,6-1,4, puis x le
// facteur de rugosite (voir rockRoughnessScale) et plafonnes a stoneSizeCap.
// Mesure (build-phase30gentA\DIAGNOSTIC.md) : a 0,36 m hors sol ils
// n'apportaient que 2 % des pixels de rochers, 3 px de mediane a 35 m.
float stoneSizeMin = 0.60f, stoneSizeMax = 1.40f;
// Plafond STRICTEMENT sous collideMinScale : un rocher moyen n'a pas de
// collision ; il ne doit donc jamais atteindre la taille d'un gros bloc qui
// en a une (sinon on traverserait un bloc d'aspect bloquant).
float stoneSizeCap = 1.29f;
// PHASE 30 : facteur de taille = clamp(rugosite / ref, min, max). Un DTM de
// 0,10 m RMS ne porte pas de blocs de 2 m ; une zone a 0,30 m RMS, si. Ne
// s'applique qu'aux rochers MOYENS (les gros blocs gardent leur loi, voir
// plus haut). Mediane de la rugosite au pied des rochers : 0,16-0,18 m,
// donc un facteur median ~1,1.
float roughScaleRef = 0.15f;
float roughScaleMin = 0.80f, roughScaleMax = 2.00f;
float boulderDistanceFar = 700.0f, boulderDistanceNear = 350.0f;
float stoneDistanceFar = 320.0f, stoneDistanceNear = 140.0f;
@@ -76,6 +94,41 @@ struct RockParams {
// de la pente est lue au centre de chaque tuile de 96 m.
float streakTile = 96.0f;
// --- PHASE 31 (Agent 2) : emplacements de PROXIMITE ---------------------
// Mesure (build-phase30\agentA\DIAGNOSTIC.md, NOTES-PHASE30.md) : le premier
// plan (0-15 m) n'avait AUCUN rocher, faute de densite. On ajoute, dans les
// MEMES cellules et sous le MEME masque (pente, couvert, rugosite -> classe,
// trainees), des emplacements supplementaires a PORTEE COURTE : c'est le LOD
// de densite existant (chaque emplacement a sa portee) prolonge vers le
// joueur. Au-dela de stone/gravelNearDistanceFar ils ne sont ni parcourus
// ni dessines : aucun surcout lointain.
// - rochers moyens seulement (jamais de gros bloc : la collision ne change
// pas), meme loi de taille, donc plafonnes a stoneSizeCap < 1,3 ;
// - pierraille : memes plaques.
// Flux de hachage DISJOINTS de ceux de la Phase 29/30 : les instances
// d'origine sont identiques au bit (empreinte dans les tests).
// Valeurs MESUREES (build-phase31\agent2\RAPPORT.md) : 40 emplacements a
// 48 m ou 60 a 80 m donnent le meme gain d'image au pierrier (6,87 / 6,93 %
// de pixels) ; on garde 60 emplacements (densite proche) sur 60 m.
uint32_t stoneNearSlots = 60; // en plus des 20 : au plus 80 rochers / 1024 m2 pres du joueur
float stoneNearDistanceFar = 60.0f, stoneNearDistanceNear = 18.0f;
uint32_t gravelNearSlots = 24; // en plus des 12 : au plus 36 plaques / 64 m2 pres du joueur
float gravelNearDistanceFar = 26.0f, gravelNearDistanceNear = 12.0f;
// Fondu par retrecissement des emplacements de proximite : sur les 40 %
// derniers de leur portee (0,82 -> 1 pour les autres). Portees courtes,
// donc bande plus large en proportion : une plaque ne doit pas "pousser"
// en 2 m de marche.
float nearFadeStart = 0.60f;
// PLAFOND d'instances par BLOC de cache (8 x 8 cellules), toutes classes.
// Seules les instances de PROXIMITE sont eclaircies pour tenir dessous
// (tirage `rank` uniforme, independant de l'ordre) : les instances
// d'origine, gros blocs compris, ne sont JAMAIS retirees. Le constructeur
// refuse un plafond sous le maximum d'origine (64 x emplacements d'origine).
// Sans plafond, le pire cas theorique serait 64 x 88 = 5 632 (blocs) et
// 64 x 36 = 2 304 (pierraille). Mesure sur la zone : max 1 080 et 1 315.
uint32_t blockInstanceCap = 1792; // = maximum d'origine 64 x 28 (le plafond le plus bas permis)
uint32_t gravelInstanceCap = 1024; // origine : au plus 64 x 12 = 768
// Part de la pente suivie par l'inclinaison du rocher (1 = normale au sol).
float tiltFollow = 0.85f;
@@ -95,6 +148,28 @@ struct RockParams {
enum class RockKind : uint8_t { Boulder = 0, Stone = 1, Gravel = 2 };
// PHASE 30 (Agent B) : facteur de taille des rochers moyens selon la rugosite
// locale du DTM (m). Borne, monotone, sans alea : il ne consomme AUCUN tirage du
// hachage, donc ne change ni la presence ni la position d'aucun rocher.
inline float rockRoughnessScale(float roughness, const RockParams& p) {
const float k = roughness / p.roughScaleRef;
return std::fmin(std::fmax(k, p.roughScaleMin), p.roughScaleMax);
}
// PHASE 31 (Agent 2) : ENFONCEMENT d'une plaque de pierraille pendant son fondu
// (m, a retrancher a y). Le fondu retrecit la plaque vers son origine ; l'assise
// (Rocks::makeCandidate) n'est sondee qu'a pleine echelle, sur deux anneaux. Mesure
// (sonde, 150 m autour des deux sites) : a 30 % d'echelle, 1 a 4 cailloux sur des
// dizaines de milliers ont leur point bas jusqu'a 1 cm AU-DESSUS du sol - defaut
// anterieur a la Phase 31, plus frequent avec la densite. On enfonce donc la plaque
// de 4 cm x echelle x (1 - fondu) : nul a pleine echelle (assise inchangee), et
// la plaque s'enterre en meme temps qu'elle rapetisse. Blocs et rochers : 0 (pied
// au sol, ils ne flottent a aucune echelle, mesure).
constexpr float kGravelFadeSink = 0.04f;
inline float rockFadeSink(RockKind kind, float scale, float fade) {
return kind == RockKind::Gravel ? kGravelFadeSink * scale * (1.0f - fade) : 0.0f;
}
// Encodage de l'inclinaison dans InstanceData::variation (voir shaders/
// foliage.vert, mode rocher = params.w < 0). La struct d'instance est pleine
// (28 o, stride fige) ; plutot que d'en creer une seconde et un second format
@@ -124,6 +199,10 @@ struct RockInstance {
float variation = 0.0f; // deja encode (packRockVariation)
float maxDistance = 0.0f; // portee propre a l'emplacement (LOD de densite)
RockKind kind = RockKind::Gravel;
// PHASE 31 : emplacement de PROXIMITE (portee courte, fondu large, eclairci
// par le plafond du bloc selon `rank`). false = emplacement d'origine.
bool nearSlot = false;
uint32_t rank = 0;
};
class Rocks : public CollisionSolver {
@@ -145,9 +224,15 @@ public:
float roughnessAt(float worldX, float worldZ) const; // m
float streakDensityAt(float worldX, float worldZ) const; // [0,1]
// Tous les candidats RETENUS par le semis d'une cellule (tests).
// Tous les candidats RETENUS par le semis d'une cellule (tests) : origine
// puis proximite, AVANT le plafond par bloc.
std::vector<RockInstance> blockCellRocks(int32_t cx, int32_t cz) const;
std::vector<RockInstance> gravelCellRocks(int32_t cx, int32_t cz) const;
// PHASE 31 : contenu d'un BLOC de cache (kBlockCells x kBlockCells
// cellules), APRES le plafond - exactement ce que gather et la collision
// lisent. Construit a neuf (fonction pure du bloc ; tests, diagnostic).
std::vector<RockInstance> blockRocks(int32_t bx, int32_t bz, bool gravelGrid) const;
static constexpr int32_t kBlockCells = 8;
// Estimation sur toute la zone (une cellule de blocs sur `step`) : part de
// la surface sous masque et nombre de rochers par hectare de masque.
@@ -182,7 +267,8 @@ private:
}
};
struct Cell {
std::vector<RockInstance> rocks;
std::vector<RockInstance> rocks; // emplacements d'origine (Phase 29/30)
std::vector<RockInstance> nearRocks; // PHASE 31 : emplacements de proximite
glm::vec3 boxMin{0.0f}, boxMax{0.0f};
};
using Cache = std::unordered_map<CellKey, Cell, CellKeyHash>;
@@ -190,7 +276,6 @@ private:
Cell buildBlockCell(int32_t cx, int32_t cz) const;
Cell buildGravelCell(int32_t cx, int32_t cz) const;
// Cache par BLOC de kBlockCells x kBlockCells cellules (voir buildBlock).
static constexpr int32_t kBlockCells = 8;
Cell buildBlock(int32_t bx, int32_t bz, bool gravelGrid) const;
const Cell& cachedBlock(int32_t bx, int32_t bz, bool gravelGrid) const;
@@ -199,9 +284,12 @@ private:
std::vector<InstanceData>* outs[3]);
// Candidat a (x, z) : filtre dur + construction. Renvoie false si rejete.
// `roughness` : rugosite deja calculee au point par le semis (blocs) ; sert
// a la taille des rochers moyens (PHASE 30), ignoree pour les autres types.
// `nearSlot` (PHASE 31) : portee tiree de stone/gravelNearDistance*.
bool makeCandidate(float x, float z, RockKind kind, uint32_t slot, uint32_t slots,
uint32_t hSize, uint32_t hYaw, uint32_t hTint,
RockInstance& out) const;
uint32_t hSize, uint32_t hYaw, uint32_t hTint, float roughness,
RockInstance& out, bool nearSlot = false) const;
float coverAt(float worldX, float worldZ) const;
void fitBox(Cell& cell, float baseX, float baseZ, float size) const;