Kelsidavis-WoWee/include/rendering/camera.hpp
Kelsi 52317d1edd Implement FSR 2.2 temporal upscaling
Full FSR 2.2 pipeline with depth-based motion vector reprojection,
temporal accumulation with YCoCg neighborhood clamping, and RCAS
contrast-adaptive sharpening.

Architecture (designed for FSR 3.x frame generation readiness):
- Camera: Halton(2,3) sub-pixel jitter with unjittered projection
  stored separately for motion vector computation
- Motion vectors: compute shader reconstructs world position from
  depth + inverse VP, reprojects with previous frame's VP
- Temporal accumulation: compute shader blends 5-10% current frame
  with 90-95% clamped history, adaptive blend for disocclusion
- History: ping-pong R16G16B16A16 buffers at display resolution
- Sharpening: RCAS fragment pass with contrast-adaptive weights

Integration:
- FSR2 replaces both FSR1 and MSAA when enabled
- Scene renders to internal resolution framebuffer (no MSAA)
- Compute passes run between scene and swapchain render passes
- Camera cut detection resets history on teleport
- Quality presets shared with FSR1 (0.50-0.77 scale factors)
- UI: "Upscaling" combo with Off/FSR 1.0/FSR 2.2 options
2026-03-07 23:13:01 -08:00

61 lines
2.1 KiB
C++

#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; }
const glm::mat4& getUnjitteredProjectionMatrix() const { return unjitteredProjectionMatrix; }
glm::mat4 getViewProjectionMatrix() const { return projectionMatrix * viewMatrix; }
glm::mat4 getUnjitteredViewProjectionMatrix() const { return unjitteredProjectionMatrix * viewMatrix; }
float getAspectRatio() const { return aspectRatio; }
// Sub-pixel jitter for temporal upscaling (FSR 2)
void setJitter(float jx, float jy);
void clearJitter();
glm::vec2 getJitter() const { return jitterOffset; }
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;
float nearPlane = 0.05f;
float farPlane = 30000.0f; // Improves depth precision vs extremely large far clip
glm::mat4 viewMatrix = glm::mat4(1.0f);
glm::mat4 projectionMatrix = glm::mat4(1.0f);
glm::mat4 unjitteredProjectionMatrix = glm::mat4(1.0f);
glm::vec2 jitterOffset = glm::vec2(0.0f); // NDC jitter (applied to projection)
};
} // namespace rendering
} // namespace wowee