Foundation
Loading...
Searching...
No Matches
EditorState.hpp
Go to the documentation of this file.
1#pragma once
2#include <algorithm>
3#include <cmath>
11#include "Camera.hpp"
12#include "Editor.hpp"
13#include "Runtime/GPUScene.hpp"
14#include "Runtime/Animation.hpp"
15#include "Scene/Scene.hpp"
16#include <RHICore/Swapchain.hpp>
17
19{
20class Presenter;
21}
22
25
26// Renderer back-ends selectable from the editor. Values are persisted (see
27// RendererSettings::defaultRenderer) so only ever append new modes at the end.
28enum class ERendererMode
29{
30 ProgressivePT = 0u, // Offline-style progressive path tracer (accumulates samples).
31 Raster = 1u, // Rasterizer.
32 RealtimePT = 2u, // Realtime path tracer (RTPT).
33};
34
35// Classification helpers. Prefer these over comparing the enum directly so that behaviour
36// shared by a whole family of renderers (accumulation resets, AOVs, PT postprocess, ...)
37// is expressed in one place and keeps working as new modes are added.
38inline constexpr bool IsPathTracer(ERendererMode mode)
39{
41}
42inline constexpr bool IsProgressive(ERendererMode mode)
43{
44 return mode == ERendererMode::ProgressivePT;
45}
46inline constexpr bool IsRaster(ERendererMode mode)
47{
48 return mode == ERendererMode::Raster;
49}
50inline const char* RendererModeDisplayName(ERendererMode mode)
51{
52 switch (mode)
53 {
54 case ERendererMode::ProgressivePT: return "Progressive Path Tracer";
55 case ERendererMode::RealtimePT: return "Realtime Path Tracer";
56 case ERendererMode::Raster: return "Raster";
57 }
58 return "Unknown";
59}
60
61enum class ERenderFormat { HDR, SDR };
62
79
80// Gizmo UI state (matches ImGuizmo::OPERATION and ImGuizmo::MODE)
82{
83 int op{7 /* TRANSLATE */}, mode{0 /* LOCAL */};
84 float translateSnap{1.0f};
85 float rotateSnap{15.0f};
86 float scaleSnap{0.1f};
87 bool showBoundingBox{true};
88 bool showLightGizmos{true};
89 bool showLightBVHBounds{false};
90 bool showImGuizmo{true};
91};
92
94{
95 bool dofEnabled = false;
96 float fStop = 2.8f;
97 float sensorHeightMm = 36.0f;
98};
99
101{
102 ImVec2 contentMin{0.0f, 0.0f};
103 ImVec2 contentMax{0.0f, 0.0f};
105 bool visible{false};
106
107 ImVec2 Size() const
108 {
109 return {
110 std::max(contentMax.x - contentMin.x, 0.0f),
111 std::max(contentMax.y - contentMin.y, 0.0f)
112 };
113 }
114
115 bool HasRect() const
116 {
117 ImVec2 size = Size();
118 return size.x > 0.0f && size.y > 0.0f;
119 }
120
121 bool Contains(ImVec2 pos) const
122 {
123 return HasRect() &&
124 pos.x >= contentMin.x && pos.x < contentMax.x &&
125 pos.y >= contentMin.y && pos.y < contentMax.y;
126 }
127
128 bool WindowPointToRenderPixel(ImVec2 pos, int2& outPixel) const
129 {
130 if (!Contains(pos) || renderExtent.x == 0u || renderExtent.y == 0u)
131 return false;
132
133 ImVec2 size = Size();
134 float u = (pos.x - contentMin.x) / size.x;
135 float v = (pos.y - contentMin.y) / size.y;
136 int x = static_cast<int>(u * static_cast<float>(renderExtent.x));
137 int y = static_cast<int>(v * static_cast<float>(renderExtent.y));
138 outPixel = {
139 std::clamp(x, 0, static_cast<int>(renderExtent.x) - 1),
140 std::clamp(y, 0, static_cast<int>(renderExtent.y) - 1)
141 };
142 return true;
143 }
144};
145
146inline float ApertureRadiusFromFStop(float fStop, float sensorHeight, float fovY)
147{
148 if (fStop <= 0.0f || sensorHeight <= 0.0f)
149 return 0.0f;
150
151 float focalLength = (0.5f * sensorHeight) / std::tan(fovY * 0.5f);
152 return focalLength / (2.0f * fStop);
153}
154
156{
157 // GPUScene owns all scene-data residency (geometry, textures) and the committed
158 // instance/material/light tables. The editor keeps the bindings needed to refill
159 // those tables from the FSCN scene (resident geometry handles, texture remap).
165 // Selection UUIDs; nil == none. Scene index == GPU index (1:1 commit order).
188
193 .center = float3{0, 0, 0},
194 .radius = 1.0f,
195 .zNear = 1e-1f,
196 .fovY = radians(60.f),
197 };
198 bool showImGui = false;
200 bool cameraUpdated = true;
201 float renderResolutionScale = 1.0f; // 0.25 .. 1.0
202 bool rasterGTAO = true;
204
205 [[nodiscard]] bool HasScene() const { return scene.has_value(); }
207 {
208 CHECK(scene.has_value());
209 return *scene;
210 }
211 FImportedScene const& Scene() const
212 {
213 CHECK(scene.has_value());
214 return *scene;
215 }
216 void OpenSceneFile(StringView path, Allocator* scratchAlloc = GLOBAL_ALLOC)
217 {
218 CHECK(scratchAlloc != nullptr);
219 scene.reset();
220 sceneFile.reset();
221 sceneFile.emplace(path, MemoryMappedAccess::ReadOnly);
222 scene.emplace(*sceneFile, scratchAlloc);
223 LoadFSCN(*scene);
224 currentSavePath = path;
225 }
226};
227
228extern EditorState GEditor;
229
230void CommitSceneToGPU(bool resetAccumulation = true);
231void UpdateSceneLights();
233void LoadScene(StringView path);
234void RequestLoadScene(StringView path, StringView envMapPath = {});
235bool PollSceneLoad();
236void LoadEnvMap(StringView path);
239void HandleFile(const char* filePath);
240
242
248void SelectInstance(FUUID instanceId, FUUID materialId);
249void SelectLight(FUUID lightId);
250void ClearSelection();
251void FHierarchyPanel();
252void FLightingPanel();
253void FRunningImGui();
255
256void DoRenderReadback(RendererOutputs const& outputs);
257void FRendering(RendererOutputs const& outputs);
258
260
261// Acquire swapchain image + BeginExecute. Returns acquire result.
263// EndExecute + Present. Returns present result; !RHISwapchainResultMayPresent means recreate swapchain.
#define GLOBAL_ALLOC
Definition Allocator.hpp:240
#define CHECK(expr)
Definition Logging.hpp:92
void ClearMaterialTexturePreviewCache()
Definition EditorUI.cpp:621
constexpr bool IsProgressive(ERendererMode mode)
Definition EditorState.hpp:42
float ApertureRadiusFromFStop(float fStop, float sensorHeight, float fovY)
Definition EditorState.hpp:146
constexpr bool IsPathTracer(ERendererMode mode)
Definition EditorState.hpp:38
int SceneMaterialIndexFromId(FUUID id)
Definition EditorState.cpp:42
bool IsSelectedInstanceValid()
Definition EditorState.cpp:44
bool ApplyMatcapSelection()
Definition EditorScene.cpp:171
void CheckDeferredSceneLoad()
Definition EditorScene.cpp:621
void DoRenderReadback(RendererOutputs const &outputs)
Definition EditorScene.cpp:306
constexpr bool IsRaster(ERendererMode mode)
Definition EditorState.hpp:46
void UpdateSceneLights()
Definition EditorScene.cpp:350
void FLightingPanel()
Definition EditorUI.cpp:2154
void EditorDockSpaceAndMenuBar()
Definition EditorUI.cpp:1614
void LoadScene(StringView path)
Definition EditorScene.cpp:637
ERendererMode
Definition EditorState.hpp:29
void CommitSceneToGPU(bool resetAccumulation=true)
Definition EditorScene.cpp:56
void HandleFile(const char *filePath)
Definition EditorScene.cpp:693
FSerializedBounds const * InstanceResourceBounds(FInstance const &instance)
Definition EditorState.cpp:54
int SceneLightIndexFromId(FUUID id)
Definition EditorState.cpp:40
const char * RendererModeDisplayName(ERendererMode mode)
Definition EditorState.hpp:50
int SceneInstanceIndexFromId(FUUID id)
Definition EditorState.cpp:38
bool ApplyViewLUTSelection()
Definition EditorScene.cpp:157
void LoadEnvMap(StringView path)
Definition EditorScene.cpp:673
ERenderFormat
Definition EditorState.hpp:61
void DeleteSelectedInstance()
Definition EditorScene.cpp:357
bool PollSceneLoad()
Definition EditorScene.cpp:597
void FHierarchyPanel()
Definition EditorUI.cpp:1890
void RequestLoadScene(StringView path, StringView envMapPath={})
Definition EditorScene.cpp:615
EditorState GEditor
Definition EditorState.cpp:11
void SelectInstance(FUUID instanceId, FUUID materialId)
Definition EditorState.cpp:75
void FRendering(RendererOutputs const &outputs)
Definition EditorUI.cpp:3281
void RecreateEditorSwapchain()
Definition EditorState.cpp:29
RHISwapchainResult EditorBeginFrame(Renderer *renderer, Presenter *presenter)
Definition EditorState.cpp:18
void FRunningImGui()
Definition EditorUI.cpp:2551
void ClearSelection()
Definition EditorState.cpp:89
void SelectLight(FUUID lightId)
Definition EditorState.cpp:82
RHISwapchainResult EditorEndFrame(Renderer *renderer, Presenter *presenter)
Definition EditorState.cpp:23
FEditorState
Definition Editor.hpp:6
@ FEInitEnter
Definition Editor.hpp:7
void LoadFSCN(FImportedScene &scene)
Definition Scene.cpp:2064
Allocator interface (noexcept)
Definition Allocator.hpp:29
Definition Presenter.hpp:12
Renderer implementing a Frame Graph system with automatic resource tracking and synchronization.
Definition Renderer.hpp:377
std::basic_string< char, std::char_traits< char >, StlDefaultAllocator< char > > String
Alias for std::basic_string<char>, without an explicit allocator constructor.
Definition Container.hpp:120
std::basic_string_view< char > StringView
Alias for std::basic_string_view<char>
Definition Container.hpp:56
vec3 float3
Definition Math.hpp:26
ivec2 int2
Definition Math.hpp:29
bool RHISwapchainResultMayPresent(RHISwapchainResult result)
Definition Swapchain.hpp:20
glm::vec< 2, uint32_t > RHIExtent2D
Definition Common.hpp:10
RHISwapchainResult
Definition Swapchain.hpp:9
Core functionalities for rendering, including the Frame Graph implementation.
Definition Bindless.cpp:2
Handle ResourceHandle
Definition Renderer.hpp:22
int GetDefaultViewLUTIndex(ViewLUTDomain domain)
Definition Postprocess.cpp:66
Definition EditorState.hpp:94
float sensorHeightMm
Definition EditorState.hpp:97
bool dofEnabled
Definition EditorState.hpp:95
float fStop
Definition EditorState.hpp:96
Definition EditorState.hpp:156
TextureHandle viewLUTHdrHandle
Definition EditorState.hpp:184
TextureHandle viewLUTSdrHandle
Definition EditorState.hpp:183
FUUID selectedLight
Definition EditorState.hpp:168
String matcapExternalPath
Definition EditorState.hpp:186
RenderOutputState renderTask
Definition EditorState.hpp:173
FEditorState state
Definition EditorState.hpp:199
GTAOConfig rasterGTAOConfig
Definition EditorState.hpp:203
int viewLUTSdrIndex
Definition EditorState.hpp:179
Optional< FAnimationRuntime > animation
Definition EditorState.hpp:161
FImportedScene & Scene()
Definition EditorState.hpp:206
float renderResolutionScale
Definition EditorState.hpp:201
bool HasScene() const
Definition EditorState.hpp:205
Optional< FImportedScene > scene
Definition EditorState.hpp:163
FUUID selectedMaterial
Definition EditorState.hpp:167
bool cameraUpdated
Definition EditorState.hpp:200
FArcballCamera camera
Definition EditorState.hpp:192
FUUID selectedInstance
Definition EditorState.hpp:166
FImportedScene const & Scene() const
Definition EditorState.hpp:211
bool rasterGTAO
Definition EditorState.hpp:202
String currentSavePath
Definition EditorState.hpp:164
RendererConfig rendererConfig
Definition EditorState.hpp:177
void OpenSceneFile(StringView path, Allocator *scratchAlloc=GLOBAL_ALLOC)
Definition EditorState.hpp:216
CameraApertureState aperture
Definition EditorState.hpp:175
ResourceHandle postprocessOutput
Definition EditorState.hpp:190
bool applySelectionDoubleClickAction
Definition EditorState.hpp:172
String viewLUTHdrExternalPath
Definition EditorState.hpp:182
FSceneGPUResources resources
Definition EditorState.hpp:160
GizmoState gizmo
Definition EditorState.hpp:174
float selectedLightHighlightStart
Definition EditorState.hpp:170
ERendererMode rendererMode
Definition EditorState.hpp:178
int matcapIndex
Definition EditorState.hpp:185
String viewLUTSdrExternalPath
Definition EditorState.hpp:181
EditorViewportState viewport
Definition EditorState.hpp:176
bool openSelectionContextMenu
Definition EditorState.hpp:171
RendererUBO shaderGlobals
Definition EditorState.hpp:189
TextureHandle matcapHandle
Definition EditorState.hpp:187
Optional< MemoryMappedFile > sceneFile
Definition EditorState.hpp:162
bool scrollSelectedLightToTop
Definition EditorState.hpp:169
PostprocessUBO postprocessGlobals
Definition EditorState.hpp:191
bool showImGui
Definition EditorState.hpp:198
int viewLUTHdrIndex
Definition EditorState.hpp:180
Definition EditorState.hpp:101
bool WindowPointToRenderPixel(ImVec2 pos, int2 &outPixel) const
Definition EditorState.hpp:128
ImVec2 Size() const
Definition EditorState.hpp:107
RHIExtent2D renderExtent
Definition EditorState.hpp:104
ImVec2 contentMax
Definition EditorState.hpp:103
bool Contains(ImVec2 pos) const
Definition EditorState.hpp:121
ImVec2 contentMin
Definition EditorState.hpp:102
bool HasRect() const
Definition EditorState.hpp:115
bool visible
Definition EditorState.hpp:105
Definition Camera.hpp:10
float3 center
Definition Camera.hpp:13
Definition Scene.hpp:376
Definition Scene.hpp:20
Definition GPUScene.hpp:8
Definition Metadata.hpp:14
128-bit identifier. Two flavors, both well-formed per RFC 9562:
Definition UUID.hpp:35
std::optional with convenience Get()/GetIf() methods.
Definition Container.hpp:256
Definition GTAO.hpp:8
Definition EditorState.hpp:82
bool showImGuizmo
Definition EditorState.hpp:90
int op
Definition EditorState.hpp:83
bool showLightBVHBounds
Definition EditorState.hpp:89
float rotateSnap
Definition EditorState.hpp:85
bool showBoundingBox
Definition EditorState.hpp:87
bool showLightGizmos
Definition EditorState.hpp:88
float translateSnap
Definition EditorState.hpp:84
float scaleSnap
Definition EditorState.hpp:86
Definition Renderer.hpp:90
Definition EditorState.hpp:64
float previousResolutionScale
Definition EditorState.hpp:77
ERenderFormat format
Definition EditorState.hpp:65
bool openRenderPopup
Definition EditorState.hpp:71
bool renderAutoPaused
Definition EditorState.hpp:73
int targetSamples
Definition EditorState.hpp:66
int previousSpp
Definition EditorState.hpp:76
int timePopupInput
Definition EditorState.hpp:69
double startTime
Definition EditorState.hpp:70
int targetTimeSeconds
Definition EditorState.hpp:68
int autoPauseSampleLimit
Definition EditorState.hpp:74
int samplePopupInput
Definition EditorState.hpp:67
bool renderPaused
Definition EditorState.hpp:72
String outputPath
Definition EditorState.hpp:75
Definition Renderer.hpp:122
Definition Renderer.hpp:310
Definition Renderer.hpp:11
Definition GPUScene.hpp:54