Skip to content

Commit 5087f6c

Browse files
committed
Created LightState
1 parent f0f67f0 commit 5087f6c

5 files changed

Lines changed: 43 additions & 4 deletions

File tree

engine/core/Scene.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Scene::Scene(){
7979
backgroundColor = Vector4(0.0, 0.0, 0.0, 1.0); //sRGB
8080
shadowsPCF = true;
8181

82+
lightState = LightState::AUTO;
8283
globalIllumColor = Vector3(1.0, 1.0, 1.0);
8384
globalIllumIntensity = 0.1;
8485

@@ -149,13 +150,27 @@ Vector4 Scene::getBackgroundColor() const{
149150
}
150151

151152
void Scene::setShadowsPCF(bool shadowsPCF){
152-
this->shadowsPCF = shadowsPCF;
153+
if (this->shadowsPCF != shadowsPCF){
154+
this->shadowsPCF = shadowsPCF;
155+
getSystem<RenderSystem>()->needReloadMeshes();
156+
}
153157
}
154158

155159
bool Scene::isShadowsPCF() const{
156160
return this->shadowsPCF;
157161
}
158162

163+
void Scene::setLightState(LightState state){
164+
if (this->lightState != state){
165+
this->lightState = state;
166+
getSystem<RenderSystem>()->needReloadMeshes();
167+
}
168+
}
169+
170+
LightState Scene::getLightState() const{
171+
return this->lightState;
172+
}
173+
159174
void Scene::setGlobalIllumination(float intensity, Vector3 color){
160175
this->globalIllumIntensity = intensity;
161176
this->globalIllumColor = Color::sRGBToLinear(color);

engine/core/Scene.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ namespace Supernova{
6262

6363
class Camera;
6464

65+
enum class LightState {
66+
OFF,
67+
ON,
68+
AUTO
69+
};
70+
6571
class SUPERNOVA_API Scene{
6672
private:
6773

@@ -71,6 +77,7 @@ namespace Supernova{
7177
Vector4 backgroundColor;
7278
bool shadowsPCF;
7379

80+
LightState lightState;
7481
Vector3 globalIllumColor;
7582
float globalIllumIntensity;
7683

@@ -108,6 +115,9 @@ namespace Supernova{
108115
void setShadowsPCF(bool shadowsPCF);
109116
bool isShadowsPCF() const;
110117

118+
void setLightState(LightState state);
119+
LightState getLightState() const;
120+
111121
void setGlobalIllumination(float intensity, Vector3 color);
112122
void setGlobalIllumination(float intensity);
113123
void setGlobalIllumination(Vector3 color);

engine/core/script/LuaBridgeAddon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ namespace luabridge
5353
template<> struct Stack<AdMobRating> : EnumWrapper<AdMobRating>{};
5454
template<> struct Stack<CursorType> : EnumWrapper<CursorType>{};
5555
template<> struct Stack<ResourceLoadState> : EnumWrapper<ResourceLoadState>{};
56+
template<> struct Stack<LightState> : EnumWrapper<LightState>{};
5657

5758
template<> struct Stack<ResourceType> : EnumWrapper<ResourceType>{};
5859

engine/core/script/binding/CoreClassesLua.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ void LuaBinding::registerCoreClasses(lua_State *L){
152152
.addVariable("Failed", ResourceLoadState::Failed)
153153
.endNamespace();
154154

155+
luabridge::getGlobalNamespace(L)
156+
.beginNamespace("LightState")
157+
.addVariable("OFF", LightState::OFF)
158+
.addVariable("ON", LightState::ON)
159+
.addVariable("AUTO", LightState::AUTO)
160+
.endNamespace();
161+
155162
luabridge::getGlobalNamespace(L)
156163
.beginClass<Engine>("Engine")
157164

@@ -475,6 +482,7 @@ void LuaBinding::registerCoreClasses(lua_State *L){
475482
luabridge::overload<float, float, float>(&Scene::setBackgroundColor),
476483
luabridge::overload<float, float, float, float>(&Scene::setBackgroundColor))
477484
.addProperty("shadowsPCF", &Scene::isShadowsPCF, &Scene::setShadowsPCF)
485+
.addProperty("lightState", &Scene::getLightState, &Scene::setLightState)
478486
.addProperty("globalIlluminationColor", &Scene::getGlobalIlluminationColor, (void (Scene::*)(Vector3))&Scene::setGlobalIllumination)
479487
.addProperty("globalIlluminationIntensity", &Scene::getGlobalIlluminationIntensity, (void (Scene::*)(float))&Scene::setGlobalIllumination)
480488
.addFunction("getGlobalIlluminationColorLinear", &Scene::getGlobalIlluminationColorLinear)

engine/core/subsystem/RenderSystem.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,12 @@ int RenderSystem::checkLightsAndShadow(){
175175
if (numLights > MAX_LIGHTS)
176176
numLights = MAX_LIGHTS;
177177

178-
if (numLights > 0)
178+
if (scene->getLightState() == LightState::AUTO){
179+
if (numLights > 0)
180+
hasLights = true;
181+
}else if (scene->getLightState() == LightState::ON){
179182
hasLights = true;
183+
}
180184

181185
for (int i = 0; i < numLights; i++){
182186
LightComponent& light = lights->getComponentFromIndex(i);
@@ -282,10 +286,11 @@ void RenderSystem::processLights(int numLights, Transform& cameraTransform){
282286
fs_lighting.color_intensity[i] = Vector4(light.color.x, light.color.y, light.color.z, light.intensity);
283287
fs_lighting.position_type[i] = Vector4(worldPosition.x, worldPosition.y, worldPosition.z, (float)type);
284288
fs_lighting.inCon_ouCon_shadows_cascades[i] = Vector4(light.innerConeCos, light.outerConeCos, light.shadowMapIndex, light.numShadowCascades);
285-
fs_lighting.eyePos = Vector4(cameraTransform.worldPosition.x, cameraTransform.worldPosition.y, cameraTransform.worldPosition.z, 0.0);
286-
fs_lighting.globalIllum = Vector4(scene->getGlobalIlluminationColorLinear(), scene->getGlobalIlluminationIntensity());
287289
}
288290

291+
fs_lighting.eyePos = Vector4(cameraTransform.worldPosition.x, cameraTransform.worldPosition.y, cameraTransform.worldPosition.z, 0.0);
292+
fs_lighting.globalIllum = Vector4(scene->getGlobalIlluminationColorLinear(), scene->getGlobalIlluminationIntensity());
293+
289294
// Setting intensity of other lights to zero
290295
for (int i = numLights; i < MAX_LIGHTS; i++){
291296
fs_lighting.color_intensity[i].w = 0.0;

0 commit comments

Comments
 (0)