diff --git a/Broken Engine/Game/Assets/Shaders/Standard.glsl b/Broken Engine/Game/Assets/Shaders/Standard.glsl index 76d74aa84..d563dc4fb 100644 --- a/Broken Engine/Game/Assets/Shaders/Standard.glsl +++ b/Broken Engine/Game/Assets/Shaders/Standard.glsl @@ -65,6 +65,7 @@ in mat3 v_TBN; //Uniforms uniform float u_GammaCorrection = 1.0; +uniform vec4 u_AmbientColor = vec4(1.0); uniform float u_Shininess = 1.5; uniform int u_UseTextures = 0; @@ -90,6 +91,7 @@ struct BrokenLight vec3 color; float intensity; + float distanceMultiplier; vec3 attenuationKLQ; vec2 InOutCutoff; @@ -146,7 +148,8 @@ vec3 CalculatePointlight(BrokenLight light, vec3 normal, vec3 viewDir) // direction = v_TBN * normalize(direction); //Attenuation Calculation - float d = length(light.pos - v_FragPos); + float dMult = 1/light.distanceMultiplier; + float d = length(light.pos - v_FragPos) * dMult; float lightAttenuation = 1.0/(light.attenuationKLQ.x + light.attenuationKLQ.y * d + light.attenuationKLQ.z *(d * d)); //Result @@ -236,11 +239,13 @@ void main() if(u_DrawNormalMapping_Lit == 0 && u_DrawNormalMapping_Lit_Adv == 0) { + vec3 finalColor = u_AmbientColor.rgb * v_Color.rgb; + //Resulting Color if(u_UseTextures == 0 || (HasTransparencies == 0 && u_UseTextures == 1 && texture(u_AlbedoTexture, v_TexCoord).a < 0.1)) - out_color = vec4(colorResult + v_Color.rgb, alpha); + out_color = vec4(colorResult + finalColor, alpha); else if(u_UseTextures == 1) - out_color = vec4(colorResult + v_Color.rgb * texture(u_AlbedoTexture, v_TexCoord).rgb, alpha); + out_color = vec4(colorResult + finalColor * texture(u_AlbedoTexture, v_TexCoord).rgb, alpha); out_color = pow(out_color, vec4(vec3(1.0/u_GammaCorrection), 1.0)); } diff --git a/Broken Engine/Game/Settings/EditorConfig.json b/Broken Engine/Game/Settings/EditorConfig.json index 768c3ff5b..b46282d0b 100644 --- a/Broken Engine/Game/Settings/EditorConfig.json +++ b/Broken Engine/Game/Settings/EditorConfig.json @@ -12,7 +12,7 @@ "Navigation": false, "Physics": true, "Project": true, - "Rendering": false, + "Rendering": true, "Resources": false, "Scene": true, "Settings": false, @@ -197,7 +197,12 @@ "staticFriction": 1.0 }, "Renderer3D": { - "GammaCorrection": 1.8650000095367432 + "GammaCorrection": 1.8650000095367432, + "SceneAmbientColor": { + "R": 1.0, + "G": 1.0, + "B": 1.0 + } }, "Window": { "borderless": false, diff --git a/Broken Engine/Source/Broken Core.vcxproj b/Broken Engine/Source/Broken Core.vcxproj index f068e8cf9..378c9cc61 100644 --- a/Broken Engine/Source/Broken Core.vcxproj +++ b/Broken Engine/Source/Broken Core.vcxproj @@ -286,6 +286,7 @@ + @@ -458,6 +459,7 @@ + diff --git a/Broken Engine/Source/Broken Core.vcxproj.filters b/Broken Engine/Source/Broken Core.vcxproj.filters index 393f94c0a..6856322e7 100644 --- a/Broken Engine/Source/Broken Core.vcxproj.filters +++ b/Broken Engine/Source/Broken Core.vcxproj.filters @@ -723,6 +723,9 @@ Sources\BrokenEngine\Modules\Scripting Functions\SuperTranslator + + Sources\BrokenEngine\Modules\Scripting Functions + @@ -1235,6 +1238,9 @@ Sources\BrokenEngine\Tools + + Sources\BrokenEngine\Modules\Scripting Functions + diff --git a/Broken Engine/Source/ComponentLight.cpp b/Broken Engine/Source/ComponentLight.cpp index 7e9876454..60f4b5b37 100644 --- a/Broken Engine/Source/ComponentLight.cpp +++ b/Broken Engine/Source/ComponentLight.cpp @@ -90,6 +90,9 @@ void ComponentLight::SendUniforms(uint shaderID, uint lightIndex) int attLoc = glGetUniformLocation(shaderID, (light_index_str + ".attenuationKLQ").c_str()); int cutoffLoc = glGetUniformLocation(shaderID, (light_index_str + ".InOutCutoff").c_str()); int LtypeLoc = glGetUniformLocation(shaderID, (light_index_str + ".LightType").c_str()); + int distMultiLoc = glGetUniformLocation(shaderID, (light_index_str + ".distanceMultiplier").c_str()); + + //u_DistanceMultiplier distMultiLoc if ((!active || m_LightType == LightType::NONE || m_LightType == LightType::MAX_LIGHT_TYPES) && !m_SetToZero) @@ -114,6 +117,9 @@ void ComponentLight::SendUniforms(uint shaderID, uint lightIndex) // --- Passing Light Attenuation glUniform3f(attLoc, 0.0f, 0.0f, 0.0f); + // --- Passing Light Distance Multiplicator --- + glUniform1f(distMultiLoc, 1.0f); + m_SetToZero = true; } else @@ -143,6 +149,9 @@ void ComponentLight::SendUniforms(uint shaderID, uint lightIndex) // --- Passing Light Attenuation glUniform3f(attLoc, m_AttenuationKLQFactors.x, m_AttenuationKLQFactors.y, m_AttenuationKLQFactors.z); + // --- Passing Light Distance Multiplicator --- + glUniform1f(distMultiLoc, m_DistanceMultiplier); + if(m_SetToZero) m_SetToZero = false; } @@ -251,9 +260,16 @@ void ComponentLight::CreateInspectorNode() ImGui::Text("Intensity"); ImGui::SameLine(0, ImGui::GetStyle().ItemInnerSpacing.x + 10.0f); ImGui::SetNextItemWidth(300.0f); - ImGui::SliderFloat("", &m_Intensity, 0.0f, INFINITY); + ImGui::SliderFloat("", &m_Intensity, 0.0f, 100.0f, "%.3f", 2.0f); ImGui::NewLine(); + // --- Distance Multiplier --- + ImGui::Text("Distance Multiplier"); + ImGui::SameLine(); ImGui::SetNextItemWidth(65.0f); + ImGui::DragFloat("##DistMulti", &m_DistanceMultiplier, 0.1f, 0.1f, INFINITY, "%.4f"); + ImGui::NewLine(); + + // --- Type-According Values --- if (m_LightType == LightType::SPOTLIGHT) { // --- Cutoff --- @@ -270,11 +286,11 @@ void ComponentLight::CreateInspectorNode() // --- Attenuation --- ImGui::Separator(); ImGui::NewLine(); ImGui::Text("Constant Attenuation Value (K):"); ImGui::SameLine(); ImGui::SetNextItemWidth(65.0f); - ImGui::DragFloat("##AttK", &m_AttenuationKLQFactors.x, 0.001f, 0.000f, 2.0f); + ImGui::DragFloat("##AttK", &m_AttenuationKLQFactors.x, 0.001f, 0.000f); ImGui::Text("Linear Attenuation Value (L):"); ImGui::SameLine(); ImGui::SetNextItemWidth(65.0f); - ImGui::DragFloat("##AttL", &m_AttenuationKLQFactors.y, 0.001f, 0.000f, 2.0f); + ImGui::DragFloat("##AttL", &m_AttenuationKLQFactors.y, 0.001f, 0.000f); ImGui::Text("Quadratic Attenuation Value (Q):"); ImGui::SameLine(); ImGui::SetNextItemWidth(65.0f); - ImGui::DragFloat("##AttQ", &m_AttenuationKLQFactors.z, 0.00001f, 0.000000f, 2.0f, "%.5f"); + ImGui::DragFloat("##AttQ", &m_AttenuationKLQFactors.z, 0.00001f, 0.000000f, 10.0f, "%.5f"); if (ImGui::Button("Default", { 57, 18 })) m_AttenuationKLQFactors = float3(1.0f, 0.09f, 0.032f); @@ -309,7 +325,7 @@ json ComponentLight::Save() const node["Intensity"] = std::to_string(m_Intensity); node["LightType"] = std::to_string((int)m_LightType); - + node["DistanceMultiplier"] = std::to_string(m_DistanceMultiplier); return node; } @@ -336,6 +352,7 @@ void ComponentLight::Load(json& node) std::string str_outCut = node["OuterCutoff"].is_null() ? "45" : node["OuterCutoff"]; std::string str_intensity = node["Intensity"].is_null() ? "0.5" : node["Intensity"]; + std::string str_distMult = node["DistanceMultiplier"].is_null() ? "1.0" : node["DistanceMultiplier"]; std::string str_LType = node["LightType"].is_null() ? "1" : node["LightType"]; // --- Pass Strings to the needed Data Type @@ -347,4 +364,5 @@ void ComponentLight::Load(json& node) m_Intensity = std::stof(str_intensity); m_LightType = (LightType)(std::stoi(str_LType)); + m_DistanceMultiplier = std::stof(str_distMult); } \ No newline at end of file diff --git a/Broken Engine/Source/ComponentLight.h b/Broken Engine/Source/ComponentLight.h index 61c7b7af7..a3c71c088 100644 --- a/Broken Engine/Source/ComponentLight.h +++ b/Broken Engine/Source/ComponentLight.h @@ -34,13 +34,14 @@ class BROKEN_API ComponentLight : public Component public: // --- Getters -- - inline const float3 GetLightDirection() const { return m_Direction; } - inline const float3 GetLightColor() const { return m_Color; } - inline const float3 GetLightAttenuationKLQ() const { return m_AttenuationKLQFactors; } - inline const float2 GetLightInOutCutoff() const { return m_InOutCutoffDegrees; } - inline const float GetLightIntensity() const { return m_Intensity; } + inline const float3 GetLightDirection() const { return m_Direction; } + inline const float3 GetLightColor() const { return m_Color; } + inline const float3 GetLightAttenuationKLQ() const { return m_AttenuationKLQFactors; } + inline const float2 GetLightInOutCutoff() const { return m_InOutCutoffDegrees; } + inline const float GetLightIntensity() const { return m_Intensity; } + inline const float GetLightDistanceMultiplier() const { return m_DistanceMultiplier; } - inline const LightType GetLightType() const { return m_LightType; } + inline const LightType GetLightType() const { return m_LightType; } // -- Setters --- void SetLightDirection(float3 dir) { m_Direction = dir; } @@ -55,6 +56,7 @@ class BROKEN_API ComponentLight : public Component void SetLightInOutCutoff(float innerCutoff, float outerCutoff) { m_InOutCutoffDegrees = float2(innerCutoff, outerCutoff); } void SetLightIntensity(float intensity) { m_Intensity = intensity; } + void SetLightDistanceMultiplier(float distMulti) { m_DistanceMultiplier = distMulti; } void SetLightType(LightType type) { if (type != LightType::NONE && (uint)type < (uint)LightType::MAX_LIGHT_TYPES) m_LightType = type; } @@ -72,6 +74,7 @@ class BROKEN_API ComponentLight : public Component float2 m_InOutCutoffDegrees = float2(12.5f, 45.0f); float m_Intensity = 0.5f; + float m_DistanceMultiplier = 1.0f; // --- Others --- LightType m_LightType = LightType::NONE; diff --git a/Broken Engine/Source/ModuleRenderer3D.cpp b/Broken Engine/Source/ModuleRenderer3D.cpp index 617881681..3eda33437 100644 --- a/Broken Engine/Source/ModuleRenderer3D.cpp +++ b/Broken Engine/Source/ModuleRenderer3D.cpp @@ -391,12 +391,22 @@ bool ModuleRenderer3D::CleanUp() void ModuleRenderer3D::LoadStatus(const json& file) { m_GammaCorrection = file["Renderer3D"]["GammaCorrection"].is_null() ? 1.0f : file["Renderer3D"]["GammaCorrection"].get(); + + float ambR = file["Renderer3D"]["SceneAmbientColor"]["R"].is_null() ? 1.0f : file["Renderer3D"]["SceneAmbientColor"]["R"].get(); + float ambG = file["Renderer3D"]["SceneAmbientColor"]["G"].is_null() ? 1.0f : file["Renderer3D"]["SceneAmbientColor"]["G"].get(); + float ambB = file["Renderer3D"]["SceneAmbientColor"]["B"].is_null() ? 1.0f : file["Renderer3D"]["SceneAmbientColor"]["B"].get(); + m_AmbientColor = float3(ambR, ambG, ambB); } const json& ModuleRenderer3D::SaveStatus() const { static json m_config; + m_config["GammaCorrection"] = m_GammaCorrection; + m_config["SceneAmbientColor"]["R"] = m_AmbientColor.x; + m_config["SceneAmbientColor"]["G"] = m_AmbientColor.y; + m_config["SceneAmbientColor"]["B"] = m_AmbientColor.z; + return m_config; } @@ -809,8 +819,9 @@ void ModuleRenderer3D::DrawRenderMesh(std::vector meshInstances) glUniform1i(glGetUniformLocation(shader, "u_DrawNormalMapping_Lit"), (int)m_Draw_normalMapping_Lit); glUniform1i(glGetUniformLocation(shader, "u_DrawNormalMapping_Lit_Adv"), (int)m_Draw_normalMapping_Lit_Adv); - // --- Gamma Correction Value --- + // --- Gamma Correction & Ambient Color Values --- glUniform1f(glGetUniformLocation(shader, "u_GammaCorrection"), m_GammaCorrection); + glUniform4f(glGetUniformLocation(shader, "u_AmbientColor"), m_AmbientColor.x, m_AmbientColor.y, m_AmbientColor.z, 1.0f); // --- Set Textures usage to 0 --- //glUniform1i(glGetUniformLocation(shader, "u_HasDiffuseTexture"), 0); diff --git a/Broken Engine/Source/ModuleRenderer3D.h b/Broken Engine/Source/ModuleRenderer3D.h index 11e13c442..f43547320 100644 --- a/Broken Engine/Source/ModuleRenderer3D.h +++ b/Broken Engine/Source/ModuleRenderer3D.h @@ -109,10 +109,12 @@ class BROKEN_API ModuleRenderer3D : public Module void SetActiveCamera(ComponentCamera* camera); void SetCullingCamera(ComponentCamera* camera); void SetGammaCorrection(float gammaCorr) { m_GammaCorrection = gammaCorr; } + void SetSceneAmbientColor(float3 color) { m_AmbientColor = color; } // --- Getters --- bool GetVSync() const { return vsync; } const float GetGammaCorrection() const { return m_GammaCorrection; } + const float3 GetSceneAmbientColor() const { return m_AmbientColor; } private: @@ -209,6 +211,7 @@ class BROKEN_API ModuleRenderer3D : public Module //Lights vector std::vector m_LightsVec; float m_GammaCorrection = 2.0f; + float3 m_AmbientColor = float3::one; uint fbo = 0; uint cubemapTexID = 0; diff --git a/Broken Engine/Source/ModuleScripting.cpp b/Broken Engine/Source/ModuleScripting.cpp index 09e7ae097..c692c43cc 100644 --- a/Broken Engine/Source/ModuleScripting.cpp +++ b/Broken Engine/Source/ModuleScripting.cpp @@ -24,6 +24,7 @@ #include "ScriptingInterface.h" #include "ScriptingScenes.h" #include "ScriptingNavigation.h" +#include "ScriptingLighting.h" #include "ScriptVar.h" #include @@ -138,6 +139,10 @@ bool ModuleScripting::JustCompile(std::string absolute_path) { .addConstructor() .endClass() + .beginClass ("Lighting") + .addConstructor() + .endClass() + .beginClass ("Audio") .addConstructor() .endClass() @@ -323,6 +328,27 @@ void ModuleScripting::CompileScriptTableClass(ScriptInstance* script) .addFunction("SetRandomParticlesScale", &ScriptingParticles::SetRandomParticleScale) .endClass() + // ---------------------------------------------------------------------------------- + // LIGHTING + // ---------------------------------------------------------------------------------- + .beginClass ("Lighting") + .addConstructor() + + .addFunction("GetLightColor", &ScriptingLighting::GetColor) + .addFunction("GetLightAttenuation", &ScriptingLighting::GetAttenuation) + .addFunction("GetLightCutoff", &ScriptingLighting::GetCutoff) + .addFunction("GetLightType", &ScriptingLighting::GetType) + .addFunction("GetLightIntensity", &ScriptingLighting::GetIntensity) + .addFunction("GetDistMultiplier", &ScriptingLighting::GetDistanceMultiplier) + + .addFunction("SetLightIntensity", &ScriptingLighting::SetIntensity) + .addFunction("SetLightType", &ScriptingLighting::SetType) + .addFunction("SetLightColor", &ScriptingLighting::SetColor) + .addFunction("SetLightAttenuation", &ScriptingLighting::SetAttenuation) + .addFunction("SetLightCutoff", &ScriptingLighting::SetCutoff) + .addFunction("SetDistMultiplier", &ScriptingLighting::SetDistanceMultiplier) + .endClass() + // ---------------------------------------------------------------------------------- // AUDIO // ---------------------------------------------------------------------------------- diff --git a/Broken Engine/Source/PanelRendering.cpp b/Broken Engine/Source/PanelRendering.cpp index f00d6050c..d2af8a938 100644 --- a/Broken Engine/Source/PanelRendering.cpp +++ b/Broken Engine/Source/PanelRendering.cpp @@ -20,6 +20,7 @@ PanelRendering::~PanelRendering() bool PanelRendering::Draw() { m_GammaCorretionValue = EngineApp->renderer3D->GetGammaCorrection(); + m_AmbientColorValue = EngineApp->renderer3D->GetSceneAmbientColor(); ImGui::SetCurrentContext(EngineApp->gui->getImgUICtx()); @@ -33,9 +34,15 @@ bool PanelRendering::Draw() ImGui::SetNextItemWidth(200.0f); ImGui::SliderFloat("##GammaCorrection", &m_GammaCorretionValue, 0.1f, 5.0f); ImGui::NewLine(); + + ImGui::Text("Ambient Color"); + ImGui::SameLine(0, ImGui::GetStyle().ItemInnerSpacing.x + 10.0f); + ImGui::ColorEdit4("##AmbientColor", (float*)&m_AmbientColorValue, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaBar); + ImGui::NewLine(); } ImGui::End(); EngineApp->renderer3D->SetGammaCorrection(m_GammaCorretionValue); + EngineApp->renderer3D->SetSceneAmbientColor(m_AmbientColorValue); return false; } diff --git a/Broken Engine/Source/PanelRendering.h b/Broken Engine/Source/PanelRendering.h index 6bc913996..421714910 100644 --- a/Broken Engine/Source/PanelRendering.h +++ b/Broken Engine/Source/PanelRendering.h @@ -2,6 +2,7 @@ #define __PANEL_RENDERING_H__ #include "Panel.h" +#include "Math.h" class PanelRendering : public Panel { @@ -15,6 +16,7 @@ class PanelRendering : public Panel private: float m_GammaCorretionValue = 1.0f; + float3 m_AmbientColorValue = float3::one; }; #endif \ No newline at end of file diff --git a/Broken Engine/Source/ResourceShader.cpp b/Broken Engine/Source/ResourceShader.cpp index a5b02e93c..7fffc84f3 100644 --- a/Broken Engine/Source/ResourceShader.cpp +++ b/Broken Engine/Source/ResourceShader.cpp @@ -298,6 +298,8 @@ void ResourceShader::GetAllUniforms(std::vector& uniforms) || strcmp(name, "u_DrawNormalMapping_Lit_Adv") == 0 || strcmp(name, "u_LightsNumber") == 0 || strcmp(name, "u_GammaCorrection") == 0 + || strcmp(name, "u_AmbientColor") == 0 + || strcmp(name, "HasTransparencies") == 0 || std::string(name).find("u_BkLights") != std::string::npos || strcmp(name, "time") == 0) continue; diff --git a/Broken Engine/Source/ScriptingLighting.cpp b/Broken Engine/Source/ScriptingLighting.cpp new file mode 100644 index 000000000..d712ac3c0 --- /dev/null +++ b/Broken Engine/Source/ScriptingLighting.cpp @@ -0,0 +1,249 @@ +#include "ScriptingLighting.h" + +// -- Modules -- +#include "Application.h" +#include "ModuleScripting.h" +#include "ModuleSceneManager.h" + +// -- Components - +#include "GameObject.h" +#include "Components.h" +#include "ComponentLight.h" + +#include "ScriptData.h" +#include "ResourceScene.h" + +// -- Utilities -- +//#include "TranslatorUtilities.h" + +using namespace Broken; + +// --- Setters --- +void ScriptingLighting::SetIntensity(float intensity, uint gameobject_UUID) +{ + GameObject* go = App->scene_manager->currentScene->GetGOWithUID(gameobject_UUID); + if (go) + { + ComponentLight* light = go->GetComponent(); + if (light) + light->SetLightIntensity(intensity); + else + ENGINE_CONSOLE_LOG("![Script]: (SetIntensity) Light Component is null"); + } + else + ENGINE_CONSOLE_LOG("![Script]: (SetIntensity) Could not find GameObject with UUID %d", gameobject_UUID); +} + +void ScriptingLighting::SetDistanceMultiplier(float distMult, uint gameobject_UUID) +{ + GameObject* go = App->scene_manager->currentScene->GetGOWithUID(gameobject_UUID); + if (go) + { + ComponentLight* light = go->GetComponent(); + if (light) + light->SetLightDistanceMultiplier(distMult); + else + ENGINE_CONSOLE_LOG("![Script]: (SetDistanceMultiplier) Light Component is null"); + } + else + ENGINE_CONSOLE_LOG("![Script]: (SetDistanceMultiplier) Could not find GameObject with UUID %d", gameobject_UUID); +} + +void ScriptingLighting::SetType(int type, uint gameobject_UUID) +{ + if (type <= -1 || type >= 3) + { + ENGINE_CONSOLE_LOG("![Script]: (SetType) Error! Light Type Parameter Invalid!"); + return; + } + + GameObject* go = App->scene_manager->currentScene->GetGOWithUID(gameobject_UUID); + if (go) + { + ComponentLight* light = go->GetComponent(); + if (light) + light->SetLightType((LightType)type); + else + ENGINE_CONSOLE_LOG("![Script]: (SetType) Light Component is null"); + } + else + ENGINE_CONSOLE_LOG("![Script]: (SetType) Could not find GameObject with UUID %d", gameobject_UUID); +} + +void ScriptingLighting::SetColor(float r, float g, float b, uint gameobject_UUID) +{ + GameObject* go = App->scene_manager->currentScene->GetGOWithUID(gameobject_UUID); + if (go) + { + ComponentLight* light = go->GetComponent(); + if (light) + light->SetLightColor(float3(r, g, b)); + else + ENGINE_CONSOLE_LOG("![Script]: (SetColor) Light Component is null"); + } + else + ENGINE_CONSOLE_LOG("![Script]: (SetColor) Could not find GameObject with UUID %d", gameobject_UUID); +} + +void ScriptingLighting::SetAttenuation(float K, float L, float Q, uint gameobject_UUID) +{ + GameObject* go = App->scene_manager->currentScene->GetGOWithUID(gameobject_UUID); + if (go) + { + ComponentLight* light = go->GetComponent(); + if (light) + light->SetLightAttenuationFactors(K, L, Q); + else + ENGINE_CONSOLE_LOG("![Script]: (SetAttenuation) Light Component is null"); + } + else + ENGINE_CONSOLE_LOG("![Script]: (SetAttenuation) Could not find GameObject with UUID %d", gameobject_UUID); +} + +void ScriptingLighting::SetCutoff(float innerCutoff, float outerCutoff, uint gameobject_UUID) +{ + GameObject* go = App->scene_manager->currentScene->GetGOWithUID(gameobject_UUID); + if (go) + { + ComponentLight* light = go->GetComponent(); + if (light) + return light->SetLightInOutCutoff(innerCutoff, outerCutoff); + else + ENGINE_CONSOLE_LOG("![Script]: (SetCutoff) Light Component is null"); + } + else + ENGINE_CONSOLE_LOG("![Script]: (SetCutoff) Could not find GameObject with UUID %d", gameobject_UUID); +} + +// --- Getters --- +float ScriptingLighting::GetIntensity(uint gameobject_UUID) const +{ + float ret = 0.0f; + + GameObject* go = App->scene_manager->currentScene->GetGOWithUID(gameobject_UUID); + if (go) + { + ComponentLight* light = go->GetComponent(); + if (light) + ret = light->GetLightIntensity(); + else + ENGINE_CONSOLE_LOG("![Script]: (GetIntensity) Light Component is null"); + } + else + ENGINE_CONSOLE_LOG("![Script]: (GetIntensity) Could not find GameObject with UUID %d", gameobject_UUID); + + return ret; +} + +float ScriptingLighting::GetDistanceMultiplier(uint gameobject_UUID) const +{ + float ret = 0.0f; + + GameObject* go = App->scene_manager->currentScene->GetGOWithUID(gameobject_UUID); + if (go) + { + ComponentLight* light = go->GetComponent(); + if (light) + ret = light->GetLightDistanceMultiplier(); + else + ENGINE_CONSOLE_LOG("![Script]: (GetDistanceMultiplier) Light Component is null"); + } + else + ENGINE_CONSOLE_LOG("![Script]: (GetDistanceMultiplier) Could not find GameObject with UUID %d", gameobject_UUID); + + return ret; +} + +int ScriptingLighting::GetType(uint gameobject_UUID) const +{ + int ret = -1; + GameObject* go = App->scene_manager->currentScene->GetGOWithUID(gameobject_UUID); + + if (go) + { + ComponentLight* light = go->GetComponent(); + if (light) + { + ret = (int)light->GetLightType(); + if(ret <= -1 || ret >= 3) + ENGINE_CONSOLE_LOG("![Script]: (GetType) WARNING! Light Type Invalid"); + } + else + ENGINE_CONSOLE_LOG("![Script]: (GetType) Light Component is null"); + } + else + ENGINE_CONSOLE_LOG("![Script]: (GetType) Could not find GameObject with UUID %d", gameobject_UUID); + + return ret; +} + +luabridge::LuaRef ScriptingLighting::GetColor(uint gameobject_UUID, lua_State* L) const +{ + float3 color = float3(0.0f); + GameObject* go = App->scene_manager->currentScene->GetGOWithUID(gameobject_UUID); + + if (go) + { + ComponentLight* light = go->GetComponent(); + if (light) + color = light->GetLightColor(); + else + ENGINE_CONSOLE_LOG("![Script]: (GetColor) Light Component is null"); + } + else + ENGINE_CONSOLE_LOG("![Script]: (GetColor) Could not find GameObject with UUID %d", gameobject_UUID); + + luabridge::LuaRef table = luabridge::newTable(L); + table.append(color.x); + table.append(color.y); + table.append(color.z); + + return table; +} + +luabridge::LuaRef ScriptingLighting::GetAttenuation(uint gameobject_UUID, lua_State* L) const +{ + float3 att = float3(0.0f); + GameObject* go = App->scene_manager->currentScene->GetGOWithUID(gameobject_UUID); + + if (go) + { + ComponentLight* light = go->GetComponent(); + if (light) + att = light->GetLightAttenuationKLQ(); + else + ENGINE_CONSOLE_LOG("![Script]: (GetAttenuation) Light Component is null"); + } + else + ENGINE_CONSOLE_LOG("![Script]: (GetAttenuation) Could not find GameObject with UUID %d", gameobject_UUID); + + luabridge::LuaRef table = luabridge::newTable(L); + table.append(att.x); + table.append(att.y); + table.append(att.z); + + return table; +} + +luabridge::LuaRef ScriptingLighting::GetCutoff(uint gameobject_UUID, lua_State* L) const +{ + float2 cutoff = float2(0.0f); + GameObject* go = App->scene_manager->currentScene->GetGOWithUID(gameobject_UUID); + + if (go) + { + ComponentLight* light = go->GetComponent(); + if (light) + cutoff = light->GetLightInOutCutoff(); + else + ENGINE_CONSOLE_LOG("![Script]: (GetCutoff) Light Component is null"); + } + else + ENGINE_CONSOLE_LOG("![Script]: (GetCutoff) Could not find GameObject with UUID %d", gameobject_UUID); + + luabridge::LuaRef table = luabridge::newTable(L); + table.append(cutoff.x); + table.append(cutoff.y); + + return table; +} diff --git a/Broken Engine/Source/ScriptingLighting.h b/Broken Engine/Source/ScriptingLighting.h new file mode 100644 index 000000000..4ac6c0d7c --- /dev/null +++ b/Broken Engine/Source/ScriptingLighting.h @@ -0,0 +1,38 @@ +#ifndef __SCRIPTINGLIGHTING_H__ +#define __SCRIPTINGLIGHTING_H__ + +#include "BrokenCore.h" + +class lua_State; + +namespace luabridge +{ + class LuaRef; +} + +BE_BEGIN_NAMESPACE +class BROKEN_API ScriptingLighting +{ +public: + + ScriptingLighting() {} + ~ScriptingLighting() {} + + // --- Setters --- + void SetIntensity(float intensity, uint gameobject_UUID); + void SetDistanceMultiplier(float distMult, uint gameobject_UUID); + void SetType(int type, uint gameobject_UUID); + void SetColor(float r, float g, float b, uint gameobject_UUID); + void SetAttenuation(float K, float L, float Q, uint gameobject_UUID); + void SetCutoff(float innerCutoff, float outerCutoff, uint gameobject_UUID); + + // --- Getters --- + float GetIntensity(uint gameobject_UUID) const; + float GetDistanceMultiplier(uint gameobject_UUID) const; + int GetType(uint gameobject_UUID) const; //NONE = -1, DIR = 0, POINT = 1, SPOT = 2, MAX = 3 + luabridge::LuaRef GetColor(uint gameobject_UUID, lua_State* L) const; + luabridge::LuaRef GetAttenuation(uint gameobject_UUID, lua_State* L) const; + luabridge::LuaRef GetCutoff(uint gameobject_UUID, lua_State* L) const; +}; +BE_END_NAMESPACE +#endif //__SCRIPTINGLIGHTING_H__ \ No newline at end of file