Skip to content

Commit

Permalink
Added option to disable/enable rendering of area light mesh.
Browse files Browse the repository at this point in the history
Moved UI rendering to beginning of frame in editor.
Added processors for moving lightsources.
  • Loading branch information
fLindahl committed Nov 16, 2024
1 parent 8362861 commit 9614556
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 23 deletions.
3 changes: 2 additions & 1 deletion code/addons/graphicsfeature/components/graphicsfeature.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
"default": 8.0
},
"twoSided": "bool",
"castShadows": "bool"
"castShadows": "bool",
"renderMesh": "bool"
},
"Model": {
"resource": {
Expand Down
63 changes: 62 additions & 1 deletion code/addons/graphicsfeature/managers/graphicsmanager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Game::Static>()
.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<Game::Static>()
.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<Game::Static>()
.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();
}

//------------------------------------------------------------------------------
/**
*/
Expand All @@ -202,6 +261,7 @@ GraphicsManager::OnActivate()
{
Manager::OnActivate();
this->InitUpdateModelTransformProcessor();
this->InitUpdateLightTransformProcessor();
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions code/addons/graphicsfeature/managers/graphicsmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class GraphicsManager : public Game::Manager

private:
void InitUpdateModelTransformProcessor();
void InitUpdateLightTransformProcessor();
};

} // namespace GraphicsFeature
40 changes: 24 additions & 16 deletions code/render/lighting/lightcontext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ LightContext::SetupAreaLight(
, const float range
, bool twoSided
, bool castShadows
, bool renderMesh
)
{
n_assert(id != Graphics::GraphicsEntityId::Invalid());
Expand All @@ -499,6 +500,7 @@ LightContext::SetupAreaLight(
areaLightAllocator.Set<AreaLight_Observer>(ali, id);
areaLightAllocator.Set<AreaLight_Shape>(ali, shape);
areaLightAllocator.Set<AreaLight_TwoSided>(ali, twoSided || shape == AreaLightShape::Tube);
areaLightAllocator.Set<AreaLight_RenderMesh>(ali, renderMesh);
//areaLightAllocator.Set<AreaLight_Projection>(ali, proj);

if (castShadows)
Expand Down Expand Up @@ -539,19 +541,22 @@ LightContext::SetupAreaLight(
break;
}

Graphics::RegisterEntity<Models::ModelContext, Visibility::ObservableContext>(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<Models::ModelContext, Visibility::ObservableContext>(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);
}
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -681,7 +686,8 @@ LightContext::SetPosition(const Graphics::GraphicsEntityId id, const Math::point
break;
case LightType::AreaLightType:
areaLightAllocator.Get<AreaLight_Transform>(lid).setposition(position);
Models::ModelContext::SetTransform(id, areaLightAllocator.Get<AreaLight_Transform>(lid).getmatrix());
if (areaLightAllocator.Get<AreaLight_RenderMesh>(lid))
Models::ModelContext::SetTransform(id, areaLightAllocator.Get<AreaLight_Transform>(lid).getmatrix());
break;
default: n_error("unhandled enum"); break;
}
Expand Down Expand Up @@ -729,7 +735,8 @@ LightContext::SetRotation(const Graphics::GraphicsEntityId id, const Math::quat&
break;
case LightType::AreaLightType:
areaLightAllocator.Get<AreaLight_Transform>(lid).setrotate(rotation);
Models::ModelContext::SetTransform(id, areaLightAllocator.Get<AreaLight_Transform>(lid).getmatrix());
if (areaLightAllocator.Get<AreaLight_RenderMesh>(lid))
Models::ModelContext::SetTransform(id, areaLightAllocator.Get<AreaLight_Transform>(lid).getmatrix());
break;
default: n_error("unhandled enum"); break;
}
Expand Down Expand Up @@ -785,7 +792,8 @@ LightContext::SetScale(const Graphics::GraphicsEntityId id, const Math::vec3& sc
adjustedScale.z = 1.0f;
}
areaLightAllocator.Get<AreaLight_Transform>(lid).setscale(adjustedScale);
Models::ModelContext::SetTransform(id, areaLightAllocator.Get<AreaLight_Transform>(lid).getmatrix());
if (areaLightAllocator.Get<AreaLight_RenderMesh>(lid))
Models::ModelContext::SetTransform(id, areaLightAllocator.Get<AreaLight_Transform>(lid).getmatrix());
} break;
default: n_error("unhandled enum"); break;
}
Expand Down
10 changes: 8 additions & 2 deletions code/render/lighting/lightcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -233,7 +234,8 @@ class LightContext : public Graphics::GraphicsContext
AreaLight_ShadowConstantBufferSet,
AreaLight_DynamicOffsets,
AreaLight_TwoSided,
AreaLight_Observer
AreaLight_Observer,
AreaLight_RenderMesh,
};

typedef Ids::IdAllocator<
Expand All @@ -243,7 +245,8 @@ class LightContext : public Graphics::GraphicsContext
ConstantBufferSet, // constant buffer binding for shadows
Util::FixedArray<uint>, // 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;

Expand All @@ -257,6 +260,7 @@ class LightContext : public Graphics::GraphicsContext
DirectionalLight_ViewProjTransform,
DirectionalLight_CascadeObservers
};

typedef Ids::IdAllocator<
Math::vector, // direction
Math::vec3, // backlight color
Expand All @@ -273,9 +277,11 @@ class LightContext : public Graphics::GraphicsContext
{
ShadowCaster_Transform
};

typedef Ids::IdAllocator<
Math::mat4
> ShadowCasterAllocator;

static ShadowCasterAllocator shadowCasterAllocator;
static Util::HashTable<Graphics::GraphicsEntityId, uint, 16, 1> shadowCasterSliceMap;

Expand Down
15 changes: 12 additions & 3 deletions toolkit/editor/editor/ui/uimanager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -187,6 +185,17 @@ void
UIManager::OnBeginFrame()
{
windowServer->Update();
ImGui::DockSpaceOverViewport();
windowServer->RunAll();
}

//------------------------------------------------------------------------------
/**
*/
void
UIManager::OnFrame()
{

}

} // namespace Editor
1 change: 1 addition & 0 deletions toolkit/editor/editor/ui/uimanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class UIManager : public Game::Manager
void OnActivate() override;
void OnDeactivate() override;
void OnBeginFrame() override;
void OnFrame() override;
};

namespace UI
Expand Down
21 changes: 21 additions & 0 deletions toolkit/editor/editorfeature/editorfeatureunit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 9614556

Please sign in to comment.