fix(editor): NPC markers always on top, mesa generator, terrain tools

- NPC markers now render with NO depth test (via gizmo pipeline) so
  they're always visible even on sloped/rough terrain
- Mesa/Plateau generator: creates raised flat areas with steep cliff
  edges — configurable radius, height, and edge steepness
- NPC markers drawn after gizmo in the render pipeline to guarantee
  they appear on top of everything
- Fixes NPC visibility on non-flat terrain
This commit is contained in:
Kelsi 2026-05-05 06:55:04 -07:00
parent 1502c2ed85
commit 88416bbb1d
4 changed files with 64 additions and 15 deletions

View file

@ -551,6 +551,19 @@ void EditorUI::renderBrushPanel(EditorApp& app) {
ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1), "No stamp copied");
}
if (ImGui::CollapsingHeader("Mesa / Plateau")) {
static float mesaRadius = 40.0f, mesaHeight = 20.0f, mesaSteep = 0.3f;
ImGui::SliderFloat("Radius##mesa", &mesaRadius, 10.0f, 150.0f);
ImGui::SliderFloat("Height##mesa", &mesaHeight, 5.0f, 100.0f);
ImGui::SliderFloat("Edge Steepness##mesa", &mesaSteep, 0.05f, 1.0f);
auto& brush6 = app.getTerrainEditor().brush();
if (ImGui::Button("Create Mesa at Cursor", ImVec2(-1, 0)) && brush6.isActive()) {
app.getTerrainEditor().createMesa(brush6.getPosition(), mesaRadius, mesaHeight, mesaSteep);
app.showToast("Mesa created");
}
ImGui::TextColored(ImVec4(0.6f, 0.6f, 0.6f, 1), "Raised flat area with cliff edges");
}
if (ImGui::CollapsingHeader("Crater Generator")) {
static float craterRadius = 30.0f, craterDepth = 10.0f, craterRim = 3.0f;
ImGui::SliderFloat("Radius##crater", &craterRadius, 5.0f, 100.0f);

View file

@ -442,21 +442,7 @@ void EditorViewport::render(VkCommandBuffer cmd) {
waterRenderer_.render(cmd, perFrameSet);
// NPC position markers (always visible)
if (npcMarkerVB_ && npcMarkerVertCount_ > 0) {
auto* wp = waterRenderer_.getPipeline();
auto* wl = waterRenderer_.getPipelineLayout();
static bool loggedOnce = false;
if (!loggedOnce) { loggedOnce = true; LOG_INFO("NPC render: vb=", (wp?"ok":"null"), " layout=", (wl?"ok":"null"), " verts=", npcMarkerVertCount_); }
if (wp && wl) {
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, wp);
vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, wl,
0, 1, &perFrameSet, 0, nullptr);
VkDeviceSize off = 0;
vkCmdBindVertexBuffers(cmd, 0, 1, &npcMarkerVB_, &off);
vkCmdDraw(cmd, npcMarkerVertCount_, 1, 0, 0);
}
}
// NPC position markers — render AFTER gizmo (no depth test = always on top)
// Brush indicator circle
if (brushVisible_ && brushVB_ && brushVertCount_ > 0) {
@ -480,6 +466,18 @@ void EditorViewport::render(VkCommandBuffer cmd) {
}
gizmo_.render(cmd, perFrameSet);
// NPC markers rendered last with no depth test (always on top via gizmo pipeline)
if (npcMarkerVB_ && npcMarkerVertCount_ > 0) {
// Gizmo pipeline has depthTestEnable=VK_FALSE — markers always visible
auto& gizmoPL = gizmo_;
// Re-bind gizmo pipeline (same vertex format, no depth test)
// gizmo_.render already set it up, just draw our buffer
VkDeviceSize off = 0;
vkCmdBindVertexBuffers(cmd, 0, 1, &npcMarkerVB_, &off);
vkCmdDraw(cmd, npcMarkerVertCount_, 1, 0, 0);
(void)gizmoPL;
}
}
void EditorViewport::setWireframe(bool enabled) {

View file

@ -805,6 +805,41 @@ void TerrainEditor::createCrater(const glm::vec3& center, float radius, float de
dirty_ = true;
}
void TerrainEditor::createMesa(const glm::vec3& center, float radius, float height, float edgeSteepness) {
if (!terrain_) return;
for (int ci = 0; ci < 256; ci++) {
auto& chunk = terrain_->chunks[ci];
if (!chunk.hasHeightMap()) continue;
bool modified = false;
for (int v = 0; v < 145; v++) {
glm::vec3 pos = chunkVertexWorldPos(ci, v);
float dist = glm::length(glm::vec2(pos.x - center.x, pos.y - center.y));
if (dist > radius * 1.5f) continue;
float t = dist / radius;
float blend;
if (t < 0.7f) {
blend = 1.0f; // flat top
} else if (t < 1.0f) {
float edgeT = (t - 0.7f) / 0.3f;
blend = 1.0f - std::pow(edgeT, 1.0f / std::max(0.1f, edgeSteepness));
} else {
blend = 0.0f;
}
chunk.heightMap.heights[v] += height * blend;
modified = true;
}
if (modified) {
stitchEdges(ci);
dirtyChunks_.push_back(ci);
}
}
dirty_ = true;
}
void TerrainEditor::flattenRoad(const glm::vec3& start, const glm::vec3& end, float width) {
if (!terrain_) return;
glm::vec2 lineStart(start.x, start.y);

View file

@ -84,6 +84,9 @@ public:
// Create a crater at a position (bowl shape with raised rim)
void createCrater(const glm::vec3& center, float radius, float depth, float rimHeight);
// Create a mesa/plateau (raised flat area with steep cliff edges)
void createMesa(const glm::vec3& center, float radius, float height, float edgeSteepness);
// Import/export heightmap (raw 16-bit grayscale, 129x129)
bool importHeightmap(const std::string& path, float heightScale);
bool exportHeightmap(const std::string& path, float heightScale);