Graphics/ViewerData: Add near and far plane
This commit is contained in:
parent
2a3da7384d
commit
929b599337
|
|
@ -239,6 +239,7 @@ int main(int argc, char* argv[])
|
|||
Nz::ViewerInstance viewerInstance;
|
||||
viewerInstance.UpdateTargetSize(Nz::Vector2f(windowSize));
|
||||
viewerInstance.UpdateProjViewMatrices(Nz::Matrix4f::Perspective(Nz::DegreeAnglef(70.f), float(windowSize.x) / windowSize.y, 0.1f, 1000.f), Nz::Matrix4f::Translate(Nz::Vector3f::Up() * 1));
|
||||
viewerInstance.UpdateNearFarPlanes(0.1f, 1000.f);
|
||||
|
||||
Nz::WorldInstance modelInstance1;
|
||||
modelInstance1.UpdateWorldMatrix(Nz::Matrix4f::Translate(Nz::Vector3f::Left() + Nz::Vector3f::Up()));
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ int main(int argc, char* argv[])
|
|||
Nz::ViewerInstance& viewerInstance = camera.GetViewerInstance();
|
||||
viewerInstance.UpdateTargetSize(Nz::Vector2f(window.GetSize()));
|
||||
viewerInstance.UpdateProjViewMatrices(Nz::Matrix4f::Perspective(Nz::DegreeAnglef(70.f), float(windowSize.x) / windowSize.y, 0.1f, 1000.f), Nz::Matrix4f::Translate(Nz::Vector3f::Backward() * 1));
|
||||
viewerInstance.UpdateNearFarPlanes(0.1f, 1000.f);
|
||||
|
||||
Nz::WorldInstancePtr modelInstance = std::make_shared<Nz::WorldInstance>();
|
||||
modelInstance->UpdateWorldMatrix(Nz::Matrix4f::Translate(Nz::Vector3f::Forward() * 2 + Nz::Vector3f::Left()));
|
||||
|
|
|
|||
|
|
@ -248,6 +248,8 @@ namespace Nz
|
|||
m_viewerInstance.UpdateProjectionMatrix(Matrix4f::Perspective(m_fov, m_aspectRatio, m_zNear, m_zFar));
|
||||
break;
|
||||
}
|
||||
|
||||
m_viewerInstance.UpdateNearFarPlanes(m_zNear, m_zFar);
|
||||
}
|
||||
|
||||
inline void Camera::UpdateViewport()
|
||||
|
|
|
|||
|
|
@ -30,9 +30,11 @@ namespace Nz
|
|||
~ViewerInstance() = default;
|
||||
|
||||
inline const Vector3f& GetEyePosition() const;
|
||||
inline float GetFarPlane() const;
|
||||
inline const Matrix4f& GetInvProjectionMatrix() const;
|
||||
inline const Matrix4f& GetInvViewMatrix() const;
|
||||
inline const Matrix4f& GetInvViewProjMatrix() const;
|
||||
inline float GetNearPlane() const;
|
||||
inline const Matrix4f& GetProjectionMatrix() const;
|
||||
inline const Vector2f& GetTargetSize() const;
|
||||
inline const Matrix4f& GetViewMatrix() const;
|
||||
|
|
@ -43,6 +45,7 @@ namespace Nz
|
|||
void OnTransfer(RenderFrame& renderFrame, CommandBufferBuilder& builder) override;
|
||||
|
||||
inline void UpdateEyePosition(const Vector3f& eyePosition);
|
||||
inline void UpdateNearFarPlanes(float nearPlane, float farPlane);
|
||||
inline void UpdateProjectionMatrix(const Matrix4f& projectionMatrix);
|
||||
inline void UpdateProjectionMatrix(const Matrix4f& projectionMatrix, const Matrix4f& invProjectionMatrix);
|
||||
inline void UpdateProjViewMatrices(const Matrix4f& projectionMatrix, const Matrix4f& viewMatrix);
|
||||
|
|
@ -68,6 +71,8 @@ namespace Nz
|
|||
Vector2f m_targetSize;
|
||||
Vector3f m_eyePosition;
|
||||
bool m_dataInvalidated;
|
||||
float m_farPlane;
|
||||
float m_nearPlane;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,11 @@ namespace Nz
|
|||
return m_eyePosition;
|
||||
}
|
||||
|
||||
inline float ViewerInstance::GetFarPlane() const
|
||||
{
|
||||
return m_farPlane;
|
||||
}
|
||||
|
||||
inline const Matrix4f& ViewerInstance::GetInvProjectionMatrix() const
|
||||
{
|
||||
return m_invProjectionMatrix;
|
||||
|
|
@ -27,6 +32,11 @@ namespace Nz
|
|||
return m_invViewProjMatrix;
|
||||
}
|
||||
|
||||
inline float ViewerInstance::GetNearPlane() const
|
||||
{
|
||||
return m_nearPlane;
|
||||
}
|
||||
|
||||
inline const Matrix4f& ViewerInstance::GetProjectionMatrix() const
|
||||
{
|
||||
return m_projectionMatrix;
|
||||
|
|
@ -64,6 +74,14 @@ namespace Nz
|
|||
InvalidateData();
|
||||
}
|
||||
|
||||
inline void ViewerInstance::UpdateNearFarPlanes(float nearPlane, float farPlane)
|
||||
{
|
||||
m_farPlane = farPlane;
|
||||
m_nearPlane = nearPlane;
|
||||
|
||||
InvalidateData();
|
||||
}
|
||||
|
||||
inline void ViewerInstance::UpdateProjectionMatrix(const Matrix4f& projectionMatrix)
|
||||
{
|
||||
m_projectionMatrix = projectionMatrix;
|
||||
|
|
|
|||
|
|
@ -63,7 +63,9 @@ namespace Nz
|
|||
|
||||
std::size_t shadowPassIndex = Graphics::Instance()->GetMaterialPassRegistry().GetPassIndex("ShadowPass");
|
||||
|
||||
Matrix4f projectionMatrix = Matrix4f::Perspective(RadianAnglef(HalfPi<float>), 1.f, 0.01f, m_light.GetRadius());
|
||||
constexpr float zNear = 0.01f;
|
||||
|
||||
Matrix4f projectionMatrix = Matrix4f::Perspective(RadianAnglef(HalfPi<float>), 1.f, zNear, m_light.GetRadius());
|
||||
|
||||
UInt32 shadowMapSize = light.GetShadowMapSize();
|
||||
for (std::size_t i = 0; i < m_directions.size(); ++i)
|
||||
|
|
@ -77,6 +79,7 @@ namespace Nz
|
|||
viewerInstance.UpdateEyePosition(m_light.GetPosition());
|
||||
viewerInstance.UpdateProjectionMatrix(projectionMatrix);
|
||||
viewerInstance.UpdateViewMatrix(Matrix4f::TransformInverse(m_light.GetPosition(), s_dirRotations[i]));
|
||||
viewerInstance.UpdateNearFarPlanes(zNear, m_light.GetRadius());
|
||||
|
||||
m_pipeline.QueueTransfer(&viewerInstance);
|
||||
|
||||
|
|
|
|||
|
|
@ -13,5 +13,7 @@ struct ViewerData
|
|||
invViewProjMatrix: mat4[f32],
|
||||
renderTargetSize: vec2[f32],
|
||||
invRenderTargetSize: vec2[f32],
|
||||
eyePosition: vec3[f32]
|
||||
eyePosition: vec3[f32],
|
||||
nearPlane: f32,
|
||||
farPlane: f32
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,11 @@ namespace Nz
|
|||
m_viewer.UpdateRenderMask(0xFFFFFFFF);
|
||||
m_viewer.UpdateViewport(Recti(0, 0, SafeCast<int>(shadowMapSize), SafeCast<int>(shadowMapSize)));
|
||||
|
||||
constexpr float zNear = 0.01f;
|
||||
|
||||
ViewerInstance& viewerInstance = m_viewer.GetViewerInstance();
|
||||
viewerInstance.UpdateProjectionMatrix(Matrix4f::Perspective(m_light.GetOuterAngle() * 2.f, 1.f, 0.01f, m_light.GetRadius()));
|
||||
viewerInstance.UpdateProjectionMatrix(Matrix4f::Perspective(m_light.GetOuterAngle() * 2.f, 1.f, zNear, m_light.GetRadius()));
|
||||
viewerInstance.UpdateNearFarPlanes(zNear, m_light.GetRadius());
|
||||
|
||||
m_onLightShadowMapSettingChange.Connect(m_light.OnLightShadowMapSettingChange, [this](Light* /*light*/, PixelFormat /*newPixelFormat*/, UInt32 newSize)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ int main()
|
|||
Nz::ViewerInstance& viewerInstance = camera.GetViewerInstance();
|
||||
viewerInstance.UpdateTargetSize(Nz::Vector2f(window.GetSize()));
|
||||
viewerInstance.UpdateProjViewMatrices(Nz::Matrix4f::Perspective(Nz::DegreeAnglef(70.f), float(windowSize.x) / windowSize.y, 0.1f, 1000.f), Nz::Matrix4f::Translate(Nz::Vector3f::Backward() * 1));
|
||||
viewerInstance.UpdateNearFarPlanes(0.1f, 1000.f);
|
||||
|
||||
Nz::WorldInstancePtr modelInstance = std::make_shared<Nz::WorldInstance>();
|
||||
modelInstance->UpdateWorldMatrix(Nz::Matrix4f::Translate(Nz::Vector3f::Forward() * 2 + Nz::Vector3f::Left()));
|
||||
|
|
|
|||
Loading…
Reference in New Issue