Graphics/LightComponent: Replace AttachLight with AddLight

This commit is contained in:
SirLynix
2022-11-26 18:32:47 +01:00
committed by Jérôme Leclercq
parent d7eab778fb
commit ec3bc45544
6 changed files with 58 additions and 49 deletions

View File

@@ -103,11 +103,11 @@ int main()
framePipeline.RegisterRenderable(worldInstanceIndex1, Nz::FramePipeline::NoSkeletonInstance, &model, 0xFFFFFFFF, scissorBox);
framePipeline.RegisterRenderable(worldInstanceIndex2, Nz::FramePipeline::NoSkeletonInstance, &model, 0xFFFFFFFF, scissorBox);
std::shared_ptr<Nz::SpotLight> light = std::make_shared<Nz::SpotLight>();
std::unique_ptr<Nz::SpotLight> light = std::make_unique<Nz::SpotLight>();
light->UpdateInnerAngle(Nz::DegreeAnglef(15.f));
light->UpdateOuterAngle(Nz::DegreeAnglef(20.f));
framePipeline.RegisterLight(light, 0xFFFFFFFF);
framePipeline.RegisterLight(light.get(), 0xFFFFFFFF);
Nz::Vector3f viewerPos = Nz::Vector3f::Zero();

View File

@@ -92,10 +92,10 @@ int main()
std::size_t worldInstanceIndex1 = framePipeline.RegisterWorldInstance(modelInstance);
framePipeline.RegisterRenderable(worldInstanceIndex1, Nz::FramePipeline::NoSkeletonInstance, &model, 0xFFFFFFFF, scissorBox);
std::shared_ptr<Nz::DirectionalLight> light = std::make_shared<Nz::DirectionalLight>();
std::unique_ptr<Nz::DirectionalLight> light = std::make_unique<Nz::DirectionalLight>();
light->UpdateRotation(Nz::EulerAnglesf(-45.f, 0.f, 0.f));
framePipeline.RegisterLight(light, 0xFFFFFFFF);
framePipeline.RegisterLight(light.get(), 0xFFFFFFFF);
Nz::Vector3f viewerPos = Nz::Vector3f::Zero();

View File

@@ -148,12 +148,10 @@ int main()
entt::entity headingEntity = registry.create();
{
auto spotLight = std::make_shared<Nz::SpotLight>();
spotLight->EnableShadowCasting(true);
spotLight->UpdateShadowMapSize(1024);
auto& entityLight = registry.emplace<Nz::LightComponent>(playerEntity);
entityLight.AttachLight(std::move(spotLight), 1);
auto& spotLight = entityLight.AddLight<Nz::SpotLight>(1);
spotLight.EnableShadowCasting(true);
spotLight.UpdateShadowMapSize(1024);
auto& entityGfx = registry.emplace<Nz::GraphicsComponent>(playerEntity);
entityGfx.AttachRenderable(model, 1);

View File

@@ -169,14 +169,13 @@ int main()
lightNode.SetPosition(Nz::Vector3f::Up() * 3.f + Nz::Vector3f::Backward() * 1.f);
lightNode.SetRotation(Nz::EulerAnglesf(-70.f, 0.f, 0.f));
auto spotLight = std::make_shared<Nz::SpotLight>();
spotLight->UpdateColor(Nz::Color::Red);
spotLight->UpdateInnerAngle(Nz::DegreeAnglef(15.f));
spotLight->UpdateOuterAngle(Nz::DegreeAnglef(20.f));
spotLight->EnableShadowCasting(true);
auto& cameraLight = registry.emplace<Nz::LightComponent>(lightEntity1);
cameraLight.AttachLight(spotLight, 0xFFFFFFFF);
auto& spotLight = cameraLight.AddLight<Nz::SpotLight>(0xFFFFFFFF);
spotLight.UpdateColor(Nz::Color::Red);
spotLight.UpdateInnerAngle(Nz::DegreeAnglef(15.f));
spotLight.UpdateOuterAngle(Nz::DegreeAnglef(20.f));
spotLight.EnableShadowCasting(true);
}
entt::entity lightEntity2 = registry.create();
@@ -185,13 +184,12 @@ int main()
lightNode.SetPosition(Nz::Vector3f::Up() * 3.5f + Nz::Vector3f::Right() * 1.5f);
lightNode.SetRotation(Nz::EulerAnglesf(-70.f, 90.f, 0.f));
auto spotLight = std::make_shared<Nz::SpotLight>();
spotLight->UpdateColor(Nz::Color::Green);
spotLight->EnableShadowCasting(true);
spotLight->UpdateShadowMapSize(1024);
auto& cameraLight = registry.emplace<Nz::LightComponent>(lightEntity2);
cameraLight.AttachLight(spotLight, 0xFFFFFFFF);
auto& spotLight = cameraLight.AddLight<Nz::SpotLight>(0xFFFFFFFF);
spotLight.UpdateColor(Nz::Color::Green);
spotLight.EnableShadowCasting(true);
spotLight.UpdateShadowMapSize(1024);
}
entt::entity lightEntity3 = registry.create();
@@ -255,14 +253,13 @@ int main()
lightNode.SetRotation(Nz::EulerAnglesf(-45.f, 180.f, 0.f));
lightNode.SetParentJoint(bobEntity, "Spine2");
auto spotLight = std::make_shared<Nz::SpotLight>();
spotLight->UpdateColor(Nz::Color::Blue);
spotLight->UpdateInnerAngle(Nz::DegreeAnglef(15.f));
spotLight->UpdateOuterAngle(Nz::DegreeAnglef(20.f));
spotLight->EnableShadowCasting(true);
auto& cameraLight = registry.emplace<Nz::LightComponent>(lightEntity3);
cameraLight.AttachLight(spotLight, 0xFFFFFFFF);
auto& spotLight = cameraLight.AddLight<Nz::SpotLight>(0xFFFFFFFF);
spotLight.UpdateColor(Nz::Color::Blue);
spotLight.UpdateInnerAngle(Nz::DegreeAnglef(15.f));
spotLight.UpdateOuterAngle(Nz::DegreeAnglef(20.f));
spotLight.EnableShadowCasting(true);
}
}
@@ -522,7 +519,7 @@ int main()
Nz::DebugDrawer& debugDrawer = renderSystem.GetFramePipeline().GetDebugDrawer();
auto& lightNode = registry.get<Nz::NodeComponent>(lightEntity3);
debugDrawer.DrawLine(lightNode.GetPosition(Nz::CoordSys::Global), lightNode.GetForward() * 10.f, Nz::Color::Blue);
//debugDrawer.DrawLine(lightNode.GetPosition(Nz::CoordSys::Global), lightNode.GetForward() * 10.f, Nz::Color::Blue);
/*Nz::Boxf test = spotLight->GetBoundingVolume().aabb;
debugDrawer.DrawBox(test, Nz::Color::Blue);
debugDrawer.DrawBox(floorBox, Nz::Color::Red);