Add support for moving shadow-casting lights

This commit is contained in:
SirLynix 2022-11-20 15:44:05 +01:00 committed by Jérôme Leclercq
parent a5d4b8f28d
commit 3623f4ccc4
5 changed files with 12 additions and 1 deletions

View File

@ -86,6 +86,7 @@ namespace Nz
UInt32 renderMask;
NazaraSlot(Light, OnLightDataInvalided, onLightInvalidated);
NazaraSlot(Light, OnLightTransformInvalided, onLightTransformInvalidated);
NazaraSlot(Light, OnLightShadowCastingChanged, onLightShadowCastingChanged);
};

View File

@ -56,6 +56,7 @@ namespace Nz
NazaraSignal(OnLightDataInvalided, Light* /*emitter*/);
NazaraSignal(OnLightShadowCastingChanged, Light* /*light*/, bool /*isShadowCasting*/);
NazaraSignal(OnLightShadowMapSettingChange, Light* /*light*/, PixelFormat /*newPixelFormat*/, UInt32 /*newSize*/);
NazaraSignal(OnLightTransformInvalided, Light* /*emitter*/);
protected:
inline void UpdateBoundingVolume(const BoundingVolumef& boundingVolume);

View File

@ -115,6 +115,7 @@ namespace Nz
UpdateBoundingVolume();
UpdateViewProjMatrix();
OnLightTransformInvalided(this);
}
inline void SpotLight::UpdateRadius(float radius)
@ -133,6 +134,7 @@ namespace Nz
UpdateBoundingVolume();
UpdateViewProjMatrix();
OnLightTransformInvalided(this);
}
inline void SpotLight::UpdateBoundingVolume()

View File

@ -292,6 +292,7 @@ namespace Nz
const Matrix4f& viewProjMatrix = lightData->camera->GetViewerInstance().GetViewProjMatrix();
Frustumf frustum = Frustumf::Extract(viewProjMatrix);
GetDebugDrawer().DrawFrustum(frustum, Nz::Color::Blue);
std::size_t visibilityHash = 5U;
@ -599,6 +600,12 @@ namespace Nz
lightData->camera->UpdateZFar(spotLight.GetRadius());
lightData->camera->UpdateViewport(Recti(0, 0, SafeCast<int>(shadowMapSize), SafeCast<int>(shadowMapSize)));
lightData->onLightTransformInvalidated.Connect(lightData->light->OnLightTransformInvalided, [lightData](Light* light)
{
SpotLight& spotLight = SafeCast<SpotLight&>(*light);
ViewerInstance& viewerInstance = lightData->camera->GetViewerInstance();
viewerInstance.UpdateViewMatrix(Nz::Matrix4f::TransformInverse(spotLight.GetPosition(), spotLight.GetRotation()));
});
viewerInstance.UpdateViewMatrix(Nz::Matrix4f::TransformInverse(spotLight.GetPosition(), spotLight.GetRotation()));
}

View File

@ -35,7 +35,7 @@ namespace Nz
void SpotLight::UpdateTransform(const Vector3f& position, const Quaternionf& rotation, const Vector3f& /*scale*/)
{
UpdatePosition(position);
m_position = position; //< don't call UpdatePosition to prevent double update
UpdateRotation(rotation);
}
}