Foundation
Loading...
Searching...
No Matches
EditorState.hpp
Go to the documentation of this file.
1#pragma once
2#include <algorithm>
3#include <cmath>
12#include "Camera.hpp"
13#include "Editor.hpp"
14#include "Runtime/GPUScene.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{
161 // Selection UUIDs; nil == none. Scene index == GPU index (1:1 commit order).
184
189 .center = float3{0, 0, 0},
190 .radius = 1.0f,
191 .zNear = 1e-1f,
192 .fovY = radians(60.f),
193 };
194 bool showImGui = false;
196 bool cameraUpdated = true;
198 float renderResolutionScale = 1.0f; // 0.25 .. 1.0
199 bool rasterGTAO = true;
201 bool rasterTAA = true;
203
204 [[nodiscard]] bool HasScene() const { return scene.has_value(); }
206 {
207 CHECK(scene.has_value());
208 return *scene;
209 }
210 FImportedScene const& Scene() const
211 {
212 CHECK(scene.has_value());
213 return *scene;
214 }
215 void OpenSceneFile(StringView path, Allocator* scratchAlloc = GLOBAL_ALLOC)
216 {
217 CHECK(scratchAlloc != nullptr);
218 scene.reset();
219 sceneFile.reset();
220 sceneFile.emplace(path, MemoryMappedAccess::ReadOnly);
221 scene.emplace(*sceneFile, scratchAlloc);
222 LoadFSCN(*scene);
223 currentSavePath = path;
224 }
225};
226
227extern EditorState GEditor;
228
229void CommitSceneToGPU(bool resetAccumulation = true);
230void UpdateSceneLights();
232void LoadScene(StringView path);
233void RequestLoadScene(StringView path, StringView envMapPath = {});
234bool PollSceneLoad();
235void LoadEnvMap(StringView path);
238void HandleFile(const char* filePath);
239
241
247void SelectInstance(FUUID instanceId, FUUID materialId);
248void SelectLight(FUUID lightId);
249void ClearSelection();
250void FHierarchyPanel();
251void FLightingPanel();
252void FRunningImGui();
254void UpdateEditorCameraGlobals(Renderer* renderer, RHIExtent2D renderExtent);
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:174
void CheckDeferredSceneLoad()
Definition EditorScene.cpp:614
void DoRenderReadback(RendererOutputs const &outputs)
Definition EditorScene.cpp:309
constexpr bool IsRaster(ERendererMode mode)
Definition EditorState.hpp:46
void UpdateSceneLights()
Definition EditorScene.cpp:353
void FLightingPanel()
Definition EditorUI.cpp:2419
void EditorDockSpaceAndMenuBar()
Definition EditorUI.cpp:1874
void LoadScene(StringView path)
Definition EditorScene.cpp:630
ERendererMode
Definition EditorState.hpp:29
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:50
int SceneInstanceIndexFromId(FUUID id)
Definition EditorState.cpp:38
void UpdateEditorCameraGlobals(Renderer *renderer, RHIExtent2D renderExtent)
Definition EditorState.cpp:101
bool ApplyViewLUTSelection()
Definition EditorScene.cpp:160
void LoadEnvMap(StringView path)
Definition EditorScene.cpp:666
ERenderFormat
Definition EditorState.hpp:61
void DeleteSelectedInstance()
Definition EditorScene.cpp:360
bool PollSceneLoad()
Definition EditorScene.cpp:590
void FHierarchyPanel()
Definition EditorUI.cpp:2155
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:3572
void RecreateEditorSwapchain()
Definition EditorState.cpp:29
RHISwapchainResult EditorBeginFrame(Renderer *renderer, Presenter *presenter)
Definition EditorState.cpp:18
void FRunningImGui()
Definition EditorUI.cpp:2782
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:1776
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:411
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:180
TextureHandle viewLUTSdrHandle
Definition EditorState.hpp:179
FUUID selectedLight
Definition EditorState.hpp:164
String matcapExternalPath
Definition EditorState.hpp:182
RenderOutputState renderTask
Definition EditorState.hpp:169
TAAConfig rasterTAAConfig
Definition EditorState.hpp:202
FEditorState state
Definition EditorState.hpp:195
GTAOConfig rasterGTAOConfig
Definition EditorState.hpp:200
int viewLUTSdrIndex
Definition EditorState.hpp:175
FImportedScene & Scene()
Definition EditorState.hpp:205
float renderResolutionScale
Definition EditorState.hpp:198
bool HasScene() const
Definition EditorState.hpp:204
Optional< FImportedScene > scene
Definition EditorState.hpp:159
FUUID selectedMaterial
Definition EditorState.hpp:163
bool cameraUpdated
Definition EditorState.hpp:196
FArcballCamera camera
Definition EditorState.hpp:188
FUUID selectedInstance
Definition EditorState.hpp:162
FImportedScene const & Scene() const
Definition EditorState.hpp:210
bool rasterGTAO
Definition EditorState.hpp:199
String currentSavePath
Definition EditorState.hpp:160
RendererConfig rendererConfig
Definition EditorState.hpp:173
void OpenSceneFile(StringView path, Allocator *scratchAlloc=GLOBAL_ALLOC)
Definition EditorState.hpp:215
CameraApertureState aperture
Definition EditorState.hpp:171
ResourceHandle postprocessOutput
Definition EditorState.hpp:186
bool applySelectionDoubleClickAction
Definition EditorState.hpp:168
String viewLUTHdrExternalPath
Definition EditorState.hpp:178
FSceneGPUResources resources
Definition EditorState.hpp:157
GizmoState gizmo
Definition EditorState.hpp:170
float selectedLightHighlightStart
Definition EditorState.hpp:166
ERendererMode rendererMode
Definition EditorState.hpp:174
int matcapIndex
Definition EditorState.hpp:181
String viewLUTSdrExternalPath
Definition EditorState.hpp:177
bool rasterTAA
Definition EditorState.hpp:201
EditorViewportState viewport
Definition EditorState.hpp:172
bool openSelectionContextMenu
Definition EditorState.hpp:167
RendererUBO shaderGlobals
Definition EditorState.hpp:185
TextureHandle matcapHandle
Definition EditorState.hpp:183
Optional< MemoryMappedFile > sceneFile
Definition EditorState.hpp:158
bool scrollSelectedLightToTop
Definition EditorState.hpp:165
PostprocessUBO postprocessGlobals
Definition EditorState.hpp:187
bool showImGui
Definition EditorState.hpp:194
bool asyncComputeEnabled
Definition EditorState.hpp:197
int viewLUTHdrIndex
Definition EditorState.hpp:176
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:311
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: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:92
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:131
Definition Renderer.hpp:320
Definition Renderer.hpp:11
Definition TAA.hpp:9
Definition GPUScene.hpp:54