Merge remote-tracking branch 'refs/remotes/origin/master' into gui
Former-commit-id: 79463d2933cbd8bc6f0b9de5021a83ef7b5aa29b [formerly 3292aa8d849c9c569315d342fdcb17002547593e] [formerly bbb62690f0e47f3248ed524657fb3e01abaf1dcd [formerly e327e6aad9af55fcf96cea232148729cb73a78d4]] Former-commit-id: cae74a258a54f3b0dc8962d02a39bc2d5d0b6fb2 [formerly 2c3dc59631a1d6923c52216498d97c7b08151520] Former-commit-id: 289eb5a199a6d775b4e0c5dc905aedc518d67e67
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void GraphicsComponent::InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, unsigned int index)
|
||||
void GraphicsComponent::InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, std::size_t index)
|
||||
{
|
||||
NazaraAssert(index < m_renderables.size(), "Invalid renderable index");
|
||||
NazaraUnused(renderable);
|
||||
|
||||
17
SDK/src/NDK/Components/ParticleEmitterComponent.cpp
Normal file
17
SDK/src/NDK/Components/ParticleEmitterComponent.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Components/ParticleEmitterComponent.hpp>
|
||||
#include <Nazara/Graphics/ParticleGroup.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void ParticleEmitterComponent::SetupParticles(Nz::ParticleMapper& mapper, unsigned int count) const
|
||||
{
|
||||
if (m_isActive && m_setupFunc)
|
||||
m_setupFunc(m_entity, mapper, count);
|
||||
}
|
||||
|
||||
ComponentIndex ParticleEmitterComponent::componentIndex;
|
||||
}
|
||||
10
SDK/src/NDK/Components/ParticleGroupComponent.cpp
Normal file
10
SDK/src/NDK/Components/ParticleGroupComponent.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Components/ParticleGroupComponent.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
ComponentIndex ParticleGroupComponent::componentIndex;
|
||||
}
|
||||
@@ -28,8 +28,8 @@ namespace Ndk
|
||||
m_characterSize(24)
|
||||
{
|
||||
Nz::MaterialRef backgroundMaterial = Nz::Material::New();
|
||||
backgroundMaterial->Enable(Nz::RendererParameter_Blend, true);
|
||||
backgroundMaterial->Enable(Nz::RendererParameter_DepthBuffer, false);
|
||||
backgroundMaterial->EnableBlending(true);
|
||||
backgroundMaterial->EnableDepthBuffer(false);
|
||||
backgroundMaterial->SetDstBlend(Nz::BlendFunc_InvSrcAlpha);
|
||||
backgroundMaterial->SetSrcBlend(Nz::BlendFunc_SrcAlpha);
|
||||
|
||||
@@ -145,6 +145,7 @@ namespace Ndk
|
||||
{
|
||||
case Nz::Keyboard::Down:
|
||||
case Nz::Keyboard::Up:
|
||||
{
|
||||
if (event.key.code == Nz::Keyboard::Up)
|
||||
m_historyPosition = std::min<std::size_t>(m_commandHistory.size(), m_historyPosition + 1);
|
||||
else
|
||||
@@ -159,6 +160,10 @@ namespace Ndk
|
||||
m_inputDrawer.SetText(s_inputPrefix + text);
|
||||
m_inputTextSprite->Update(m_inputDrawer);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Ndk
|
||||
BaseComponent& component = *m_components[index].get();
|
||||
component.SetEntity(this);
|
||||
|
||||
for (unsigned int i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
|
||||
for (std::size_t i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
|
||||
{
|
||||
if (i != index)
|
||||
m_components[i]->OnComponentAttached(component);
|
||||
@@ -73,8 +73,8 @@ namespace Ndk
|
||||
|
||||
void Entity::RemoveAllComponents()
|
||||
{
|
||||
for (unsigned int i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
|
||||
RemoveComponent(i);
|
||||
for (std::size_t i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
|
||||
RemoveComponent(static_cast<ComponentIndex>(i));
|
||||
|
||||
NazaraAssert(m_componentBits.TestNone(), "All components should be gone");
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace Ndk
|
||||
{
|
||||
// On récupère le component et on informe les composants du détachement
|
||||
BaseComponent& component = *m_components[index].get();
|
||||
for (unsigned int i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
|
||||
for (std::size_t i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
|
||||
{
|
||||
if (i != index)
|
||||
m_components[i]->OnComponentDetached(component);
|
||||
@@ -114,7 +114,7 @@ namespace Ndk
|
||||
void Entity::Destroy()
|
||||
{
|
||||
// On informe chaque système
|
||||
for (SystemIndex index = m_systemBits.FindFirst(); index != m_systemBits.npos; index = m_systemBits.FindNext(index))
|
||||
for (std::size_t index = m_systemBits.FindFirst(); index != m_systemBits.npos; index = m_systemBits.FindNext(index))
|
||||
{
|
||||
if (m_world->HasSystem(index))
|
||||
{
|
||||
|
||||
@@ -29,8 +29,8 @@ namespace Ndk
|
||||
|
||||
// SDK
|
||||
application("Application"),
|
||||
nodeComponent("NodeComponent"),
|
||||
entityClass("Entity"),
|
||||
nodeComponent("NodeComponent"),
|
||||
velocityComponent("VelocityComponent"),
|
||||
worldClass("World")
|
||||
|
||||
@@ -39,9 +39,9 @@ namespace Ndk
|
||||
|
||||
// Audio
|
||||
musicClass("Music"),
|
||||
soundClass("Sound"),
|
||||
soundBuffer("SoundBuffer"),
|
||||
soundEmitter("SoundEmitter"),
|
||||
soundClass("Sound"),
|
||||
|
||||
// Graphics
|
||||
instancedRenderable("InstancedRenderable"),
|
||||
|
||||
@@ -76,6 +76,8 @@ namespace Ndk
|
||||
/*********************************** Nz::SoundBuffer **********************************/
|
||||
soundBuffer.SetConstructor([] (Nz::LuaInstance& lua, Nz::SoundBufferRef* instance)
|
||||
{
|
||||
NazaraUnused(lua);
|
||||
|
||||
Nz::PlacementNew(instance, Nz::SoundBuffer::New());
|
||||
return true;
|
||||
});
|
||||
@@ -115,16 +117,16 @@ namespace Ndk
|
||||
return 1;
|
||||
});
|
||||
|
||||
soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& soundBuffer) -> int
|
||||
soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int
|
||||
{
|
||||
Nz::StringStream stream("SoundBuffer(");
|
||||
if (soundBuffer->IsValid())
|
||||
if (instance->IsValid())
|
||||
{
|
||||
Nz::String filePath = soundBuffer->GetFilePath();
|
||||
Nz::String filePath = instance->GetFilePath();
|
||||
if (!filePath.IsEmpty())
|
||||
stream << "File: " << filePath << ", ";
|
||||
|
||||
stream << "Duration: " << soundBuffer->GetDuration() / 1000.f << "s";
|
||||
|
||||
stream << "Duration: " << instance->GetDuration() / 1000.f << "s";
|
||||
}
|
||||
stream << ')';
|
||||
|
||||
@@ -148,17 +150,17 @@ namespace Ndk
|
||||
|
||||
soundEmitter.BindMethod("IsLooping", &Nz::SoundEmitter::IsLooping);
|
||||
soundEmitter.BindMethod("IsSpatialized", &Nz::SoundEmitter::IsSpatialized);
|
||||
|
||||
|
||||
soundEmitter.BindMethod("Pause", &Nz::SoundEmitter::Pause);
|
||||
soundEmitter.BindMethod("Play", &Nz::SoundEmitter::Play);
|
||||
|
||||
|
||||
soundEmitter.BindMethod("SetAttenuation", &Nz::SoundEmitter::SetAttenuation);
|
||||
soundEmitter.BindMethod("SetMinDistance", &Nz::SoundEmitter::SetMinDistance);
|
||||
soundEmitter.BindMethod("SetPitch", &Nz::SoundEmitter::SetPitch);
|
||||
soundEmitter.BindMethod("SetPosition", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetPosition);
|
||||
soundEmitter.BindMethod("SetVelocity", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetVelocity);
|
||||
soundEmitter.BindMethod("SetVolume", &Nz::SoundEmitter::SetVolume);
|
||||
|
||||
|
||||
soundEmitter.BindMethod("Stop", &Nz::SoundEmitter::Stop);
|
||||
}
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ namespace Ndk
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
long long index = lua.CheckInteger(1);
|
||||
auto index = lua.CheckBoundInteger<std::size_t>(1);
|
||||
if (index < 1 || index > 4)
|
||||
return false;
|
||||
|
||||
@@ -238,9 +238,15 @@ namespace Ndk
|
||||
case 'h':
|
||||
lua.Push(instance.height);
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -252,7 +258,7 @@ namespace Ndk
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
long long index = lua.CheckInteger(1);
|
||||
auto index = lua.CheckBoundInteger<std::size_t>(1);
|
||||
if (index < 1 || index > 4)
|
||||
return false;
|
||||
|
||||
@@ -290,6 +296,9 @@ namespace Ndk
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -313,7 +322,7 @@ namespace Ndk
|
||||
Nz::PlacementNew(quaternion, *static_cast<Nz::Quaterniond*>(lua.ToUserdata(1)));
|
||||
else
|
||||
break;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -389,6 +398,9 @@ namespace Ndk
|
||||
case 'z':
|
||||
instance.z = value;
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -455,9 +467,15 @@ namespace Ndk
|
||||
case 'y':
|
||||
lua.Push(instance.y);
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -496,9 +514,15 @@ namespace Ndk
|
||||
case 'y':
|
||||
instance.y = value;
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -513,11 +537,12 @@ namespace Ndk
|
||||
case 0:
|
||||
case 3:
|
||||
Nz::PlacementNew(vector, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0));
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
Nz::PlacementNew(vector, lua.CheckNumber(1), *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)));
|
||||
Nz::PlacementNew(vector, lua.CheckNumber(1), *static_cast<Nz::Vector2d*>(lua.CheckUserdata(1, "Vector2")));
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)));
|
||||
else if (lua.IsOfType(1, "Vector3"))
|
||||
@@ -582,9 +607,15 @@ namespace Ndk
|
||||
case 'z':
|
||||
lua.Push(instance.z);
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -627,9 +658,15 @@ namespace Ndk
|
||||
case 'z':
|
||||
instance.z = value;
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#include <NDK/Components/LightComponent.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/ParticleEmitterComponent.hpp>
|
||||
#include <NDK/Components/ParticleGroupComponent.hpp>
|
||||
#include <NDK/Systems/ParticleSystem.hpp>
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#endif
|
||||
@@ -71,6 +74,8 @@ namespace Ndk
|
||||
InitializeComponent<LightComponent>("NdkLight");
|
||||
InitializeComponent<ListenerComponent>("NdkList");
|
||||
InitializeComponent<GraphicsComponent>("NdkGfx");
|
||||
InitializeComponent<ParticleEmitterComponent>("NdkPaEmi");
|
||||
InitializeComponent<ParticleGroupComponent>("NdkPaGrp");
|
||||
#endif
|
||||
|
||||
// Systems
|
||||
@@ -84,6 +89,7 @@ namespace Ndk
|
||||
#ifndef NDK_SERVER
|
||||
// Client systems
|
||||
InitializeSystem<ListenerSystem>();
|
||||
InitializeSystem<ParticleSystem>();
|
||||
InitializeSystem<RenderSystem>();
|
||||
#endif
|
||||
|
||||
@@ -112,6 +118,12 @@ namespace Ndk
|
||||
// Uninitialize the SDK
|
||||
s_referenceCounter = 0;
|
||||
|
||||
// Components
|
||||
BaseComponent::Uninitialize();
|
||||
|
||||
// Systems
|
||||
BaseSystem::Uninitialize();
|
||||
|
||||
// Uninitialize the engine
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
|
||||
10
SDK/src/NDK/State.cpp
Normal file
10
SDK/src/NDK/State.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/State.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
State::~State() = default;
|
||||
}
|
||||
26
SDK/src/NDK/Systems/ParticleSystem.cpp
Normal file
26
SDK/src/NDK/Systems/ParticleSystem.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Systems/ParticleSystem.hpp>
|
||||
#include <NDK/Components/ParticleGroupComponent.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
ParticleSystem::ParticleSystem()
|
||||
{
|
||||
Requires<ParticleGroupComponent>();
|
||||
}
|
||||
|
||||
void ParticleSystem::OnUpdate(float elapsedTime)
|
||||
{
|
||||
for (const Ndk::EntityHandle& entity : GetEntities())
|
||||
{
|
||||
ParticleGroupComponent& group = entity->GetComponent<ParticleGroupComponent>();
|
||||
|
||||
group.Update(elapsedTime);
|
||||
}
|
||||
}
|
||||
|
||||
SystemIndex ParticleSystem::systemIndex;
|
||||
}
|
||||
@@ -4,10 +4,13 @@
|
||||
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#include <Nazara/Graphics/ColorBackground.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <NDK/Components/CameraComponent.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/LightComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/ParticleGroupComponent.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
@@ -23,8 +26,11 @@ namespace Ndk
|
||||
void RenderSystem::OnEntityRemoved(Entity* entity)
|
||||
{
|
||||
m_cameras.Remove(entity);
|
||||
m_directionalLights.Remove(entity);
|
||||
m_drawables.Remove(entity);
|
||||
m_lights.Remove(entity);
|
||||
m_particleGroups.Remove(entity);
|
||||
m_pointSpotLights.Remove(entity);
|
||||
}
|
||||
|
||||
void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded)
|
||||
@@ -48,9 +54,32 @@ namespace Ndk
|
||||
m_drawables.Remove(entity);
|
||||
|
||||
if (entity->HasComponent<LightComponent>() && entity->HasComponent<NodeComponent>())
|
||||
{
|
||||
LightComponent& lightComponent = entity->GetComponent<LightComponent>();
|
||||
if (lightComponent.GetLightType() == Nz::LightType_Directional)
|
||||
{
|
||||
m_directionalLights.Insert(entity);
|
||||
m_pointSpotLights.Remove(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_directionalLights.Remove(entity);
|
||||
m_pointSpotLights.Insert(entity);
|
||||
}
|
||||
|
||||
m_lights.Insert(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_directionalLights.Remove(entity);
|
||||
m_lights.Remove(entity);
|
||||
m_pointSpotLights.Remove(entity);
|
||||
}
|
||||
|
||||
if (entity->HasComponent<ParticleGroupComponent>())
|
||||
m_particleGroups.Insert(entity);
|
||||
else
|
||||
m_particleGroups.Remove(entity);
|
||||
}
|
||||
|
||||
void RenderSystem::OnUpdate(float elapsedTime)
|
||||
@@ -69,10 +98,13 @@ namespace Ndk
|
||||
m_coordinateSystemInvalidated = false;
|
||||
}
|
||||
|
||||
UpdatePointSpotShadowMaps();
|
||||
|
||||
for (const Ndk::EntityHandle& camera : m_cameras)
|
||||
{
|
||||
CameraComponent& camComponent = camera->GetComponent<CameraComponent>();
|
||||
camComponent.ApplyView();
|
||||
|
||||
//UpdateDirectionalShadowMaps(camComponent);
|
||||
|
||||
Nz::AbstractRenderQueue* renderQueue = m_renderTechnique->GetRenderQueue();
|
||||
renderQueue->Clear();
|
||||
@@ -89,12 +121,21 @@ namespace Ndk
|
||||
for (const Ndk::EntityHandle& light : m_lights)
|
||||
{
|
||||
LightComponent& lightComponent = light->GetComponent<LightComponent>();
|
||||
NodeComponent& drawableNode = light->GetComponent<NodeComponent>();
|
||||
NodeComponent& lightNode = light->GetComponent<NodeComponent>();
|
||||
|
||||
///TODO: Cache somehow?
|
||||
lightComponent.AddToRenderQueue(renderQueue, Nz::Matrix4f::ConcatenateAffine(m_coordinateSystemMatrix, drawableNode.GetTransformMatrix()));
|
||||
lightComponent.AddToRenderQueue(renderQueue, Nz::Matrix4f::ConcatenateAffine(m_coordinateSystemMatrix, lightNode.GetTransformMatrix()));
|
||||
}
|
||||
|
||||
for (const Ndk::EntityHandle& particleGroup : m_particleGroups)
|
||||
{
|
||||
ParticleGroupComponent& groupComponent = particleGroup->GetComponent<ParticleGroupComponent>();
|
||||
|
||||
groupComponent.AddToRenderQueue(renderQueue, Nz::Matrix4f::Identity()); //< ParticleGroup doesn't use Matrix4f
|
||||
}
|
||||
|
||||
camComponent.ApplyView();
|
||||
|
||||
Nz::SceneData sceneData;
|
||||
sceneData.ambientColor = Nz::Color(25, 25, 25);
|
||||
sceneData.background = m_background;
|
||||
@@ -105,5 +146,146 @@ namespace Ndk
|
||||
}
|
||||
}
|
||||
|
||||
void RenderSystem::UpdateDirectionalShadowMaps(const Nz::AbstractViewer& viewer)
|
||||
{
|
||||
if (!m_shadowRT.IsValid())
|
||||
m_shadowRT.Create();
|
||||
|
||||
Nz::SceneData dummySceneData;
|
||||
dummySceneData.ambientColor = Nz::Color(0, 0, 0);
|
||||
dummySceneData.background = nullptr;
|
||||
dummySceneData.viewer = nullptr; //< Depth technique doesn't require any viewer
|
||||
|
||||
for (const Ndk::EntityHandle& light : m_directionalLights)
|
||||
{
|
||||
LightComponent& lightComponent = light->GetComponent<LightComponent>();
|
||||
NodeComponent& lightNode = light->GetComponent<NodeComponent>();
|
||||
|
||||
if (!lightComponent.IsShadowCastingEnabled())
|
||||
continue;
|
||||
|
||||
Nz::Vector2ui shadowMapSize(lightComponent.GetShadowMap()->GetSize());
|
||||
|
||||
m_shadowRT.AttachTexture(Nz::AttachmentPoint_Depth, 0, lightComponent.GetShadowMap());
|
||||
Nz::Renderer::SetTarget(&m_shadowRT);
|
||||
Nz::Renderer::SetViewport(Nz::Recti(0, 0, shadowMapSize.x, shadowMapSize.y));
|
||||
|
||||
Nz::AbstractRenderQueue* renderQueue = m_shadowTechnique.GetRenderQueue();
|
||||
renderQueue->Clear();
|
||||
|
||||
///TODO: Culling
|
||||
for (const Ndk::EntityHandle& drawable : m_drawables)
|
||||
{
|
||||
GraphicsComponent& graphicsComponent = drawable->GetComponent<GraphicsComponent>();
|
||||
NodeComponent& drawableNode = drawable->GetComponent<NodeComponent>();
|
||||
|
||||
graphicsComponent.AddToRenderQueue(renderQueue);
|
||||
}
|
||||
|
||||
///TODO: Cache the matrices in the light?
|
||||
Nz::Renderer::SetMatrix(Nz::MatrixType_Projection, Nz::Matrix4f::Ortho(0.f, 100.f, 100.f, 0.f, 1.f, 100.f));
|
||||
Nz::Renderer::SetMatrix(Nz::MatrixType_View, Nz::Matrix4f::ViewMatrix(lightNode.GetRotation() * Nz::Vector3f::Forward() * 100.f, lightNode.GetRotation()));
|
||||
|
||||
m_shadowTechnique.Clear(dummySceneData);
|
||||
m_shadowTechnique.Draw(dummySceneData);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderSystem::UpdatePointSpotShadowMaps()
|
||||
{
|
||||
if (!m_shadowRT.IsValid())
|
||||
m_shadowRT.Create();
|
||||
|
||||
Nz::SceneData dummySceneData;
|
||||
dummySceneData.ambientColor = Nz::Color(0, 0, 0);
|
||||
dummySceneData.background = nullptr;
|
||||
dummySceneData.viewer = nullptr; //< Depth technique doesn't require any viewer
|
||||
|
||||
for (const Ndk::EntityHandle& light : m_pointSpotLights)
|
||||
{
|
||||
LightComponent& lightComponent = light->GetComponent<LightComponent>();
|
||||
NodeComponent& lightNode = light->GetComponent<NodeComponent>();
|
||||
|
||||
if (!lightComponent.IsShadowCastingEnabled())
|
||||
continue;
|
||||
|
||||
Nz::Vector2ui shadowMapSize(lightComponent.GetShadowMap()->GetSize());
|
||||
|
||||
switch (lightComponent.GetLightType())
|
||||
{
|
||||
case Nz::LightType_Directional:
|
||||
NazaraInternalError("Directional lights included in point/spot light list");
|
||||
break;
|
||||
|
||||
case Nz::LightType_Point:
|
||||
{
|
||||
static Nz::Quaternionf rotations[6] =
|
||||
{
|
||||
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), Nz::Vector3f::UnitX()), // nzCubemapFace_PositiveX
|
||||
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), -Nz::Vector3f::UnitX()), // nzCubemapFace_NegativeX
|
||||
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), -Nz::Vector3f::UnitY()), // nzCubemapFace_PositiveY
|
||||
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), Nz::Vector3f::UnitY()), // nzCubemapFace_NegativeY
|
||||
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), -Nz::Vector3f::UnitZ()), // nzCubemapFace_PositiveZ
|
||||
Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), Nz::Vector3f::UnitZ()) // nzCubemapFace_NegativeZ
|
||||
};
|
||||
|
||||
for (unsigned int face = 0; face < 6; ++face)
|
||||
{
|
||||
m_shadowRT.AttachTexture(Nz::AttachmentPoint_Depth, 0, lightComponent.GetShadowMap(), face);
|
||||
Nz::Renderer::SetTarget(&m_shadowRT);
|
||||
Nz::Renderer::SetViewport(Nz::Recti(0, 0, shadowMapSize.x, shadowMapSize.y));
|
||||
|
||||
///TODO: Cache the matrices in the light?
|
||||
Nz::Renderer::SetMatrix(Nz::MatrixType_Projection, Nz::Matrix4f::Perspective(Nz::FromDegrees(90.f), 1.f, 0.1f, lightComponent.GetRadius()));
|
||||
Nz::Renderer::SetMatrix(Nz::MatrixType_View, Nz::Matrix4f::ViewMatrix(lightNode.GetPosition(), rotations[face]));
|
||||
|
||||
Nz::AbstractRenderQueue* renderQueue = m_shadowTechnique.GetRenderQueue();
|
||||
renderQueue->Clear();
|
||||
|
||||
///TODO: Culling
|
||||
for (const Ndk::EntityHandle& drawable : m_drawables)
|
||||
{
|
||||
GraphicsComponent& graphicsComponent = drawable->GetComponent<GraphicsComponent>();
|
||||
NodeComponent& drawableNode = drawable->GetComponent<NodeComponent>();
|
||||
|
||||
graphicsComponent.AddToRenderQueue(renderQueue);
|
||||
}
|
||||
|
||||
m_shadowTechnique.Clear(dummySceneData);
|
||||
m_shadowTechnique.Draw(dummySceneData);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Nz::LightType_Spot:
|
||||
{
|
||||
m_shadowRT.AttachTexture(Nz::AttachmentPoint_Depth, 0, lightComponent.GetShadowMap());
|
||||
Nz::Renderer::SetTarget(&m_shadowRT);
|
||||
Nz::Renderer::SetViewport(Nz::Recti(0, 0, shadowMapSize.x, shadowMapSize.y));
|
||||
|
||||
///TODO: Cache the matrices in the light?
|
||||
Nz::Renderer::SetMatrix(Nz::MatrixType_Projection, Nz::Matrix4f::Perspective(lightComponent.GetOuterAngle()*2.f, 1.f, 0.1f, lightComponent.GetRadius()));
|
||||
Nz::Renderer::SetMatrix(Nz::MatrixType_View, Nz::Matrix4f::ViewMatrix(lightNode.GetPosition(), lightNode.GetRotation()));
|
||||
|
||||
Nz::AbstractRenderQueue* renderQueue = m_shadowTechnique.GetRenderQueue();
|
||||
renderQueue->Clear();
|
||||
|
||||
///TODO: Culling
|
||||
for (const Ndk::EntityHandle& drawable : m_drawables)
|
||||
{
|
||||
GraphicsComponent& graphicsComponent = drawable->GetComponent<GraphicsComponent>();
|
||||
NodeComponent& drawableNode = drawable->GetComponent<NodeComponent>();
|
||||
|
||||
graphicsComponent.AddToRenderQueue(renderQueue);
|
||||
}
|
||||
|
||||
m_shadowTechnique.Clear(dummySceneData);
|
||||
m_shadowTechnique.Draw(dummySceneData);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SystemIndex RenderSystem::systemIndex;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Ndk
|
||||
NodeComponent& node = entity->GetComponent<NodeComponent>();
|
||||
const VelocityComponent& velocity = entity->GetComponent<VelocityComponent>();
|
||||
|
||||
node.Move(velocity.linearVelocity * elapsedTime);
|
||||
node.Move(velocity.linearVelocity * elapsedTime, Nz::CoordSys_Global);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/ParticleSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#endif
|
||||
|
||||
@@ -27,6 +28,7 @@ namespace Ndk
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
AddSystem<ListenerSystem>();
|
||||
AddSystem<ParticleSystem>();
|
||||
AddSystem<RenderSystem>();
|
||||
#endif
|
||||
}
|
||||
@@ -94,7 +96,7 @@ namespace Ndk
|
||||
void World::Update()
|
||||
{
|
||||
// Gestion des entités tuées depuis le dernier appel
|
||||
for (unsigned int i = m_killedEntities.FindFirst(); i != m_killedEntities.npos; i = m_killedEntities.FindNext(i))
|
||||
for (std::size_t i = m_killedEntities.FindFirst(); i != m_killedEntities.npos; i = m_killedEntities.FindNext(i))
|
||||
{
|
||||
EntityBlock& block = m_entities[i];
|
||||
Entity& entity = block.entity;
|
||||
@@ -127,7 +129,7 @@ namespace Ndk
|
||||
m_killedEntities.Reset();
|
||||
|
||||
// Gestion des entités nécessitant une mise à jour de leurs systèmes
|
||||
for (unsigned int i = m_dirtyEntities.FindFirst(); i != m_dirtyEntities.npos; i = m_dirtyEntities.FindNext(i))
|
||||
for (std::size_t i = m_dirtyEntities.FindFirst(); i != m_dirtyEntities.npos; i = m_dirtyEntities.FindNext(i))
|
||||
{
|
||||
NazaraAssert(i < m_entities.size(), "Entity index out of range");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user