Experimental new algorithm to sort transparents objets

Former-commit-id: ad8704584598e1edcd3699d234abaa132d88e581
This commit is contained in:
Lynix 2013-06-26 15:20:07 +02:00
parent f9c9c67076
commit 245d6e105e
2 changed files with 16 additions and 8 deletions

View File

@ -9,6 +9,7 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/AbstractRenderQueue.hpp> #include <Nazara/Graphics/AbstractRenderQueue.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Matrix4.hpp> #include <Nazara/Math/Matrix4.hpp>
#include <map> #include <map>
@ -57,6 +58,7 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue
struct TransparentModel struct TransparentModel
{ {
NzBoxf aabb;
NzMatrix4f transformMatrix; NzMatrix4f transformMatrix;
NzMaterial* material; NzMaterial* material;
}; };

View File

@ -107,6 +107,8 @@ void NzForwardRenderQueue::AddModel(const NzModel* model)
transparentStaticModels.resize(index+1); transparentStaticModels.resize(index+1);
TransparentStaticModel& data = transparentStaticModels.back(); TransparentStaticModel& data = transparentStaticModels.back();
data.aabb = staticMesh->GetAABB();
data.aabb.Transform(transformMatrix);
data.material = material; data.material = material;
data.mesh = staticMesh; data.mesh = staticMesh;
data.transformMatrix = transformMatrix; data.transformMatrix = transformMatrix;
@ -139,22 +141,26 @@ void NzForwardRenderQueue::Sort(const NzCamera& camera)
{ {
bool operator()(const std::pair<unsigned int, bool>& index1, const std::pair<unsigned int, bool>& index2) bool operator()(const std::pair<unsigned int, bool>& index1, const std::pair<unsigned int, bool>& index2)
{ {
const NzMatrix4f& matrix1 = (index1.second) ? const NzBoxf& aabb1 = (index1.second) ?
queue->transparentStaticModels[index1.first].transformMatrix : queue->transparentStaticModels[index1.first].aabb :
queue->transparentSkeletalModels[index1.first].transformMatrix; queue->transparentSkeletalModels[index1.first].aabb;
const NzMatrix4f& matrix2 = (index1.second) ? const NzBoxf& aabb2 = (index1.second) ?
queue->transparentStaticModels[index2.first].transformMatrix : queue->transparentStaticModels[index2.first].aabb :
queue->transparentSkeletalModels[index2.first].transformMatrix; queue->transparentSkeletalModels[index2.first].aabb;
return nearPlane.Distance(matrix1.GetTranslation()) < nearPlane.Distance(matrix2.GetTranslation()); NzVector3f position1 = aabb1.GetNegativeVertex(cameraNormal);
NzVector3f position2 = aabb2.GetNegativeVertex(cameraNormal);
return nearPlane.Distance(position1) < nearPlane.Distance(position2);
} }
NzForwardRenderQueue* queue; NzForwardRenderQueue* queue;
NzPlanef nearPlane; NzPlanef nearPlane;
NzVector3f cameraNormal;
}; };
TransparentModelComparator comparator {this, camera.GetFrustum().GetPlane(nzFrustumPlane_Near)}; TransparentModelComparator comparator {this, camera.GetFrustum().GetPlane(nzFrustumPlane_Near), camera.GetForward()};
std::sort(visibleTransparentsModels.begin(), visibleTransparentsModels.end(), comparator); std::sort(visibleTransparentsModels.begin(), visibleTransparentsModels.end(), comparator);
} }