Skip to content

Commit 8362861

Browse files
committed
Added an AreaLight component to the GraphicsFeature
1 parent 1e79ac0 commit 8362861

File tree

5 files changed

+88
-4
lines changed

5 files changed

+88
-4
lines changed

code/addons/graphicsfeature/components/graphicsfeature.json

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
"enums": {
44
"ProjectionMode": {
55
"Perspective": 0,
6-
"Orthographic": 1,
6+
"Orthographic": 1
7+
},
8+
"AreaLightShape": {
9+
"Disk": 0,
10+
"Rectangle": 1,
11+
"Tube": 2
712
}
813
},
914
"components": {
@@ -13,7 +18,7 @@
1318
"default": -1
1419
},
1520
"color": {
16-
"type": "colour",
21+
"type": "color",
1722
"default": [ 1.0, 1.0, 1.0, 1.0 ]
1823
},
1924
"intensity": {
@@ -32,7 +37,7 @@
3237
"default": -1
3338
},
3439
"color": {
35-
"type": "colour",
40+
"type": "color",
3641
"default": [ 1.0, 1.0, 1.0, 1.0 ]
3742
},
3843
"intensity": {
@@ -53,6 +58,30 @@
5358
},
5459
"castShadows": "bool"
5560
},
61+
"AreaLight": {
62+
"graphicsEntityId": {
63+
"type": "uint",
64+
"default": -1
65+
},
66+
"shape": {
67+
"type": "GraphicsFeature::AreaLightShape",
68+
"default": 0
69+
},
70+
"color": {
71+
"type": "color",
72+
"default": [ 1.0, 1.0, 1.0, 1.0 ]
73+
},
74+
"intensity": {
75+
"type": "float",
76+
"default": 50.0 // candela
77+
},
78+
"range": {
79+
"type": "float",
80+
"default": 8.0
81+
},
82+
"twoSided": "bool",
83+
"castShadows": "bool"
84+
},
5685
"Model": {
5786
"resource": {
5887
"type": "resource",

code/addons/graphicsfeature/graphicsfeatureunit.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ GraphicsFeatureUnit::OnAttach()
8585
{
8686
this->RegisterComponentType<PointLight>({.decay = true, .OnInit = &GraphicsManager::InitPointLight });
8787
this->RegisterComponentType<SpotLight>({.decay = true, .OnInit = &GraphicsManager::InitSpotLight });
88+
this->RegisterComponentType<AreaLight>({.decay = true, .OnInit = &GraphicsManager::InitAreaLight });
8889
this->RegisterComponentType<Model>({.decay = true, .OnInit = &GraphicsManager::InitModel });
8990
this->RegisterComponentType<Camera>();
9091
Scripting::RegisterDearguiModule();

code/addons/graphicsfeature/managers/graphicsmanager.cc

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ GraphicsManager::OnDecay()
161161
SpotLight* light = spotLightData + i;
162162
DeregisterLight(light->graphicsEntityId);
163163
}
164+
165+
Game::ComponentDecayBuffer const areaLightDecayBuffer = world->GetDecayBuffer(Game::GetComponentId<AreaLight>());
166+
AreaLight* areaLightData = (AreaLight*)areaLightDecayBuffer.buffer;
167+
for (int i = 0; i < areaLightDecayBuffer.size; i++)
168+
{
169+
AreaLight* light = areaLightData + i;
170+
DeregisterLight(light->graphicsEntityId);
171+
}
164172
}
165173

166174
//------------------------------------------------------------------------------
@@ -242,6 +250,33 @@ GraphicsManager::InitSpotLight(Game::World* world, Game::Entity entity, SpotLigh
242250
Lighting::LightContext::SetRotation(light->graphicsEntityId, rot);
243251
}
244252

253+
//------------------------------------------------------------------------------
254+
/**
255+
*/
256+
void
257+
GraphicsManager::InitAreaLight(Game::World* world, Game::Entity entity, AreaLight* light)
258+
{
259+
light->graphicsEntityId = Graphics::CreateEntity().id;
260+
261+
Game::Position pos = world->GetComponent<Game::Position>(entity);
262+
Game::Orientation rot = world->GetComponent<Game::Orientation>(entity);
263+
Game::Scale scale = world->GetComponent<Game::Scale>(entity);
264+
265+
Lighting::LightContext::RegisterEntity(light->graphicsEntityId);
266+
Lighting::LightContext::SetupAreaLight(
267+
light->graphicsEntityId,
268+
(Lighting::LightContext::AreaLightShape)light->shape,
269+
light->color.vec,
270+
light->intensity,
271+
light->range,
272+
light->twoSided,
273+
light->castShadows
274+
);
275+
Lighting::LightContext::SetPosition(light->graphicsEntityId, pos);
276+
Lighting::LightContext::SetRotation(light->graphicsEntityId, rot);
277+
Lighting::LightContext::SetScale(light->graphicsEntityId, scale);
278+
}
279+
245280
//------------------------------------------------------------------------------
246281
/**
247282
*/
@@ -313,6 +348,23 @@ GraphicsManager::OnCleanup(Game::World* world)
313348
}
314349
}
315350

351+
Game::DestroyFilter(filter);
352+
}
353+
{ // AreaLight cleanup
354+
Game::Filter filter = Game::FilterBuilder().Including<AreaLight>().Build();
355+
Game::Dataset data = world->Query(filter);
356+
357+
for (int v = 0; v < data.numViews; v++)
358+
{
359+
Game::Dataset::View const& view = data.views[v];
360+
AreaLight const* const componentData = (AreaLight*)view.buffers[0];
361+
362+
for (IndexT i = 0; i < view.numInstances; ++i)
363+
{
364+
DeregisterLight((componentData + i)->graphicsEntityId);
365+
}
366+
}
367+
316368
Game::DestroyFilter(filter);
317369
}
318370
}

code/addons/graphicsfeature/managers/graphicsmanager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class GraphicsManager : public Game::Manager
3939
static void InitPointLight(Game::World* world, Game::Entity entity, PointLight* light);
4040
/// called automatically when a spot light needs to be initialized
4141
static void InitSpotLight(Game::World* world, Game::Entity entity, SpotLight* light);
42+
/// called automatically when an area light needs to be initialized
43+
static void InitAreaLight(Game::World* world, Game::Entity entity, AreaLight* light);
4244

4345
private:
4446
void InitUpdateModelTransformProcessor();

fips-files/generators/NIDL.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Version = 144
1+
Version = 145
22

33
import sys
44
if __name__ == '__main__':

0 commit comments

Comments
 (0)