Foundation
Loading...
Searching...
No Matches
Renderer.hpp
Go to the documentation of this file.
1#pragma once
2#include <Math/Math.hpp>
4using namespace Foundation;
5using namespace Foundation::RenderCore;
6#pragma pack(push, 4)
7struct UBO
8{
14 float lodThreshold{0.005f};
15 float zNear;
20 float4 projPlanes; // ij:left, kl:top
21 float aperture{0.0f}; // Aperture radius in world units
24 float apertureRotation{0.0f};
25 float apertureRatio{1.0f};
27 // -- Framebuffers
28 float fbWidth;
29 float fbHeight;
33 // -- Lighting
34 float camEV{0.0f};
37 // Environment light
38 float3 ambientColor{0.05f, 0.05f, 0.05f};
39 float ambientPower{1.0f};
41 float envAzimuthOffset{0.0f}; // [-180, 180]
54 // Scene lights
60 // -- Path Tracing
65 float ptFireflyClamp{1.0f}; // 10^x
66 uint32_t ptSamplesPerPixel{1u}; // Always >= 1; fractional SPP uses ptDispatchTileSide instead.
67 uint32_t ptDispatchTileSide{3u}; // 1 = full dispatch, n > 1 = 1/(n*n) tile dispatch.
68 // -- Debug
71};
72#pragma pack(pop)
73
75{
76 return ubo.ptDispatchTileSide > 0u ? ubo.ptDispatchTileSide : 1u;
77}
78
84
86{
87 return ubo.ptSamplesPerPixel > 0u ? ubo.ptSamplesPerPixel : 1u;
88}
89
91{
92 return ubo.ptAccumulatedFrames / PTTileSampleCount(ubo);
93}
94
95static const int kViewOverdraw = 1 << 0;
96static const int kViewMeshlet = 1 << 1;
97static const int kViewBaseColor = 1 << 2;
98static const int kViewNormal = 1 << 3;
99static const int kViewMaterialID = 1 << 4;
100static const int kViewPosition = 1 << 5;
101static const int kViewPTDirect = 1 << 6;
102
103// Per-lobe AOV view flags (Diffuse / Specular)
104static const int kViewAOVDiffuse = 1 << 7;
105static const int kViewAOVSpecular = 1 << 8;
106static const int kViewTextureLOD = 1 << 9;
107
108static const int kEnableRasterRTShadows = 1 << 16;
109static const int kForceTextureLOD0 = 1 << 24;
110
111static const int kCullFrustum = 1 << 0;
112static const int kCullOcclusion = 1 << 1;
113static const int kCullBackface = 1 << 2;
114
115static const int kCullStageEarly = 1 << 16;
116static const int kCullStageLate = 1 << 17;
117
118static constexpr uint32_t kPTSamplerPCG = 0u;
119static constexpr uint32_t kPTSamplerSobol = 1u;
120
121static constexpr uint32_t kPTCompileOptionSamplerSobol = 1u << 1;
122static constexpr uint32_t kPTCompileOptionSamplerPCG = 1u << 2;
124
127
128inline uint32_t PTPackCompileOptions(uint32_t sampler, bool forceTextureLOD0)
129{
130 uint32_t options = 0u;
132 options |= forceTextureLOD0 ? kPTCompileOptionForceTextureLOD0 : 0u;
133 return options;
134}
135
137{
142 bool forceTextureLOD0{false};
144 bool enableHDR{false}; // Output color space: A2B10G10R10 vs R8G8B8A8
145};
146
147class GPUScene;
148
150{
151 int2 pendingPixel{-1, -1}; // (-1,-1) = no pending pick
152};
153
155{
156 // GPUScene owns all scene-data residency (geometry, instances, lights, materials);
157 // the renderer only carries view/render config and picking state.
160};
161
170
static constexpr uint32_t kCameraProjectionPanoramic
Definition Renderer.hpp:126
static const int kViewBaseColor
Definition Renderer.hpp:97
static constexpr uint32_t kPTCompileOptionSamplerPCG
Definition Renderer.hpp:122
uint32_t PTCompletedPixelSamples(UBO const &ubo)
Definition Renderer.hpp:90
static const int kViewPTDirect
Definition Renderer.hpp:101
static const int kEnableRasterRTShadows
Definition Renderer.hpp:108
static const int kViewAOVDiffuse
Definition Renderer.hpp:104
static const int kCullStageLate
Definition Renderer.hpp:116
static const int kViewPosition
Definition Renderer.hpp:100
static constexpr uint32_t kPTSamplerPCG
Definition Renderer.hpp:118
static constexpr uint32_t kPTSamplerSobol
Definition Renderer.hpp:119
static const int kViewAOVSpecular
Definition Renderer.hpp:105
static const int kViewMeshlet
Definition Renderer.hpp:96
static const int kViewNormal
Definition Renderer.hpp:98
static constexpr uint32_t kPTCompileOptionForceTextureLOD0
Definition Renderer.hpp:123
uint32_t PTTileSampleCount(UBO const &ubo)
Definition Renderer.hpp:79
static const int kCullBackface
Definition Renderer.hpp:113
static const int kCullFrustum
Definition Renderer.hpp:111
static const int kViewOverdraw
Definition Renderer.hpp:95
static const int kCullStageEarly
Definition Renderer.hpp:115
static constexpr uint32_t kPTCompileOptionSamplerSobol
Definition Renderer.hpp:121
static const int kCullOcclusion
Definition Renderer.hpp:112
static const int kViewMaterialID
Definition Renderer.hpp:99
static constexpr uint32_t kCameraProjectionPerspective
Definition Renderer.hpp:125
void BuildRasterRenderGraph(Renderer *renderer, GPUScene *gpu, RendererConfig cfg, RendererScene scene, RHIExtent2D renderExtent, RendererHandles &outHandles)
Definition Rasterizer.cpp:43
uint32_t PTPackCompileOptions(uint32_t sampler, bool forceTextureLOD0)
Definition Renderer.hpp:128
static const int kViewTextureLOD
Definition Renderer.hpp:106
void BuildPathTracerRenderGraph(Renderer *renderer, GPUScene *gpu, RendererConfig cfg, RendererScene scene, RHIExtent2D renderExtent, RendererHandles &outHandles, bool const *renderPaused)
Definition Pathtracer.cpp:11
uint32_t PTDispatchTileSide(UBO const &ubo)
Definition Renderer.hpp:74
uint32_t PTSamplesPerDispatch(UBO const &ubo)
Definition Renderer.hpp:85
static const int kForceTextureLOD0
Definition Renderer.hpp:109
Scoped move-only RAII handle wrapper for RHI Objects.
Definition Details.hpp:86
Renderer implementing a Frame Graph system with automatic resource tracking and synchronization.
Definition Renderer.hpp:89
Owns all GPU-resident scene data (geometry, textures, instance/material/light tables,...
Definition GPUScene.hpp:218
RHIScopedHandle< RHIDevice, T > RHIDeviceScopedHandle
Definition Details.hpp:209
static constexpr Handle kInvalidHandle
Definition Details.hpp:9
glm::vec< 2, uint32_t > RHIExtent2D
Definition Common.hpp:10
Core functionalities for rendering, including the Frame Graph implementation.
Definition Bindless.cpp:2
Handle ResourceHandle
Definition RenderPass.hpp:11
Definition Allocator.hpp:5
Definition Renderer.hpp:137
bool energyCompensation
Definition Renderer.hpp:143
unsigned cullFlags
Definition Renderer.hpp:139
bool enableHDR
Definition Renderer.hpp:144
bool forceTextureLOD0
Definition Renderer.hpp:142
unsigned viewFlags
Definition Renderer.hpp:138
uint32_t ptSampler
Definition Renderer.hpp:140
bool ptShaderExecutionReordering
Definition Renderer.hpp:141
Definition Renderer.hpp:163
ResourceHandle pickBuffer
Definition Renderer.hpp:167
ResourceHandle hdrRT[2]
Definition Renderer.hpp:164
ResourceHandle sdrRT
Definition Renderer.hpp:166
uint32_t numHdrRT
Definition Renderer.hpp:165
Definition Renderer.hpp:150
int2 pendingPixel
Definition Renderer.hpp:151
Definition Renderer.hpp:155
RendererPicking * picking
Definition Renderer.hpp:159
UBO * gsGlobals
Definition Renderer.hpp:158
Definition Renderer.hpp:8
uint32_t useEnvMap
Definition Renderer.hpp:40
uint32_t envMapConditionalCDFIndex
Definition Renderer.hpp:52
uint32_t firstInstance
Definition Renderer.hpp:10
float focalDistance
Definition Renderer.hpp:22
uint32_t apertureBlades
Definition Renderer.hpp:23
uint32_t ptAccumulatedFrames
Definition Renderer.hpp:61
float aperture
Definition Renderer.hpp:21
uint32_t viewLutIndex
Definition Renderer.hpp:49
uint32_t cameraProjection
Definition Renderer.hpp:26
uint32_t firstLightAliasTable
Definition Renderer.hpp:56
uint32_t ggxLutEIORavgIndex
Definition Renderer.hpp:45
float4x4 inverseViewProj
Definition Renderer.hpp:19
float3 ambientColor
Definition Renderer.hpp:38
float fbHeight
Definition Renderer.hpp:29
uint32_t hizHeight
Definition Renderer.hpp:32
float4 camPosition
Definition Renderer.hpp:35
uint32_t frameNumber
Definition Renderer.hpp:9
uint32_t energyCompensation
Definition Renderer.hpp:59
float apertureRatio
Definition Renderer.hpp:25
uint32_t postShowOutline
Definition Renderer.hpp:69
float zNear
Definition Renderer.hpp:15
uint32_t numSceneLights
Definition Renderer.hpp:57
uint32_t ggxLutEIORInvIndex
Definition Renderer.hpp:46
uint32_t firstLight
Definition Renderer.hpp:55
uint32_t ggxLutEIndex
Definition Renderer.hpp:42
uint32_t ptMaxBouncesDiffuse
Definition Renderer.hpp:62
float4 projPlanes
Definition Renderer.hpp:20
uint32_t ggxLutEavgIndex
Definition Renderer.hpp:43
float sceneLightWeightSum
Definition Renderer.hpp:58
float ptFireflyClamp
Definition Renderer.hpp:65
float camEV
Definition Renderer.hpp:34
float4x4 inverseView
Definition Renderer.hpp:18
float ambientPower
Definition Renderer.hpp:39
uint32_t hizWidth
Definition Renderer.hpp:31
uint32_t ggxLutEIORInvavgIndex
Definition Renderer.hpp:47
uint32_t hizLevels
Definition Renderer.hpp:30
float4x4 proj
Definition Renderer.hpp:17
uint32_t sheenLtcIndex
Definition Renderer.hpp:48
uint32_t ptDispatchTileSide
Definition Renderer.hpp:67
uint32_t ptSamplesPerPixel
Definition Renderer.hpp:66
uint32_t ptMaxBouncesSpecular
Definition Renderer.hpp:63
uint32_t envMapMarginalCDFIndex
Definition Renderer.hpp:51
uint32_t numInstances
Definition Renderer.hpp:11
float envAzimuthOffset
Definition Renderer.hpp:41
float apertureRotation
Definition Renderer.hpp:24
float fbWidth
Definition Renderer.hpp:28
uint32_t ptMaxBouncesTransmission
Definition Renderer.hpp:64
uint32_t ptViewFlags
Definition Renderer.hpp:70
uint32_t _envTexturePad0
Definition Renderer.hpp:53
float4x4 view
Definition Renderer.hpp:16
float4 camDirection
Definition Renderer.hpp:36
float lodThreshold
Definition Renderer.hpp:14
uint32_t envMapTextureIndex
Definition Renderer.hpp:50
uint32_t firstMaterial
Definition Renderer.hpp:12
uint32_t ggxLutEIORIndex
Definition Renderer.hpp:44
uint32_t numMaterials
Definition Renderer.hpp:13