2026-02-02 12:24:50 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <glm/glm.hpp>
|
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
|
|
|
|
|
|
namespace wowee {
|
|
|
|
|
namespace rendering {
|
|
|
|
|
|
|
|
|
|
struct Ray {
|
|
|
|
|
glm::vec3 origin;
|
|
|
|
|
glm::vec3 direction;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Camera {
|
|
|
|
|
public:
|
|
|
|
|
Camera();
|
|
|
|
|
|
|
|
|
|
void setPosition(const glm::vec3& pos) { position = pos; updateViewMatrix(); }
|
|
|
|
|
void setRotation(float yaw, float pitch) { this->yaw = yaw; this->pitch = pitch; updateViewMatrix(); }
|
|
|
|
|
void setAspectRatio(float aspect) { aspectRatio = aspect; updateProjectionMatrix(); }
|
|
|
|
|
void setFov(float fov) { this->fov = fov; updateProjectionMatrix(); }
|
|
|
|
|
|
|
|
|
|
const glm::vec3& getPosition() const { return position; }
|
|
|
|
|
const glm::mat4& getViewMatrix() const { return viewMatrix; }
|
|
|
|
|
const glm::mat4& getProjectionMatrix() const { return projectionMatrix; }
|
2026-03-07 23:13:01 -08:00
|
|
|
const glm::mat4& getUnjitteredProjectionMatrix() const { return unjitteredProjectionMatrix; }
|
2026-02-02 12:24:50 -08:00
|
|
|
glm::mat4 getViewProjectionMatrix() const { return projectionMatrix * viewMatrix; }
|
2026-03-07 23:13:01 -08:00
|
|
|
glm::mat4 getUnjitteredViewProjectionMatrix() const { return unjitteredProjectionMatrix * viewMatrix; }
|
2026-02-02 12:24:50 -08:00
|
|
|
float getAspectRatio() const { return aspectRatio; }
|
2026-03-08 19:56:52 -07:00
|
|
|
float getFovDegrees() const { return fov; }
|
|
|
|
|
float getNearPlane() const { return nearPlane; }
|
|
|
|
|
float getFarPlane() const { return farPlane; }
|
2026-02-02 12:24:50 -08:00
|
|
|
|
2026-03-07 23:13:01 -08:00
|
|
|
// Sub-pixel jitter for temporal upscaling (FSR 2)
|
|
|
|
|
void setJitter(float jx, float jy);
|
|
|
|
|
void clearJitter();
|
|
|
|
|
glm::vec2 getJitter() const { return jitterOffset; }
|
|
|
|
|
|
2026-02-02 12:24:50 -08:00
|
|
|
glm::vec3 getForward() const;
|
|
|
|
|
glm::vec3 getRight() const;
|
|
|
|
|
glm::vec3 getUp() const;
|
|
|
|
|
|
|
|
|
|
Ray screenToWorldRay(float screenX, float screenY, float screenW, float screenH) const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void updateViewMatrix();
|
|
|
|
|
void updateProjectionMatrix();
|
|
|
|
|
|
|
|
|
|
glm::vec3 position = glm::vec3(0.0f);
|
|
|
|
|
float yaw = 0.0f;
|
|
|
|
|
float pitch = 0.0f;
|
|
|
|
|
float fov = 45.0f;
|
|
|
|
|
float aspectRatio = 16.0f / 9.0f;
|
feat(rendering): GPU architecture + visual quality fixes
M2 GPU instancing
- M2InstanceGPU SSBO (96 B/entry, double-buffered, 16384 max)
- Group opaque instances by (modelId, LOD); single vkCmdDrawIndexed per group
- boneBase field indexes into mega bone SSBO via gl_InstanceIndex
Indirect terrain drawing
- 24 MB mega index buffer (6M uint32) + 64 MB mega vertex buffer
- CPU builds VkDrawIndexedIndirectCommand per visible chunk
- Single VB/IB bind per frame; shadow pass reuses mega buffers
- Replaced vkCmdDrawIndexedIndirect with direct vkCmdDrawIndexed to fix
host-mapped buffer race condition that caused terrain flickering
GPU frustum culling (compute shader)
- m2_cull.comp.glsl: 64-thread workgroups, sphere-vs-6-planes + distance cull
- CullInstanceGPU SSBO input, uint visibility[] output, double-buffered
- dispatchCullCompute() runs before main pass via render graph node
Consolidated bone matrix SSBOs
- 16 MB double-buffered mega bone SSBO (2048 instances × 128 bones)
- Eliminated per-instance descriptor sets; one megaBoneSet_ per frame
- prepareRender() packs bone matrices consecutively into current frame slot
Render graph / frame graph
- RenderGraph: RGResource handles, RGPass nodes, Kahn topological sort
- Automatic VkImageMemoryBarrier/VkBufferMemoryBarrier between passes
- Passes: minimap_composite, worldmap_composite, preview_composite,
shadow_pass, reflection_pass, compute_cull
- beginFrame() uses buildFrameGraph() + renderGraph_->execute(cmd)
Pipeline derivatives
- PipelineBuilder::setFlags/setBasePipeline for VK_PIPELINE_CREATE_DERIVATIVE_BIT
- M2 opaque = base; alphaTest/alpha/additive are derivatives
- Applied to terrain (wireframe) and WMO (alpha-test) renderers
Rendering bug fixes:
- fix(shadow): compute lightSpaceMatrix before updatePerFrameUBO to eliminate
one-frame lag that caused shadow trails and flicker on moving objects
- fix(shadow): scale depth bias with shadowDistance_ instead of hardcoded 0.8f
to prevent acne at close range and gaps at far range
- fix(visibility): WMO group distance threshold 500u → 1200u to match terrain
view distance; buildings were disappearing on the horizon
- fix(precision): camera near plane 0.05 → 0.5 (ratio 600K:1 → 60K:1),
eliminating Z-fighting and improving frustum plane extraction stability
- fix(streaming): terrain load radius 4 → 6 tiles (~2133u → ~3200u) to exceed
M2 render distance (2800u) and eliminate pop-in when camera turns;
unload radius 7 → 9; spawn radius 3 → 4
- fix(visibility): ground-detail M2 distance multiplier 0.75 → 0.9 to reduce
early pop of grass and debris
2026-04-04 13:43:16 +03:00
|
|
|
float nearPlane = 0.5f;
|
2026-02-03 16:04:21 -08:00
|
|
|
float farPlane = 30000.0f; // Improves depth precision vs extremely large far clip
|
2026-02-02 12:24:50 -08:00
|
|
|
|
|
|
|
|
glm::mat4 viewMatrix = glm::mat4(1.0f);
|
|
|
|
|
glm::mat4 projectionMatrix = glm::mat4(1.0f);
|
2026-03-07 23:13:01 -08:00
|
|
|
glm::mat4 unjitteredProjectionMatrix = glm::mat4(1.0f);
|
|
|
|
|
glm::vec2 jitterOffset = glm::vec2(0.0f); // NDC jitter (applied to projection)
|
2026-02-02 12:24:50 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace rendering
|
|
|
|
|
} // namespace wowee
|