diff --git a/code/addons/graphicsfeature/components/graphicsfeature.json b/code/addons/graphicsfeature/components/graphicsfeature.json index 0a9ce4673..1819babc5 100644 --- a/code/addons/graphicsfeature/components/graphicsfeature.json +++ b/code/addons/graphicsfeature/components/graphicsfeature.json @@ -80,7 +80,8 @@ "default": 8.0 }, "twoSided": "bool", - "castShadows": "bool" + "castShadows": "bool", + "renderMesh": "bool" }, "Model": { "resource": { diff --git a/code/addons/graphicsfeature/managers/graphicsmanager.cc b/code/addons/graphicsfeature/managers/graphicsmanager.cc index 7c0416e4a..be763ee92 100644 --- a/code/addons/graphicsfeature/managers/graphicsmanager.cc +++ b/code/addons/graphicsfeature/managers/graphicsmanager.cc @@ -194,6 +194,65 @@ GraphicsManager::InitUpdateModelTransformProcessor() .Build(); } +//------------------------------------------------------------------------------ +/** +*/ +void +GraphicsManager::InitUpdateLightTransformProcessor() +{ + Game::World* world = Game::GetWorld(WORLD_DEFAULT); + + Game::ProcessorBuilder(world, "GraphicsManager.UpdatePointLightPositions"_atm) + .On("OnEndFrame") + .Excluding() + .Func( + [](Game::World* world, Game::Position const& pos, GraphicsFeature::PointLight const& light) + { + if (Lighting::LightContext::IsEntityRegistered(light.graphicsEntityId)) + Lighting::LightContext::SetPosition(light.graphicsEntityId, pos); + } + ) + .Build(); + + Game::ProcessorBuilder(world, "GraphicsManager.UpdateSpotLightTransform"_atm) + .On("OnEndFrame") + .Excluding() + .Func( + [](Game::World* world, + Game::Position const& pos, + Game::Orientation const& rot, + GraphicsFeature::SpotLight const& light) + { + if (Lighting::LightContext::IsEntityRegistered(light.graphicsEntityId)) + { + Lighting::LightContext::SetPosition(light.graphicsEntityId, pos); + Lighting::LightContext::SetRotation(light.graphicsEntityId, rot); + } + } + ) + .Build(); + + Game::ProcessorBuilder(world, "GraphicsManager.UpdateAreaLightTransform"_atm) + .On("OnEndFrame") + .Excluding() + .Func( + [](Game::World* world, + Game::Position const& pos, + Game::Orientation const& rot, + Game::Scale const& scale, + GraphicsFeature::AreaLight const& light) + { + if (Lighting::LightContext::IsEntityRegistered(light.graphicsEntityId)) + { + Lighting::LightContext::SetPosition(light.graphicsEntityId, pos); + Lighting::LightContext::SetRotation(light.graphicsEntityId, rot); + Lighting::LightContext::SetScale(light.graphicsEntityId, scale); + } + } + ) + .Build(); +} + //------------------------------------------------------------------------------ /** */ @@ -202,6 +261,7 @@ GraphicsManager::OnActivate() { Manager::OnActivate(); this->InitUpdateModelTransformProcessor(); + this->InitUpdateLightTransformProcessor(); } //------------------------------------------------------------------------------ @@ -270,7 +330,8 @@ GraphicsManager::InitAreaLight(Game::World* world, Game::Entity entity, AreaLigh light->intensity, light->range, light->twoSided, - light->castShadows + light->castShadows, + light->renderMesh ); Lighting::LightContext::SetPosition(light->graphicsEntityId, pos); Lighting::LightContext::SetRotation(light->graphicsEntityId, rot); diff --git a/code/addons/graphicsfeature/managers/graphicsmanager.h b/code/addons/graphicsfeature/managers/graphicsmanager.h index 6ab6da660..a7773bd0b 100644 --- a/code/addons/graphicsfeature/managers/graphicsmanager.h +++ b/code/addons/graphicsfeature/managers/graphicsmanager.h @@ -44,6 +44,7 @@ class GraphicsManager : public Game::Manager private: void InitUpdateModelTransformProcessor(); + void InitUpdateLightTransformProcessor(); }; } // namespace GraphicsFeature diff --git a/code/render/lighting/lightcontext.cc b/code/render/lighting/lightcontext.cc index 1f2e27665..5328ff84e 100644 --- a/code/render/lighting/lightcontext.cc +++ b/code/render/lighting/lightcontext.cc @@ -479,6 +479,7 @@ LightContext::SetupAreaLight( , const float range , bool twoSided , bool castShadows + , bool renderMesh ) { n_assert(id != Graphics::GraphicsEntityId::Invalid()); @@ -499,6 +500,7 @@ LightContext::SetupAreaLight( areaLightAllocator.Set(ali, id); areaLightAllocator.Set(ali, shape); areaLightAllocator.Set(ali, twoSided || shape == AreaLightShape::Tube); + areaLightAllocator.Set(ali, renderMesh); //areaLightAllocator.Set(ali, proj); if (castShadows) @@ -539,19 +541,22 @@ LightContext::SetupAreaLight( break; } - Graphics::RegisterEntity(id); - Math::bbox box; - Models::ModelContext::Setup( - id - , Math::mat4() - , box - , material - , mesh - , 0 - ); - Models::ModelContext::SetTransform(id, Math::mat4()); - - Visibility::ObservableContext::Setup(id, Visibility::VisibilityEntityType::Model); + if (renderMesh) + { + Graphics::RegisterEntity(id); + Math::bbox box; + Models::ModelContext::Setup( + id + , Math::mat4() + , box + , material + , mesh + , 0 + ); + Models::ModelContext::SetTransform(id, Math::mat4()); + + Visibility::ObservableContext::Setup(id, Visibility::VisibilityEntityType::Model); + } } //------------------------------------------------------------------------------ @@ -681,7 +686,8 @@ LightContext::SetPosition(const Graphics::GraphicsEntityId id, const Math::point break; case LightType::AreaLightType: areaLightAllocator.Get(lid).setposition(position); - Models::ModelContext::SetTransform(id, areaLightAllocator.Get(lid).getmatrix()); + if (areaLightAllocator.Get(lid)) + Models::ModelContext::SetTransform(id, areaLightAllocator.Get(lid).getmatrix()); break; default: n_error("unhandled enum"); break; } @@ -729,7 +735,8 @@ LightContext::SetRotation(const Graphics::GraphicsEntityId id, const Math::quat& break; case LightType::AreaLightType: areaLightAllocator.Get(lid).setrotate(rotation); - Models::ModelContext::SetTransform(id, areaLightAllocator.Get(lid).getmatrix()); + if (areaLightAllocator.Get(lid)) + Models::ModelContext::SetTransform(id, areaLightAllocator.Get(lid).getmatrix()); break; default: n_error("unhandled enum"); break; } @@ -785,7 +792,8 @@ LightContext::SetScale(const Graphics::GraphicsEntityId id, const Math::vec3& sc adjustedScale.z = 1.0f; } areaLightAllocator.Get(lid).setscale(adjustedScale); - Models::ModelContext::SetTransform(id, areaLightAllocator.Get(lid).getmatrix()); + if (areaLightAllocator.Get(lid)) + Models::ModelContext::SetTransform(id, areaLightAllocator.Get(lid).getmatrix()); } break; default: n_error("unhandled enum"); break; } diff --git a/code/render/lighting/lightcontext.h b/code/render/lighting/lightcontext.h index 892da3adc..c6d494a1c 100644 --- a/code/render/lighting/lightcontext.h +++ b/code/render/lighting/lightcontext.h @@ -83,6 +83,7 @@ class LightContext : public Graphics::GraphicsContext , const float range , bool twoSided = false , bool castShadows = false + , bool renderMesh = false ); /// set color of light @@ -233,7 +234,8 @@ class LightContext : public Graphics::GraphicsContext AreaLight_ShadowConstantBufferSet, AreaLight_DynamicOffsets, AreaLight_TwoSided, - AreaLight_Observer + AreaLight_Observer, + AreaLight_RenderMesh, }; typedef Ids::IdAllocator< @@ -243,7 +245,8 @@ class LightContext : public Graphics::GraphicsContext ConstantBufferSet, // constant buffer binding for shadows Util::FixedArray, // dynamic offsets bool, // two sides - Graphics::GraphicsEntityId // graphics entity used for observer stuff + Graphics::GraphicsEntityId, // graphics entity used for observer stuff + bool // render mesh as well > AreaLightAllocator; static AreaLightAllocator areaLightAllocator; @@ -257,6 +260,7 @@ class LightContext : public Graphics::GraphicsContext DirectionalLight_ViewProjTransform, DirectionalLight_CascadeObservers }; + typedef Ids::IdAllocator< Math::vector, // direction Math::vec3, // backlight color @@ -273,9 +277,11 @@ class LightContext : public Graphics::GraphicsContext { ShadowCaster_Transform }; + typedef Ids::IdAllocator< Math::mat4 > ShadowCasterAllocator; + static ShadowCasterAllocator shadowCasterAllocator; static Util::HashTable shadowCasterSliceMap; diff --git a/toolkit/editor/editor/ui/uimanager.cc b/toolkit/editor/editor/ui/uimanager.cc index 189867ebf..cf4f9e518 100644 --- a/toolkit/editor/editor/ui/uimanager.cc +++ b/toolkit/editor/editor/ui/uimanager.cc @@ -148,11 +148,9 @@ UIManager::OnActivate() } }, "Import nlvl (game only)", "Ctrl+Shift+I", "File"); - // + // Graphics::GraphicsServer::Instance()->AddPostViewCall([](IndexT frameIndex, IndexT bufferIndex) { - ImGui::DockSpaceOverViewport(); - windowServer->RunAll(); FrameScript_editorframe::Bind_Scene(FrameScript_default::Submission_Scene); FrameScript_editorframe::Bind_SceneBuffer(Frame::TextureImport::FromExport(FrameScript_default::Export_ColorBuffer)); CoreGraphics::DisplayMode mode = CoreGraphics::WindowGetDisplayMode(CoreGraphics::CurrentWindow); @@ -187,6 +185,17 @@ void UIManager::OnBeginFrame() { windowServer->Update(); + ImGui::DockSpaceOverViewport(); + windowServer->RunAll(); +} + +//------------------------------------------------------------------------------ +/** +*/ +void +UIManager::OnFrame() +{ + } } // namespace Editor diff --git a/toolkit/editor/editor/ui/uimanager.h b/toolkit/editor/editor/ui/uimanager.h index f0f8fff9e..d9ede874f 100644 --- a/toolkit/editor/editor/ui/uimanager.h +++ b/toolkit/editor/editor/ui/uimanager.h @@ -22,6 +22,7 @@ class UIManager : public Game::Manager void OnActivate() override; void OnDeactivate() override; void OnBeginFrame() override; + void OnFrame() override; }; namespace UI diff --git a/toolkit/editor/editorfeature/editorfeatureunit.cc b/toolkit/editor/editorfeature/editorfeatureunit.cc index 894178353..57133dcc4 100644 --- a/toolkit/editor/editorfeature/editorfeatureunit.cc +++ b/toolkit/editor/editorfeature/editorfeatureunit.cc @@ -117,6 +117,27 @@ EditorFeatureUnit::OnActivate() ) .Build(); + Game::ProcessorBuilder(world, "EditorGameManager.UpdateAreaLightTransform"_atm) + .On("OnEndFrame") + .OnlyModified() + .RunInEditor() + .Func( + [](Game::World* world, + Game::Position const& pos, + Game::Orientation const& rot, + Game::Scale const& scale, + GraphicsFeature::AreaLight const& light) + { + if (Lighting::LightContext::IsEntityRegistered(light.graphicsEntityId)) + { + Lighting::LightContext::SetPosition(light.graphicsEntityId, pos); + Lighting::LightContext::SetRotation(light.graphicsEntityId, rot); + Lighting::LightContext::SetScale(light.graphicsEntityId, scale); + } + } + ) + .Build(); + //if (!Editor::ConnectToBackend(...)) // Editor::SpawnLocalBackend(); }