vkmEngine 1.0.15
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
render_settings.h
1#pragma once
2
3#include <algorithm>
4#include <cmath>
5#include <cstddef>
6#include <cstdint>
7#include <iterator>
8
9#include "l_assert.h"
10
11#include "core/reflect.h"
12
13namespace Vkm::Engine {
14
22enum class TextureFiltering : uint8_t {
23 Nearest = 0,
24 Bilinear,
25 Trilinear,
26 Count
27};
28
37#define VKM_RENDER_MODES(X) \
38 X(Default, "Default", DEFAULT, true) \
39 X(Wireframe, "Wireframe", WIREFRAME, true) \
40 X(LightingOnly, "Lighting Only", LIGHTING_ONLY, true) \
41 X(Albedo, "Albedo", ALBEDO, false) \
42 X(Roughness, "Roughness", ROUGHNESS, false) \
43 X(Metalness, "Metalness", METALNESS, false) \
44 X(Normals, "Normals", NORMALS, false) \
45 X(Depth, "Depth", DEPTH, false) \
46 X(AmbientOcclusion, "Ambient Occlusion", AMBIENT_OCCLUSION, false) \
47 X(ScreenShadows, "Screen Shadows", SCREEN_SHADOWS, false) \
48 X(GiOnly, "GI Only", GI_ONLY, true) \
49 X(DirectOnly, "Direct Only", DIRECT_ONLY, true) \
50 X(Clusters, "Light Clusters", CLUSTERS, true) \
51 X(Bloom, "Bloom", BLOOM, false) \
52 X(ShadowAtlas, "Shadow Atlas", SHADOW_ATLAS, false) \
53 X(Fog, "Fog", FOG, false)
54
62#define VKM_TONEMAPS(X) \
63 X(Reinhard, "Reinhard", REINHARD) \
64 X(ACES, "ACES (filmic)", ACES) \
65 X(KhronosNeutral, "Khronos PBR Neutral", KHRONOS_NEUTRAL) \
66 X(AgX, "AgX", AGX)
67
77enum class Tonemap : uint8_t {
78#define VKM_TONEMAP_ENUMERATOR(name, label, glsl) name,
79 VKM_TONEMAPS(VKM_TONEMAP_ENUMERATOR)
80#undef VKM_TONEMAP_ENUMERATOR
81 Count,
82};
83
89enum class RenderMode : uint8_t {
90#define VKM_RENDER_MODE_ENUMERATOR(name, label, glsl, shaded) name,
91 VKM_RENDER_MODES(VKM_RENDER_MODE_ENUMERATOR)
92#undef VKM_RENDER_MODE_ENUMERATOR
93 Count,
94};
95
102 // Debug
103 RenderMode renderMode = RenderMode::Default;
104
105 // Pass toggles
106 bool gtao = true;
107 bool bloom = true;
108 bool probes = true;
109 bool ssr = true;
110 bool screenShadows = true;
111
112 // GTAO
113 float gtaoRadius = 0.6f;
114 float gtaoIntensity = 1.0f;
115 float gtaoPower = 1.5f;
116
117 // Screen-space reflections
118 float ssrMaxRoughness = 0.6f;
119 float ssrMaxDistance = 50.0f;
122 bool ssrHalfResolution = false;
123
124 // Bloom
125 float bloomStrength = 0.06f;
128 float bloomThreshold = 2.0f;
129 float bloomKnee = 0.5f;
130 float bloomRadius = 0.005f;
131
132 // Display transform
133 Tonemap tonemap = Tonemap::ACES;
134
141 float exposure = 1.0f;
142
144 bool autoExposure = false;
147 float exposureMinimum = -4.0f;
148 float exposureMaximum = 8.0f;
151 float adaptBrighter = 1.0f;
152 float adaptDarker = 3.0f;
153
154 // Culling
155 float cullMaxDistance = 500.0f;
156 float cullMinPixels = 3.0f;
163 bool occlusionCulling = false;
164
165 // Anti-aliasing
167 uint32_t msaaSamples = 4;
168
175 TextureFiltering textureFiltering = TextureFiltering::Trilinear;
177 uint32_t textureAnisotropy = 16;
178
179 // Shadows
181 uint32_t shadowResolution = 4096;
188 bool softShadows = true;
189
190 // Resolution
198 float renderScale = 1.0f;
199
200 // Overlays
201 // The editor's world grid: each axis's line, and the plane of every two axes on.
202 bool gridAxisX = false;
203 bool gridAxisY = false;
204 bool gridAxisZ = false;
205
207 static constexpr float MIN_GTAO_RADIUS = 0.05f;
209 static constexpr float MAX_GTAO_RADIUS = 5.0f;
210
211 static constexpr uint32_t MSAA_SAMPLE_COUNTS[] = {1, 2, 4, 8};
212 static constexpr uint32_t SHADOW_RESOLUTIONS[] = {1024, 2048, 4096};
213
215 static constexpr float MIN_RENDER_SCALE = 0.5f;
217 static constexpr float MAX_RENDER_SCALE = 1.0f;
218
229 static float renderScaleFor(uint32_t height, uint32_t viewportHeight) {
230 if (viewportHeight == 0) return 1.0f;
231 const float share = static_cast<float>(height) / static_cast<float>(viewportHeight);
232 return std::clamp(share, MIN_RENDER_SCALE, MAX_RENDER_SCALE);
233 }
234
242 uint32_t sceneExtent(uint32_t viewportPixels) const {
243 const float scale = std::clamp(renderScale, MIN_RENDER_SCALE, MAX_RENDER_SCALE);
244 return static_cast<uint32_t>(std::lround(static_cast<float>(viewportPixels) * scale));
245 }
246
252 bool gridShown() const {
253 return gridAxisX || gridAxisY || gridAxisZ;
254 }
255
262 static bool isMsaaSampleCount(uint32_t samples) {
263 for (const uint32_t count : MSAA_SAMPLE_COUNTS) {
264 if (count == samples) return true;
265 }
266 return false;
267 }
268};
269
280template <typename Settings, typename Fn>
281void visitShippedRenderFields(Settings& r, Fn&& f) {
282 f("gtao", r.gtao);
283 f("bloom", r.bloom);
284 f("probes", r.probes);
285 f("ssr", r.ssr);
286 f("screenShadows", r.screenShadows);
287 f("gtaoRadius", r.gtaoRadius);
288 f("gtaoIntensity", r.gtaoIntensity);
289 f("gtaoPower", r.gtaoPower);
290 f("ssrMaxRoughness", r.ssrMaxRoughness);
291 f("ssrMaxDistance", r.ssrMaxDistance);
292 f("ssrHalfResolution", r.ssrHalfResolution);
293 f("bloomStrength", r.bloomStrength);
294 f("bloomThreshold", r.bloomThreshold);
295 f("bloomKnee", r.bloomKnee);
296 f("bloomRadius", r.bloomRadius);
297 f("tonemap", r.tonemap);
298 f("exposure", r.exposure);
299 f("autoExposure", r.autoExposure);
300 f("exposureMinimum", r.exposureMinimum);
301 f("exposureMaximum", r.exposureMaximum);
302 f("adaptBrighter", r.adaptBrighter);
303 f("adaptDarker", r.adaptDarker);
304 f("cullMaxDistance", r.cullMaxDistance);
305 f("cullMinPixels", r.cullMinPixels);
306 f("occlusionCulling", r.occlusionCulling);
307 f("msaaSamples", r.msaaSamples);
308 f("textureFiltering", r.textureFiltering);
309 f("textureAnisotropy", r.textureAnisotropy);
310 f("shadowResolution", r.shadowResolution);
311 f("softShadows", r.softShadows);
312 f("renderScale", r.renderScale);
313}
314
318enum class GraphicsPreset : uint8_t {
319 Low,
320 Medium,
321 High,
322 Ultra,
323 Count
324};
325
340inline RenderSettings withPreset(const RenderSettings& project, GraphicsPreset preset) {
341 VKM_ASSERT(preset < GraphicsPreset::Count, "withPreset takes a tier, not the Count sentinel");
342 struct Tier {
343 uint32_t msaa;
344 uint32_t shadows;
345 bool gtao;
346 bool screenShadows;
347 bool ssr;
348 bool bloom;
349 uint32_t anisotropy;
350 bool softShadows;
351 float renderScale;
352 bool ssrHalf;
353 };
354 // Low to Ultra, in GraphicsPreset order.
355 static constexpr Tier TIERS[] = {
356 {1, 1024, false, false, false, false, 4, false, 0.67f, true}, // Low
357 {2, 2048, true, true, false, true, 8, false, 0.85f, true}, // Medium
358 {4, 4096, true, true, true, true, 16, true, 1.0f, true}, // High
359 {8, 4096, true, true, true, true, 16, true, 1.0f, false}, // Ultra
360 };
361 static_assert(std::size(TIERS) == static_cast<size_t>(GraphicsPreset::Count));
362 const Tier& tier = TIERS[std::min(static_cast<size_t>(preset), std::size(TIERS) - 1)];
363 RenderSettings r = project;
364 r.msaaSamples = tier.msaa;
365 r.shadowResolution = tier.shadows;
366 r.gtao = project.gtao && tier.gtao;
367 r.screenShadows = project.screenShadows && tier.screenShadows;
368 r.ssr = project.ssr && tier.ssr;
369 r.bloom = project.bloom && tier.bloom;
370 r.textureAnisotropy = tier.anisotropy;
371 r.softShadows = project.softShadows && tier.softShadows;
372 r.renderScale = tier.renderScale;
373 r.ssrHalfResolution = tier.ssrHalf;
374 return r;
375}
376
377} // namespace Vkm::Engine
378
379#define VKM_TONEMAP_LABEL(name, label, glsl) label,
380VKM_ENUM_NAMES(::Vkm::Engine::Tonemap, VKM_TONEMAPS(VKM_TONEMAP_LABEL))
381#undef VKM_TONEMAP_LABEL
382
383#define VKM_RENDER_MODE_LABEL(name, label, glsl, shaded) label,
384VKM_ENUM_NAMES(::Vkm::Engine::RenderMode, VKM_RENDER_MODES(VKM_RENDER_MODE_LABEL))
385#undef VKM_RENDER_MODE_LABEL
386
387VKM_ENUM_NAMES(::Vkm::Engine::TextureFiltering, "Nearest", "Bilinear", "Trilinear")
388
389VKM_ENUM_NAMES(::Vkm::Engine::GraphicsPreset, "Low", "Medium", "High", "Ultra")
Editable render tuning: pass toggles + per-effect parameters.
Definition render_settings.h:101
float cullMaxDistance
World-space.
Definition render_settings.h:155
float exposureMinimum
Definition render_settings.h:147
bool ssr
Screen-space reflections, over the probes and the sky.
Definition render_settings.h:109
float cullMinPixels
Screen-pixel size; 0 disables.
Definition render_settings.h:156
uint32_t shadowResolution
The largest shadow tile's edge, one of SHADOW_RESOLUTIONS, the sun's near cascades'; costly to raise.
Definition render_settings.h:181
TextureFiltering textureFiltering
The frame's default texel sampling; TextureParams::filterOverride outranks it.
Definition render_settings.h:175
float renderScale
The scene's pixels as a share of the viewport's on each axis, MIN_RENDER_SCALE..MAX_RENDER_SCALE.
Definition render_settings.h:198
float bloomStrength
Definition render_settings.h:125
static constexpr float MIN_GTAO_RADIUS
The search divides by the radius, so it is never zero.
Definition render_settings.h:207
bool softShadows
Shadows soft as each light's sourceRadius makes them (PCSS); off, every shadow takes the hard 3x3 fil...
Definition render_settings.h:188
float bloomRadius
Upsample tent radius, fraction of frame width.
Definition render_settings.h:130
float ssrMaxDistance
Definition render_settings.h:119
float ssrMaxRoughness
Rougher surfaces reflect the probes and the sky alone.
Definition render_settings.h:118
bool screenShadows
The cascaded sun's contacts its cascades are too coarse for.
Definition render_settings.h:110
float bloomThreshold
Definition render_settings.h:128
uint32_t msaaSamples
Scene-pass MSAA samples, one of MSAA_SAMPLE_COUNTS; post runs on the resolved buffer.
Definition render_settings.h:167
float adaptBrighter
Definition render_settings.h:151
float bloomKnee
Soft-knee width around the threshold.
Definition render_settings.h:129
static bool isMsaaSampleCount(uint32_t samples)
Whether samples is one of MSAA_SAMPLE_COUNTS.
Definition render_settings.h:262
static constexpr uint32_t SHADOW_RESOLUTIONS[]
What shadowResolution may be.
Definition render_settings.h:212
static constexpr float MAX_GTAO_RADIUS
Past this the search reads the screen, not a neighbourhood.
Definition render_settings.h:209
float gtaoPower
Contrast curve.
Definition render_settings.h:115
bool ssrHalfResolution
Definition render_settings.h:122
static constexpr float MAX_RENDER_SCALE
The scene never renders past the viewport's resolution.
Definition render_settings.h:217
uint32_t sceneExtent(uint32_t viewportPixels) const
viewportPixels at the scene's scale, renderScale clamped to MIN_RENDER_SCALE..MAX_RENDER_SCALE.
Definition render_settings.h:242
bool gridShown() const
Whether the editor's world grid draws at all.
Definition render_settings.h:252
float gtaoIntensity
Occlusion strength.
Definition render_settings.h:114
static constexpr float MIN_RENDER_SCALE
Below half, the upscale is a blur no tier wants.
Definition render_settings.h:215
float gtaoRadius
World-space sample radius, MIN_GTAO_RADIUS..MAX_GTAO_RADIUS.
Definition render_settings.h:113
static constexpr uint32_t MSAA_SAMPLE_COUNTS[]
1 is off.
Definition render_settings.h:211
uint32_t textureAnisotropy
Degree when the mode is Trilinear (1 = off); clamped to the driver's ceiling.
Definition render_settings.h:177
bool occlusionCulling
Cull the opaque geometry other geometry hides, on the GPU.
Definition render_settings.h:163
static float renderScaleFor(uint32_t height, uint32_t viewportHeight)
The renderScale that renders a viewport viewportHeight pixels tall at height.
Definition render_settings.h:229
bool autoExposure
Adapt the exposure to the frame's brightness, as an eye does (system/render/exposure....
Definition render_settings.h:144
float exposure
The exposure in stops: the frame is scaled by 2^exposure before the tonemap.
Definition render_settings.h:141