SceneNode::VisiblityTest now use Camera instead of Frustum
Former-commit-id: 71199e3e80c5fbd6116d5fedb13276480f4e4731
This commit is contained in:
parent
d509fddc82
commit
13b505f91f
|
|
@ -63,7 +63,7 @@ class NAZARA_API NzCamera : public NzSceneNode, NzRenderTarget::Listener
|
||||||
void UpdateViewMatrix() const;
|
void UpdateViewMatrix() const;
|
||||||
void UpdateViewport() const;
|
void UpdateViewport() const;
|
||||||
|
|
||||||
bool VisibilityTest(const NzFrustumf& frustum) override;
|
bool VisibilityTest(const NzCamera* camera) override;
|
||||||
|
|
||||||
mutable NzFrustumf m_frustum;
|
mutable NzFrustumf m_frustum;
|
||||||
mutable NzMatrix4f m_projectionMatrix;
|
mutable NzMatrix4f m_projectionMatrix;
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ class NAZARA_API NzLight : public NzSceneNode
|
||||||
void Register();
|
void Register();
|
||||||
void Unregister();
|
void Unregister();
|
||||||
void UpdateBoundingVolume() const;
|
void UpdateBoundingVolume() const;
|
||||||
bool VisibilityTest(const NzFrustumf& frustum);
|
bool VisibilityTest(const NzCamera* camera) override;
|
||||||
|
|
||||||
nzLightType m_type;
|
nzLightType m_type;
|
||||||
mutable NzBoundingVolumef m_boundingVolume;
|
mutable NzBoundingVolumef m_boundingVolume;
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ class NAZARA_API NzModel : public NzSceneNode, public NzUpdatable
|
||||||
void Unregister() override;
|
void Unregister() override;
|
||||||
void Update() override;
|
void Update() override;
|
||||||
void UpdateBoundingVolume() const;
|
void UpdateBoundingVolume() const;
|
||||||
bool VisibilityTest(const NzFrustumf& frustum) override;
|
bool VisibilityTest(const NzCamera* camera) override;
|
||||||
|
|
||||||
std::vector<NzMaterialRef> m_materials;
|
std::vector<NzMaterialRef> m_materials;
|
||||||
NzAnimationRef m_animation;
|
NzAnimationRef m_animation;
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ class NAZARA_API NzScene
|
||||||
operator const NzSceneNode&() const;
|
operator const NzSceneNode&() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void RecursiveFrustumCull(NzAbstractRenderQueue* renderQueue, const NzFrustumf& frustum, NzNode* node);
|
void RecursiveCameraCull(NzAbstractRenderQueue* renderQueue, const NzCamera* camera, NzNode* node);
|
||||||
void SetActiveCamera(NzCamera* camera);
|
void SetActiveCamera(NzCamera* camera);
|
||||||
|
|
||||||
NzSceneImpl* m_impl;
|
NzSceneImpl* m_impl;
|
||||||
|
|
|
||||||
|
|
@ -40,13 +40,13 @@ class NAZARA_API NzSceneNode : public NzNode
|
||||||
void SetScene(NzScene* scene);
|
void SetScene(NzScene* scene);
|
||||||
virtual void Unregister();
|
virtual void Unregister();
|
||||||
virtual void Update();
|
virtual void Update();
|
||||||
virtual bool VisibilityTest(const NzFrustumf& frustum) = 0;
|
virtual bool VisibilityTest(const NzCamera* camera) = 0;
|
||||||
|
|
||||||
NzScene* m_scene;
|
NzScene* m_scene;
|
||||||
bool m_visible;
|
bool m_visible;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void UpdateVisibility(const NzFrustumf& frustum);
|
void UpdateVisibility(const NzCamera* camera);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NAZARA_SCENENODE_HPP
|
#endif // NAZARA_SCENENODE_HPP
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ class NAZARA_API NzSceneRoot : public NzSceneNode
|
||||||
|
|
||||||
void Register();
|
void Register();
|
||||||
void Unregister();
|
void Unregister();
|
||||||
bool VisibilityTest(const NzFrustumf& frustum) override;
|
bool VisibilityTest(const NzCamera* camera) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NAZARA_SCENEROOT_HPP
|
#endif // NAZARA_SCENEROOT_HPP
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,6 @@ void NzCamera::SetFOV(float fov)
|
||||||
|
|
||||||
void NzCamera::SetTarget(const NzRenderTarget* renderTarget)
|
void NzCamera::SetTarget(const NzRenderTarget* renderTarget)
|
||||||
{
|
{
|
||||||
NazaraError(NzString::Pointer(m_target));
|
|
||||||
if (m_target)
|
if (m_target)
|
||||||
m_target->RemoveListener(this);
|
m_target->RemoveListener(this);
|
||||||
|
|
||||||
|
|
@ -307,9 +306,9 @@ void NzCamera::UpdateViewport() const
|
||||||
m_viewportUpdated = true;
|
m_viewportUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzCamera::VisibilityTest(const NzFrustumf& frustum)
|
bool NzCamera::VisibilityTest(const NzCamera* camera)
|
||||||
{
|
{
|
||||||
NazaraUnused(frustum);
|
NazaraUnused(camera);
|
||||||
//NazaraInternalError("SceneNode::IsVisible() called on Camera");
|
//NazaraInternalError("SceneNode::IsVisible() called on Camera");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <Nazara/Graphics/Light.hpp>
|
#include <Nazara/Graphics/Light.hpp>
|
||||||
#include <Nazara/Core/Error.hpp>
|
#include <Nazara/Core/Error.hpp>
|
||||||
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
|
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
|
||||||
|
#include <Nazara/Graphics/Camera.hpp>
|
||||||
#include <Nazara/Math/Basic.hpp>
|
#include <Nazara/Math/Basic.hpp>
|
||||||
#include <Nazara/Math/Sphere.hpp>
|
#include <Nazara/Math/Sphere.hpp>
|
||||||
#include <Nazara/Renderer/Renderer.hpp>
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
|
|
@ -307,7 +308,7 @@ void NzLight::UpdateBoundingVolume() const
|
||||||
m_boundingVolumeUpdated = true;
|
m_boundingVolumeUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzLight::VisibilityTest(const NzFrustumf& frustum)
|
bool NzLight::VisibilityTest(const NzCamera* camera)
|
||||||
{
|
{
|
||||||
switch (m_type)
|
switch (m_type)
|
||||||
{
|
{
|
||||||
|
|
@ -319,13 +320,13 @@ bool NzLight::VisibilityTest(const NzFrustumf& frustum)
|
||||||
UpdateDerived();
|
UpdateDerived();
|
||||||
|
|
||||||
// Un test sphérique est bien plus rapide et précis que celui de la bounding box
|
// Un test sphérique est bien plus rapide et précis que celui de la bounding box
|
||||||
return frustum.Contains(NzSpheref(m_derivedPosition, m_radius));
|
return camera->GetFrustum().Contains(NzSpheref(m_derivedPosition, m_radius));
|
||||||
|
|
||||||
case nzLightType_Spot:
|
case nzLightType_Spot:
|
||||||
if (!m_boundingVolumeUpdated)
|
if (!m_boundingVolumeUpdated)
|
||||||
UpdateBoundingVolume();
|
UpdateBoundingVolume();
|
||||||
|
|
||||||
return frustum.Contains(m_boundingVolume);
|
return camera->GetFrustum().Contains(m_boundingVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
NazaraError("Invalid light type (0x" + NzString::Number(m_type, 16) + ')');
|
NazaraError("Invalid light type (0x" + NzString::Number(m_type, 16) + ')');
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@
|
||||||
|
|
||||||
#include <Nazara/Graphics/Model.hpp>
|
#include <Nazara/Graphics/Model.hpp>
|
||||||
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
|
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
|
||||||
|
#include <Nazara/Graphics/Camera.hpp>
|
||||||
#include <Nazara/Graphics/Config.hpp>
|
#include <Nazara/Graphics/Config.hpp>
|
||||||
#include <Nazara/Utility/SkeletalMesh.hpp>
|
#include <Nazara/Utility/SkeletalMesh.hpp>
|
||||||
#include <Nazara/Utility/StaticMesh.hpp>
|
#include <Nazara/Utility/StaticMesh.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <tuple>
|
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
bool NzModelParameters::IsValid() const
|
bool NzModelParameters::IsValid() const
|
||||||
|
|
@ -671,7 +671,7 @@ void NzModel::UpdateBoundingVolume() const
|
||||||
m_boundingVolumeUpdated = true;
|
m_boundingVolumeUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzModel::VisibilityTest(const NzFrustumf& frustum)
|
bool NzModel::VisibilityTest(const NzCamera* camera)
|
||||||
{
|
{
|
||||||
#if NAZARA_GRAPHICS_SAFE
|
#if NAZARA_GRAPHICS_SAFE
|
||||||
if (!IsDrawable())
|
if (!IsDrawable())
|
||||||
|
|
@ -687,7 +687,7 @@ bool NzModel::VisibilityTest(const NzFrustumf& frustum)
|
||||||
if (!m_boundingVolumeUpdated)
|
if (!m_boundingVolumeUpdated)
|
||||||
UpdateBoundingVolume();
|
UpdateBoundingVolume();
|
||||||
|
|
||||||
return frustum.Contains(m_boundingVolume);
|
return camera->GetFrustum().Contains(m_boundingVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
NzModelLoader::LoaderList NzModel::s_loaders;
|
NzModelLoader::LoaderList NzModel::s_loaders;
|
||||||
|
|
|
||||||
|
|
@ -76,8 +76,8 @@ void NzScene::Cull()
|
||||||
|
|
||||||
m_impl->visibleUpdateList.clear();
|
m_impl->visibleUpdateList.clear();
|
||||||
|
|
||||||
// Frustum culling
|
// Frustum culling/Viewport culling
|
||||||
RecursiveFrustumCull(m_impl->renderTechnique->GetRenderQueue(), m_impl->activeCamera->GetFrustum(), &m_impl->root);
|
RecursiveCameraCull(m_impl->renderTechnique->GetRenderQueue(), m_impl->activeCamera, &m_impl->root);
|
||||||
|
|
||||||
///TODO: Occlusion culling
|
///TODO: Occlusion culling
|
||||||
|
|
||||||
|
|
@ -209,21 +209,22 @@ NzScene::operator const NzSceneNode&() const
|
||||||
return m_impl->root;
|
return m_impl->root;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzScene::RecursiveFrustumCull(NzAbstractRenderQueue* renderQueue, const NzFrustumf& frustum, NzNode* node)
|
void NzScene::RecursiveCameraCull(NzAbstractRenderQueue* renderQueue, const NzCamera* camera, NzNode* node)
|
||||||
{
|
{
|
||||||
for (NzNode* child : node->GetChilds())
|
for (NzNode* child : node->GetChilds())
|
||||||
{
|
{
|
||||||
if (child->GetNodeType() == nzNodeType_Scene)
|
if (child->GetNodeType() == nzNodeType_Scene)
|
||||||
{
|
{
|
||||||
NzSceneNode* sceneNode = static_cast<NzSceneNode*>(child);
|
NzSceneNode* sceneNode = static_cast<NzSceneNode*>(child);
|
||||||
|
|
||||||
///TODO: Empêcher le rendu des enfants si le parent est cullé selon un flag
|
///TODO: Empêcher le rendu des enfants si le parent est cullé selon un flag
|
||||||
sceneNode->UpdateVisibility(frustum);
|
sceneNode->UpdateVisibility(camera);
|
||||||
if (sceneNode->IsVisible())
|
if (sceneNode->IsVisible())
|
||||||
sceneNode->AddToRenderQueue(renderQueue);
|
sceneNode->AddToRenderQueue(renderQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (child->HasChilds())
|
if (child->HasChilds())
|
||||||
RecursiveFrustumCull(renderQueue, frustum, child);
|
RecursiveCameraCull(renderQueue, camera, child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,11 +97,11 @@ void NzSceneNode::Update()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzSceneNode::UpdateVisibility(const NzFrustumf& frustum)
|
void NzSceneNode::UpdateVisibility(const NzCamera* camera)
|
||||||
{
|
{
|
||||||
bool wasVisible = m_visible;
|
bool wasVisible = m_visible;
|
||||||
|
|
||||||
m_visible = VisibilityTest(frustum);
|
m_visible = VisibilityTest(camera);
|
||||||
|
|
||||||
if (m_visible != wasVisible)
|
if (m_visible != wasVisible)
|
||||||
OnVisibilityChange(m_visible);
|
OnVisibilityChange(m_visible);
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,9 @@ void NzSceneRoot::Unregister()
|
||||||
NazaraInternalError("SceneNode::Unregister() called on SceneRoot");
|
NazaraInternalError("SceneNode::Unregister() called on SceneRoot");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzSceneRoot::VisibilityTest(const NzFrustumf& frustum)
|
bool NzSceneRoot::VisibilityTest(const NzCamera* camera)
|
||||||
{
|
{
|
||||||
NazaraUnused(frustum);
|
NazaraUnused(camera);
|
||||||
|
|
||||||
return true; // Toujours visible
|
return true; // Toujours visible
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -204,6 +204,7 @@ void NzSkyboxBackground::Draw(const NzScene* scene) const
|
||||||
skyboxMatrix.SetTranslation(NzVector3f::Zero());
|
skyboxMatrix.SetTranslation(NzVector3f::Zero());
|
||||||
|
|
||||||
NzRenderer::SetIndexBuffer(m_indexBuffer);
|
NzRenderer::SetIndexBuffer(m_indexBuffer);
|
||||||
|
NzRenderer::SetMatrix(nzMatrixType_Projection, camera->GetProjectionMatrix());
|
||||||
NzRenderer::SetMatrix(nzMatrixType_View, skyboxMatrix);
|
NzRenderer::SetMatrix(nzMatrixType_View, skyboxMatrix);
|
||||||
NzRenderer::SetMatrix(nzMatrixType_World, NzMatrix4f::Scale(NzVector3f(camera->GetZNear())));
|
NzRenderer::SetMatrix(nzMatrixType_World, NzMatrix4f::Scale(NzVector3f(camera->GetZNear())));
|
||||||
NzRenderer::SetRenderStates(states);
|
NzRenderer::SetRenderStates(states);
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,8 @@ NzRenderTarget::~NzRenderTarget()
|
||||||
|
|
||||||
void NzRenderTarget::AddListener(Listener* listener, void* userdata) const
|
void NzRenderTarget::AddListener(Listener* listener, void* userdata) const
|
||||||
{
|
{
|
||||||
NazaraError("What the");
|
|
||||||
if (!m_listenersLocked)
|
if (!m_listenersLocked)
|
||||||
m_listeners.insert(std::make_pair(listener, userdata));
|
m_listeners.insert(std::make_pair(listener, userdata));
|
||||||
NazaraError("What the");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzRenderTarget::IsActive() const
|
bool NzRenderTarget::IsActive() const
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue