@@ -45,6 +45,9 @@ namespace Math
45
45
const Matrix4& GetViewMatrix () const { return m_ViewMatrix; }
46
46
const Matrix4& GetProjMatrix () const { return m_ProjMatrix; }
47
47
const Matrix4& GetViewProjMatrix () const { return m_ViewProjMatrix; }
48
+ const Matrix4& GetReprojectionMatrix () const { return m_ReprojectMatrix; }
49
+ const Frustum& GetViewSpaceFrustum () const { return m_FrustumVS; }
50
+ const Frustum& GetWorldSpaceFrustum () const { return m_FrustumWS; }
48
51
49
52
protected:
50
53
@@ -57,19 +60,29 @@ namespace Math
57
60
// Redundant data cached for faster lookups.
58
61
Matrix3 m_Basis;
59
62
60
- // 0 矩阵变换
61
- // 1. 渲染目标从模型坐标系转到世界坐标系--->世界变换矩阵
62
- // 2. 再从世界坐标系转到视角坐标系--->视角变换矩阵 m_ViewMatrix
63
- // 3. 从视角坐标系转换到投影坐标系--->投影变换矩阵 m_ProjMatrix
64
-
65
- // 世界坐标系转换到视角坐标系
63
+ // Transforms homogeneous coordinates from world space to view space. In this case, view space is defined as +X is
64
+ // to the right, +Y is up, and -Z is forward. This has to match what the projection matrix expects, but you might
65
+ // also need to know what the convention is if you work in view space in a shader.
66
66
Matrix4 m_ViewMatrix; // i.e. "World-to-View" matrix
67
67
68
- // 视角坐标系转到投影坐标系
68
+ // The projection matrix transforms view space to clip space. Once division by W has occurred, the final coordinates
69
+ // can be transformed by the viewport matrix to screen space. The projection matrix is determined by the screen aspect
70
+ // and camera field of view. A projection matrix can also be orthographic. In that case, field of view would be defined
71
+ // in linear units, not angles.
69
72
Matrix4 m_ProjMatrix; // i.e. "View-to-Projection" matrix
70
73
71
- // 从世界坐标系直接转换到投影坐标系
74
+ // A concatenation of the view and projection matrices.
72
75
Matrix4 m_ViewProjMatrix; // i.e. "World-To-Projection" matrix.
76
+
77
+ // The view-projection matrix from the previous frame
78
+ Matrix4 m_PreviousViewProjMatrix;
79
+
80
+ // Projects a clip-space coordinate to the previous frame (useful for temporal effects).
81
+ Matrix4 m_ReprojectMatrix;
82
+
83
+ Frustum m_FrustumVS; // View-space view frustum
84
+ Frustum m_FrustumWS; // World-space view frustum
85
+
73
86
};
74
87
75
88
class Camera : public BaseCamera
@@ -78,14 +91,16 @@ namespace Math
78
91
Camera ();
79
92
80
93
// Controls the view-to-projection matrix
81
- void SetPerspectiveMatrix ( float verticalFovRadians, float aspectWidthOverHeight , float nearZClip, float farZClip );
94
+ void SetPerspectiveMatrix ( float verticalFovRadians, float aspectHeightOverWidth , float nearZClip, float farZClip );
82
95
void SetFOV ( float verticalFovInRadians ) { m_VerticalFOV = verticalFovInRadians; UpdateProjMatrix (); }
83
- void SetAspectRatio ( float widthOverHeight ) { m_AspectRatio = widthOverHeight ; UpdateProjMatrix (); }
96
+ void SetAspectRatio ( float heightOverWidth ) { m_AspectRatio = heightOverWidth ; UpdateProjMatrix (); }
84
97
void SetZRange ( float nearZ, float farZ) { m_NearClip = nearZ; m_FarClip = farZ; UpdateProjMatrix (); }
98
+ void ReverseZ ( bool enable ) { m_ReverseZ = enable; UpdateProjMatrix (); }
85
99
86
100
float GetFOV () const { return m_VerticalFOV; }
87
101
float GetNearClip () const { return m_NearClip; }
88
102
float GetFarClip () const { return m_FarClip; }
103
+ float GetClearDepth () const { return m_ReverseZ ? 0 .0f : 1 .0f ; }
89
104
90
105
private:
91
106
@@ -95,6 +110,7 @@ namespace Math
95
110
float m_AspectRatio;
96
111
float m_NearClip;
97
112
float m_FarClip;
113
+ bool m_ReverseZ; // Invert near and far clip distances so that Z=0 is the far plane
98
114
};
99
115
100
116
inline void BaseCamera::SetEyeAtUp ( Vector3 eye, Vector3 at, Vector3 up )
@@ -121,19 +137,21 @@ namespace Math
121
137
m_Basis = Matrix3 (m_CameraToWorld.GetRotation ());
122
138
}
123
139
124
- inline Camera::Camera ()
140
+ inline Camera::Camera () : m_ReverseZ( true )
125
141
{
126
- SetPerspectiveMatrix ( XM_PIDIV4, 16 .0f / 9 .0f , 1 .0f , 1000 .0f );
142
+ SetPerspectiveMatrix ( XM_PIDIV4, 9 .0f / 16 .0f , 1 .0f , 1000 .0f );
127
143
}
128
144
129
- inline void Camera::SetPerspectiveMatrix ( float verticalFovRadians, float aspectWidthOverHeight , float nearZClip, float farZClip )
145
+ inline void Camera::SetPerspectiveMatrix ( float verticalFovRadians, float aspectHeightOverWidth , float nearZClip, float farZClip )
130
146
{
131
147
m_VerticalFOV = verticalFovRadians;
132
- m_AspectRatio = aspectWidthOverHeight ;
148
+ m_AspectRatio = aspectHeightOverWidth ;
133
149
m_NearClip = nearZClip;
134
150
m_FarClip = farZClip;
135
151
136
152
UpdateProjMatrix ();
153
+
154
+ m_PreviousViewProjMatrix = m_ViewProjMatrix;
137
155
}
138
156
139
157
} // namespace Math
0 commit comments