Remade sprite rendering
Added VertexColor shader flag Added color sprite attribute Added VertexStruct_XY_Color(_UV) struct & declaration Former-commit-id: b664f4520aa55f4502f85f9dedab9b92040a8c16
This commit is contained in:
parent
97ff9bc4ac
commit
4de17fdffb
|
|
@ -12,6 +12,7 @@
|
||||||
#include <Nazara/Math/Box.hpp>
|
#include <Nazara/Math/Box.hpp>
|
||||||
#include <Nazara/Math/Matrix4.hpp>
|
#include <Nazara/Math/Matrix4.hpp>
|
||||||
#include <Nazara/Utility/Enums.hpp>
|
#include <Nazara/Utility/Enums.hpp>
|
||||||
|
#include <Nazara/Utility/VertexStruct.hpp>
|
||||||
|
|
||||||
class NzDrawable;
|
class NzDrawable;
|
||||||
class NzLight;
|
class NzLight;
|
||||||
|
|
@ -28,7 +29,7 @@ class NAZARA_API NzAbstractRenderQueue : NzNonCopyable
|
||||||
virtual void AddDrawable(const NzDrawable* drawable) = 0;
|
virtual void AddDrawable(const NzDrawable* drawable) = 0;
|
||||||
virtual void AddLight(const NzLight* light) = 0;
|
virtual void AddLight(const NzLight* light) = 0;
|
||||||
virtual void AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) = 0;
|
virtual void AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) = 0;
|
||||||
virtual void AddSprite(const NzSprite* sprite) = 0;
|
virtual void AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount) = 0;
|
||||||
|
|
||||||
virtual void Clear(bool fully) = 0;
|
virtual void Clear(bool fully) = 0;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class NAZARA_API NzDeferredRenderQueue : public NzAbstractRenderQueue, NzResourc
|
||||||
void AddDrawable(const NzDrawable* drawable) override;
|
void AddDrawable(const NzDrawable* drawable) override;
|
||||||
void AddLight(const NzLight* light) override;
|
void AddLight(const NzLight* light) override;
|
||||||
void AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) override;
|
void AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) override;
|
||||||
void AddSprite(const NzSprite* sprite) override;
|
void AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount) override;
|
||||||
|
|
||||||
void Clear(bool fully);
|
void Clear(bool fully);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,10 +85,11 @@ enum nzShaderFlags
|
||||||
{
|
{
|
||||||
nzShaderFlags_None = 0,
|
nzShaderFlags_None = 0,
|
||||||
|
|
||||||
nzShaderFlags_Deferred = 0x1,
|
nzShaderFlags_Deferred = 0x1,
|
||||||
nzShaderFlags_Instancing = 0x2,
|
nzShaderFlags_Instancing = 0x2,
|
||||||
|
nzShaderFlags_VertexColor = 0x4,
|
||||||
|
|
||||||
nzShaderFlags_Max = nzShaderFlags_Instancing*2-1
|
nzShaderFlags_Max = nzShaderFlags_VertexColor*2-1
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NAZARA_ENUMS_GRAPHICS_HPP
|
#endif // NAZARA_ENUMS_GRAPHICS_HPP
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
|
||||||
void AddDrawable(const NzDrawable* drawable) override;
|
void AddDrawable(const NzDrawable* drawable) override;
|
||||||
void AddLight(const NzLight* light) override;
|
void AddLight(const NzLight* light) override;
|
||||||
void AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) override;
|
void AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) override;
|
||||||
void AddSprite(const NzSprite* sprite) override;
|
void AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount) override;
|
||||||
|
|
||||||
void Clear(bool fully);
|
void Clear(bool fully);
|
||||||
|
|
||||||
|
|
@ -43,6 +43,12 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
|
||||||
bool OnResourceDestroy(const NzResource* resource, int index) override;
|
bool OnResourceDestroy(const NzResource* resource, int index) override;
|
||||||
void OnResourceReleased(const NzResource* resource, int index) override;
|
void OnResourceReleased(const NzResource* resource, int index) override;
|
||||||
|
|
||||||
|
struct SpriteChain_XYZ_Color_UV
|
||||||
|
{
|
||||||
|
const NzVertexStruct_XYZ_Color_UV* vertices;
|
||||||
|
unsigned int spriteCount;
|
||||||
|
};
|
||||||
|
|
||||||
struct TransparentModelData
|
struct TransparentModelData
|
||||||
{
|
{
|
||||||
NzMatrix4f transformMatrix;
|
NzMatrix4f transformMatrix;
|
||||||
|
|
@ -68,12 +74,12 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
|
||||||
|
|
||||||
typedef std::map<NzMeshData, std::pair<NzSpheref, std::vector<NzMatrix4f>>, MeshDataComparator> MeshInstanceContainer;
|
typedef std::map<NzMeshData, std::pair<NzSpheref, std::vector<NzMatrix4f>>, MeshDataComparator> MeshInstanceContainer;
|
||||||
typedef std::map<const NzMaterial*, std::tuple<bool, bool, MeshInstanceContainer>, BatchedModelMaterialComparator> ModelBatches;
|
typedef std::map<const NzMaterial*, std::tuple<bool, bool, MeshInstanceContainer>, BatchedModelMaterialComparator> ModelBatches;
|
||||||
typedef std::map<const NzMaterial*, std::vector<const NzSprite*>> BatchedSpriteContainer;
|
typedef std::map<const NzMaterial*, std::vector<SpriteChain_XYZ_Color_UV>> BasicSpriteBatches;
|
||||||
typedef std::vector<const NzLight*> LightContainer;
|
typedef std::vector<const NzLight*> LightContainer;
|
||||||
typedef std::vector<unsigned int> TransparentModelContainer;
|
typedef std::vector<unsigned int> TransparentModelContainer;
|
||||||
|
|
||||||
|
BasicSpriteBatches basicSprites;
|
||||||
ModelBatches opaqueModels;
|
ModelBatches opaqueModels;
|
||||||
BatchedSpriteContainer sprites;
|
|
||||||
TransparentModelContainer transparentModels;
|
TransparentModelContainer transparentModels;
|
||||||
std::vector<TransparentModelData> transparentModelData;
|
std::vector<TransparentModelData> transparentModelData;
|
||||||
std::vector<const NzDrawable*> otherDrawables;
|
std::vector<const NzDrawable*> otherDrawables;
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,8 @@ class NAZARA_API NzForwardRenderTechnique : public NzAbstractRenderTechnique, Nz
|
||||||
private:
|
private:
|
||||||
struct LightUniforms;
|
struct LightUniforms;
|
||||||
|
|
||||||
|
void DrawBasicSprites(const NzScene* scene) const;
|
||||||
void DrawOpaqueModels(const NzScene* scene) const;
|
void DrawOpaqueModels(const NzScene* scene) const;
|
||||||
void DrawSprites(const NzScene* scene) const;
|
|
||||||
void DrawTransparentModels(const NzScene* scene) const;
|
void DrawTransparentModels(const NzScene* scene) const;
|
||||||
const LightUniforms* GetLightUniforms(const NzShader* shader) const;
|
const LightUniforms* GetLightUniforms(const NzShader* shader) const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Graphics/Material.hpp>
|
#include <Nazara/Graphics/Material.hpp>
|
||||||
#include <Nazara/Graphics/SceneNode.hpp>
|
#include <Nazara/Graphics/SceneNode.hpp>
|
||||||
|
#include <Nazara/Utility/VertexStruct.hpp>
|
||||||
|
|
||||||
class NAZARA_API NzSprite : public NzSceneNode
|
class NAZARA_API NzSprite : public NzSceneNode
|
||||||
{
|
{
|
||||||
|
|
@ -23,6 +24,7 @@ class NAZARA_API NzSprite : public NzSceneNode
|
||||||
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
|
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
|
||||||
|
|
||||||
const NzBoundingVolumef& GetBoundingVolume() const override;
|
const NzBoundingVolumef& GetBoundingVolume() const override;
|
||||||
|
const NzColor& GetColor() const;
|
||||||
NzMaterial* GetMaterial() const;
|
NzMaterial* GetMaterial() const;
|
||||||
nzSceneNodeType GetSceneNodeType() const override;
|
nzSceneNodeType GetSceneNodeType() const override;
|
||||||
const NzVector2f& GetSize() const;
|
const NzVector2f& GetSize() const;
|
||||||
|
|
@ -30,6 +32,7 @@ class NAZARA_API NzSprite : public NzSceneNode
|
||||||
|
|
||||||
bool IsDrawable() const;
|
bool IsDrawable() const;
|
||||||
|
|
||||||
|
void SetColor(const NzColor& color);
|
||||||
void SetMaterial(NzMaterial* material, bool resizeSprite = true);
|
void SetMaterial(NzMaterial* material, bool resizeSprite = true);
|
||||||
void SetSize(const NzVector2f& size);
|
void SetSize(const NzVector2f& size);
|
||||||
void SetSize(float sizeX, float sizeY);
|
void SetSize(float sizeX, float sizeY);
|
||||||
|
|
@ -42,12 +45,16 @@ class NAZARA_API NzSprite : public NzSceneNode
|
||||||
void Register() override;
|
void Register() override;
|
||||||
void Unregister() override;
|
void Unregister() override;
|
||||||
void UpdateBoundingVolume() const;
|
void UpdateBoundingVolume() const;
|
||||||
|
void UpdateVertices() const;
|
||||||
|
|
||||||
mutable NzBoundingVolumef m_boundingVolume;
|
mutable NzBoundingVolumef m_boundingVolume;
|
||||||
|
NzColor m_color;
|
||||||
NzMaterialRef m_material;
|
NzMaterialRef m_material;
|
||||||
NzRectf m_textureCoords;
|
NzRectf m_textureCoords;
|
||||||
NzVector2f m_size;
|
NzVector2f m_size;
|
||||||
|
mutable NzVertexStruct_XYZ_Color_UV m_vertices[4];
|
||||||
mutable bool m_boundingVolumeUpdated;
|
mutable bool m_boundingVolumeUpdated;
|
||||||
|
mutable bool m_verticesUpdated;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NAZARA_SPRITE_HPP
|
#endif // NAZARA_SPRITE_HPP
|
||||||
|
|
|
||||||
|
|
@ -254,6 +254,8 @@ enum nzVertexLayout
|
||||||
nzVertexLayout_XY,
|
nzVertexLayout_XY,
|
||||||
nzVertexLayout_XY_UV,
|
nzVertexLayout_XY_UV,
|
||||||
nzVertexLayout_XYZ,
|
nzVertexLayout_XYZ,
|
||||||
|
nzVertexLayout_XYZ_Color,
|
||||||
|
nzVertexLayout_XYZ_Color_UV,
|
||||||
nzVertexLayout_XYZ_Normal,
|
nzVertexLayout_XYZ_Normal,
|
||||||
nzVertexLayout_XYZ_Normal_UV,
|
nzVertexLayout_XYZ_Normal_UV,
|
||||||
nzVertexLayout_XYZ_Normal_UV_Tangent,
|
nzVertexLayout_XYZ_Normal_UV_Tangent,
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#ifndef NAZARA_VERTEXSTRUCT_HPP
|
#ifndef NAZARA_VERTEXSTRUCT_HPP
|
||||||
#define NAZARA_VERTEXSTRUCT_HPP
|
#define NAZARA_VERTEXSTRUCT_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Core/Color.hpp>
|
||||||
#include <Nazara/Math/Vector2.hpp>
|
#include <Nazara/Math/Vector2.hpp>
|
||||||
#include <Nazara/Math/Vector3.hpp>
|
#include <Nazara/Math/Vector3.hpp>
|
||||||
|
|
||||||
|
|
@ -17,7 +18,7 @@ struct NzVertexStruct_XY
|
||||||
NzVector2f position;
|
NzVector2f position;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NzVertexStruct_XY_UV : public NzVertexStruct_XY
|
struct NzVertexStruct_XY_UV : NzVertexStruct_XY
|
||||||
{
|
{
|
||||||
NzVector2f uv;
|
NzVector2f uv;
|
||||||
};
|
};
|
||||||
|
|
@ -29,29 +30,39 @@ struct NzVertexStruct_XYZ
|
||||||
NzVector3f position;
|
NzVector3f position;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NzVertexStruct_XYZ_Normal : public NzVertexStruct_XYZ
|
struct NzVertexStruct_XYZ_Color : NzVertexStruct_XYZ
|
||||||
{
|
{
|
||||||
NzVector3f normal;
|
NzColor color;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NzVertexStruct_XYZ_Normal_UV : public NzVertexStruct_XYZ_Normal
|
struct NzVertexStruct_XYZ_Color_UV : NzVertexStruct_XYZ_Color
|
||||||
{
|
{
|
||||||
NzVector2f uv;
|
NzVector2f uv;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NzVertexStruct_XYZ_Normal_UV_Tangent : public NzVertexStruct_XYZ_Normal_UV
|
struct NzVertexStruct_XYZ_Normal : NzVertexStruct_XYZ
|
||||||
|
{
|
||||||
|
NzVector3f normal;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NzVertexStruct_XYZ_Normal_UV : NzVertexStruct_XYZ_Normal
|
||||||
|
{
|
||||||
|
NzVector2f uv;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NzVertexStruct_XYZ_Normal_UV_Tangent : NzVertexStruct_XYZ_Normal_UV
|
||||||
{
|
{
|
||||||
NzVector3f tangent;
|
NzVector3f tangent;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NzVertexStruct_XYZ_UV : public NzVertexStruct_XYZ
|
struct NzVertexStruct_XYZ_UV : NzVertexStruct_XYZ
|
||||||
{
|
{
|
||||||
NzVector2f uv;
|
NzVector2f uv;
|
||||||
};
|
};
|
||||||
|
|
||||||
/************************* Structures 3D (+ Skinning) ************************/
|
/************************* Structures 3D (+ Skinning) ************************/
|
||||||
|
|
||||||
struct NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning : public NzVertexStruct_XYZ_Normal_UV_Tangent
|
struct NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning : NzVertexStruct_XYZ_Normal_UV_Tangent
|
||||||
{
|
{
|
||||||
nzInt32 weightCount;
|
nzInt32 weightCount;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,29 +103,15 @@ void NzDeferredRenderQueue::AddMesh(const NzMaterial* material, const NzMeshData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzDeferredRenderQueue::AddSprite(const NzSprite* sprite)
|
void NzDeferredRenderQueue::AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount)
|
||||||
{
|
{
|
||||||
#if NAZARA_GRAPHICS_SAFE
|
|
||||||
if (!sprite)
|
|
||||||
{
|
|
||||||
NazaraError("Invalid sprite");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sprite->IsDrawable())
|
|
||||||
{
|
|
||||||
NazaraError("Sprite is not drawable");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*NzMaterial* material = sprite->GetMaterial();
|
/*NzMaterial* material = sprite->GetMaterial();
|
||||||
if (!material->IsLightingEnabled() || material->IsEnabled(nzRendererParameter_Blend))
|
if (!material->IsLightingEnabled() || material->IsEnabled(nzRendererParameter_Blend))
|
||||||
m_forwardQueue->AddSprite(sprite);
|
m_forwardQueue->AddSprite(sprite);
|
||||||
else
|
else
|
||||||
sprites[material].push_back(sprite);*/
|
sprites[material].push_back(sprite);*/
|
||||||
|
|
||||||
m_forwardQueue->AddSprite(sprite);
|
m_forwardQueue->AddSprites(material, vertices, spriteCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzDeferredRenderQueue::Clear(bool fully)
|
void NzDeferredRenderQueue::Clear(bool fully)
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@
|
||||||
#include <Nazara/Utility/StaticMesh.hpp>
|
#include <Nazara/Utility/StaticMesh.hpp>
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
|
///FIXME: Régler ce problème de dépendance aux ressources
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
enum ResourceType
|
enum ResourceType
|
||||||
|
|
@ -121,23 +123,17 @@ void NzForwardRenderQueue::AddMesh(const NzMaterial* material, const NzMeshData&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzForwardRenderQueue::AddSprite(const NzSprite* sprite)
|
void NzForwardRenderQueue::AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount)
|
||||||
{
|
{
|
||||||
#if NAZARA_GRAPHICS_SAFE
|
BasicSpriteBatches::iterator it = basicSprites.find(material);
|
||||||
if (!sprite)
|
if (it == basicSprites.end())
|
||||||
{
|
{
|
||||||
NazaraError("Invalid sprite");
|
it = basicSprites.insert(std::make_pair(material, BasicSpriteBatches::mapped_type())).first;
|
||||||
return;
|
material->AddResourceListener(this, ResourceType_Material);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sprite->IsDrawable())
|
auto& spriteVector = it->second;
|
||||||
{
|
spriteVector.push_back(SpriteChain_XYZ_Color_UV({vertices, spriteCount}));
|
||||||
NazaraError("Sprite is not drawable");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
sprites[sprite->GetMaterial()].push_back(sprite);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzForwardRenderQueue::Clear(bool fully)
|
void NzForwardRenderQueue::Clear(bool fully)
|
||||||
|
|
@ -150,6 +146,13 @@ void NzForwardRenderQueue::Clear(bool fully)
|
||||||
|
|
||||||
if (fully)
|
if (fully)
|
||||||
{
|
{
|
||||||
|
for (auto& matIt : basicSprites)
|
||||||
|
{
|
||||||
|
const NzMaterial* material = matIt.first;
|
||||||
|
material->RemoveResourceListener(this);
|
||||||
|
}
|
||||||
|
basicSprites.clear();
|
||||||
|
|
||||||
for (auto& matIt : opaqueModels)
|
for (auto& matIt : opaqueModels)
|
||||||
{
|
{
|
||||||
const NzMaterial* material = matIt.first;
|
const NzMaterial* material = matIt.first;
|
||||||
|
|
@ -167,7 +170,6 @@ void NzForwardRenderQueue::Clear(bool fully)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
opaqueModels.clear();
|
opaqueModels.clear();
|
||||||
sprites.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -210,6 +212,7 @@ bool NzForwardRenderQueue::OnResourceDestroy(const NzResource* resource, int ind
|
||||||
}
|
}
|
||||||
|
|
||||||
case ResourceType_Material:
|
case ResourceType_Material:
|
||||||
|
basicSprites.erase(static_cast<const NzMaterial*>(resource));
|
||||||
opaqueModels.erase(static_cast<const NzMaterial*>(resource));
|
opaqueModels.erase(static_cast<const NzMaterial*>(resource));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -260,6 +263,15 @@ void NzForwardRenderQueue::OnResourceReleased(const NzResource* resource, int in
|
||||||
|
|
||||||
case ResourceType_Material:
|
case ResourceType_Material:
|
||||||
{
|
{
|
||||||
|
for (auto it = basicSprites.begin(); it != basicSprites.end(); ++it)
|
||||||
|
{
|
||||||
|
if (it->first == resource)
|
||||||
|
{
|
||||||
|
basicSprites.erase(it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (auto it = opaqueModels.begin(); it != opaqueModels.end(); ++it)
|
for (auto it = opaqueModels.begin(); it != opaqueModels.end(); ++it)
|
||||||
{
|
{
|
||||||
if (it->first == resource)
|
if (it->first == resource)
|
||||||
|
|
@ -268,6 +280,7 @@ void NzForwardRenderQueue::OnResourceReleased(const NzResource* resource, int in
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -299,7 +312,6 @@ bool NzForwardRenderQueue::BatchedModelMaterialComparator::operator()(const NzMa
|
||||||
|
|
||||||
const NzShader* shader1 = mat1->GetShaderInstance()->GetShader();
|
const NzShader* shader1 = mat1->GetShaderInstance()->GetShader();
|
||||||
const NzShader* shader2 = mat2->GetShaderInstance()->GetShader();
|
const NzShader* shader2 = mat2->GetShaderInstance()->GetShader();
|
||||||
|
|
||||||
if (shader1 != shader2)
|
if (shader1 != shader2)
|
||||||
return shader1 < shader2;
|
return shader1 < shader2;
|
||||||
|
|
||||||
|
|
@ -320,7 +332,6 @@ bool NzForwardRenderQueue::BatchedSpriteMaterialComparator::operator()(const NzM
|
||||||
|
|
||||||
const NzShader* shader1 = mat1->GetShaderInstance()->GetShader();
|
const NzShader* shader1 = mat1->GetShaderInstance()->GetShader();
|
||||||
const NzShader* shader2 = mat2->GetShaderInstance()->GetShader();
|
const NzShader* shader2 = mat2->GetShaderInstance()->GetShader();
|
||||||
|
|
||||||
if (shader1 != shader2)
|
if (shader1 != shader2)
|
||||||
return shader1 < shader2;
|
return shader1 < shader2;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
NzForwardRenderTechnique::NzForwardRenderTechnique() :
|
NzForwardRenderTechnique::NzForwardRenderTechnique() :
|
||||||
m_spriteBuffer(NzVertexDeclaration::Get(nzVertexLayout_XYZ_UV), s_maxSprites*4, nzBufferStorage_Hardware, nzBufferUsage_Dynamic),
|
m_spriteBuffer(NzVertexDeclaration::Get(nzVertexLayout_XYZ_Color_UV), s_maxSprites*4, nzBufferStorage_Hardware, nzBufferUsage_Dynamic),
|
||||||
m_maxLightPassPerObject(3)
|
m_maxLightPassPerObject(3)
|
||||||
{
|
{
|
||||||
if (!s_indexBuffer)
|
if (!s_indexBuffer)
|
||||||
|
|
@ -87,8 +87,8 @@ bool NzForwardRenderTechnique::Draw(const NzScene* scene) const
|
||||||
if (!m_renderQueue.transparentModels.empty())
|
if (!m_renderQueue.transparentModels.empty())
|
||||||
DrawTransparentModels(scene);
|
DrawTransparentModels(scene);
|
||||||
|
|
||||||
if (!m_renderQueue.sprites.empty())
|
if (!m_renderQueue.basicSprites.empty())
|
||||||
DrawSprites(scene);
|
DrawBasicSprites(scene);
|
||||||
|
|
||||||
// Les autres drawables (Exemple: Terrain)
|
// Les autres drawables (Exemple: Terrain)
|
||||||
for (const NzDrawable* drawable : m_renderQueue.otherDrawables)
|
for (const NzDrawable* drawable : m_renderQueue.otherDrawables)
|
||||||
|
|
@ -162,6 +162,77 @@ void NzForwardRenderTechnique::SetMaxLightPassPerObject(unsigned int passCount)
|
||||||
m_maxLightPassPerObject = passCount;
|
m_maxLightPassPerObject = passCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NzForwardRenderTechnique::DrawBasicSprites(const NzScene* scene) const
|
||||||
|
{
|
||||||
|
NzAbstractViewer* viewer = scene->GetViewer();
|
||||||
|
const NzShader* lastShader = nullptr;
|
||||||
|
|
||||||
|
NzRenderer::SetIndexBuffer(m_indexBuffer);
|
||||||
|
NzRenderer::SetMatrix(nzMatrixType_World, NzMatrix4f::Identity());
|
||||||
|
NzRenderer::SetVertexBuffer(&m_spriteBuffer);
|
||||||
|
|
||||||
|
for (auto& matIt : m_renderQueue.basicSprites)
|
||||||
|
{
|
||||||
|
const NzMaterial* material = matIt.first;
|
||||||
|
auto& spriteChainVector = matIt.second;
|
||||||
|
|
||||||
|
unsigned int spriteChainCount = spriteChainVector.size();
|
||||||
|
if (spriteChainCount > 0)
|
||||||
|
{
|
||||||
|
// On commence par appliquer du matériau (et récupérer le shader ainsi activé)
|
||||||
|
const NzShader* shader = material->Apply(nzShaderFlags_VertexColor);
|
||||||
|
|
||||||
|
// Les uniformes sont conservées au sein d'un programme, inutile de les renvoyer tant qu'il ne change pas
|
||||||
|
if (shader != lastShader)
|
||||||
|
{
|
||||||
|
// Couleur ambiante de la scène
|
||||||
|
shader->SendColor(shader->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
||||||
|
// Position de la caméra
|
||||||
|
shader->SendVector(shader->GetUniformLocation(nzShaderUniform_EyePosition), viewer->GetEyePosition());
|
||||||
|
|
||||||
|
lastShader = shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int spriteChain = 0; // Quelle chaîne de sprite traitons-nous
|
||||||
|
unsigned int spriteChainOffset = 0; // À quel offset dans la dernière chaîne nous sommes-nous arrêtés
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
// On ouvre le buffer en écriture
|
||||||
|
NzBufferMapper<NzVertexBuffer> vertexMapper(m_spriteBuffer, nzBufferAccess_DiscardAndWrite);
|
||||||
|
NzVertexStruct_XYZ_Color_UV* vertices = reinterpret_cast<NzVertexStruct_XYZ_Color_UV*>(vertexMapper.GetPointer());
|
||||||
|
|
||||||
|
unsigned int spriteCount = 0;
|
||||||
|
{
|
||||||
|
NzForwardRenderQueue::SpriteChain_XYZ_Color_UV& currentChain = spriteChainVector[spriteChain];
|
||||||
|
unsigned int count = std::min(s_maxSprites - spriteCount, currentChain.spriteCount - spriteChainOffset);
|
||||||
|
|
||||||
|
std::memcpy(vertices, currentChain.vertices + spriteChainOffset*4, 4*count*sizeof(NzVertexStruct_XYZ_Color_UV));
|
||||||
|
vertices += count*4;
|
||||||
|
|
||||||
|
spriteCount += count;
|
||||||
|
spriteChainOffset += count;
|
||||||
|
|
||||||
|
// Avons-nous traité la chaîne entière ?
|
||||||
|
if (spriteChainOffset == currentChain.spriteCount)
|
||||||
|
{
|
||||||
|
spriteChain++;
|
||||||
|
spriteChainOffset = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (spriteCount < s_maxSprites && spriteChain < spriteChainCount);
|
||||||
|
|
||||||
|
vertexMapper.Unmap();
|
||||||
|
|
||||||
|
NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode_TriangleList, 0, spriteCount*6);
|
||||||
|
}
|
||||||
|
while (spriteChain < spriteChainCount);
|
||||||
|
|
||||||
|
spriteChainVector.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||||
{
|
{
|
||||||
NzAbstractViewer* viewer = scene->GetViewer();
|
NzAbstractViewer* viewer = scene->GetViewer();
|
||||||
|
|
@ -275,7 +346,7 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||||
|
|
||||||
const NzMatrix4f* instanceMatrices = &instances[0];
|
const NzMatrix4f* instanceMatrices = &instances[0];
|
||||||
unsigned int instanceCount = instances.size();
|
unsigned int instanceCount = instances.size();
|
||||||
unsigned int maxInstanceCount = instanceBuffer->GetVertexCount(); // On calcule le nombre d'instances que l'on pourra afficher cette fois-ci (Selon la taille du buffer d'instancing)
|
unsigned int maxInstanceCount = instanceBuffer->GetVertexCount(); // Le nombre maximum d'instances en une fois
|
||||||
|
|
||||||
while (instanceCount > 0)
|
while (instanceCount > 0)
|
||||||
{
|
{
|
||||||
|
|
@ -351,7 +422,7 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Sans instancing, on doit effectuer un drawcall pour chaque instance
|
// Sans instancing, on doit effectuer un draw call pour chaque instance
|
||||||
// Cela reste néanmoins plus rapide que l'instancing en dessous d'un certain nombre d'instances
|
// Cela reste néanmoins plus rapide que l'instancing en dessous d'un certain nombre d'instances
|
||||||
// À cause du temps de modification du buffer d'instancing
|
// À cause du temps de modification du buffer d'instancing
|
||||||
for (const NzMatrix4f& matrix : instances)
|
for (const NzMatrix4f& matrix : instances)
|
||||||
|
|
@ -373,82 +444,6 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzForwardRenderTechnique::DrawSprites(const NzScene* scene) const
|
|
||||||
{
|
|
||||||
NzAbstractViewer* viewer = scene->GetViewer();
|
|
||||||
const NzShader* lastShader = nullptr;
|
|
||||||
|
|
||||||
NzRenderer::SetIndexBuffer(m_indexBuffer);
|
|
||||||
NzRenderer::SetMatrix(nzMatrixType_World, NzMatrix4f::Identity());
|
|
||||||
NzRenderer::SetVertexBuffer(&m_spriteBuffer);
|
|
||||||
|
|
||||||
for (auto& matIt : m_renderQueue.sprites)
|
|
||||||
{
|
|
||||||
const NzMaterial* material = matIt.first;
|
|
||||||
auto& spriteVector = matIt.second;
|
|
||||||
|
|
||||||
unsigned int spriteCount = spriteVector.size();
|
|
||||||
if (spriteCount > 0)
|
|
||||||
{
|
|
||||||
// On commence par appliquer du matériau (et récupérer le shader ainsi activé)
|
|
||||||
const NzShader* shader = material->Apply();
|
|
||||||
|
|
||||||
// Les uniformes sont conservées au sein d'un programme, inutile de les renvoyer tant qu'il ne change pas
|
|
||||||
if (shader != lastShader)
|
|
||||||
{
|
|
||||||
// Couleur ambiante de la scène
|
|
||||||
shader->SendColor(shader->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
|
||||||
// Position de la caméra
|
|
||||||
shader->SendVector(shader->GetUniformLocation(nzShaderUniform_EyePosition), viewer->GetEyePosition());
|
|
||||||
|
|
||||||
lastShader = shader;
|
|
||||||
}
|
|
||||||
|
|
||||||
const NzSprite** spritePtr = &spriteVector[0];
|
|
||||||
do
|
|
||||||
{
|
|
||||||
unsigned int renderedSpriteCount = std::min(spriteCount, 64U);
|
|
||||||
spriteCount -= renderedSpriteCount;
|
|
||||||
|
|
||||||
NzBufferMapper<NzVertexBuffer> vertexMapper(m_spriteBuffer, nzBufferAccess_DiscardAndWrite, 0, renderedSpriteCount*4);
|
|
||||||
NzVertexStruct_XYZ_UV* vertices = reinterpret_cast<NzVertexStruct_XYZ_UV*>(vertexMapper.GetPointer());
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < renderedSpriteCount; ++i)
|
|
||||||
{
|
|
||||||
const NzSprite* sprite = *spritePtr++;
|
|
||||||
const NzRectf& textureCoords = sprite->GetTextureCoords();
|
|
||||||
const NzVector2f& halfSize = sprite->GetSize()*0.5f;
|
|
||||||
NzVector3f center = sprite->GetPosition();
|
|
||||||
NzQuaternionf rotation = sprite->GetRotation();
|
|
||||||
|
|
||||||
vertices->position = center + rotation * NzVector3f(-halfSize.x, halfSize.y, 0.f);
|
|
||||||
vertices->uv.Set(textureCoords.x, textureCoords.y + textureCoords.height);
|
|
||||||
vertices++;
|
|
||||||
|
|
||||||
vertices->position = center + rotation * NzVector3f(halfSize.x, halfSize.y, 0.f);
|
|
||||||
vertices->uv.Set(textureCoords.width, textureCoords.y + textureCoords.height);
|
|
||||||
vertices++;
|
|
||||||
|
|
||||||
vertices->position = center + rotation * NzVector3f(-halfSize.x, -halfSize.y, 0.f);
|
|
||||||
vertices->uv.Set(textureCoords.x, textureCoords.y);
|
|
||||||
vertices++;
|
|
||||||
|
|
||||||
vertices->position = center + rotation * NzVector3f(halfSize.x, -halfSize.y, 0.f);
|
|
||||||
vertices->uv.Set(textureCoords.width, textureCoords.y);
|
|
||||||
vertices++;
|
|
||||||
}
|
|
||||||
|
|
||||||
vertexMapper.Unmap();
|
|
||||||
|
|
||||||
NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode_TriangleList, 0, renderedSpriteCount*6);
|
|
||||||
}
|
|
||||||
while (spriteCount > 0);
|
|
||||||
|
|
||||||
spriteVector.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NzForwardRenderTechnique::DrawTransparentModels(const NzScene* scene) const
|
void NzForwardRenderTechnique::DrawTransparentModels(const NzScene* scene) const
|
||||||
{
|
{
|
||||||
NzAbstractViewer* viewer = scene->GetViewer();
|
NzAbstractViewer* viewer = scene->GetViewer();
|
||||||
|
|
|
||||||
|
|
@ -692,6 +692,7 @@ void NzMaterial::GenerateShader(nzUInt32 flags) const
|
||||||
|
|
||||||
list.SetParameter("FLAG_DEFERRED", static_cast<bool>((flags & nzShaderFlags_Deferred) != 0));
|
list.SetParameter("FLAG_DEFERRED", static_cast<bool>((flags & nzShaderFlags_Deferred) != 0));
|
||||||
list.SetParameter("FLAG_INSTANCING", static_cast<bool>((flags & nzShaderFlags_Instancing) != 0));
|
list.SetParameter("FLAG_INSTANCING", static_cast<bool>((flags & nzShaderFlags_Instancing) != 0));
|
||||||
|
list.SetParameter("FLAG_VERTEXCOLOR", static_cast<bool>((flags & nzShaderFlags_VertexColor) != 0));
|
||||||
|
|
||||||
ShaderInstance& instance = m_shaders[flags];
|
ShaderInstance& instance = m_shaders[flags];
|
||||||
instance.uberInstance = m_uberShader->Get(list);
|
instance.uberInstance = m_uberShader->Get(list);
|
||||||
|
|
@ -759,7 +760,7 @@ bool NzMaterial::Initialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
uberShader->SetShader(nzShaderStage_Fragment, fragmentShader, "ALPHA_MAPPING ALPHA_TEST AUTO_TEXCOORDS DIFFUSE_MAPPING");
|
uberShader->SetShader(nzShaderStage_Fragment, fragmentShader, "ALPHA_MAPPING ALPHA_TEST AUTO_TEXCOORDS DIFFUSE_MAPPING");
|
||||||
uberShader->SetShader(nzShaderStage_Vertex, vertexShader, "FLAG_INSTANCING TEXTURE_MAPPING TRANSFORM UNIFORM_VERTEX_DEPTH");
|
uberShader->SetShader(nzShaderStage_Vertex, vertexShader, "FLAG_INSTANCING FLAG_VERTEXCOLOR TEXTURE_MAPPING TRANSFORM UNIFORM_VERTEX_DEPTH");
|
||||||
|
|
||||||
NzUberShaderLibrary::Register("Basic", uberShader.get());
|
NzUberShaderLibrary::Register("Basic", uberShader.get());
|
||||||
uberShader.release();
|
uberShader.release();
|
||||||
|
|
@ -800,7 +801,7 @@ bool NzMaterial::Initialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
uberShader->SetShader(nzShaderStage_Fragment, fragmentShader, "FLAG_DEFERRED ALPHA_MAPPING ALPHA_TEST DIFFUSE_MAPPING EMISSIVE_MAPPING LIGHTING NORMAL_MAPPING PARALLAX_MAPPING SPECULAR_MAPPING");
|
uberShader->SetShader(nzShaderStage_Fragment, fragmentShader, "FLAG_DEFERRED ALPHA_MAPPING ALPHA_TEST DIFFUSE_MAPPING EMISSIVE_MAPPING LIGHTING NORMAL_MAPPING PARALLAX_MAPPING SPECULAR_MAPPING");
|
||||||
uberShader->SetShader(nzShaderStage_Vertex, vertexShader, "FLAG_DEFERRED FLAG_INSTANCING COMPUTE_TBNMATRIX LIGHTING PARALLAX_MAPPING TEXTURE_MAPPING TRANSFORM UNIFORM_VERTEX_DEPTH");
|
uberShader->SetShader(nzShaderStage_Vertex, vertexShader, "FLAG_DEFERRED FLAG_INSTANCING FLAG_VERTEXCOLOR COMPUTE_TBNMATRIX LIGHTING PARALLAX_MAPPING TEXTURE_MAPPING TRANSFORM UNIFORM_VERTEX_DEPTH");
|
||||||
|
|
||||||
NzUberShaderLibrary::Register("PhongLighting", uberShader.get());
|
NzUberShaderLibrary::Register("PhongLighting", uberShader.get());
|
||||||
uberShader.release();
|
uberShader.release();
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ layout(early_fragment_tests) in;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/********************Entrant********************/
|
/********************Entrant********************/
|
||||||
|
in vec4 vColor;
|
||||||
in vec2 vTexCoord;
|
in vec2 vTexCoord;
|
||||||
|
|
||||||
/********************Sortant********************/
|
/********************Sortant********************/
|
||||||
|
|
@ -18,7 +19,7 @@ uniform vec2 InvTargetSize;
|
||||||
/********************Fonctions********************/
|
/********************Fonctions********************/
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 fragmentColor = MaterialDiffuse;
|
vec4 fragmentColor = MaterialDiffuse * vColor;
|
||||||
|
|
||||||
#if AUTO_TEXCOORDS
|
#if AUTO_TEXCOORDS
|
||||||
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
35,105,102,32,69,65,82,76,89,95,70,82,65,71,77,69,78,84,95,84,69,83,84,83,32,38,38,32,33,65,76,80,72,65,95,84,69,83,84,13,10,108,97,121,111,117,116,40,101,97,114,108,121,95,102,114,97,103,109,101,110,116,95,116,101,115,116,115,41,32,105,110,59,13,10,35,101,110,100,105,102,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,105,110,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,83,111,114,116,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,59,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,59,13,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,52,32,102,114,97,103,109,101,110,116,67,111,108,111,114,32,61,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,13,10,13,10,35,105,102,32,65,85,84,79,95,84,69,88,67,79,79,82,68,83,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,35,101,108,115,101,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,118,84,101,120,67,111,111,114,100,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,13,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,32,42,61,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,44,32,116,101,120,67,111,111,114,100,41,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,13,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,42,61,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,44,32,116,101,120,67,111,111,114,100,41,46,114,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,65,76,80,72,65,95,84,69,83,84,13,10,9,105,102,32,40,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,60,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,41,13,10,9,9,100,105,115,99,97,114,100,59,13,10,35,101,110,100,105,102,13,10,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,102,114,97,103,109,101,110,116,67,111,108,111,114,59,13,10,125,
|
35,105,102,32,69,65,82,76,89,95,70,82,65,71,77,69,78,84,95,84,69,83,84,83,32,38,38,32,33,65,76,80,72,65,95,84,69,83,84,13,10,108,97,121,111,117,116,40,101,97,114,108,121,95,102,114,97,103,109,101,110,116,95,116,101,115,116,115,41,32,105,110,59,13,10,35,101,110,100,105,102,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,105,110,32,118,101,99,52,32,118,67,111,108,111,114,59,13,10,105,110,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,83,111,114,116,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,111,117,116,32,118,101,99,52,32,82,101,110,100,101,114,84,97,114,103,101,116,48,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,59,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,59,13,10,117,110,105,102,111,114,109,32,118,101,99,52,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,59,13,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,59,13,10,117,110,105,102,111,114,109,32,118,101,99,50,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,9,118,101,99,52,32,102,114,97,103,109,101,110,116,67,111,108,111,114,32,61,32,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,32,42,32,118,67,111,108,111,114,59,13,10,13,10,35,105,102,32,65,85,84,79,95,84,69,88,67,79,79,82,68,83,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,103,108,95,70,114,97,103,67,111,111,114,100,46,120,121,32,42,32,73,110,118,84,97,114,103,101,116,83,105,122,101,59,13,10,35,101,108,115,101,13,10,9,118,101,99,50,32,116,101,120,67,111,111,114,100,32,61,32,118,84,101,120,67,111,111,114,100,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,68,73,70,70,85,83,69,95,77,65,80,80,73,78,71,13,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,32,42,61,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,68,105,102,102,117,115,101,77,97,112,44,32,116,101,120,67,111,111,114,100,41,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,65,76,80,72,65,95,77,65,80,80,73,78,71,13,10,9,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,42,61,32,116,101,120,116,117,114,101,40,77,97,116,101,114,105,97,108,65,108,112,104,97,77,97,112,44,32,116,101,120,67,111,111,114,100,41,46,114,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,65,76,80,72,65,95,84,69,83,84,13,10,9,105,102,32,40,102,114,97,103,109,101,110,116,67,111,108,111,114,46,97,32,60,32,77,97,116,101,114,105,97,108,65,108,112,104,97,84,104,114,101,115,104,111,108,100,41,13,10,9,9,100,105,115,99,97,114,100,59,13,10,35,101,110,100,105,102,13,10,13,10,9,82,101,110,100,101,114,84,97,114,103,101,116,48,32,61,32,102,114,97,103,109,101,110,116,67,111,108,111,114,59,13,10,125,
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
/********************Entrant********************/
|
/********************Entrant********************/
|
||||||
in mat4 InstanceData0;
|
in mat4 InstanceData0;
|
||||||
|
in vec4 VertexColor;
|
||||||
in vec3 VertexPosition;
|
in vec3 VertexPosition;
|
||||||
in vec2 VertexTexCoord;
|
in vec2 VertexTexCoord;
|
||||||
|
|
||||||
/********************Sortant********************/
|
/********************Sortant********************/
|
||||||
|
out vec4 vColor;
|
||||||
out vec2 vTexCoord;
|
out vec2 vTexCoord;
|
||||||
|
|
||||||
/********************Uniformes********************/
|
/********************Uniformes********************/
|
||||||
|
|
@ -14,6 +16,12 @@ uniform mat4 WorldViewProjMatrix;
|
||||||
/********************Fonctions********************/
|
/********************Fonctions********************/
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
#if FLAG_VERTEXCOLOR
|
||||||
|
vec4 color = VertexColor;
|
||||||
|
#else
|
||||||
|
vec4 color = vec4(1.0);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if FLAG_INSTANCING
|
#if FLAG_INSTANCING
|
||||||
#if TRANSFORM
|
#if TRANSFORM
|
||||||
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
|
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
|
||||||
|
|
@ -36,6 +44,7 @@ void main()
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
vColor = color;
|
||||||
#if TEXTURE_MAPPING
|
#if TEXTURE_MAPPING
|
||||||
vTexCoord = vec2(VertexTexCoord);
|
vTexCoord = vec2(VertexTexCoord);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,105,110,32,109,97,116,52,32,73,110,115,116,97,110,99,101,68,97,116,97,48,59,13,10,105,110,32,118,101,99,51,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,59,13,10,105,110,32,118,101,99,50,32,86,101,114,116,101,120,84,101,120,67,111,111,114,100,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,83,111,114,116,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,111,117,116,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,86,101,114,116,101,120,68,101,112,116,104,59,13,10,117,110,105,102,111,114,109,32,109,97,116,52,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,13,10,117,110,105,102,111,114,109,32,109,97,116,52,32,87,111,114,108,100,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,35,105,102,32,70,76,65,71,95,73,78,83,84,65,78,67,73,78,71,13,10,9,35,105,102,32,84,82,65,78,83,70,79,82,77,13,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,13,10,9,35,101,108,115,101,13,10,9,9,35,105,102,32,85,78,73,70,79,82,77,95,86,69,82,84,69,88,95,68,69,80,84,72,13,10,9,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,121,44,32,86,101,114,116,101,120,68,101,112,116,104,44,32,49,46,48,41,59,13,10,9,9,35,101,108,115,101,13,10,9,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,13,10,9,9,35,101,110,100,105,102,13,10,9,35,101,110,100,105,102,13,10,35,101,108,115,101,13,10,9,35,105,102,32,84,82,65,78,83,70,79,82,77,13,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,87,111,114,108,100,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,13,10,9,35,101,108,115,101,13,10,9,9,35,105,102,32,85,78,73,70,79,82,77,95,86,69,82,84,69,88,95,68,69,80,84,72,13,10,9,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,121,44,32,86,101,114,116,101,120,68,101,112,116,104,44,32,49,46,48,41,59,13,10,9,9,35,101,108,115,101,13,10,9,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,13,10,9,9,35,101,110,100,105,102,13,10,9,35,101,110,100,105,102,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,84,69,88,84,85,82,69,95,77,65,80,80,73,78,71,13,10,9,118,84,101,120,67,111,111,114,100,32,61,32,118,101,99,50,40,86,101,114,116,101,120,84,101,120,67,111,111,114,100,41,59,13,10,35,101,110,100,105,102,13,10,125,13,10,
|
47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,69,110,116,114,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,105,110,32,109,97,116,52,32,73,110,115,116,97,110,99,101,68,97,116,97,48,59,13,10,105,110,32,118,101,99,52,32,86,101,114,116,101,120,67,111,108,111,114,59,13,10,105,110,32,118,101,99,51,32,86,101,114,116,101,120,80,111,115,105,116,105,111,110,59,13,10,105,110,32,118,101,99,50,32,86,101,114,116,101,120,84,101,120,67,111,111,114,100,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,83,111,114,116,97,110,116,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,111,117,116,32,118,101,99,52,32,118,67,111,108,111,114,59,13,10,111,117,116,32,118,101,99,50,32,118,84,101,120,67,111,111,114,100,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,85,110,105,102,111,114,109,101,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,117,110,105,102,111,114,109,32,102,108,111,97,116,32,86,101,114,116,101,120,68,101,112,116,104,59,13,10,117,110,105,102,111,114,109,32,109,97,116,52,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,13,10,117,110,105,102,111,114,109,32,109,97,116,52,32,87,111,114,108,100,86,105,101,119,80,114,111,106,77,97,116,114,105,120,59,13,10,13,10,47,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,70,111,110,99,116,105,111,110,115,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,47,13,10,118,111,105,100,32,109,97,105,110,40,41,13,10,123,13,10,35,105,102,32,70,76,65,71,95,86,69,82,84,69,88,67,79,76,79,82,13,10,9,118,101,99,52,32,99,111,108,111,114,32,61,32,86,101,114,116,101,120,67,111,108,111,114,59,13,10,35,101,108,115,101,13,10,9,118,101,99,52,32,99,111,108,111,114,32,61,32,118,101,99,52,40,49,46,48,41,59,13,10,35,101,110,100,105,102,13,10,13,10,35,105,102,32,70,76,65,71,95,73,78,83,84,65,78,67,73,78,71,13,10,9,35,105,102,32,84,82,65,78,83,70,79,82,77,13,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,13,10,9,35,101,108,115,101,13,10,9,9,35,105,102,32,85,78,73,70,79,82,77,95,86,69,82,84,69,88,95,68,69,80,84,72,13,10,9,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,121,44,32,86,101,114,116,101,120,68,101,112,116,104,44,32,49,46,48,41,59,13,10,9,9,35,101,108,115,101,13,10,9,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,73,110,115,116,97,110,99,101,68,97,116,97,48,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,13,10,9,9,35,101,110,100,105,102,13,10,9,35,101,110,100,105,102,13,10,35,101,108,115,101,13,10,9,35,105,102,32,84,82,65,78,83,70,79,82,77,13,10,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,87,111,114,108,100,86,105,101,119,80,114,111,106,77,97,116,114,105,120,32,42,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,13,10,9,35,101,108,115,101,13,10,9,9,35,105,102,32,85,78,73,70,79,82,77,95,86,69,82,84,69,88,95,68,69,80,84,72,13,10,9,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,46,120,121,44,32,86,101,114,116,101,120,68,101,112,116,104,44,32,49,46,48,41,59,13,10,9,9,35,101,108,115,101,13,10,9,9,103,108,95,80,111,115,105,116,105,111,110,32,61,32,118,101,99,52,40,86,101,114,116,101,120,80,111,115,105,116,105,111,110,44,32,49,46,48,41,59,13,10,9,9,35,101,110,100,105,102,13,10,9,35,101,110,100,105,102,13,10,35,101,110,100,105,102,13,10,13,10,9,118,67,111,108,111,114,32,61,32,99,111,108,111,114,59,13,10,35,105,102,32,84,69,88,84,85,82,69,95,77,65,80,80,73,78,71,13,10,9,118,84,101,120,67,111,111,114,100,32,61,32,118,101,99,50,40,86,101,114,116,101,120,84,101,120,67,111,111,114,100,41,59,13,10,35,101,110,100,105,102,13,10,125,13,10,
|
||||||
|
|
@ -7,6 +7,7 @@ layout(early_fragment_tests) in;
|
||||||
#define LIGHT_SPOT 2
|
#define LIGHT_SPOT 2
|
||||||
|
|
||||||
/********************Entrant********************/
|
/********************Entrant********************/
|
||||||
|
in vec4 vColor;
|
||||||
in mat3 vLightToWorld;
|
in mat3 vLightToWorld;
|
||||||
in vec3 vNormal;
|
in vec3 vNormal;
|
||||||
in vec2 vTexCoord;
|
in vec2 vTexCoord;
|
||||||
|
|
@ -76,7 +77,7 @@ vec4 EncodeNormal(in vec3 normal)
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 diffuseColor = MaterialDiffuse;
|
vec4 diffuseColor = MaterialDiffuse * vColor;
|
||||||
vec2 texCoord = vTexCoord;
|
vec2 texCoord = vTexCoord;
|
||||||
#if LIGHTING && PARALLAX_MAPPING
|
#if LIGHTING && PARALLAX_MAPPING
|
||||||
float height = texture(MaterialHeightMap, texCoord).r;
|
float height = texture(MaterialHeightMap, texCoord).r;
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,11 +1,13 @@
|
||||||
/********************Entrant********************/
|
/********************Entrant********************/
|
||||||
in mat4 InstanceData0;
|
in mat4 InstanceData0;
|
||||||
|
in vec4 VertexColor;
|
||||||
in vec3 VertexPosition;
|
in vec3 VertexPosition;
|
||||||
in vec3 VertexNormal;
|
in vec3 VertexNormal;
|
||||||
in vec3 VertexTangent;
|
in vec3 VertexTangent;
|
||||||
in vec2 VertexTexCoord;
|
in vec2 VertexTexCoord;
|
||||||
|
|
||||||
/********************Sortant********************/
|
/********************Sortant********************/
|
||||||
|
out vec4 vColor;
|
||||||
out mat3 vLightToWorld;
|
out mat3 vLightToWorld;
|
||||||
out vec3 vNormal;
|
out vec3 vNormal;
|
||||||
out vec2 vTexCoord;
|
out vec2 vTexCoord;
|
||||||
|
|
@ -22,6 +24,12 @@ uniform mat4 WorldViewProjMatrix;
|
||||||
/********************Fonctions********************/
|
/********************Fonctions********************/
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
#if FLAG_VERTEXCOLOR
|
||||||
|
vec4 color = VertexColor;
|
||||||
|
#else
|
||||||
|
vec4 color = vec4(1.0);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if FLAG_INSTANCING
|
#if FLAG_INSTANCING
|
||||||
#if TRANSFORM
|
#if TRANSFORM
|
||||||
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
|
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
|
||||||
|
|
@ -44,6 +52,8 @@ void main()
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
vColor = color;
|
||||||
|
|
||||||
#if LIGHTING
|
#if LIGHTING
|
||||||
#if FLAG_INSTANCING
|
#if FLAG_INSTANCING
|
||||||
mat3 rotationMatrix = mat3(InstanceData0);
|
mat3 rotationMatrix = mat3(InstanceData0);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -3,20 +3,25 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Graphics/Sprite.hpp>
|
#include <Nazara/Graphics/Sprite.hpp>
|
||||||
|
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
NzSprite::NzSprite() :
|
NzSprite::NzSprite() :
|
||||||
m_boundingVolume(NzBoundingVolumef::Null()),
|
m_boundingVolume(NzBoundingVolumef::Null()),
|
||||||
|
m_color(NzColor::White),
|
||||||
m_textureCoords(0.f, 0.f, 1.f, 1.f),
|
m_textureCoords(0.f, 0.f, 1.f, 1.f),
|
||||||
m_size(64.f, 64.f),
|
m_size(64.f, 64.f),
|
||||||
m_boundingVolumeUpdated(true)
|
m_boundingVolumeUpdated(true),
|
||||||
|
m_verticesUpdated(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NzSprite::NzSprite(NzTexture* texture) :
|
NzSprite::NzSprite(NzTexture* texture) :
|
||||||
m_boundingVolume(NzBoundingVolumef::Null()),
|
m_boundingVolume(NzBoundingVolumef::Null()),
|
||||||
m_textureCoords(0.f, 0.f, 1.f, 1.f)
|
m_color(NzColor::White),
|
||||||
|
m_textureCoords(0.f, 0.f, 1.f, 1.f),
|
||||||
|
m_verticesUpdated(false)
|
||||||
{
|
{
|
||||||
if (texture)
|
if (texture)
|
||||||
{
|
{
|
||||||
|
|
@ -44,7 +49,9 @@ m_boundingVolume(sprite.m_boundingVolume),
|
||||||
m_material(sprite.m_material),
|
m_material(sprite.m_material),
|
||||||
m_textureCoords(sprite.m_textureCoords),
|
m_textureCoords(sprite.m_textureCoords),
|
||||||
m_size(sprite.m_size),
|
m_size(sprite.m_size),
|
||||||
m_boundingVolumeUpdated(sprite.m_boundingVolumeUpdated)
|
m_vertices(sprite.m_vertices),
|
||||||
|
m_boundingVolumeUpdated(sprite.m_boundingVolumeUpdated),
|
||||||
|
m_verticesUpdated(sprite.m_verticesUpdated)
|
||||||
{
|
{
|
||||||
SetParent(sprite);
|
SetParent(sprite);
|
||||||
}
|
}
|
||||||
|
|
@ -55,7 +62,9 @@ m_boundingVolume(sprite.m_boundingVolume),
|
||||||
m_material(std::move(sprite.m_material)),
|
m_material(std::move(sprite.m_material)),
|
||||||
m_textureCoords(sprite.m_textureCoords),
|
m_textureCoords(sprite.m_textureCoords),
|
||||||
m_size(sprite.m_size),
|
m_size(sprite.m_size),
|
||||||
m_boundingVolumeUpdated(sprite.m_boundingVolumeUpdated)
|
m_vertices(sprite.m_vertices),
|
||||||
|
m_boundingVolumeUpdated(sprite.m_boundingVolumeUpdated),
|
||||||
|
m_verticesUpdated(sprite.m_verticesUpdated)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,13 +72,23 @@ NzSprite::~NzSprite() = default;
|
||||||
|
|
||||||
void NzSprite::AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const
|
void NzSprite::AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const
|
||||||
{
|
{
|
||||||
renderQueue->AddSprite(this);
|
if (!m_verticesUpdated)
|
||||||
|
UpdateVertices();
|
||||||
|
|
||||||
|
renderQueue->AddSprites(m_material, m_vertices, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const NzBoundingVolumef& NzSprite::GetBoundingVolume() const
|
const NzBoundingVolumef& NzSprite::GetBoundingVolume() const
|
||||||
{
|
{
|
||||||
static NzBoundingVolumef infinity(NzBoundingVolumef::Infinite());
|
if (!m_boundingVolumeUpdated)
|
||||||
return infinity;
|
UpdateBoundingVolume();
|
||||||
|
|
||||||
|
return m_boundingVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
const NzColor& NzSprite::GetColor() const
|
||||||
|
{
|
||||||
|
return m_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
NzMaterial* NzSprite::GetMaterial() const
|
NzMaterial* NzSprite::GetMaterial() const
|
||||||
|
|
@ -97,6 +116,12 @@ bool NzSprite::IsDrawable() const
|
||||||
return m_material != nullptr;
|
return m_material != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NzSprite::SetColor(const NzColor& color)
|
||||||
|
{
|
||||||
|
m_color = color;
|
||||||
|
m_verticesUpdated = false;
|
||||||
|
}
|
||||||
|
|
||||||
void NzSprite::SetMaterial(NzMaterial* material, bool resizeSprite)
|
void NzSprite::SetMaterial(NzMaterial* material, bool resizeSprite)
|
||||||
{
|
{
|
||||||
m_material = material;
|
m_material = material;
|
||||||
|
|
@ -113,6 +138,7 @@ void NzSprite::SetSize(const NzVector2f& size)
|
||||||
// On invalide la bounding box
|
// On invalide la bounding box
|
||||||
m_boundingVolume.MakeNull();
|
m_boundingVolume.MakeNull();
|
||||||
m_boundingVolumeUpdated = false;
|
m_boundingVolumeUpdated = false;
|
||||||
|
m_verticesUpdated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzSprite::SetSize(float sizeX, float sizeY)
|
void NzSprite::SetSize(float sizeX, float sizeY)
|
||||||
|
|
@ -136,6 +162,7 @@ void NzSprite::SetTexture(NzTexture* texture, bool resizeSprite)
|
||||||
void NzSprite::SetTextureCoords(const NzRectf& coords)
|
void NzSprite::SetTextureCoords(const NzRectf& coords)
|
||||||
{
|
{
|
||||||
m_textureCoords = coords;
|
m_textureCoords = coords;
|
||||||
|
m_verticesUpdated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzSprite::SetTextureRect(const NzRectui& rect)
|
void NzSprite::SetTextureRect(const NzRectui& rect)
|
||||||
|
|
@ -167,10 +194,13 @@ void NzSprite::InvalidateNode()
|
||||||
NzSceneNode::InvalidateNode();
|
NzSceneNode::InvalidateNode();
|
||||||
|
|
||||||
m_boundingVolumeUpdated = false;
|
m_boundingVolumeUpdated = false;
|
||||||
|
m_verticesUpdated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzSprite::Register()
|
void NzSprite::Register()
|
||||||
{
|
{
|
||||||
|
// Le changement de scène peut affecter les sommets
|
||||||
|
m_verticesUpdated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzSprite::Unregister()
|
void NzSprite::Unregister()
|
||||||
|
|
@ -180,7 +210,12 @@ void NzSprite::Unregister()
|
||||||
void NzSprite::UpdateBoundingVolume() const
|
void NzSprite::UpdateBoundingVolume() const
|
||||||
{
|
{
|
||||||
if (m_boundingVolume.IsNull())
|
if (m_boundingVolume.IsNull())
|
||||||
m_boundingVolume.Set(-m_size.x*0.5f, -m_size.y*0.5f, 0.f, m_size.x, m_size.y, 0.f);
|
{
|
||||||
|
NzVector3f down = m_scene->GetDown();
|
||||||
|
NzVector3f right = m_scene->GetRight();
|
||||||
|
|
||||||
|
m_boundingVolume.Set(NzVector3f(0.f), m_size.x*right + m_size.y*down);
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_transformMatrixUpdated)
|
if (!m_transformMatrixUpdated)
|
||||||
UpdateTransformMatrix();
|
UpdateTransformMatrix();
|
||||||
|
|
@ -188,3 +223,30 @@ void NzSprite::UpdateBoundingVolume() const
|
||||||
m_boundingVolume.Update(m_transformMatrix);
|
m_boundingVolume.Update(m_transformMatrix);
|
||||||
m_boundingVolumeUpdated = true;
|
m_boundingVolumeUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NzSprite::UpdateVertices() const
|
||||||
|
{
|
||||||
|
if (!m_transformMatrixUpdated)
|
||||||
|
UpdateTransformMatrix();
|
||||||
|
|
||||||
|
NzVector3f down = m_scene->GetDown();
|
||||||
|
NzVector3f right = m_scene->GetRight();
|
||||||
|
|
||||||
|
m_vertices[0].color = m_color;
|
||||||
|
m_vertices[0].position = m_transformMatrix.Transform(NzVector3f(0.f));
|
||||||
|
m_vertices[0].uv.Set(m_textureCoords.GetCorner(nzRectCorner_LeftTop));
|
||||||
|
|
||||||
|
m_vertices[1].color = m_color;
|
||||||
|
m_vertices[1].position = m_transformMatrix.Transform(m_size.x*right);
|
||||||
|
m_vertices[1].uv.Set(m_textureCoords.GetCorner(nzRectCorner_RightTop));
|
||||||
|
|
||||||
|
m_vertices[2].color = m_color;
|
||||||
|
m_vertices[2].position = m_transformMatrix.Transform(m_size.y*down);
|
||||||
|
m_vertices[2].uv.Set(m_textureCoords.GetCorner(nzRectCorner_LeftBottom));
|
||||||
|
|
||||||
|
m_vertices[3].color = m_color;
|
||||||
|
m_vertices[3].position = m_transformMatrix.Transform(m_size.x*right + m_size.y*down);
|
||||||
|
m_vertices[3].uv.Set(m_textureCoords.GetCorner(nzRectCorner_RightBottom));
|
||||||
|
|
||||||
|
m_verticesUpdated = true;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -205,6 +205,21 @@ bool NzVertexDeclaration::Initialize()
|
||||||
|
|
||||||
NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ), "Invalid stride for declaration nzVertexLayout_XYZ");
|
NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ), "Invalid stride for declaration nzVertexLayout_XYZ");
|
||||||
|
|
||||||
|
// nzVertexLayout_XYZ_Color : NzVertexStruct_XYZ_Color
|
||||||
|
declaration = &s_declarations[nzVertexLayout_XYZ_Color_UV];
|
||||||
|
declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Color, position));
|
||||||
|
declaration->EnableComponent(nzVertexComponent_Color, nzComponentType_Color, NzOffsetOf(NzVertexStruct_XYZ_Color, color));
|
||||||
|
|
||||||
|
NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Color), "Invalid stride for declaration nzVertexLayout_XYZ_Color");
|
||||||
|
|
||||||
|
// nzVertexLayout_XYZ_Color_UV : NzVertexStruct_XYZ_Color_UV
|
||||||
|
declaration = &s_declarations[nzVertexLayout_XYZ_Color_UV];
|
||||||
|
declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Color_UV, position));
|
||||||
|
declaration->EnableComponent(nzVertexComponent_Color, nzComponentType_Color, NzOffsetOf(NzVertexStruct_XYZ_Color_UV, color));
|
||||||
|
declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Color_UV, uv));
|
||||||
|
|
||||||
|
NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Color_UV), "Invalid stride for declaration nzVertexLayout_XYZ_Color_UV");
|
||||||
|
|
||||||
// nzVertexLayout_XYZ_Normal : NzVertexStruct_XYZ_Normal
|
// nzVertexLayout_XYZ_Normal : NzVertexStruct_XYZ_Normal
|
||||||
declaration = &s_declarations[nzVertexLayout_XYZ_Normal];
|
declaration = &s_declarations[nzVertexLayout_XYZ_Normal];
|
||||||
declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal, position));
|
declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal, position));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue