14#include <glm/gtc/quaternion.hpp>
44 bool init(SDL_Window* window)
override;
51 void drawFrame(glm::vec3 eye,
float yaw,
float pitch,
float roll)
override;
60 bool setVSync(
bool enabled)
override;
70 [[nodiscard]] SDL_GPUDevice*
getDevice()
const override {
return device; }
76 [[nodiscard]] SDL_GPUShaderFormat
getShaderFormat()
const override {
return shaderFormat; }
81 return SDL_GPU_TEXTUREFORMAT_R16G16B16A16_FLOAT;
86 void setEntityRenderList(std::vector<EntityRenderCmd> cmds)
override { entityRenderCmds = std::move(cmds); }
92 void setPointLights(std::vector<PointLight> lights)
override { pointLights = std::move(lights); }
100 if (modelIndex >= 0 &&
static_cast<size_t>(modelIndex) < models.size())
101 for (
auto& m : models[
static_cast<size_t>(modelIndex)].meshes)
102 m.material.emissiveFactor = emissiveFactor;
109 int loadSceneModel(
const char* filename, glm::vec3 pos,
float scale,
bool flipUVs =
false)
override;
126 [[nodiscard]]
int modelCount()
const override {
return static_cast<int>(models.size()); }
142 SDL_Window* window =
nullptr;
143 SDL_GPUDevice* device =
nullptr;
144 SDL_GPUTextureFormat swapchainFormat = SDL_GPU_TEXTUREFORMAT_INVALID;
145 SDL_GPUShaderFormat shaderFormat = SDL_GPU_SHADERFORMAT_INVALID;
150 SDL_GPUGraphicsPipeline* scenePipeline =
nullptr;
151 SDL_GPUGraphicsPipeline* pbrPipeline =
nullptr;
152 SDL_GPUGraphicsPipeline* pbrTransparentPipeline =
nullptr;
153 SDL_GPUGraphicsPipeline* skyboxPipeline =
nullptr;
154 SDL_GPUGraphicsPipeline* tonemapPipeline =
nullptr;
155 SDL_GPUGraphicsPipeline* shadowPipeline =
nullptr;
156 SDL_GPUGraphicsPipeline* sceneShadowPipeline =
nullptr;
159 SDL_GPUTexture* depthTexture =
nullptr;
160 SDL_GPUTexture* weaponDepthTexture =
nullptr;
161 Uint32 depthWidth = 0;
162 Uint32 depthHeight = 0;
164 SDL_GPUTexture* hdrTarget =
nullptr;
166 Uint32 hdrHeight = 0;
168 static constexpr int k_shadowCascades = 4;
169 static constexpr int k_shadowMapSize = 2048;
170 SDL_GPUTexture* shadowMap =
nullptr;
173 SDL_GPUTexture* brdfLUT =
nullptr;
174 SDL_GPUTexture* irradianceMap =
nullptr;
175 SDL_GPUTexture* prefilterMap =
nullptr;
176 SDL_GPUTexture* irradianceWorkMap =
nullptr;
177 SDL_GPUTexture* prefilterWorkMap =
nullptr;
178 SDL_GPUSampler* iblSampler =
nullptr;
179 SDL_GPUTexture* envCubemap =
nullptr;
182 SDL_GPUComputePipeline* brdfLutPipeline =
nullptr;
183 SDL_GPUComputePipeline* irradiancePipeline =
nullptr;
184 SDL_GPUComputePipeline* prefilterPipeline =
nullptr;
187 SDL_GPUSampler* pbrSampler =
nullptr;
188 SDL_GPUSampler* shadowSampler =
nullptr;
189 SDL_GPUSampler* tonemapSampler =
nullptr;
190 SDL_GPUSampler* nearestDepthSampler =
nullptr;
197 SDL_GPUBuffer* vertexBuffer =
nullptr;
198 SDL_GPUBuffer* indexBuffer =
nullptr;
199 Uint32 indexCount = 0;
200 int albedoTexIndex = -1;
201 int normalTexIndex = -1;
202 int metallicRoughnessTexIndex = -1;
203 int emissiveTexIndex = -1;
205 bool isTransparent =
false;
211 std::vector<GpuMesh> meshes;
212 std::vector<SDL_GPUTexture*> textures;
213 glm::mat4 transform{1.0f};
214 bool drawInScenePass =
true;
217 std::vector<ModelInstance> models;
220 SDL_GPUTexture* fallbackWhite =
nullptr;
221 SDL_GPUTexture* fallbackFlatNormal =
nullptr;
222 SDL_GPUTexture* fallbackMR =
nullptr;
223 SDL_GPUTexture* fallbackBlack =
nullptr;
229 std::vector<EntityRenderCmd> entityRenderCmds;
230 std::vector<PointLight> pointLights;
238 struct PendingVertexUpload
240 SDL_GPUBuffer* dstBuffer =
nullptr;
241 std::vector<uint8_t> data;
243 std::vector<PendingVertexUpload> pendingVertexUploads;
245 SDL_GPUTransferBuffer* skinTransferBuf =
nullptr;
246 Uint32 skinTransferBufSize = 0;
249 SDL_GPUTexture* captureRT =
nullptr;
250 Uint32 captureRTW = 0, captureRTH = 0;
251 SDL_GPUTextureFormat captureRTFmt = SDL_GPU_TEXTUREFORMAT_INVALID;
252 std::string pendingCapPath;
255 Uint32 postProcW = 0, postProcH = 0;
258 static constexpr int k_bloomMips = 6;
259 SDL_GPUTexture* bloomMips[k_bloomMips] = {};
260 SDL_GPUComputePipeline* bloomDownsamplePipeline =
nullptr;
261 SDL_GPUComputePipeline* bloomUpsamplePipeline =
nullptr;
264 SDL_GPUTexture* ssaoTexture =
nullptr;
265 SDL_GPUTexture* ssaoBlurTexture =
nullptr;
266 SDL_GPUComputePipeline* ssaoPipeline =
nullptr;
267 SDL_GPUComputePipeline* ssaoBlurPipeline =
nullptr;
268 SDL_GPUTexture* ssaoNoiseTexture =
nullptr;
271 SDL_GPUGraphicsPipeline* smaaEdgePipeline =
nullptr;
272 SDL_GPUGraphicsPipeline* smaaBlendPipeline =
nullptr;
273 SDL_GPUGraphicsPipeline* smaaNeighborhoodPipeline =
275 SDL_GPUComputePipeline* smaaResolvePipeline =
nullptr;
276 SDL_GPUTexture* smaaEdgeTex =
nullptr;
277 SDL_GPUTexture* smaaBlendTex =
nullptr;
278 SDL_GPUTexture* smaaOutputTex =
nullptr;
279 SDL_GPUTexture* smaaAreaTex =
nullptr;
280 SDL_GPUTexture* smaaSearchTex =
nullptr;
283 SDL_GPUComputePipeline* casPipeline =
nullptr;
284 SDL_GPUTexture* casOutputTex =
nullptr;
287 SDL_GPUTexture* taaHistory[2] = {};
288 int taaCurrentIdx = 0;
289 glm::mat4 previousVP{1.0f};
290 SDL_GPUTexture* motionVectorTexture =
nullptr;
291 SDL_GPUComputePipeline* motionVectorPipeline =
nullptr;
297 SDL_GPUTexture* ssrTexture[2] = {};
298 int ssrCurrentIdx = 0;
299 SDL_GPUComputePipeline* ssrPipeline =
nullptr;
340 SDL_GPUTexture* volumetricTexture =
nullptr;
341 SDL_GPUComputePipeline* volumetricPipeline =
nullptr;
344 SDL_GPUTexture* oitAccumTexture =
nullptr;
345 SDL_GPUTexture* oitRevealTexture =
nullptr;
346 SDL_GPUGraphicsPipeline* oitPipeline =
nullptr;
347 SDL_GPUGraphicsPipeline* oitResolvePipeline =
nullptr;
350 bool initScenePipeline();
351 bool initPBRPipeline();
352 bool initSkyboxPipeline();
353 bool initTonemapPipeline();
354 bool initShadowPipeline();
355 bool initSceneShadowPipeline();
366 bool regenerateIBLFromCubemap(SDL_GPUTexture* envCube);
373 bool initVolumetrics();
376 SDL_GPUComputePipeline* createComputePipeline(
const char* shaderName,
378 Uint32 numReadonlyStorageTextures,
379 Uint32 numReadonlyStorageBuffers,
380 Uint32 numReadwriteStorageTextures,
381 Uint32 numReadwriteStorageBuffers,
382 Uint32 numUniformBuffers,
385 Uint32 threadCountZ);
387 bool ensureDepthTexture(Uint32 w, Uint32 h);
390 bool ensureHDRTarget(Uint32 w, Uint32 h);
393 bool ensureCaptureRT(Uint32 w, Uint32 h, SDL_GPUTextureFormat fmt);
396 bool uploadModel(
const LoadedModel& model, ModelInstance& outInstance);
404 SDL_GPUTexture* uploadTexture(
const uint8_t* pixels,
int width,
int height,
bool sRGB =
true);
407 void downloadAndSaveCapture(Uint32 w, Uint32 h);
410 SDL_GPUShader* loadShaderFromFile(
const char* name,
411 SDL_GPUShaderStage stage,
413 Uint32 uniformBufferCount,
414 Uint32 storageBufferCount = 0,
415 Uint32 storageTextureCount = 0);
Abstract renderer interface used by the hybrid dispatcher to route calls to either the legacy rendere...
RendererFeature
Stable identifiers for each dispatchable renderer method.
Definition IRenderer.hpp:31
Assimp-based model loading and CPU-side mesh/texture data types.
Shared data types used across renderer implementations.
AAMode
Anti-aliasing mode selection – exposed to ImGui.
Definition RendererTypes.hpp:13
@ SMAA_T2x
2-sample temporal + spatial SMAA (recommended).
Abstract renderer contract.
Definition IRenderer.hpp:53
Top-level particle system orchestrator.
Definition ParticleSystem.hpp:35
Forward-declared to avoid circular includes.
Definition Renderer.hpp:35
float ambientB
PBR ambient color.
Definition Renderer.hpp:315
const Camera & getCamera() const override
Returns the current camera (updated every drawFrame call).
Definition Renderer.hpp:73
float sharpenStr
Post-TAA sharpening strength.
Definition Renderer.hpp:328
AAMode aaMode
Current AA mode (default: recommended T2x).
Definition Renderer.hpp:306
float sunElevation
Degrees above horizon (default 60° ≈ 11am).
Definition Renderer.hpp:312
bool casEnabled
CAS sharpening on/off.
Definition Renderer.hpp:307
float shadowNormalBiasVal
Definition Renderer.hpp:330
int uploadSceneModel(const LoadedModel &model) override
Upload a pre-built LoadedModel (e.g. from CharacterRig::templateLoadedModel()) and return its index.
Definition Renderer.cpp:3361
int modelCount() const override
Returns the number of loaded models.
Definition Renderer.hpp:126
float iblDiffuseIntensity
Multiplier on IBL diffuse term.
Definition Renderer.hpp:316
void setPointLights(std::vector< PointLight > lights) override
Set dynamic point lights for this frame.
Definition Renderer.hpp:92
void updateModelMeshVertices(int modelIndex, int meshIndex, const ModelVertex *vertices, Uint32 vertexCount) override
Queue a skinned vertex re-upload for one mesh of an animated model.
Definition Renderer.cpp:3376
bool loadHDRSkybox(const std::string &path)
Load an equirectangular HDR image as the environment skybox + IBL source.
Definition Renderer.cpp:1246
float ambientR
Definition Renderer.hpp:315
float shadowDistance
Max shadow range (world units).
Definition Renderer.hpp:331
float ssaoPower
AO power curve (1=linear, higher=softer).
Definition Renderer.hpp:325
bool setVSync(bool enabled) override
Enable or disable vertical sync.
Definition Renderer.cpp:3400
float ssaoRadius
GTAO world-space radius.
Definition Renderer.hpp:323
void drawFrame(glm::vec3 eye, float yaw, float pitch, float roll) override
Render one frame from the given camera pose.
Definition Renderer.cpp:2012
float casStrength
CAS sharpness (0.0 = minimal, 1.0 = max).
Definition Renderer.hpp:308
std::vector< std::string > availableHDRFiles
Available HDR file paths (populated by scanHDRFiles).
Definition Renderer.hpp:134
float ssaoStr
SSAO compositing strength.
Definition Renderer.hpp:322
float ssrStr
SSR compositing strength.
Definition Renderer.hpp:326
float ambientG
Definition Renderer.hpp:315
float iblSpecularIntensity
Multiplier on IBL specular term – default below 1.0 to tame the over-glossy / pseudo-metallic look di...
Definition Renderer.hpp:320
float sunIntensity
Primary directional light intensity.
Definition Renderer.hpp:313
void setModelEmissive(int modelIndex, glm::vec4 emissiveFactor) override
Update the emissive factor on every mesh of a loaded model.
Definition Renderer.hpp:98
std::string currentHDRName
Currently loaded HDR file (display name).
Definition Renderer.hpp:136
float fillIntensity
Fill/bounce light intensity.
Definition Renderer.hpp:314
float bloomStr
Bloom compositing strength.
Definition Renderer.hpp:321
SDL_GPUShaderFormat getShaderFormat() const override
Shader format selected during init() (SPIR-V or MSL).
Definition Renderer.hpp:76
void setParticleSystem(ParticleSystem *ps) override
Register a particle system to be rendered each frame (after scene, before ImGui).
Definition Renderer.hpp:67
static constexpr SDL_GPUTextureFormat getHdrFormat()
HDR render target format (RGBA16F). Particle pipelines must match this.
Definition Renderer.hpp:79
void scanHDRFiles()
Scan the assets HDR directory and populate availableHDRFiles.
Definition Renderer.cpp:1227
float volStr
Volumetric compositing strength.
Definition Renderer.hpp:327
RenderToggles toggles
Live-tunable feature toggles (checked every frame).
Definition Renderer.hpp:303
SDL_GPUDevice * getDevice() const override
Returns the SDL GPU device. Valid between init() and quit().
Definition Renderer.hpp:70
float shadowBiasVal
Definition Renderer.hpp:329
int ssrMode
0=Sharp, 1=Stochastic, 2=Masked (default).
Definition Renderer.hpp:302
float ssaoFalloff
GTAO distance falloff exponent.
Definition Renderer.hpp:324
float sunAzimuth
Degrees, 0=North, 90=East, 180=South (default ~SSW).
Definition Renderer.hpp:311
void setEntityRenderList(std::vector< EntityRenderCmd > cmds) override
Set the list of entity render commands for this frame.
Definition Renderer.hpp:86
void setWeaponViewmodel(const WeaponViewmodel &vm) override
Set the first-person weapon viewmodel for this frame.
Definition Renderer.hpp:106
float cascadeLambda
Log vs linear cascade split blend (0=linear, 1=log).
Definition Renderer.hpp:332
void quit() override
Release all GPU resources and shut down the renderer.
Definition Renderer.cpp:3416
glm::vec3 getSunDirection() const
Compute the sun direction (unit vector TO sun) from azimuth/elevation.
Definition Renderer.cpp:1870
bool useHDRSkybox
True when an HDR cubemap is loaded and should be used for skybox + IBL.
Definition Renderer.hpp:138
bool init(SDL_Window *window) override
Initialise the GPU device, pipelines, and default scene assets.
Definition Renderer.cpp:1600
int loadSceneModel(const char *filename, glm::vec3 pos, float scale, bool flipUVs=false) override
Load a model and return its index in the models[] vector, or -1 on failure.
Definition Renderer.cpp:3292
bool supports(RendererFeature) const override
Report which RendererFeature entries this renderer implements.
Definition Renderer.hpp:39
void requestScreenshot(const std::string &path) override
Queue a screenshot to be saved after the next frame.
Definition Renderer.cpp:3395
Everything returned by loadModel().
Definition ModelLoader.hpp:76
PBR material scalar parameters extracted from Assimp/glTF.
Definition ModelLoader.hpp:41
One vertex in a loaded 3-D model (PBR-ready).
Definition ModelLoader.hpp:19
Live toggles for every render system – exposed to ImGui.
Definition RendererTypes.hpp:24
First-person weapon viewmodel descriptor sent per frame.
Definition RendererTypes.hpp:65