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 "Scene/Scene.hpp"
15#include <RHICore/Swapchain.hpp>
16
18{
19class Presenter;
20}
21
24
25// Renderer back-ends selectable from the editor. Values are persisted (see
26// RendererSettings::defaultRenderer) so only ever append new modes at the end.
27enum class ERendererMode
28{
29 ProgressivePT = 0u, // Offline-style progressive path tracer (accumulates samples).
30 Raster = 1u, // Rasterizer.
31 RealtimePT = 2u, // Realtime path tracer (RTPT).
32};
33
34// Classification helpers. Prefer these over comparing the enum directly so that behaviour
35// shared by a whole family of renderers (accumulation resets, AOVs, PT postprocess, ...)
36// is expressed in one place and keeps working as new modes are added.
37inline constexpr bool IsPathTracer(ERendererMode mode)
38{
40}
41inline constexpr bool IsProgressive(ERendererMode mode)
42{
43 return mode == ERendererMode::ProgressivePT;
44}
45inline constexpr bool IsRaster(ERendererMode mode)
46{
47 return mode == ERendererMode::Raster;
48}
49inline const char* RendererModeDisplayName(ERendererMode mode)
50{
51 switch (mode)
52 {
53 case ERendererMode::ProgressivePT: return "Progressive Path Tracer";
54 case ERendererMode::RealtimePT: return "Realtime Path Tracer";
55 case ERendererMode::Raster: return "Raster";
56 }
57 return "Unknown";
58}
59
60enum class ERenderFormat { HDR, SDR };
61
78
79// Gizmo UI state (matches ImGuizmo::OPERATION and ImGuizmo::MODE)
81{
82 int op{7 /* TRANSLATE */}, mode{0 /* LOCAL */};
83 float translateSnap{1.0f};
84 float rotateSnap{15.0f};
85 float scaleSnap{0.1f};
86 bool showBoundingBox{true};
87 bool showLightGizmos{true};
88 bool showLightBVHBounds{false};
89 bool showImGuizmo{true};
90};
91
93{
94 bool dofEnabled = false;
95 float fStop = 2.8f;
96 float sensorHeightMm = 36.0f;
97};
98
100{
101 ImVec2 contentMin{0.0f, 0.0f};
102 ImVec2 contentMax{0.0f, 0.0f};
104 bool visible{false};
105
106 ImVec2 Size() const
107 {
108 return {
109 std::max(contentMax.x - contentMin.x, 0.0f),
110 std::max(contentMax.y - contentMin.y, 0.0f)
111 };
112 }
113
114 bool HasRect() const
115 {
116 ImVec2 size = Size();
117 return size.x > 0.0f && size.y > 0.0f;
118 }
119
120 bool Contains(ImVec2 pos) const
121 {
122 return HasRect() &&
123 pos.x >= contentMin.x && pos.x < contentMax.x &&
124 pos.y >= contentMin.y && pos.y < contentMax.y;
125 }
126
127 bool WindowPointToRenderPixel(ImVec2 pos, int2& outPixel) const
128 {
129 if (!Contains(pos) || renderExtent.x == 0u || renderExtent.y == 0u)
130 return false;
131
132 ImVec2 size = Size();
133 float u = (pos.x - contentMin.x) / size.x;
134 float v = (pos.y - contentMin.y) / size.y;
135 int x = static_cast<int>(u * static_cast<float>(renderExtent.x));
136 int y = static_cast<int>(v * static_cast<float>(renderExtent.y));
137 outPixel = {
138 std::clamp(x, 0, static_cast<int>(renderExtent.x) - 1),
139 std::clamp(y, 0, static_cast<int>(renderExtent.y) - 1)
140 };
141 return true;
142 }
143};
144
145inline float ApertureRadiusFromFStop(float fStop, float sensorHeight, float fovY)
146{
147 if (fStop <= 0.0f || sensorHeight <= 0.0f)
148 return 0.0f;
149
150 float focalLength = (0.5f * sensorHeight) / std::tan(fovY * 0.5f);
151 return focalLength / (2.0f * fStop);
152}
153
155{
160 // Selection UUIDs; nil == none. Scene index == GPU index (1:1 commit order).
183
188 .center = float3{0, 0, 0},
189 .radius = 1.0f,
190 .zNear = 1e-1f,
191 .fovY = radians(60.f),
192 };
193 bool showImGui = false;
195 bool cameraUpdated = true;
197 float renderResolutionScale = 1.0f; // 0.25 .. 1.0
198 bool rasterGTAO = true;
200
201 [[nodiscard]] bool HasScene() const { return scene.has_value(); }
203 {
204 CHECK(scene.has_value());
205 return *scene;
206 }
207 FImportedScene const& Scene() const
208 {
209 CHECK(scene.has_value());
210 return *scene;
211 }
212 void OpenSceneFile(StringView path, Allocator* scratchAlloc = GLOBAL_ALLOC)
213 {
214 CHECK(scratchAlloc != nullptr);
215 scene.reset();
216 sceneFile.reset();
217 sceneFile.emplace(path, MemoryMappedAccess::ReadOnly);
218 scene.emplace(*sceneFile, scratchAlloc);
219 LoadFSCN(*scene);
220 currentSavePath = path;
221 }
222};
223
224extern EditorState GEditor;
225
226void CommitSceneToGPU(bool resetAccumulation = true);
227void UpdateSceneLights();
229void LoadScene(StringView path);
230void RequestLoadScene(StringView path, StringView envMapPath = {});
231bool PollSceneLoad();
232void LoadEnvMap(StringView path);
235void HandleFile(const char* filePath);
236
238
244void SelectInstance(FUUID instanceId, FUUID materialId);
245void SelectLight(FUUID lightId);
246void ClearSelection();
247void FHierarchyPanel();
248void FLightingPanel();
249void FRunningImGui();
251
252void DoRenderReadback(RendererOutputs const& outputs);
253void FRendering(RendererOutputs const& outputs);
254
256
257// Acquire swapchain image + BeginExecute. Returns acquire result.
259// 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:41
float ApertureRadiusFromFStop(float fStop, float sensorHeight, float fovY)
Definition EditorState.hpp:145
constexpr bool IsPathTracer(ERendererMode mode)
Definition EditorState.hpp:37
int SceneMaterialIndexFromId(FUUID id)
Definition EditorState.cpp:42
bool IsSelectedInstanceValid()
Definition EditorState.cpp:44
bool ApplyMatcapSelection()
Definition EditorScene.cpp:174
void CheckDeferredSceneLoad()
Definition EditorScene.cpp:614
void DoRenderReadback(RendererOutputs const &outputs)
Definition EditorScene.cpp:309
constexpr bool IsRaster(ERendererMode mode)
Definition EditorState.hpp:45
void UpdateSceneLights()
Definition EditorScene.cpp:353
void FLightingPanel()
Definition EditorUI.cpp:2413
void EditorDockSpaceAndMenuBar()
Definition EditorUI.cpp:1874
void LoadScene(StringView path)
Definition EditorScene.cpp:630
ERendererMode
Definition EditorState.hpp:28
void CommitSceneToGPU(bool resetAccumulation=true)
Definition EditorScene.cpp:56
void HandleFile(const char *filePath)
Definition EditorScene.cpp:686
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:49
int SceneInstanceIndexFromId(FUUID id)
Definition EditorState.cpp:38
bool ApplyViewLUTSelection()
Definition EditorScene.cpp:160
void LoadEnvMap(StringView path)
Definition EditorScene.cpp:666
ERenderFormat
Definition EditorState.hpp:60
void DeleteSelectedInstance()
Definition EditorScene.cpp:360
bool PollSceneLoad()
Definition EditorScene.cpp:590
void FHierarchyPanel()
Definition EditorUI.cpp:2149
void RequestLoadScene(StringView path, StringView envMapPath={})
Definition EditorScene.cpp:608
EditorState GEditor
Definition EditorState.cpp:11
void SelectInstance(FUUID instanceId, FUUID materialId)
Definition EditorState.cpp:75
void FRendering(RendererOutputs const &outputs)
Definition EditorUI.cpp:3545
void RecreateEditorSwapchain()
Definition EditorState.cpp:29
RHISwapchainResult EditorBeginFrame(Renderer *renderer, Presenter *presenter)
Definition EditorState.cpp:18
void FRunningImGui()
Definition EditorUI.cpp:2778
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:1778
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:404
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:93
float sensorHeightMm
Definition EditorState.hpp:96
bool dofEnabled
Definition EditorState.hpp:94
float fStop
Definition EditorState.hpp:95
Definition EditorState.hpp:155
TextureHandle viewLUTHdrHandle
Definition EditorState.hpp:179
TextureHandle viewLUTSdrHandle
Definition EditorState.hpp:178
FUUID selectedLight
Definition EditorState.hpp:163
String matcapExternalPath
Definition EditorState.hpp:181
RenderOutputState renderTask
Definition EditorState.hpp:168
FEditorState state
Definition EditorState.hpp:194
GTAOConfig rasterGTAOConfig
Definition EditorState.hpp:199
int viewLUTSdrIndex
Definition EditorState.hpp:174
FImportedScene & Scene()
Definition EditorState.hpp:202
float renderResolutionScale
Definition EditorState.hpp:197
bool HasScene() const
Definition EditorState.hpp:201
Optional< FImportedScene > scene
Definition EditorState.hpp:158
FUUID selectedMaterial
Definition EditorState.hpp:162
bool cameraUpdated
Definition EditorState.hpp:195
FArcballCamera camera
Definition EditorState.hpp:187
FUUID selectedInstance
Definition EditorState.hpp:161
FImportedScene const & Scene() const
Definition EditorState.hpp:207
bool rasterGTAO
Definition EditorState.hpp:198
String currentSavePath
Definition EditorState.hpp:159
RendererConfig rendererConfig
Definition EditorState.hpp:172
void OpenSceneFile(StringView path, Allocator *scratchAlloc=GLOBAL_ALLOC)
Definition EditorState.hpp:212
CameraApertureState aperture
Definition EditorState.hpp:170
ResourceHandle postprocessOutput
Definition EditorState.hpp:185
bool applySelectionDoubleClickAction
Definition EditorState.hpp:167
String viewLUTHdrExternalPath
Definition EditorState.hpp:177
FSceneGPUResources resources
Definition EditorState.hpp:156
GizmoState gizmo
Definition EditorState.hpp:169
float selectedLightHighlightStart
Definition EditorState.hpp:165
ERendererMode rendererMode
Definition EditorState.hpp:173
int matcapIndex
Definition EditorState.hpp:180
String viewLUTSdrExternalPath
Definition EditorState.hpp:176
EditorViewportState viewport
Definition EditorState.hpp:171
bool openSelectionContextMenu
Definition EditorState.hpp:166
RendererUBO shaderGlobals
Definition EditorState.hpp:184
TextureHandle matcapHandle
Definition EditorState.hpp:182
Optional< MemoryMappedFile > sceneFile
Definition EditorState.hpp:157
bool scrollSelectedLightToTop
Definition EditorState.hpp:164
PostprocessUBO postprocessGlobals
Definition EditorState.hpp:186
bool showImGui
Definition EditorState.hpp:193
bool asyncComputeEnabled
Definition EditorState.hpp:196
int viewLUTHdrIndex
Definition EditorState.hpp:175
Definition EditorState.hpp:100
bool WindowPointToRenderPixel(ImVec2 pos, int2 &outPixel) const
Definition EditorState.hpp:127
ImVec2 Size() const
Definition EditorState.hpp:106
RHIExtent2D renderExtent
Definition EditorState.hpp:103
ImVec2 contentMax
Definition EditorState.hpp:102
bool Contains(ImVec2 pos) const
Definition EditorState.hpp:120
ImVec2 contentMin
Definition EditorState.hpp:101
bool HasRect() const
Definition EditorState.hpp:114
bool visible
Definition EditorState.hpp:104
Definition Camera.hpp:10
float3 center
Definition Camera.hpp:13
Definition Scene.hpp:312
Definition Scene.hpp:19
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:81
bool showImGuizmo
Definition EditorState.hpp:89
int op
Definition EditorState.hpp:82
bool showLightBVHBounds
Definition EditorState.hpp:88
float rotateSnap
Definition EditorState.hpp:84
bool showBoundingBox
Definition EditorState.hpp:86
bool showLightGizmos
Definition EditorState.hpp:87
float translateSnap
Definition EditorState.hpp:83
float scaleSnap
Definition EditorState.hpp:85
Definition Renderer.hpp:91
Definition EditorState.hpp:63
float previousResolutionScale
Definition EditorState.hpp:76
ERenderFormat format
Definition EditorState.hpp:64
bool openRenderPopup
Definition EditorState.hpp:70
bool renderAutoPaused
Definition EditorState.hpp:72
int targetSamples
Definition EditorState.hpp:65
int previousSpp
Definition EditorState.hpp:75
int timePopupInput
Definition EditorState.hpp:68
double startTime
Definition EditorState.hpp:69
int targetTimeSeconds
Definition EditorState.hpp:67
int autoPauseSampleLimit
Definition EditorState.hpp:73
int samplePopupInput
Definition EditorState.hpp:66
bool renderPaused
Definition EditorState.hpp:71
String outputPath
Definition EditorState.hpp:74
Definition Renderer.hpp:124
Definition Renderer.hpp:313
Definition Renderer.hpp:11
Definition GPUScene.hpp:54