Graphics/ViewerData: Add near and far plane

This commit is contained in:
SirLynix
2023-09-05 22:34:00 +02:00
committed by Jérôme Leclercq
parent 2a3da7384d
commit 929b599337
9 changed files with 39 additions and 3 deletions

View File

@@ -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);

View File

@@ -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
}

View File

@@ -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)
{