vkmEngine 1.0.15
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
20 glm::mat4 viewmodelViewProjection = glm::mat4(1.0f);
21
22 float zNear = 0.1f;
23 float zFar = 1000.0f;
24
25 // Depth of field, as Camera states it; zero (captures, previews) draws sharp.
26 float focusDistance = 0.0f;
27 float dofAmount = 0.0f;
28 float dofMaxBlur = 0.0f;
29
40 static CameraData from(const glm::mat4& view, const glm::mat4& projection, const glm::vec3& position) {
41 CameraData camera;
42 camera.view = view;
43 camera.projection = projection;
44 camera.position = position;
45 camera.viewProjection = projection * view;
46 camera.viewmodelViewProjection = camera.viewProjection;
47 camera.invProjection = glm::inverse(projection);
48 camera.invView = glm::inverse(view);
49 camera.invViewProj = glm::inverse(camera.viewProjection);
50
51 // Perspective and ortho need different identities: the perspective form on
52 // an ortho matrix yields a negative zFar, which shaders/depth.glsl takes a log of.
53 if (projection[3][3] == 0.0f) {
54 camera.zNear = projection[3][2] / (projection[2][2] - 1.0f);
55 camera.zFar = projection[3][2] / (projection[2][2] + 1.0f);
56 } else {
57 camera.zNear = (projection[3][2] + 1.0f) / projection[2][2];
58 camera.zFar = (projection[3][2] - 1.0f) / projection[2][2];
59 }
60 return camera;
61 }
62};
63
64} // 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:40
float zNear
Extracted from the projection.
Definition camera_data.h:22
glm::mat4 viewmodelViewProjection
World to clip for Viewmodel meshes (Camera::computeViewmodelProjection); from sets viewProjection.
Definition camera_data.h:20
float zFar
Extracted from the projection.
Definition camera_data.h:23