Merge branch 'master' into vulkan

This commit is contained in:
Lynix
2017-11-24 20:14:39 +01:00
559 changed files with 10925 additions and 3359 deletions

View File

@@ -9,5 +9,6 @@ EXAMPLE.Files = {
EXAMPLE.Libraries = {
"NazaraAudio",
"NazaraCore",
"NazaraPlatform",
"NazaraUtility"
}
}

View File

@@ -12,14 +12,14 @@
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Core/Thread.hpp> // Thread::Sleep
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Utility/Keyboard.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <Nazara/Platform/Keyboard.hpp>
#include <Nazara/Platform/Platform.hpp>
#include <iostream>
int main()
{
// NzKeyboard nécessite l'initialisation du module Utilitaire
Nz::Initializer<Nz::Audio, Nz::Utility> audio;
Nz::Initializer<Nz::Audio, Nz::Platform> audio;
if (!audio)
{
std::cout << "Failed to initialize audio module" << std::endl;

View File

@@ -307,7 +307,8 @@ int main()
// Pour éviter que le curseur ne sorte de l'écran, nous le renvoyons au centre de la fenêtre
// Cette fonction est codée de sorte à ne pas provoquer d'évènement MouseMoved
Nz::Mouse::SetPosition(window.GetWidth() / 2, window.GetHeight() / 2, window);
Nz::Vector2ui size = window.GetSize();
Nz::Mouse::SetPosition(size.x / 2, size.y / 2, window);
break;
}

View File

@@ -12,6 +12,7 @@ EXAMPLE.Files = {
EXAMPLE.Libraries = {
"NazaraCore",
"NazaraPlatform",
"NazaraRenderer",
"NazaraUtility"
}

View File

@@ -8,6 +8,7 @@ EXAMPLE.Files = {
EXAMPLE.Libraries = {
"NazaraCore",
"NazaraPlatform",
"NazaraUtility"
}

View File

@@ -2,8 +2,11 @@
#include <Nazara/Core/File.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Utility/Animation.hpp>
#include <Nazara/Utility/Joint.hpp>
#include <Nazara/Utility/MaterialData.hpp>
#include <Nazara/Utility/Mesh.hpp>
#include <Nazara/Utility/Sequence.hpp>
#include <Nazara/Utility/Skeleton.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <cctype>
#include <iostream>

View File

@@ -11,7 +11,7 @@ m_name(name)
{
}
void ParticleDemo::Enter(Ndk::StateMachine& fsm)
void ParticleDemo::Enter(Ndk::StateMachine& /*fsm*/)
{
m_shared.demoName->Update(Nz::SimpleTextDrawer::Draw(Nz::String::Number(m_index+1) + " - " + m_name, 48));
m_fpsCounter = 0;
@@ -23,7 +23,7 @@ void ParticleDemo::Enter(Ndk::StateMachine& fsm)
m_oldBackground3D = renderSystem3D.GetDefaultBackground();
}
void ParticleDemo::Leave(Ndk::StateMachine& fsm)
void ParticleDemo::Leave(Ndk::StateMachine& /*fsm*/)
{
m_shared.world2D->GetSystem<Ndk::RenderSystem>().SetDefaultBackground(m_oldBackground2D);
m_shared.world3D->GetSystem<Ndk::RenderSystem>().SetDefaultBackground(m_oldBackground3D);
@@ -32,7 +32,7 @@ void ParticleDemo::Leave(Ndk::StateMachine& fsm)
m_particleGroups.clear();
}
bool ParticleDemo::Update(Ndk::StateMachine& fsm, float elapsedTime)
bool ParticleDemo::Update(Ndk::StateMachine& /*fsm*/, float elapsedTime)
{
m_fpsCounter++;
if (m_updateClock.GetMilliseconds() > 1000)

View File

@@ -21,7 +21,7 @@ struct ParticleData
{
Nz::Color color;
Nz::Vector2f destination;
Nz::Vector2f position;
Nz::Vector3f position;
Nz::Vector2f velocity;
};
@@ -33,18 +33,18 @@ struct SpriteController : public Nz::ParticleController
return;
auto destPtr = mapper.GetComponentPtr<Nz::Vector2f>(Nz::ParticleComponent_Userdata0);
auto posPtr = mapper.GetComponentPtr<Nz::Vector2f>(Nz::ParticleComponent_Position);
auto posPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Position);
auto velPtr = mapper.GetComponentPtr<Nz::Vector2f>(Nz::ParticleComponent_Velocity);
std::uniform_real_distribution<float> dis(-1.f, 1.f);
for (unsigned int i = startId; i <= endId; ++i)
{
Nz::Vector2f newVel = destPtr[i] - posPtr[i];
Nz::Vector2f newVel = destPtr[i] - Nz::Vector2f(posPtr[i]);
float length;
newVel.Normalize(&length);
float distance = SquaredDistancePointSegment(oldMousePos, actualMousePos, posPtr[i]);
float distance = SquaredDistancePointSegment(oldMousePos, actualMousePos, Nz::Vector2f(posPtr[i]));
if (distance < 250.f)
{
Nz::Vector2f mouseLine = actualMousePos - oldMousePos;
@@ -162,7 +162,7 @@ ParticleDemo("Logo", sharedData)
m_declaration = Nz::ParticleDeclaration::New();
m_declaration->EnableComponent(Nz::ParticleComponent_Color, Nz::ComponentType_Color, NazaraOffsetOf(ParticleData, color));
m_declaration->EnableComponent(Nz::ParticleComponent_Position, Nz::ComponentType_Float2, NazaraOffsetOf(ParticleData, position));
m_declaration->EnableComponent(Nz::ParticleComponent_Position, Nz::ComponentType_Float3, NazaraOffsetOf(ParticleData, position));
m_declaration->EnableComponent(Nz::ParticleComponent_Userdata0, Nz::ComponentType_Float2, NazaraOffsetOf(ParticleData, destination));
m_declaration->EnableComponent(Nz::ParticleComponent_Velocity, Nz::ComponentType_Float2, NazaraOffsetOf(ParticleData, velocity));
}
@@ -231,7 +231,7 @@ bool LogoExample::Update(Ndk::StateMachine& fsm, float elapsedTime)
ParticleData* sprite = static_cast<ParticleData*>(m_particles);
for (std::size_t i = 0; i < m_pixels.size(); ++i)
{
Nz::Vector2f particleToMouse = sprite[i].position - controller->actualMousePos;
Nz::Vector2f particleToMouse = Nz::Vector2f(sprite[i].position) - controller->actualMousePos;
float sqDist = particleToMouse.GetSquaredLength();
if (sqDist < 10000.f)
{
@@ -251,21 +251,20 @@ bool LogoExample::Update(Ndk::StateMachine& fsm, float elapsedTime)
void LogoExample::ResetParticles(float elapsed)
{
unsigned int width = m_shared.target->GetWidth();
unsigned int height = m_shared.target->GetHeight();
Nz::Vector2ui size = m_shared.target->GetSize();
Nz::Vector2f center = {width / 2.f, height / 2.f};
Nz::Vector2f center = {size.x / 2.f, size.y / 2.f};
Nz::Vector2f offset = center - Nz::Vector2f(Nz::Vector2ui(m_logo.GetSize()) / 2);
std::uniform_real_distribution<float> disX(0.f, float(width));
std::uniform_real_distribution<float> disY(-float(height) * 0.5f, float(height) * 1.5f);
std::uniform_real_distribution<float> disX(0.f, float(size.x));
std::uniform_real_distribution<float> disY(-float(size.y) * 0.5f, float(size.y) * 1.5f);
ParticleData* sprite = static_cast<ParticleData*>(m_particles);
for (PixelData& data : m_pixels)
{
sprite->color = data.color;
sprite->destination = offset + Nz::Vector2f(data.pos);
sprite->position.Set(disX(m_shared.randomGen) - float(width), disY(m_shared.randomGen));
sprite->position.Set(disX(m_shared.randomGen) - float(size.x), disY(m_shared.randomGen), 0.f);
sprite->velocity = Nz::Vector2f::Zero();
sprite++;
}

View File

@@ -2,6 +2,7 @@
#include <Nazara/Audio/Sound.hpp>
#include <Nazara/Core/OffsetOf.hpp>
#include <Nazara/Graphics.hpp>
#include <Nazara/Platform.hpp>
#include <Nazara/Utility.hpp>
#include <NDK/Components.hpp>
#include <NDK/Systems.hpp>
@@ -317,10 +318,10 @@ ParticleDemo("Space battle", sharedData)
m_spaceshipTemplate = m_shared.world3D->CreateEntity();
m_spaceshipTemplate->Enable(false);
m_spaceshipTemplate->AddComponent<Ndk::NodeComponent>();
m_spaceshipTemplate->AddComponent<Ndk::VelocityComponent>();
m_spaceshipTemplate->AddComponent<SpaceshipComponent>();
auto& gfxComponent = m_spaceshipTemplate->AddComponent<Ndk::GraphicsComponent>();
auto& nodeComponent = m_spaceshipTemplate->AddComponent<Ndk::NodeComponent>();
auto& velocityComponent = m_spaceshipTemplate->AddComponent<Ndk::VelocityComponent>();
auto& spaceshipComponent = m_spaceshipTemplate->AddComponent<SpaceshipComponent>();
gfxComponent.Attach(&m_spaceshipModel);
m_ambientMusic.OpenFromFile("resources/ambience.ogg");
@@ -385,9 +386,7 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
m_torpedoGroup->AddController(Nz::ParticleFunctionController::New([this] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
{
auto positionPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Position);
auto rotationPtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Rotation);
auto sizePtr = mapper.GetComponentPtr<Nz::Vector2f>(Nz::ParticleComponent_Size);
auto velocityPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Velocity);
auto& spaceshipSystem = m_shared.world3D->GetSystem<SpaceshipSystem>();
@@ -421,7 +420,7 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
emitter.SetEmissionCount(2);
emitter.SetEmissionRate(200.f);
emitter.SetSetupFunc([this] (const Ndk::EntityHandle& entity, Nz::ParticleMapper& mapper, unsigned int count)
emitter.SetSetupFunc([this] (const Ndk::EntityHandle& emitterEntity, Nz::ParticleMapper& particleMapper, unsigned int count)
{
auto& gen = m_shared.randomGen;
@@ -433,29 +432,29 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
std::uniform_real_distribution<float> sizeDis(1.0f, 4.f);
std::uniform_real_distribution<float> velDis(-maxFireVel, maxFireVel);
Nz::Vector3f pos = entity->GetComponent<Ndk::NodeComponent>().GetPosition();
Nz::Vector3f pos = emitterEntity->GetComponent<Ndk::NodeComponent>().GetPosition();
Nz::ParticleStruct_Billboard* billboards = static_cast<Nz::ParticleStruct_Billboard*>(mapper.GetPointer());
Nz::ParticleStruct_Billboard* billboards = static_cast<Nz::ParticleStruct_Billboard*>(particleMapper.GetPointer());
Nz::ParticleStruct_Billboard* smokeParticles = static_cast<Nz::ParticleStruct_Billboard*>(m_smokeGroup->CreateParticles(count));
for (unsigned int i = 0; i < count; ++i)
for (unsigned int j = 0; j < count; ++j)
{
billboards[i].color = Nz::Color::White;
billboards[i].life = 1.f + lifeDis(gen);
billboards[i].position = pos + Nz::Vector3f(posDis(gen), posDis(gen), posDis(gen));
billboards[i].rotation = rotDis(gen);
billboards[i].size = {1.28f, 1.28f};
billboards[i].size *= sizeDis(gen);
billboards[i].velocity.Set(normalDis(gen), normalDis(gen), normalDis(gen));
billboards[i].velocity.Normalize();
billboards[i].velocity *= velDis(gen);
billboards[j].color = Nz::Color::White;
billboards[j].life = 1.f + lifeDis(gen);
billboards[j].position = pos + Nz::Vector3f(posDis(gen), posDis(gen), posDis(gen));
billboards[j].rotation = rotDis(gen);
billboards[j].size = {1.28f, 1.28f};
billboards[j].size *= sizeDis(gen);
billboards[j].velocity.Set(normalDis(gen), normalDis(gen), normalDis(gen));
billboards[j].velocity.Normalize();
billboards[j].velocity *= velDis(gen);
smokeParticles[i].color = Nz::Color(128, 128, 128, 0);
smokeParticles[i].life = maxSmokeLife;
smokeParticles[i].position = billboards[i].position;
smokeParticles[i].rotation = billboards[i].rotation;
smokeParticles[i].size = {2.56f, 2.56f};
smokeParticles[i].size *= sizeDis(gen);
smokeParticles[i].velocity = billboards[i].velocity / 2.f;
smokeParticles[j].color = Nz::Color(128, 128, 128, 0);
smokeParticles[j].life = maxSmokeLife;
smokeParticles[j].position = billboards[j].position;
smokeParticles[j].rotation = billboards[j].rotation;
smokeParticles[j].size = {2.56f, 2.56f};
smokeParticles[j].size *= sizeDis(gen);
smokeParticles[j].velocity = billboards[j].velocity / 2.f;
}
});
m_fireGroup->AddEmitter(entity);
@@ -466,12 +465,11 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
}
}));
m_torpedoGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([sparkleMat1 = Nz::MaterialLibrary::Get("TorpedoFlare1")] (const Nz::ParticleGroup& group, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
m_torpedoGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([sparkleMat1 = Nz::MaterialLibrary::Get("TorpedoFlare1")] (const Nz::ParticleGroup& /*group*/, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
{
auto positionPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Position);
auto rotationPtr = mapper.GetComponentPtr<const float>(Nz::ParticleComponent_Rotation);
auto sizePtr = mapper.GetComponentPtr<const Nz::Vector2f>(Nz::ParticleComponent_Size);
auto velocityPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Velocity);
renderQueue->AddBillboards(0, sparkleMat1, endId - startId + 1, positionPtr, sizePtr, rotationPtr);
for (unsigned int i = startId; i <= endId; ++i)
@@ -580,7 +578,7 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
});
m_fireGroup->AddController(movementController);
m_fireGroup->AddController(Nz::ParticleFunctionController::New([] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
m_fireGroup->AddController(Nz::ParticleFunctionController::New([] (Nz::ParticleGroup& /*group*/, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
{
auto colorPtr = mapper.GetComponentPtr<Nz::Color>(Nz::ParticleComponent_Color);
auto lifePtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Life);
@@ -591,7 +589,7 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
}));
m_smokeGroup->AddController(movementController);
m_smokeGroup->AddController(Nz::ParticleFunctionController::New([] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
m_smokeGroup->AddController(Nz::ParticleFunctionController::New([] (Nz::ParticleGroup& /*group*/, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
{
auto colorPtr = mapper.GetComponentPtr<Nz::Color>(Nz::ParticleComponent_Color);
auto lifePtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Life);
@@ -617,7 +615,7 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
smokeMat->SetDiffuseColor(Nz::Color(128, 128, 128));
smokeMat->SetDiffuseMap("resources/smoke.png");
m_fireGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([fireMat] (const Nz::ParticleGroup& group, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
m_fireGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([fireMat] (const Nz::ParticleGroup& /*group*/, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
{
auto colorPtr = mapper.GetComponentPtr<const Nz::Color>(Nz::ParticleComponent_Color);
auto posPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Position);
@@ -627,7 +625,7 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
renderQueue->AddBillboards(0, fireMat, endId - startId + 1, posPtr, sizePtr, rotPtr, colorPtr);
}));
m_smokeGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([smokeMat] (const Nz::ParticleGroup& group, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
m_smokeGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([smokeMat] (const Nz::ParticleGroup& /*group*/, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
{
auto colorPtr = mapper.GetComponentPtr<const Nz::Color>(Nz::ParticleComponent_Color);
auto posPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Position);
@@ -643,13 +641,13 @@ void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
m_turretFireSound.LoadFromFile("resources/turretFire.wav");
m_turretReloadSound.LoadFromFile("resources/turretReload.wav");
//m_onMouseMoved.Connect(m_shared.target->GetEventHandler().OnMouseMoved, this, &SpacebattleExample::OnMouseMoved);
//m_shared.target->SetCursor(Nz::SystemCursor_None);
m_onMouseMoved.Connect(m_shared.target->GetEventHandler().OnMouseMoved, this, &SpacebattleExample::OnMouseMoved);
m_shared.target->SetCursor(Nz::SystemCursor_None);
//////////////////////////////////////////////////////////////////////////
Nz::TextSpriteRef introText = Nz::TextSprite::New();
introText->Update(Nz::SimpleTextDrawer::Draw("--Tourelle de défense du secteur A407M2--\nLes contrôles ont été adaptés à vos contrôleurs:\nZQSD pour orienter la tourelle, espace pour tirer.\n", 72));
introText->Update(Nz::SimpleTextDrawer::Draw("--Tourelle de défense du secteur A407M2--\nLes contrôles ont été adaptés à vos contrôleurs:\nLa souris contrôle l'orientation de la tourelle, cliquez pour tirer.\n", 72));
introText->SetScale(0.5f);
m_introText = m_shared.world3D->CreateEntity();
@@ -682,7 +680,7 @@ bool SpacebattleExample::Update(Ndk::StateMachine& fsm, float elapsedTime)
const float speed = 100.f;
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Z))
/*if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Z))
m_turretCannonBaseRotation = std::max(m_turretCannonBaseRotation - speed * elapsedTime, -65.f);
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::S))
@@ -692,13 +690,13 @@ bool SpacebattleExample::Update(Ndk::StateMachine& fsm, float elapsedTime)
m_turretBaseRotation += speed * elapsedTime;
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::D))
m_turretBaseRotation -= speed * elapsedTime;
m_turretBaseRotation -= speed * elapsedTime;*/
m_turret.cannonBaseEntity->GetComponent<Ndk::NodeComponent>().SetRotation(Nz::EulerAnglesf(m_turretCannonBaseRotation, 0.f, 0.f));
m_turret.rotatingBaseEntity->GetComponent<Ndk::NodeComponent>().SetRotation(Nz::EulerAnglesf(0.f, m_turretBaseRotation, 0.f));
bool discharged = m_turretShootTimer < 1.f;
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Space) && !discharged)
if (Nz::Mouse::IsButtonPressed(Nz::Mouse::Left) && !discharged)
{
m_turretFireSound.Play();
@@ -729,7 +727,7 @@ bool SpacebattleExample::Update(Ndk::StateMachine& fsm, float elapsedTime)
auto& spacestationNode = m_spacestationEntity->GetComponent<Ndk::NodeComponent>();
Ndk::EntityHandle spaceship = m_spaceshipTemplate->Clone();
const Ndk::EntityHandle& spaceship = m_spaceshipTemplate->Clone();
RegisterEntity(spaceship);
auto& nodeComponent = spaceship->GetComponent<Ndk::NodeComponent>();
auto& spaceshipComponent = spaceship->GetComponent<SpaceshipComponent>();
@@ -815,12 +813,13 @@ void SpacebattleExample::CreateTurret()
cannonGfx.Attach(&m_turret.cannonModel);
}
void SpacebattleExample::OnMouseMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseMoveEvent& event)
void SpacebattleExample::OnMouseMoved(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseMoveEvent& event)
{
const float speed = 0.1f;
m_turretCannonBaseRotation = Nz::Clamp(m_turretCannonBaseRotation + speed * event.deltaY, -65.f, 40.f);
m_turretBaseRotation -= event.deltaX * speed;
Nz::Mouse::SetPosition(m_shared.target->GetWidth() / 2, m_shared.target->GetHeight() / 2, *m_shared.target);
Nz::Vector2ui size = m_shared.target->GetSize();
Nz::Mouse::SetPosition(size.x / 2, size.y / 2, *m_shared.target);
}

View File

@@ -10,7 +10,7 @@
#include <Nazara/Graphics/ParticleStruct.hpp>
#include <Nazara/Graphics/SkyboxBackground.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Utility/EventHandler.hpp>
#include <Nazara/Platform/EventHandler.hpp>
#include <NDK/Entity.hpp>
#include <NDK/State.hpp>
#include <vector>

View File

@@ -59,7 +59,7 @@ int main()
shared.particleCount->Update(Nz::SimpleTextDrawer::Draw("XXXXX particles", 36));
world2D.GetSystem<Ndk::RenderSystem>().SetGlobalUp(Nz::Vector3f::Down());
world3D.GetSystem<Ndk::RenderSystem>().ChangeRenderTechnique<Nz::DeferredRenderTechnique>();
//world3D.GetSystem<Ndk::RenderSystem>().ChangeRenderTechnique<Nz::DeferredRenderTechnique>();
Ndk::EntityHandle viewEntity = world2D.CreateEntity();
@@ -100,9 +100,10 @@ int main()
Nz::Boxf fpsCountBox = fpsGfx.GetBoundingVolume().aabb;
Nz::Boxf particleCountBox = particleCountGfx.GetBoundingVolume().aabb;
Nz::Vector2ui windowSize = window.GetSize();
demoNameNode.SetPosition(5.f, 5.f);
particleCountNode.SetPosition(5.f, window.GetHeight() - particleCountBox.height - 5.f);
fpsNode.SetPosition(5.f, window.GetHeight() - fpsCountBox.height - particleCountBox.height - 5.f);
particleCountNode.SetPosition(5.f, windowSize.y - particleCountBox.height - 5.f);
fpsNode.SetPosition(5.f, windowSize.x - fpsCountBox.height - particleCountBox.height - 5.f);
shared.demos.push_back(std::make_shared<LogoExample>(shared));
@@ -125,7 +126,7 @@ int main()
switch (event.key.code)
{
case Nz::Keyboard::Backspace:
stateMachine.ChangeState(stateMachine.GetCurrentState());
stateMachine.ChangeState(shared.demos[demoIndex]);
break;
case Nz::Keyboard::Escape:

View File

@@ -15,6 +15,7 @@ EXAMPLE.Libraries = {
"NazaraNoise",
"NazaraPhysics2D",
"NazaraPhysics3D",
"NazaraPlatform",
"NazaraRenderer",
"NazaraUtility",
"NazaraSDK"

View File

@@ -40,7 +40,8 @@ int main(int argc, char* argv[])
graphicsComponent.Attach(textSprite);
Nz::Boxf textBox = graphicsComponent.GetBoundingVolume().aabb;
nodeComponent.SetPosition(mainWindow.GetWidth() / 2 - textBox.width / 2, mainWindow.GetHeight() / 2 - textBox.height / 2);
Nz::Vector2ui windowSize = mainWindow.GetSize();
nodeComponent.SetPosition(windowSize.x / 2 - textBox.width / 2, windowSize.y / 2 - textBox.height / 2);
while (application.Run())
{

View File

@@ -0,0 +1,488 @@
#if EARLY_FRAGMENT_TESTS && !ALPHA_TEST
layout(early_fragment_tests) in;
#endif
// HACK UNTIL PROPER FIX
#if GLSL_VERSION < 400
#undef SHADOW_MAPPING
#define SHADOW_MAPPING 0
#endif
// HACK
#define LIGHT_DIRECTIONAL 0
#define LIGHT_POINT 1
#define LIGHT_SPOT 2
/********************Entrant********************/
in vec4 vColor;
in vec4 vLightSpacePos[3];
in mat3 vLightToWorld;
in vec3 vNormal;
in vec2 vTexCoord;
in vec3 vViewDir;
in vec3 vWorldPos;
/********************Sortant********************/
out vec4 RenderTarget0;
out vec4 RenderTarget1;
out vec4 RenderTarget2;
/********************Uniformes********************/
struct Light
{
int type;
vec4 color;
vec2 factors;
vec4 parameters1;
vec4 parameters2;
vec2 parameters3;
bool shadowMapping;
};
// Lumières
uniform Light Lights[3];
uniform samplerCube PointLightShadowMap[3];
uniform sampler2D DirectionalSpotLightShadowMap[3];
// Matériau
uniform sampler2D MaterialAlphaMap;
uniform float MaterialAlphaThreshold;
uniform vec4 MaterialAmbient;
uniform vec4 MaterialDiffuse;
uniform sampler2D MaterialDiffuseMap;
uniform sampler2D MaterialEmissiveMap;
uniform sampler2D MaterialHeightMap;
uniform sampler2D MaterialNormalMap;
uniform float MaterialShininess;
uniform vec4 MaterialSpecular;
uniform sampler2D MaterialSpecularMap;
// Autres
uniform float ParallaxBias = -0.03;
uniform float ParallaxScale = 0.02;
uniform vec2 InvTargetSize;
uniform vec3 EyePosition;
uniform samplerCube ReflectionMap;
uniform vec4 SceneAmbient;
uniform mat4 WorldMatrix;
uniform sampler2D TextureOverlay;
/********************Fonctions********************/
#define kPI 3.1415926536
vec4 EncodeNormal(in vec3 normal)
{
//return vec4(normal*0.5 + 0.5, 0.0);
return vec4(vec2(atan(normal.y, normal.x)/kPI, normal.z), 0.0, 0.0);
}
float VectorToDepthValue(vec3 vec, float zNear, float zFar)
{
vec3 absVec = abs(vec);
float localZ = max(absVec.x, max(absVec.y, absVec.z));
float normZ = ((zFar + zNear) * localZ - (2.0*zFar*zNear)) / ((zFar - zNear)*localZ);
return (normZ + 1.0) * 0.5;
}
#if SHADOW_MAPPING
float CalculateDirectionalShadowFactor(int lightIndex)
{
vec4 lightSpacePos = vLightSpacePos[lightIndex];
return (texture(DirectionalSpotLightShadowMap[lightIndex], lightSpacePos.xy).x >= (lightSpacePos.z - 0.0005)) ? 1.0 : 0.0;
}
float CalculatePointShadowFactor(int lightIndex, vec3 lightToWorld, float zNear, float zFar)
{
return (texture(PointLightShadowMap[lightIndex], vec3(lightToWorld.x, -lightToWorld.y, -lightToWorld.z)).x >= VectorToDepthValue(lightToWorld, zNear, zFar)) ? 1.0 : 0.0;
}
float CalculateSpotShadowFactor(int lightIndex, float lambert)
{
vec4 lightSpacePos = vLightSpacePos[lightIndex];
#if 0
float visibility = 1.0;
float bias = 0.005 * tan(acos(NoL));
bias = clamp(bias, MinAllowedBias, MaxAllowedBias);
float x,y;
for (y = -1.0; y <= 1.0; y+= 1.0)
for (x = -1.0; x <= 1.0; x+= 1.0)
visibility += (textureProj(DirectionalSpotLightShadowMap[lightIndex], lightSpacePos.xyw + vec3(x/1024.0 * lightSpacePos.w, y/1024.0 * lightSpacePos.w, 0.0)).x >= (lightSpacePos.z - 0.0005)/lightSpacePos.w) ? 1.0 : 0.0;
visibility /= 9.0;
return visibility;
#else
float bias = 0.005 * tan(acos(lambert));
return (textureProj(DirectionalSpotLightShadowMap[lightIndex], lightSpacePos.xyw).x >= (lightSpacePos.z - bias)/lightSpacePos.w) ? 1.0 : 0.0;
#endif
}
#endif
void main()
{
vec4 diffuseColor = MaterialDiffuse * vColor;
#if AUTO_TEXCOORDS
vec2 texCoord = gl_FragCoord.xy * InvTargetSize;
#else
vec2 texCoord = vTexCoord;
#endif
#if PARALLAX_MAPPING
float height = texture(MaterialHeightMap, texCoord).r;
float v = height*ParallaxScale + ParallaxBias;
vec3 viewDir = normalize(vViewDir);
texCoord += v * viewDir.xy;
#endif
#if DIFFUSE_MAPPING
diffuseColor *= texture(MaterialDiffuseMap, texCoord);
#endif
#if FLAG_TEXTUREOVERLAY
diffuseColor *= texture(TextureOverlay, texCoord);
#endif
#if FLAG_DEFERRED
#if ALPHA_TEST
// Inutile de faire de l'alpha-mapping sans alpha-test en Deferred (l'alpha n'est pas sauvegardé dans le G-Buffer)
#if ALPHA_MAPPING
diffuseColor.a *= texture(MaterialAlphaMap, texCoord).r;
#endif
if (diffuseColor.a < MaterialAlphaThreshold)
discard;
#endif // ALPHA_TEST
#if NORMAL_MAPPING
vec3 normal = normalize(vLightToWorld * (2.0 * vec3(texture(MaterialNormalMap, texCoord)) - 1.0));
#else
vec3 normal = normalize(vNormal);
#endif // NORMAL_MAPPING
vec3 specularColor = MaterialSpecular.rgb;
#if SPECULAR_MAPPING
specularColor *= texture(MaterialSpecularMap, texCoord).rgb;
#endif
/*
Texture0: Diffuse Color + Specular
Texture1: Normal + Specular
Texture2: Encoded depth + Shininess
*/
RenderTarget0 = vec4(diffuseColor.rgb, dot(specularColor, vec3(0.3, 0.59, 0.11)));
RenderTarget1 = vec4(EncodeNormal(normal));
RenderTarget2 = vec4(0.0, 0.0, 0.0, (MaterialShininess == 0.0) ? 0.0 : max(log2(MaterialShininess), 0.1)/10.5); // http://www.guerrilla-games.com/publications/dr_kz2_rsx_dev07.pdf
#else // FLAG_DEFERRED
#if ALPHA_MAPPING
diffuseColor.a *= texture(MaterialAlphaMap, texCoord).r;
#endif
#if ALPHA_TEST
if (diffuseColor.a < MaterialAlphaThreshold)
discard;
#endif
vec3 lightAmbient = vec3(0.0);
vec3 lightDiffuse = vec3(0.0);
vec3 lightSpecular = vec3(0.0);
#if NORMAL_MAPPING
vec3 normal = normalize(vLightToWorld * (2.0 * vec3(texture(MaterialNormalMap, texCoord)) - 1.0));
#else
vec3 normal = normalize(vNormal);
#endif
if (MaterialShininess > 0.0)
{
vec3 eyeVec = normalize(EyePosition - vWorldPos);
for (int i = 0; i < 3; ++i)
{
vec4 lightColor = Lights[i].color;
float lightAmbientFactor = Lights[i].factors.x;
float lightDiffuseFactor = Lights[i].factors.y;
switch (Lights[i].type)
{
case LIGHT_DIRECTIONAL:
{
vec3 lightDir = -Lights[i].parameters1.xyz;
// Ambient
lightAmbient += lightColor.rgb * lightAmbientFactor * (MaterialAmbient.rgb + SceneAmbient.rgb);
float att = 1.0;
float lambert = max(dot(normal, lightDir), 0.0);
#if SHADOW_MAPPING
if (Lights[i].shadowMapping)
{
float shadowFactor = CalculateDirectionalShadowFactor(i);
if (shadowFactor == 0.0)
break;
att *= shadowFactor;
}
#endif
// Diffuse
lightDiffuse += att * lambert * lightColor.rgb * lightDiffuseFactor;
// Specular
vec3 reflection = reflect(-lightDir, normal);
float specularFactor = max(dot(reflection, eyeVec), 0.0);
specularFactor = pow(specularFactor, MaterialShininess);
lightSpecular += att * specularFactor * lightColor.rgb;
break;
}
case LIGHT_POINT:
{
vec3 lightPos = Lights[i].parameters1.xyz;
float lightAttenuation = Lights[i].parameters1.w;
float lightInvRadius = Lights[i].parameters2.w;
vec3 worldToLight = lightPos - vWorldPos;
float lightDirLength = length(worldToLight);
vec3 lightDir = worldToLight / lightDirLength; // Normalisation
float att = max(lightAttenuation - lightInvRadius * lightDirLength, 0.0);
// Ambient
lightAmbient += att * lightColor.rgb * lightAmbientFactor * (MaterialAmbient.rgb + SceneAmbient.rgb);
#if SHADOW_MAPPING
if (Lights[i].shadowMapping)
{
float shadowFactor = CalculatePointShadowFactor(i, vWorldPos - lightPos, 0.1, 50.0);
if (shadowFactor == 0.0)
break;
att *= shadowFactor;
}
#endif
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightDiffuse += att * lambert * lightColor.rgb * lightDiffuseFactor;
// Specular
vec3 reflection = reflect(-lightDir, normal);
float specularFactor = max(dot(reflection, eyeVec), 0.0);
specularFactor = pow(specularFactor, MaterialShininess);
lightSpecular += att * specularFactor * lightColor.rgb;
break;
}
case LIGHT_SPOT:
{
vec3 lightPos = Lights[i].parameters1.xyz;
vec3 lightDir = Lights[i].parameters2.xyz;
float lightAttenuation = Lights[i].parameters1.w;
float lightInvRadius = Lights[i].parameters2.w;
float lightInnerAngle = Lights[i].parameters3.x;
float lightOuterAngle = Lights[i].parameters3.y;
vec3 worldToLight = lightPos - vWorldPos;
float lightDistance = length(worldToLight);
worldToLight /= lightDistance; // Normalisation
float att = max(lightAttenuation - lightInvRadius * lightDistance, 0.0);
// Ambient
lightAmbient += att * lightColor.rgb * lightAmbientFactor * (MaterialAmbient.rgb + SceneAmbient.rgb);
float lambert = max(dot(normal, worldToLight), 0.0);
#if SHADOW_MAPPING
if (Lights[i].shadowMapping)
{
float shadowFactor = CalculateSpotShadowFactor(i, lambert);
if (shadowFactor == 0.0)
break;
att *= shadowFactor;
}
#endif
// Modification de l'atténuation pour gérer le spot
float curAngle = dot(lightDir, -worldToLight);
float innerMinusOuterAngle = lightInnerAngle - lightOuterAngle;
att *= max((curAngle - lightOuterAngle) / innerMinusOuterAngle, 0.0);
// Diffuse
lightDiffuse += att * lambert * lightColor.rgb * lightDiffuseFactor;
// Specular
vec3 reflection = reflect(-worldToLight, normal);
float specularFactor = max(dot(reflection, eyeVec), 0.0);
specularFactor = pow(specularFactor, MaterialShininess);
lightSpecular += att * specularFactor * lightColor.rgb;
break;
}
default:
break;
}
}
}
else
{
for (int i = 0; i < 3; ++i)
{
vec4 lightColor = Lights[i].color;
float lightAmbientFactor = Lights[i].factors.x;
float lightDiffuseFactor = Lights[i].factors.y;
switch (Lights[i].type)
{
case LIGHT_DIRECTIONAL:
{
vec3 lightDir = -Lights[i].parameters1.xyz;
// Ambient
lightAmbient += lightColor.rgb * lightAmbientFactor * (MaterialAmbient.rgb + SceneAmbient.rgb);
float att = 1.0;
#if SHADOW_MAPPING
if (Lights[i].shadowMapping)
{
float shadowFactor = CalculateDirectionalShadowFactor(i);
if (shadowFactor == 0.0)
break;
att *= shadowFactor;
}
#endif
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightDiffuse += att * lambert * lightColor.rgb * lightDiffuseFactor;
break;
}
case LIGHT_POINT:
{
vec3 lightPos = Lights[i].parameters1.xyz;
float lightAttenuation = Lights[i].parameters1.w;
float lightInvRadius = Lights[i].parameters2.w;
vec3 worldToLight = lightPos - vWorldPos;
float lightDirLength = length(worldToLight);
vec3 lightDir = worldToLight / lightDirLength; // Normalisation
float att = max(lightAttenuation - lightInvRadius * lightDirLength, 0.0);
// Ambient
lightAmbient += att * lightColor.rgb * lightAmbientFactor * (MaterialAmbient.rgb + SceneAmbient.rgb);
#if SHADOW_MAPPING
if (Lights[i].shadowMapping)
{
float shadowFactor = CalculatePointShadowFactor(i, vWorldPos - lightPos, 0.1, 50.0);
if (shadowFactor == 0.0)
break;
att *= shadowFactor;
}
#endif
// Diffuse
float lambert = max(dot(normal, lightDir), 0.0);
lightDiffuse += att * lambert * lightColor.rgb * lightDiffuseFactor;
break;
}
case LIGHT_SPOT:
{
vec3 lightPos = Lights[i].parameters1.xyz;
vec3 lightDir = Lights[i].parameters2.xyz;
float lightAttenuation = Lights[i].parameters1.w;
float lightInvRadius = Lights[i].parameters2.w;
float lightInnerAngle = Lights[i].parameters3.x;
float lightOuterAngle = Lights[i].parameters3.y;
vec3 worldToLight = lightPos - vWorldPos;
float lightDistance = length(worldToLight);
worldToLight /= lightDistance; // Normalisation
float att = max(lightAttenuation - lightInvRadius * lightDistance, 0.0);
// Ambient
lightAmbient += att * lightColor.rgb * lightAmbientFactor * (MaterialAmbient.rgb + SceneAmbient.rgb);
float lambert = max(dot(normal, worldToLight), 0.0);
#if SHADOW_MAPPING
if (Lights[i].shadowMapping)
{
float shadowFactor = CalculateSpotShadowFactor(i, lambert);
if (shadowFactor == 0.0)
break;
att *= shadowFactor;
}
#endif
// Modification de l'atténuation pour gérer le spot
float curAngle = dot(lightDir, -worldToLight);
float innerMinusOuterAngle = lightInnerAngle - lightOuterAngle;
att *= max((curAngle - lightOuterAngle) / innerMinusOuterAngle, 0.0);
// Diffuse
lightDiffuse += att * lambert * lightColor.rgb * lightDiffuseFactor;
}
default:
break;
}
}
}
lightSpecular *= MaterialSpecular.rgb;
#if SPECULAR_MAPPING
lightSpecular *= texture(MaterialSpecularMap, texCoord).rgb; // Utiliser l'alpha de MaterialSpecular n'aurait aucun sens
#endif
vec3 lightColor = (lightAmbient + lightDiffuse + lightSpecular);
#if REFLECTION_MAPPING
vec3 eyeVec = normalize(vWorldPos - EyePosition);
vec3 reflected = normalize(reflect(eyeVec, normal));
//reflected = vec3(inverse(WorldMatrix) * vec4(reflected, 0.0));
lightColor *= texture(ReflectionMap, reflected).rgb;
#endif
vec4 fragmentColor = vec4(lightColor, 1.0) * diffuseColor;
#if EMISSIVE_MAPPING
float lightIntensity = dot(lightColor, vec3(0.3, 0.59, 0.11));
vec3 emissionColor = MaterialDiffuse.rgb * texture(MaterialEmissiveMap, texCoord).rgb;
RenderTarget0 = vec4(mix(fragmentColor.rgb, emissionColor, clamp(1.0 - 3.0*lightIntensity, 0.0, 1.0)), fragmentColor.a);
#else
RenderTarget0 = fragmentColor;
#endif // EMISSIVE_MAPPING
#endif // FLAG_DEFERRED
}

View File

@@ -0,0 +1,148 @@
/********************Entrant********************/
#if FLAG_BILLBOARD
in vec3 InstanceData0; // center
in vec4 InstanceData1; // size | sin cos
in vec4 InstanceData2; // color
#else
in mat4 InstanceData0;
#endif
in vec4 VertexColor;
in vec3 VertexPosition;
in vec3 VertexNormal;
in vec3 VertexTangent;
in vec2 VertexTexCoord;
in vec4 VertexUserdata0;
/********************Sortant********************/
out vec4 vColor;
out vec4 vLightSpacePos[3];
out mat3 vLightToWorld;
out vec3 vNormal;
out vec2 vTexCoord;
out vec3 vViewDir;
out vec3 vWorldPos;
/********************Uniformes********************/
uniform vec3 EyePosition;
uniform mat4 InvViewMatrix;
uniform mat4 LightViewProjMatrix[3];
uniform float VertexDepth;
uniform mat4 ViewMatrix;
uniform mat4 ViewProjMatrix;
uniform mat4 WorldMatrix;
uniform mat4 WorldViewProjMatrix;
/********************Fonctions********************/
void main()
{
#if FLAG_VERTEXCOLOR
vec4 color = VertexColor;
#else
vec4 color = vec4(1.0);
#endif
vec2 texCoords;
#if FLAG_BILLBOARD
#if FLAG_INSTANCING
vec3 billboardCenter = InstanceData0;
vec2 billboardSize = InstanceData1.xy;
vec2 billboardSinCos = InstanceData1.zw;
vec4 billboardColor = InstanceData2;
vec2 rotatedPosition;
rotatedPosition.x = VertexPosition.x*billboardSinCos.y - VertexPosition.y*billboardSinCos.x;
rotatedPosition.y = VertexPosition.y*billboardSinCos.y + VertexPosition.x*billboardSinCos.x;
rotatedPosition *= billboardSize;
vec3 cameraRight = vec3(ViewMatrix[0][0], ViewMatrix[1][0], ViewMatrix[2][0]);
vec3 cameraUp = vec3(ViewMatrix[0][1], ViewMatrix[1][1], ViewMatrix[2][1]);
vec3 vertexPos = billboardCenter + cameraRight*rotatedPosition.x + cameraUp*rotatedPosition.y;
gl_Position = ViewProjMatrix * vec4(vertexPos, 1.0);
color = billboardColor;
texCoords = VertexPosition.xy + 0.5;
#else
vec2 billboardCorner = VertexTexCoord - 0.5;
vec2 billboardSize = VertexUserdata0.xy;
vec2 billboardSinCos = VertexUserdata0.zw;
vec2 rotatedPosition;
rotatedPosition.x = billboardCorner.x*billboardSinCos.y - billboardCorner.y*billboardSinCos.x;
rotatedPosition.y = billboardCorner.y*billboardSinCos.y + billboardCorner.x*billboardSinCos.x;
rotatedPosition *= billboardSize;
vec3 cameraRight = vec3(ViewMatrix[0][0], ViewMatrix[1][0], ViewMatrix[2][0]);
vec3 cameraUp = vec3(ViewMatrix[0][1], ViewMatrix[1][1], ViewMatrix[2][1]);
vec3 vertexPos = VertexPosition + cameraRight*rotatedPosition.x + cameraUp*rotatedPosition.y;
gl_Position = ViewProjMatrix * vec4(vertexPos, 1.0);
texCoords = VertexTexCoord;
#endif
texCoords.y = 1.0 - texCoords.y;
#else
#if FLAG_INSTANCING
#if TRANSFORM
gl_Position = ViewProjMatrix * InstanceData0 * vec4(VertexPosition, 1.0);
#else
#if UNIFORM_VERTEX_DEPTH
gl_Position = InstanceData0 * vec4(VertexPosition.xy, VertexDepth, 1.0);
#else
gl_Position = InstanceData0 * vec4(VertexPosition, 1.0);
#endif
#endif
#else
#if TRANSFORM
gl_Position = WorldViewProjMatrix * vec4(VertexPosition, 1.0);
#else
#if UNIFORM_VERTEX_DEPTH
gl_Position = vec4(VertexPosition.xy, VertexDepth, 1.0);
#else
gl_Position = vec4(VertexPosition, 1.0);
#endif
#endif
#endif
texCoords = VertexTexCoord;
#endif
vColor = color;
#if FLAG_INSTANCING
mat3 rotationMatrix = mat3(InstanceData0);
#else
mat3 rotationMatrix = mat3(WorldMatrix);
#endif
#if COMPUTE_TBNMATRIX
vec3 binormal = cross(VertexNormal, VertexTangent);
vLightToWorld[0] = normalize(rotationMatrix * VertexTangent);
vLightToWorld[1] = normalize(rotationMatrix * binormal);
vLightToWorld[2] = normalize(rotationMatrix * VertexNormal);
#else
vNormal = normalize(rotationMatrix * VertexNormal);
#endif
#if SHADOW_MAPPING
for (int i = 0; i < 3; ++i)
vLightSpacePos[i] = LightViewProjMatrix[i] * WorldMatrix * vec4(VertexPosition, 1.0);
#endif
#if TEXTURE_MAPPING
vTexCoord = VertexTexCoord;
#endif
#if PARALLAX_MAPPING
vViewDir = EyePosition - VertexPosition;
vViewDir *= vLightToWorld;
#endif
#if !FLAG_DEFERRED
#if FLAG_INSTANCING
vWorldPos = vec3(InstanceData0 * vec4(VertexPosition, 1.0));
#else
vWorldPos = vec3(WorldMatrix * vec4(VertexPosition, 1.0));
#endif
#endif
}