vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
camera_data.h
1#pragma once
2
3#include <glm/glm.hpp>
4
5namespace Vkm::Engine {
6
10struct CameraData {
11 glm::mat4 view = glm::mat4(1.0f);
12 glm::mat4 projection = glm::mat4(1.0f);
13 glm::mat4 viewProjection = glm::mat4(1.0f);
14 glm::mat4 invProjection = glm::mat4(1.0f);
15 glm::mat4 invView = glm::mat4(1.0f);
16 glm::mat4 invViewProj = glm::mat4(1.0f);
17 glm::vec3 position = glm::vec3(0.0f);
18
19 float zNear = 0.1f;
20 float zFar = 1000.0f;
21
22 // Depth of field, as Camera states it; zero (captures, previews) draws sharp.
23 float focusDistance = 0.0f;
24 float dofAmount = 0.0f;
25 float dofMaxBlur = 0.0f;
26
37 static CameraData from(const glm::mat4& view, const glm::mat4& projection, const glm::vec3& position) {
38 CameraData camera;
39 camera.view = view;
40 camera.projection = projection;
41 camera.position = position;
42 camera.viewProjection = projection * view;
43 camera.invProjection = glm::inverse(projection);
44 camera.invView = glm::inverse(view);
45 camera.invViewProj = glm::inverse(camera.viewProjection);
46
47 // Perspective and ortho need different identities: the perspective form on
48 // an ortho matrix yields a negative zFar, which shaders/depth.glsl takes a log of.
49 if (projection[3][3] == 0.0f) {
50 camera.zNear = projection[3][2] / (projection[2][2] - 1.0f);
51 camera.zFar = projection[3][2] / (projection[2][2] + 1.0f);
52 } else {
53 camera.zNear = (projection[3][2] + 1.0f) / projection[2][2];
54 camera.zFar = (projection[3][2] - 1.0f) / projection[2][2];
55 }
56 return camera;
57 }
58};
59
60} // namespace Vkm::Engine
Flattened camera for the frame.
Definition camera_data.h:10
static CameraData from(const glm::mat4 &view, const glm::mat4 &projection, const glm::vec3 &position)
A camera with every derived field filled from its two matrices.
Definition camera_data.h:37
float zNear
Extracted from the projection.
Definition camera_data.h:19
float zFar
Extracted from the projection.
Definition camera_data.h:20