Skip to content

Editor terrain integration#67

Open
tippesi wants to merge 170 commits intomasterfrom
feature/editor-terrain-integration
Open

Editor terrain integration#67
tippesi wants to merge 170 commits intomasterfrom
feature/editor-terrain-integration

Conversation

@tippesi
Copy link
Copy Markdown
Owner

@tippesi tippesi commented Nov 6, 2024

Summary

Integrates terrain authoring into the Atlas editor and updates the runtime/rendering stack needed to make terrain, vegetation, local lighting, ray tracing, and post-processing work together in editable scenes.

This PR adds editor-facing terrain generation, terrain painting, vegetation generation, spline editing, stronger hierarchy/content workflows, terrain streaming/storage improvements, terrain-aware ray tracing, clustered local lighting, SSR, auto exposure, bloom, and a broader render-state preparation path.

Major Changes

Editor terrain workflow

  • Added a new terrain panel for creating, assigning, editing, baking, and inspecting scene terrain.
  • Added terrain editing mode with height, smooth, flatten, material, and hole brushes.
  • Added controls for terrain height scale, tessellation, LoD distances, wireframe rendering, terrain materials, and physics shape recalculation.
  • Added a terrain generator that can:
    • Generate procedural Perlin heightmaps.
    • Load heightmaps from texture files.
    • Reuse an existing terrain as the source heightmap.
    • Generate basic single-material terrain.
    • Generate biome-based splat maps from elevation, moisture, and slope rules.
    • Preview height, moisture, and biome maps before generation.
  • Added terrain serialization support for generated terrain settings, material slots, biome settings, and referenced resources.
  • Added terrain resource creation under terrains/<name>/<name>.aeterrain.

Vegetation generation

  • Added a procedural vegetation generator and editor panel.
  • Supports multiple vegetation types with source entities, seeds, height/slope filters, excluded terrain material slots, scale/rotation ranges, offsets, and surface alignment.
  • Adds collision and shade-radius checks using spatial queries to reduce overlapping placements.
  • Supports growth iterations and offspring generation for more organic distribution.
  • Generated vegetation is inserted into the scene hierarchy under a generated parent entity.

Editor UX and scene tools

  • Added editor copy/paste helpers for typed single-value and multi-value editor data.
  • Added async file-system operations for copy, delete, duplicate, paste, and content rediscovery.
  • Added ImGuizmo integration for transform, rotate, and scale tools.
  • Expanded the scene viewport toolbar with transform tools, snapping/settings, play/stop controls, viewport settings, and visualization settings.
  • Added viewport ray selection for entities, splines, and terrain.
  • Added scene debug drawing for bounding volumes, cameras, lights, shadow frusta, text rectangles, audio volumes, and splines.
  • Added spline component editing with control-point selection/manipulation, interpolation modes, bake modes, reordering, and point transforms.
  • Expanded hierarchy panel support for multi-selection, async filtering, visibility toggles, drag/drop reparenting, component filters, duplicate/delete operations, and scene-level nodes.
  • Reworked the content browser into a folder/resource workflow with search, recursive filtering, grid multi-select, create/rename/duplicate/delete/copy/paste, external open, prefab creation, and scene drag/drop.
  • Updated geometry brush tooling to support scene creation/deletion using ray casts, terrain-only queries, parent/source drag-drop, surface alignment, and brush configuration.

Terrain runtime

  • Refactored terrain storage around shared terrain storage references and explicit editing state.
  • Added terrain cell request, unload, and BVH queues for async loading and ray-tracing preparation.
  • Added terrain manager support for background loading/unloading of storage cells.
  • Updated terrain storage cells to preserve height/material/normal data, support editing-mode retention, and build BLAS data from terrain triangles.
  • Added terrain ray intersection support for editor picking and brush placement.
  • Updated terrain height queries to account for terrain translation, unloaded cells, invalid heights, and holes.
  • Expanded terrain loading/saving to include material slots, terrain translation, bake resolution, tessellation, LoD distances, height data, normal data, and splat/material data.
  • Added partial terrain cell loading by seeking into saved terrain data.
  • Added terrain baking and update paths that rebuild height, normal, splat, LoD, and GPU texture data.

Terrain tools and brushes

  • Reworked terrain generation to support both single-material and splat/biome material generation.
  • Added heightmap and splat-map resizing paths.
  • Added terrain hole support using invalid height data.
  • Added circular terrain brushes for:
    • Height painting.
    • Smooth height.
    • Flatten height.
    • Material painting.
    • Hole painting.
  • Added normal and splat recalculation around edited cells and neighboring cell borders.
  • Added batched terrain texture uploads through the memory transfer system.
  • Added missing-cell loading for terrain editing and baking.

Rendering architecture

  • Added SceneRenderState to own per-frame render preparation data, including render lists, material buffers, bindless texture state, bindless BLAS state, light buffers, volumetric light buffers, and async preparation jobs.
  • Reworked the main renderer around scene render-state preparation.
  • Consolidated path tracing onto the general render target path and removed the separate path trace render target.
  • Updated render target handling for history, post-processing, bloom, exposure, temporal paths, and path tracing.
  • Reworked the main render sequence across gbuffer, shadows, DDGI, sky/atmosphere, RTGI, SSGI, reflections, volumetrics, ocean, primitives, temporal upscaling/AA, bloom, exposure, and final post-process output.
  • Added cleaner async synchronization points between scene update, renderer preparation, and ray-tracing data updates.

Lighting and shadows

  • Added point and spot light support across editor UI, scene data, serialization, rendering, shadowing, and ray tracing.
  • Added volumetric intensity/local volumetric light handling.
  • Added clustered/tiled local light culling for deferred direct lighting.
  • Added volumetric local light culling.
  • Updated directional light shadows, point cubemap shadows, spot shadows, long-range cascades, and terrain/cloud shadow support.
  • Removed the old point-light vertex/fragment deferred pass in favor of compute/light-culling based direct lighting.

Ray tracing

  • Added a generic BLAS abstraction for mesh and terrain acceleration data.
  • Added a ray tracing manager for background mesh and terrain BLAS construction.
  • Added terrain cell BLAS instances to the ray tracing world.
  • Updated bindless BLAS, material, texture, and terrain normal/tiling data used by ray-traced effects.
  • Updated software and hardware TLAS paths for the new scene/terrain/material structures.
  • Updated ray tracing helpers for point, spot, and directional light data.
  • Updated path tracing, RT reflections, RTGI, DDGI, and ray-tracing shaders to use the new scene, light, material, and acceleration-structure data.

Reflections, GI, AO, and post-processing

  • Added screen-space reflections and shared screen-space tracing helpers.
  • Split deferred indirect lighting into separate indirect diffuse and indirect specular paths.
  • Removed the old AO renderer and old AO shader passes.
  • Updated SSGI, RTGI, DDGI, and reflection denoising/temporal paths.
  • Added auto exposure with histogram and temporal exposure compute passes.
  • Added compute bloom downsample/upsample passes.
  • Updated post-processing to integrate bloom, exposure, temporal history, and the new render target layout.

Shaders

  • Added shared shader helpers for light data, screen-space tracing, and common types.
  • Added bloom shaders under data/shader/bloom.
  • Added exposure shaders under data/shader/exposure.
  • Added deferred light culling and split indirect diffuse/specular shaders.
  • Added SSR shader support under data/shader/reflection.
  • Updated terrain shaders for splat/material data, holes, LoD, normal maps, and translated terrain.
  • Updated volumetric shaders for local light culling and revised volumetric integration.
  • Updated shadow, DDGI, RTGI, SSGI, reflection, path tracing, ray tracing, ocean, cloud, impostor, vegetation, gbuffer, decal, and post-process shaders to match the new render-state, light, terrain, and material layouts.

Scene, ECS, and components

  • Added SplineComponent with linear, Catmull-Rom, and Hermite interpolation plus baked spline data.
  • Updated scene ray casting to support rigid bodies, meshes, text, and terrain.
  • Added scene backup/restore support for editor play mode.
  • Updated scene update flow for scripts, terrain, ocean, hierarchy transforms, physics, cameras, space partitioning, render-state jobs, lights, shadows, ray tracing, and audio.
  • Expanded scene queries with AABB/frustum/ray helpers used by editor tools and vegetation generation.
  • Updated hierarchy, transform, mesh, light, terrain, and spline serialization paths.
  • Updated ECS storage/pool internals to support the new component and editor workflows.

Resources, loaders, and asset data

  • Updated material resources for emissive maps and packed material usage data.
  • Updated model import to handle point/spot lights, emissive textures, improved material import, and better texture handling.
  • Added impostor loading support and updated impostor generation/rendering/shadow paths.
  • Updated mesh data, mesh serialization, resource handles, texture resources, and resource manager paths to support the new renderer/editor expectations.
  • Added generated/editor resource handling for terrain, materials, textures, and imported files.

Job system and async work

  • Added JobSemaphore and Signal.
  • Updated job groups, workers, priority pools, and thread-safe queues.
  • Added async editor filtering/search and background render/terrain/ray-tracing preparation paths.
  • Added explicit waits where editor scene reload, play/stop, rendering, and resource cleanup need completed async work.

Graphics/backend infrastructure

  • Updated graphics buffers, memory transfer, render passes, descriptor binding, image views, acceleration-structure builders, and Vulkan helpers for the new renderer paths.
  • Added batched memory transfer usage for terrain and render data uploads.
  • Updated pipeline and shader binding paths for new compute-heavy lighting, bloom, exposure, terrain, and ray-tracing workflows.

Build, dependencies, CI, and docs

  • Bumped project version to 0.2.1.
  • Updated CMake minimum/version settings and moved the codebase to C++23.
  • Added ImGuizmo/ImPlot related dependency support.
  • Updated vcpkg baseline and dependency overrides, including newer Assimp, ImGui, Jolt, Lua, sol2, Vulkan/SPIR-V tooling, and stb handling.
  • Updated GitHub Actions build/release workflows for newer Vulkan SDK, Ubuntu 24.04, GCC/G++ 14, SwiftShader setup, and release defaults.
  • Updated README version/build requirements.

Tests and demo app

  • Updated the test app for the new render target and resource-handle paths.
  • Removed the separate path tracing render target from tests.
  • Added/updated test toggles for FSR, lights, RTGI, and local volumetrics.
  • Added waits for async scene/render work during scene reload and loading flows.
  • Adjusted test render resolution and configuration flags for the updated renderer.

@tippesi tippesi marked this pull request as ready for review April 4, 2026 12:08
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7efafe4f37

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/editor/tools/TerrainGenerator.cpp Outdated
Comment thread src/editor/tools/ToolSerializer.cpp
Comment on lines +664 to +666
for (auto mat : materials) {
if (mat.first == selectedMaterial) {
pair = mat;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid reading mutable material list from preview worker

The preview generation lambda runs on a background job but reads materials/selectedMaterial through this; the UI thread can modify materials via add/delete actions while the job is running, which is an unsynchronized std::vector access and can lead to intermittent crashes or corrupted preview output. Capture a snapshot of the material state for the job instead of accessing shared mutable members.

Useful? React with 👍 / 👎.

@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 7, 2026

Not up to standards ⛔

🔴 Issues 3 critical · 8 medium

Alerts:
⚠ 11 issues (≤ 0 issues of at least minor severity)

Results:
11 new issues

Category Results
UnusedCode 3 medium
ErrorProne 5 medium
Security 3 critical

View in Codacy

🟢 Metrics 529 complexity · 46 duplication

Metric Results
Complexity 529
Duplication 46

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@tippesi
Copy link
Copy Markdown
Owner Author

tippesi commented Apr 7, 2026

@codex

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b48800b2f5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/editor/tools/TerrainGenerator.cpp Outdated
Comment thread src/editor/tools/ToolSerializer.cpp
Comment on lines +159 to +163
else if (!editingMode && LoDDistances.size()) {
// If we are here it means we have exited editing mode
for (int32_t i = 0; i < terrain->LoDCount; i++) {
terrain->SetLoDDistance(i, LoDDistances[i]);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Clear cached LoD distances after restoring edit mode

When editing mode is turned off, this branch restores distances from LoDDistances but never clears the cache, so it keeps running every frame and can index past the vector if the user later switches to a terrain with more LoDs than were cached. That creates an out-of-bounds read/write path and applies stale LoD values to unrelated terrains.

Useful? React with 👍 / 👎.

@tippesi
Copy link
Copy Markdown
Owner Author

tippesi commented Apr 30, 2026

@codex

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8bbf60513b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +23 to +24
semaphore.acquire();
condition = false;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Prevent lost wakeups in Signal::Wait

Signal::Wait clears condition only after semaphore.acquire() returns, so a concurrent Notify in that window sees condition == true and skips release(). That drops a wakeup and can leave worker threads sleeping even though new jobs were enqueued, which is especially visible in PriorityPool where workers immediately re-enter Wait() after Work().

Useful? React with 👍 / 👎.

Comment on lines +85 to +89
heightData[idx] == FLT_MAX ? FLT_MAX : heightData[idx] * heightFactor,
float(i) * stretchFactor
);

aabb.min = glm::min(aabb.min, vertices[idx]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Exclude hole sentinels from terrain cell bounds

In BuildBVH, hole samples are encoded as FLT_MAX but still fed into aabb.min/max updates. Any cell containing at least one hole will get an effectively unbounded Y extent, which breaks broad-phase culling/queries and can degrade ray-tracing and streaming decisions for that cell.

Useful? React with 👍 / 👎.

Comment on lines +103 to +107
bool hole = heightData[idx] == FLT_MAX || heightData[idx + 1] == FLT_MAX ||
heightData[idx + heightFieldSideLength] == FLT_MAX ||
heightData[idx + heightFieldSideLength + 1] == FLT_MAX;
if (hole)
continue;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Compact triangle indices when skipping hole quads

The index buffer is pre-sized for every quad, but hole quads continue without writing their 6 indices. Later, the code still builds/uploads triangles for the full indices.size(), so skipped quads become zero-index degenerate triangles (vertex 0) in the BLAS, causing incorrect intersections and unnecessary RT workload whenever holes are present.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants