26#include <glm/gtc/matrix_transform.hpp>
37#include <unordered_set>
40#include <glm/gtx/string_cast.hpp>
125 float deltaTime = 0.0f,
bool autoClearSwapWindow =
true);
288 unsigned int rgbToId(
unsigned int r,
unsigned int g,
unsigned int b);
368 int mouseX,
int mouseY,
369 int viewWidth,
int viewHeight);
408 const std::vector<kString> &selectedUuids,
410 float thickness = 3.0f);
426 const std::vector<kString> &selectedUuids);
456 uint32_t engineVersion = 0;
459 std::unique_ptr<kOctree> sceneOctree = std::make_unique<kOctree>();
460 bool octreeCullingEnabled =
true;
461 bool octreeDirty =
true;
462 bool octreeDebugEnabled =
false;
463 kCamera *cullingCamera =
nullptr;
464 std::unordered_set<kMesh*> visibleMeshSet;
466 bool currentFrustumValid =
false;
472 kVec4 clearColor =
kVec4(0.0f, 0.0f, 0.0f, 1.0f);
486 bool transparent =
false,
float deltaTime = 0.0f);
497 const kMat4 &lightSpaceMatrix,
498 float deltaTime = 0.0f);
511 bool enableScreenBuffer =
false;
512 kShader *screenShader =
nullptr;
513 uint32_t quadVao = 0, quadVbo = 0, quadEbo = 0;
514 uint32_t fbo = 0, fboTexColor = 0, rboDepth = 0;
515 uint32_t fboMsaa = 0, fboTexColorMsaa = 0, rboDepthMsaa = 0;
517 int fboWidth = 0, fboHeight = 0;
520 static constexpr int kMaxShadowCascades = 4;
521 bool enableShadow =
false;
522 kShader *shadowShader =
nullptr;
523 int shadowResolution = 2048;
524 int shadowCascadeCount = 3;
525 float shadowSplitLambda = 0.85f;
526 bool shadowDebug =
false;
527 float shadowBias = 0.0008f;
528 float shadowNormalBias = 0.003f;
529 float shadowSoftness = 1.5f;
530 uint32_t shadowFbo = 0;
531 uint32_t shadowTexArray = 0;
532 kMat4 lightSpaceMatrices[kMaxShadowCascades];
533 float cascadeSplits[kMaxShadowCascades] = {};
536 bool enablePicking =
false;
537 kShader *pickingShader =
nullptr;
538 kShader *pickingIconShader =
nullptr;
539 uint32_t pickingIconVAO = 0, pickingIconVBO = 0;
540 uint32_t pickFbo = 0, pickFboTex = 0, pickRboDepth = 0;
541 int pickFboWidth = 0, pickFboHeight = 0;
544 kShader *outlineShader =
nullptr;
547 kShader *debugPickShader =
nullptr;
550 kShader *debugAlbedoShader =
nullptr;
551 kShader *debugNormalsShader =
nullptr;
552 kShader *debugWireShader =
nullptr;
553 kShader *debugDepthShader =
nullptr;
556 kShader *debugLineShader =
nullptr;
557 uint32_t debugLineVao = 0;
558 uint32_t debugLineVbo = 0;
571 kShader *shader,
bool wireframe);
574 bool enableAutoExposure =
false;
575 float averageLuminance = 0.0f;
576 float averageLuminanceColor[4] = {};
577 float exposureKey = 0.18f;
578 float exposureAdaptationRate = 2.0f;
579 float exposure = 1.0f;
Scene-graph camera node.
Definition kcamera.h:33
Pure-virtual graphics driver interface.
Definition kdriver.h:86
View frustum defined by six planes extracted from a view-projection matrix.
Definition koctree.h:41
Base scene-graph node.
Definition kobject.h:43
Loose octree that spatially indexes scene meshes for frustum culling.
Definition koctree.h:84
void setEnableShadow(bool newEnable, bool useDefaultShader=true)
Enables or disables shadow mapping.
kShader * getShadowShader()
Returns the current shadow-map shader.
kDriver * getDriver()
Returns the active graphics driver.
float getShadowBias() const
Returns the constant shadow bias.
Definition krenderer.h:221
kCamera * getCullingCamera() const
Returns the override culling camera, or nullptr if using main camera.
Definition krenderer.h:345
void setEnableObjectPicking(bool enable, bool useDefaultShader=true)
Enables or disables the color-ID picking FBO and compiles the built-in picking shader.
int getShadowCascadeCount() const
Returns the active cascade count.
Definition krenderer.h:198
void destroy()
Destroys all GPU resources and the driver.
void renderDebugLines(kWorld *world, const std::vector< kVec3 > &segments, kVec3 color)
Draws world-space line segments in a single colour into the view FBO. Used for editor debug overlays ...
int getShadowResolution() const
Returns the per-cascade shadow-map resolution.
Definition krenderer.h:206
void setOctreeCullingEnabled(bool enable)
Enable or disable octree-based frustum culling (default: enabled).
Definition krenderer.h:318
void setRenderMode(kRenderMode mode)
Sets the debug visualization mode for subsequent render() calls.
float srgbToLinear(float c)
Converts an sRGB component value to linear space.
bool getEnableAutoExposure()
Returns whether automatic exposure adjustment is active.
kShader * getScreenShader()
Returns the current screen-space shader.
void setShadowResolution(int resolution)
Sets the per-cascade shadow-map resolution (e.g. 1024/2048/4096). Rebuilds the shadow texture if shad...
void setShadowNormalBias(float bias)
Sets the slope-scaled (normal) shadow bias passed to lit shaders.
Definition krenderer.h:224
void setShadowSoftness(float softness)
Sets the PCF tap spacing (in shadow-map texels) passed to lit shaders.
Definition krenderer.h:229
void setShadowDebug(bool enable)
Toggles a debug view that tints each cascade a distinct colour.
Definition krenderer.h:214
unsigned int rgbToId(unsigned int r, unsigned int g, unsigned int b)
Converts an RGB colour read back from the GPU to an object ID.
void setCullingCamera(kCamera *camera)
Override the camera used to compute the culling frustum.
Definition krenderer.h:342
bool getEnableShadow()
Returns whether shadow mapping is active.
bool getEnableScreenBuffer()
Returns whether the screen buffer post-process FBO is active.
void setShadowSplitLambda(float lambda)
Sets the cascade split blend: 0 = uniform, 1 = logarithmic.
Definition krenderer.h:209
bool getOctreeDebugEnabled() const
Returns whether octree debug visualization is active.
Definition krenderer.h:432
void setEnableScreenBuffer(bool newEnable, bool useDefaultShader=true)
Enables or disables the off-screen screen buffer (post-process FBO).
void resizeFbo(int newWidth, int newHeight)
Resizes the screen-buffer FBOs to match a new viewport size.
void setOctreeDebugEnabled(bool enable)
Enable or disable octree AABB wireframe debug visualization.
Definition krenderer.h:429
float getShadowSplitLambda() const
Returns the cascade split blend factor.
Definition krenderer.h:211
void setShadowBias(float bias)
Sets the constant shadow bias passed to lit shaders.
Definition krenderer.h:219
void setShadowCascadeCount(int count)
Sets the number of cascades (1..4). Cheap; the underlying texture array always allocates the maximum,...
void clear()
Clears the active framebuffer to the clear colour.
bool getEnableObjectPicking()
Returns whether color-ID object picking is active.
bool init(kWindow *window=nullptr, kRendererType type=kRendererType::RENDERER_GL)
Initialises the renderer and creates the graphics driver.
void renderOutline(kWorld *world, kScene *scene, const std::vector< kString > &selectedUuids, kVec4 color=kVec4(1.0f, 0.6f, 0.0f, 1.0f), float thickness=3.0f)
Renders a color-ID-based outline around selected objects.
void renderOctreeDebug(kWorld *world, kScene *scene)
Draws octree node AABBs and mesh world AABBs as wireframe boxes.
const kOctree & getOctree() const
Returns a reference to the scene octree (read-only).
Definition krenderer.h:348
bool getOctreeCullingEnabled() const
Returns whether octree frustum culling is active.
Definition krenderer.h:330
int getFboHeight()
Returns the current FBO height in pixels.
void render(kWorld *world, kScene *scene, int x, int y, int width, int height, float deltaTime=0.0f, bool autoClearSwapWindow=true)
Renders the scene from the world's main camera.
void setEngineInfo(const kString name, uint32_t version)
Stores an optional application name/version for driver diagnostics.
kVec3 idToRgb(unsigned int i)
Converts a packed integer ID to an RGB colour for object picking.
void renderPickingPass(kWorld *world, kScene *scene, int viewWidth, int viewHeight)
Renders the color-ID picking pass into the picking FBO.
float getShadowNormalBias() const
Returns the slope-scaled shadow bias.
Definition krenderer.h:226
bool getShadowDebug() const
Returns whether the cascade debug view is active.
Definition krenderer.h:216
kRenderMode getRenderMode()
Returns the current debug visualization mode.
kVec4 getClearColor()
Returns the background clear colour.
uint32_t getFboTexture()
Returns the resolved (single-sample) FBO colour texture handle.
void setScreenShader(kShader *newShader)
Sets a custom screen-space shader for post-processing.
void setShadowShader(kShader *newShader)
Sets the shadow-map depth shader.
kObject * pickObject(kWorld *world, kScene *scene, int mouseX, int mouseY, int viewWidth, int viewHeight)
Returns the scene object under the given viewport-relative pixel coordinate using a color-ID render p...
int getFboWidth()
Returns the current FBO width in pixels.
void renderDebugShapes(kWorld *world, kScene *scene, const std::vector< kString > &selectedUuids)
Draws editor debug shapes for selected lights and cameras.
kWindow * getWindow()
Returns the window the renderer was initialised with.
float getShadowSoftness() const
Returns the PCF tap spacing.
Definition krenderer.h:231
void setClearColor(kVec4 newColor)
Sets the background clear colour.
void setEnableAutoExposure(bool newEnable)
Enables or disables automatic exposure adjustment.
void setOctreeDirty()
Marks the static-mesh octree as needing a rebuild.
Definition krenderer.h:327
Holds all objects, lights, and rendering settings for one scene.
Definition kscene.h:36
Wraps a compiled GLSL shader program.
Definition kshader.h:55
Creates and manages an SDL3 application window.
Definition kwindow.h:32
Root container for the entire simulation environment.
Definition kworld.h:54
Perspective camera node (free-look or look-at).
Core type aliases, enumerations, structs, and utility functions used throughout the engine.
Abstract graphics driver interface used by the engine.
Symbol visibility / linkage macro for the Kemena3D library.
#define KEMENA3D_API
Definition kexport.h:35
Light source scene-graph node (point, directional, spotlight).
Polygonal mesh node with skeletal animation support.
Base class for all scene-graph nodes in the Kemena3D engine.
Frustum class and loose octree for scene-level mesh culling.
Container for a self-contained scene (objects, lights, skybox).
GLSL shader program wrapper.
Application window management backed by SDL3.
Top-level container holding scenes and cameras.
Top-level Kemena3D engine namespace.
Definition kanimation.h:23
std::string kString
Standard string alias.
Definition kdatatype.h:42
kRenderMode
Selects the debug visualization mode for the scene viewport.
Definition kdatatype.h:62
@ RENDER_MODE_FULL
Normal fully-lit render.
Definition kdatatype.h:63
kRendererType
Identifies the graphics backend used by kRenderer.
Definition kdatatype.h:54
@ RENDERER_GL
OpenGL renderer.
Definition kdatatype.h:55
glm::vec4 kVec4
4-component float vector.
Definition kdatatype.h:34
glm::vec3 kVec3
3-component float vector.
Definition kdatatype.h:33
glm::mat4 kMat4
4x4 float matrix.
Definition kdatatype.h:39