diff --git a/Source/Core/Editor/Widgets/GUI_Widget_ObjectProperties.cpp b/Source/Core/Editor/Widgets/GUI_Widget_ObjectProperties.cpp index 66e8af176b..769cdde017 100644 --- a/Source/Core/Editor/Widgets/GUI_Widget_ObjectProperties.cpp +++ b/Source/Core/Editor/Widgets/GUI_Widget_ObjectProperties.cpp @@ -47,35 +47,18 @@ void Widget_ObjectProperties::Draw() { unsigned long Index = SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SceneObjects_[SelectedSceneObject].Index_; if (ImGui::CollapsingHeader("Point Light Settings", ImGuiTreeNodeFlags_DefaultOpen)) { - float DiffuseColor[3]; - VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->Diffuse, DiffuseColor); - ImGui::ColorEdit3("Diffuse", DiffuseColor); + float Color[3]; + VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->Color, Color); + ImGui::ColorEdit3("Color", Color); ImGui::SameLine(); ImGui::HelpMarker("Controls the main color of the light."); - FloatToVec(DiffuseColor, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->Diffuse); - float AmbientColor[3]; - VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->Ambient, AmbientColor); - ImGui::ColorEdit3("Ambient", AmbientColor); - ImGui::SameLine(); - ImGui::HelpMarker("Controls any additions to the ambient color of the environment. Generally, you shouldn't do this with a point light, use a directional light whenever possible instead."); - FloatToVec(AmbientColor, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->Ambient); - float SpecularColor[3]; - VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->Specular, SpecularColor); - ImGui::ColorEdit3("Specular", SpecularColor); - ImGui::SameLine(); - ImGui::HelpMarker("Controls the color of the reflection."); - FloatToVec(SpecularColor, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->Specular); - ImGui::Separator(); + FloatToVec(Color, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->Color); + - ImGui::DragFloat("Rolloff Constant", &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->RolloffConstant, 0.01f); - ImGui::SameLine(); - ImGui::HelpMarker("Sets the constant offset controlling lamp attenuation over distance. If you're trying to make the rolloff sharper, try linear or quadratic."); - ImGui::DragFloat("Rolloff Linear", &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->RolloffLinear, 0.01f); - ImGui::SameLine(); - ImGui::HelpMarker("Component of rolloff proportional to distance from light to object. E.g. twice the distance means half the brightness."); - ImGui::DragFloat("Rolloff Quadratic", &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->RolloffQuadratic, 0.01f); + ImGui::DragFloat("Intensity", &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->PointLights[Index]->Intensity, 0.01f); ImGui::SameLine(); - ImGui::HelpMarker("Exponential component of rolloff. Increasing this, makes the rolloff much sharper. For a linear rolloff, use the 'Rolloff Linear' value."); + ImGui::HelpMarker("Sets the brightness of the light source, increase this for a brighter light."); + } @@ -84,25 +67,13 @@ void Widget_ObjectProperties::Draw() { unsigned long Index = SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SceneObjects_[SelectedSceneObject].Index_; if (ImGui::CollapsingHeader("Directional Light Settings", ImGuiTreeNodeFlags_DefaultOpen)) { - float DiffuseColor[3]; - VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->DirectionalLights[Index]->Diffuse, DiffuseColor); - ImGui::ColorEdit3("Diffuse", DiffuseColor); + float Color[3]; + VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->DirectionalLights[Index]->Color, Color); + ImGui::ColorEdit3("Color", Color); ImGui::SameLine(); ImGui::HelpMarker("Controls the main color of the light."); - FloatToVec(DiffuseColor, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->DirectionalLights[Index]->Diffuse); - float AmbientColor[3]; - VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->DirectionalLights[Index]->Ambient, AmbientColor); - ImGui::ColorEdit3("Ambient", AmbientColor); - ImGui::SameLine(); - ImGui::HelpMarker("Controls any additions to the ambient color of the environment."); - FloatToVec(AmbientColor, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->DirectionalLights[Index]->Ambient); - float SpecularColor[3]; - VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->DirectionalLights[Index]->Specular, SpecularColor); - ImGui::ColorEdit3("Specular", SpecularColor); - ImGui::SameLine(); - ImGui::HelpMarker("Controls the color of the reflection. Generally, you shouldn't do this with a directional light, use a spot or point light instead."); - FloatToVec(SpecularColor, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->DirectionalLights[Index]->Specular); - ImGui::Separator(); + FloatToVec(Color, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->DirectionalLights[Index]->Color); + } @@ -111,36 +82,18 @@ void Widget_ObjectProperties::Draw() { unsigned long Index = SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SceneObjects_[SelectedSceneObject].Index_; if (ImGui::CollapsingHeader("Spot Light Settings", ImGuiTreeNodeFlags_DefaultOpen)) { - float DiffuseColor[3]; - VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->Diffuse, DiffuseColor); - ImGui::ColorEdit3("Diffuse", DiffuseColor); + float Color[3]; + VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->Color, Color); + ImGui::ColorEdit3("Color", Color); ImGui::SameLine(); ImGui::HelpMarker("Controls the main color of the light."); - FloatToVec(DiffuseColor, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->Diffuse); - float AmbientColor[3]; - VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->Ambient, AmbientColor); - ImGui::ColorEdit3("Ambient", AmbientColor); - ImGui::SameLine(); - ImGui::HelpMarker("Controls any additions to the ambient color of the environment. Generally, you shouldn't do this with a spot light, use a directional light whenever possible instead."); - FloatToVec(AmbientColor, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->Ambient); - float SpecularColor[3]; - VecToFloat(&SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->Specular, SpecularColor); - ImGui::ColorEdit3("Specular", SpecularColor); - ImGui::SameLine(); - ImGui::HelpMarker("Controls the color of the reflection."); - FloatToVec(SpecularColor, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->Specular); - ImGui::Separator(); + FloatToVec(Color, &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->Color); - ImGui::DragFloat("Rolloff Constant", &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->RolloffConstant, 0.01f); - ImGui::SameLine(); - ImGui::HelpMarker("Sets the constant offset controlling lamp attenuation over distance. If you're trying to make the rolloff sharper, try linear or quadratic."); - ImGui::DragFloat("Rolloff Linear", &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->RolloffLinear, 0.01f); - ImGui::SameLine(); - ImGui::HelpMarker("Component of rolloff proportional to distance from light to object. E.g. twice the distance means half the brightness."); - ImGui::DragFloat("Rolloff Quadratic", &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->RolloffQuadratic, 0.01f); + + ImGui::DragFloat("Intensity", &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->Intensity, 0.01f); ImGui::SameLine(); - ImGui::HelpMarker("Exponential component of rolloff. Increasing this, makes the rolloff much sharper. For a linear rolloff, use the 'Rolloff Linear' value."); - ImGui::Separator(); + ImGui::HelpMarker("Sets the brightness of the light source, increase this for a brighter light."); + ImGui::DragFloat("Cutoff", &SceneManager_->Scenes_[SceneManager_->ActiveScene_]->SpotLights[Index]->CutOff, 0.01f); ImGui::SameLine(); diff --git a/Source/Core/Loader/ERS_SceneLoader/ERS_SceneLoader.cpp b/Source/Core/Loader/ERS_SceneLoader/ERS_SceneLoader.cpp index b24acee2c6..2183f0429c 100644 --- a/Source/Core/Loader/ERS_SceneLoader/ERS_SceneLoader.cpp +++ b/Source/Core/Loader/ERS_SceneLoader/ERS_SceneLoader.cpp @@ -121,22 +121,15 @@ ERS_STRUCT_Scene ERS_CLASS_SceneLoader::ProcessScene(YAML::Node RawSceneData, lo int LightIndex = Scene.DirectionalLights.size() - 1; Scene.DirectionalLights[LightIndex]->UserDefinedName = AssetName; - - Scene.DirectionalLights[LightIndex]->Ambient = glm::vec3( - SceneDataNode[i]["AmbientRed"].as(), - SceneDataNode[i]["AmbientGreen"].as(), - SceneDataNode[i]["AmbientBlue"].as() - ); - Scene.DirectionalLights[LightIndex]->Diffuse = glm::vec3( - SceneDataNode[i]["DiffuseRed"].as(), - SceneDataNode[i]["DiffuseGreen"].as(), - SceneDataNode[i]["DiffuseBlue"].as() - ); - Scene.DirectionalLights[LightIndex]->Specular = glm::vec3( - SceneDataNode[i]["SpecularRed"].as(), - SceneDataNode[i]["SpecularGreen"].as(), - SceneDataNode[i]["SpecularBlue"].as() - ); + + if (SceneDataNode[i]["ColorRed"] && SceneDataNode[i]["ColorGreen"] && SceneDataNode[i]["ColorBlue"]) { + Scene.DirectionalLights[LightIndex]->Color = glm::vec3( + SceneDataNode[i]["ColorRed"].as(), + SceneDataNode[i]["ColorGreen"].as(), + SceneDataNode[i]["ColorBlue"].as() + ); + } + Scene.DirectionalLights[LightIndex]->Pos = glm::vec3( SceneDataNode[i]["PosX"].as(), @@ -164,28 +157,18 @@ ERS_STRUCT_Scene ERS_CLASS_SceneLoader::ProcessScene(YAML::Node RawSceneData, lo int LightIndex = Scene.PointLights.size() - 1; Scene.PointLights[LightIndex]->UserDefinedName = AssetName; - - - Scene.PointLights[LightIndex]->RolloffConstant = SceneDataNode[i]["RolloffConstant"].as(); - Scene.PointLights[LightIndex]->RolloffLinear = SceneDataNode[i]["RolloffLinear"].as(); - Scene.PointLights[LightIndex]->RolloffQuadratic = SceneDataNode[i]["RolloffQuadratic"].as(); + if (SceneDataNode[i]["Intensity"]) { + Scene.PointLights[LightIndex]->Intensity = SceneDataNode[i]["Intensity"].as(); + } - Scene.PointLights[LightIndex]->Ambient = glm::vec3( - SceneDataNode[i]["AmbientRed"].as(), - SceneDataNode[i]["AmbientGreen"].as(), - SceneDataNode[i]["AmbientBlue"].as() - ); - Scene.PointLights[LightIndex]->Diffuse = glm::vec3( - SceneDataNode[i]["DiffuseRed"].as(), - SceneDataNode[i]["DiffuseGreen"].as(), - SceneDataNode[i]["DiffuseBlue"].as() - ); - Scene.PointLights[LightIndex]->Specular = glm::vec3( - SceneDataNode[i]["SpecularRed"].as(), - SceneDataNode[i]["SpecularGreen"].as(), - SceneDataNode[i]["SpecularBlue"].as() - ); + if (SceneDataNode[i]["ColorRed"] && SceneDataNode[i]["ColorGreen"] && SceneDataNode[i]["ColorBlue"]) { + Scene.PointLights[LightIndex]->Color = glm::vec3( + SceneDataNode[i]["ColorRed"].as(), + SceneDataNode[i]["ColorGreen"].as(), + SceneDataNode[i]["ColorBlue"].as() + ); + } Scene.PointLights[LightIndex]->Pos = glm::vec3( SceneDataNode[i]["PosX"].as(), @@ -209,31 +192,20 @@ ERS_STRUCT_Scene ERS_CLASS_SceneLoader::ProcessScene(YAML::Node RawSceneData, lo Scene.SpotLights[LightIndex]->UserDefinedName = AssetName; - - Scene.SpotLights[LightIndex]->RolloffConstant = SceneDataNode[i]["RolloffConstant"].as(); - Scene.SpotLights[LightIndex]->RolloffLinear = SceneDataNode[i]["RolloffLinear"].as(); - Scene.SpotLights[LightIndex]->RolloffQuadratic = SceneDataNode[i]["RolloffQuadratic"].as(); - - + if (SceneDataNode[i]["Intensity"]) { + Scene.SpotLights[LightIndex]->Intensity = SceneDataNode[i]["Intensity"].as(); + } Scene.SpotLights[LightIndex]->CutOff = SceneDataNode[i]["CutOff"].as(); Scene.SpotLights[LightIndex]->OuterCutOff = SceneDataNode[i]["OuterCutOff"].as(); + if (SceneDataNode[i]["ColorRed"] && SceneDataNode[i]["ColorGreen"] && SceneDataNode[i]["ColorBlue"]) { + Scene.SpotLights[LightIndex]->Color = glm::vec3( + SceneDataNode[i]["ColorRed"].as(), + SceneDataNode[i]["ColorGreen"].as(), + SceneDataNode[i]["ColorBlue"].as() + ); + } - Scene.SpotLights[LightIndex]->Ambient = glm::vec3( - SceneDataNode[i]["AmbientRed"].as(), - SceneDataNode[i]["AmbientGreen"].as(), - SceneDataNode[i]["AmbientBlue"].as() - ); - Scene.SpotLights[LightIndex]->Diffuse = glm::vec3( - SceneDataNode[i]["DiffuseRed"].as(), - SceneDataNode[i]["DiffuseGreen"].as(), - SceneDataNode[i]["DiffuseBlue"].as() - ); - Scene.SpotLights[LightIndex]->Specular = glm::vec3( - SceneDataNode[i]["SpecularRed"].as(), - SceneDataNode[i]["SpecularGreen"].as(), - SceneDataNode[i]["SpecularBlue"].as() - ); Scene.SpotLights[LightIndex]->Pos = glm::vec3( SceneDataNode[i]["PosX"].as(), diff --git a/Source/Core/Manager/ERS_SceneManager/ERS_SceneManager.cpp b/Source/Core/Manager/ERS_SceneManager/ERS_SceneManager.cpp index b6d5903463..1d189097e5 100644 --- a/Source/Core/Manager/ERS_SceneManager/ERS_SceneManager.cpp +++ b/Source/Core/Manager/ERS_SceneManager/ERS_SceneManager.cpp @@ -120,13 +120,10 @@ void ERS_CLASS_SceneManager::AddPointLight() { std::shared_ptr Light = std::make_shared(); Light->UserDefinedName = "New Point Light"; - Light->Ambient = glm::vec3(0.0f); - Light->Diffuse = glm::vec3(0.5f); - Light->Specular = glm::vec3(0.5f); + Light->Color = glm::vec3(0.0f); - Light->RolloffConstant = 1.0f; - Light->RolloffLinear = 0.18f; - Light->RolloffQuadratic = 0.064f; + + Light->Intensity = 1.0f; Scenes_[ActiveScene_]->PointLights.push_back(Light); Scenes_[ActiveScene_]->IndexSceneObjects(); @@ -138,9 +135,8 @@ void ERS_CLASS_SceneManager::AddDirectionalLight() { std::shared_ptr Light = std::make_shared(); Light->UserDefinedName = "New Directional Light"; - Light->Ambient = glm::vec3(0.0f); - Light->Diffuse = glm::vec3(0.5f); - Light->Specular = glm::vec3(0.5f); + Light->Color = glm::vec3(0.0f); + Scenes_[ActiveScene_]->DirectionalLights.push_back(Light); Scenes_[ActiveScene_]->IndexSceneObjects(); @@ -152,13 +148,10 @@ void ERS_CLASS_SceneManager::AddSpotLight() { std::shared_ptr Light = std::make_shared(); Light->UserDefinedName = "New Spot Light"; - Light->Ambient = glm::vec3(0.0f); - Light->Diffuse = glm::vec3(0.5f); - Light->Specular = glm::vec3(0.5f); + Light->Color = glm::vec3(0.0f); + - Light->RolloffConstant = 1.0f; - Light->RolloffLinear = 0.18f; - Light->RolloffQuadratic = 0.064f; + Light->Intensity = 1.0f; Light->CutOff = 0.970f; Light->OuterCutOff = 0.960f; diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_VisualRenderer.cpp b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_VisualRenderer.cpp index 8c946f0a1f..667b87e69c 100644 --- a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_VisualRenderer.cpp +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_VisualRenderer.cpp @@ -544,7 +544,7 @@ void ERS_CLASS_VisualRenderer::CreateViewport(std::string ViewportName) { Viewport->ShaderIndex = DefaultShader_; Viewport->Camera = std::make_unique(); Viewport->Grid = std::make_unique(SystemUtils_, Shaders_[FindShaderIndex(std::string("_Grid"))]); - Viewport->LightIconRenderer = std::make_unique(OpenGLDefaults_, SystemUtils_, Shaders_[FindShaderIndex(std::string("LightIcon"))]); //Set TO Shader 19 For Billboard Shader, Temp. Disabled As It Doesn't Work ATM + Viewport->LightIconRenderer = std::make_unique(OpenGLDefaults_, SystemUtils_, Shaders_[FindShaderIndex(std::string("_LightIcon"))]); //Set TO Shader 19 For Billboard Shader, Temp. Disabled As It Doesn't Work ATM Viewport->Name = ViewportName; Viewport->Width = 1; @@ -672,9 +672,7 @@ void ERS_CLASS_VisualRenderer::UpdateShader(int ShaderIndex, float DeltaTime, in ActiveShader->SetVec3((UniformName + std::string(".Direction")).c_str(), ActiveScene->DirectionalLights[i]->Rot); - ActiveShader->SetVec3((UniformName + std::string(".Ambient")).c_str(), ActiveScene->DirectionalLights[i]->Ambient); - ActiveShader->SetVec3((UniformName + std::string(".Diffuse")).c_str(), ActiveScene->DirectionalLights[i]->Diffuse); - ActiveShader->SetVec3((UniformName + std::string(".Specular")).c_str(), ActiveScene->DirectionalLights[i]->Specular); + ActiveShader->SetVec3((UniformName + std::string(".Color")).c_str(), ActiveScene->DirectionalLights[i]->Color); } @@ -687,13 +685,9 @@ void ERS_CLASS_VisualRenderer::UpdateShader(int ShaderIndex, float DeltaTime, in ActiveShader->SetVec3((UniformName + std::string(".Position")).c_str(), ActiveScene->PointLights[i]->Pos); - ActiveShader->SetFloat((UniformName + std::string(".ConstantRolloff")).c_str(), ActiveScene->PointLights[i]->RolloffConstant); - ActiveShader->SetFloat((UniformName + std::string(".LinearRolloff")).c_str(), ActiveScene->PointLights[i]->RolloffLinear); - ActiveShader->SetFloat((UniformName + std::string(".QuadraticRolloff")).c_str(), ActiveScene->PointLights[i]->RolloffQuadratic); + ActiveShader->SetFloat((UniformName + std::string(".Intensity")).c_str(), ActiveScene->PointLights[i]->Intensity); - ActiveShader->SetVec3((UniformName + std::string(".Ambient")).c_str(), ActiveScene->PointLights[i]->Ambient); - ActiveShader->SetVec3((UniformName + std::string(".Diffuse")).c_str(), ActiveScene->PointLights[i]->Diffuse); - ActiveShader->SetVec3((UniformName + std::string(".Specular")).c_str(), ActiveScene->PointLights[i]->Specular); + ActiveShader->SetVec3((UniformName + std::string(".Color")).c_str(), ActiveScene->PointLights[i]->Color); } @@ -708,16 +702,12 @@ void ERS_CLASS_VisualRenderer::UpdateShader(int ShaderIndex, float DeltaTime, in ActiveShader->SetVec3((UniformName + std::string(".Position")).c_str(), ActiveScene->SpotLights[i]->Pos); ActiveShader->SetVec3((UniformName + std::string(".Direction")).c_str(), ActiveScene->SpotLights[i]->Rot); - ActiveShader->SetFloat((UniformName + std::string(".ConstantRolloff")).c_str(), ActiveScene->SpotLights[i]->RolloffConstant); - ActiveShader->SetFloat((UniformName + std::string(".LinearRolloff")).c_str(), ActiveScene->SpotLights[i]->RolloffLinear); - ActiveShader->SetFloat((UniformName + std::string(".QuadraticRolloff")).c_str(), ActiveScene->SpotLights[i]->RolloffQuadratic); + ActiveShader->SetFloat((UniformName + std::string(".Intensity")).c_str(), ActiveScene->SpotLights[i]->Intensity); ActiveShader->SetFloat((UniformName + std::string(".CutOff")).c_str(), ActiveScene->SpotLights[i]->CutOff); ActiveShader->SetFloat((UniformName + std::string(".OuterCutOff")).c_str(), ActiveScene->SpotLights[i]->OuterCutOff); - ActiveShader->SetVec3((UniformName + std::string(".Ambient")).c_str(), ActiveScene->SpotLights[i]->Ambient); - ActiveShader->SetVec3((UniformName + std::string(".Diffuse")).c_str(), ActiveScene->SpotLights[i]->Diffuse); - ActiveShader->SetVec3((UniformName + std::string(".Specular")).c_str(), ActiveScene->SpotLights[i]->Specular); + ActiveShader->SetVec3((UniformName + std::string(".Color")).c_str(), ActiveScene->SpotLights[i]->Color); } diff --git a/Source/Core/Script/ERS_CLASS_PythonInterpreterIntegration/ERS_CLASS_PythonInterpreterIntegration.cpp b/Source/Core/Script/ERS_CLASS_PythonInterpreterIntegration/ERS_CLASS_PythonInterpreterIntegration.cpp index bd2a42ff88..d75aae27d7 100644 --- a/Source/Core/Script/ERS_CLASS_PythonInterpreterIntegration/ERS_CLASS_PythonInterpreterIntegration.cpp +++ b/Source/Core/Script/ERS_CLASS_PythonInterpreterIntegration/ERS_CLASS_PythonInterpreterIntegration.cpp @@ -188,21 +188,11 @@ bool ERS_CLASS_PythonInterpreterIntegration::ExecutePointLightScript(std::string PointLightModule.attr("PointLightPosY") = PointLight->Pos.y; PointLightModule.attr("PointLightPosZ") = PointLight->Pos.z; - PointLightModule.attr("PointLightDiffuseR") = PointLight->Diffuse.r; - PointLightModule.attr("PointLightDiffuseG") = PointLight->Diffuse.g; - PointLightModule.attr("PointLightDiffuseB") = PointLight->Diffuse.b; + PointLightModule.attr("PointLightColorR") = PointLight->Color.r; + PointLightModule.attr("PointLightColorG") = PointLight->Color.g; + PointLightModule.attr("PointLightColorB") = PointLight->Color.b; - PointLightModule.attr("PointLightSpecularR") = PointLight->Specular.r; - PointLightModule.attr("PointLightSpecularG") = PointLight->Specular.g; - PointLightModule.attr("PointLightSpecularB") = PointLight->Specular.b; - - PointLightModule.attr("PointLightAmbientR") = PointLight->Ambient.r; - PointLightModule.attr("PointLightAmbientG") = PointLight->Ambient.g; - PointLightModule.attr("PointLightAmbientB") = PointLight->Ambient.b; - - PointLightModule.attr("PointLightRolloffConstant") = PointLight->RolloffConstant; - PointLightModule.attr("PointLightRolloffLinear") = PointLight->RolloffLinear; - PointLightModule.attr("PointLightRolloffQuadratic") = PointLight->RolloffQuadratic; + PointLightModule.attr("PointLightIntensity") = PointLight->Intensity; // Get Local Dict @@ -273,9 +263,7 @@ bool ERS_CLASS_PythonInterpreterIntegration::ExecutePointLightScript(std::string // Write Back PointLight Data double PointLightPosX, PointLightPosY, PointLightPosZ; - float DiffuseR, DiffuseG, DiffuseB; - float SpecularR, SpecularG, SpecularB; - float AmbientR, AmbientG, AmbientB; + float ColorR, ColorG, ColorB; try { PointLightPosX = PointLightModule.attr("PointLightPosX").cast(); @@ -287,38 +275,18 @@ bool ERS_CLASS_PythonInterpreterIntegration::ExecutePointLightScript(std::string } try { - DiffuseR = PointLightModule.attr("PointLightDiffuseR").cast(); - DiffuseG = PointLightModule.attr("PointLightDiffuseG").cast(); - DiffuseB = PointLightModule.attr("PointLightDiffuseB").cast(); - PointLight->Diffuse = glm::vec3(DiffuseR, DiffuseG, DiffuseB); - } catch (pybind11::cast_error const&) { - ErrorMessageString->push_back("PointLight Diffuse CAST_ERROR"); - } - - try { - SpecularR = PointLightModule.attr("PointLightSpecularR").cast(); - SpecularG = PointLightModule.attr("PointLightSpecularG").cast(); - SpecularB = PointLightModule.attr("PointLightSpecularB").cast(); - PointLight->Specular = glm::vec3(SpecularR, SpecularG, SpecularB); + ColorR = PointLightModule.attr("PointLightColorR").cast(); + ColorG = PointLightModule.attr("PointLightColorG").cast(); + ColorB = PointLightModule.attr("PointLightColorB").cast(); + PointLight->Color = glm::vec3(ColorR, ColorG, ColorB); } catch (pybind11::cast_error const&) { - ErrorMessageString->push_back("PointLight Specular CAST_ERROR"); + ErrorMessageString->push_back("PointLight Color CAST_ERROR"); } try { - AmbientR = PointLightModule.attr("PointLightAmbientR").cast(); - AmbientG = PointLightModule.attr("PointLightAmbientG").cast(); - AmbientB = PointLightModule.attr("PointLightAmbientB").cast(); - PointLight->Ambient = glm::vec3(AmbientR, AmbientG, AmbientB); + PointLight->Intensity = PointLightModule.attr("PointLightIntensity").cast(); } catch (pybind11::cast_error const&) { - ErrorMessageString->push_back("PointLight Ambient CAST_ERROR"); - } - - try { - PointLight->RolloffConstant = PointLightModule.attr("PointLightRolloffConstant").cast(); - PointLight->RolloffLinear = PointLightModule.attr("PointLightRolloffLinear").cast(); - PointLight->RolloffQuadratic = PointLightModule.attr("PointLightRolloffQuadratic").cast(); - } catch (pybind11::cast_error const&) { - ErrorMessageString->push_back("PointLight Rolloff CAST_ERROR"); + ErrorMessageString->push_back("PointLight Intensity CAST_ERROR"); } // Return Status @@ -344,17 +312,9 @@ bool ERS_CLASS_PythonInterpreterIntegration::ExecuteDirectionalLightScript(std:: DirectionalLightModule.attr("DirectionalLightRotY") = DirectionalLight->Rot.y; DirectionalLightModule.attr("DirectionalLightRotZ") = DirectionalLight->Rot.z; - DirectionalLightModule.attr("DirectionalLightDiffuseR") = DirectionalLight->Diffuse.r; - DirectionalLightModule.attr("DirectionalLightDiffuseG") = DirectionalLight->Diffuse.g; - DirectionalLightModule.attr("DirectionalLightDiffuseB") = DirectionalLight->Diffuse.b; - - DirectionalLightModule.attr("DirectionalLightSpecularR") = DirectionalLight->Specular.r; - DirectionalLightModule.attr("DirectionalLightSpecularG") = DirectionalLight->Specular.g; - DirectionalLightModule.attr("DirectionalLightSpecularB") = DirectionalLight->Specular.b; - - DirectionalLightModule.attr("DirectionalLightAmbientR") = DirectionalLight->Ambient.r; - DirectionalLightModule.attr("DirectionalLightAmbientG") = DirectionalLight->Ambient.g; - DirectionalLightModule.attr("DirectionalLightAmbientB") = DirectionalLight->Ambient.b; + DirectionalLightModule.attr("DirectionalLightColorR") = DirectionalLight->Color.r; + DirectionalLightModule.attr("DirectionalLightColorG") = DirectionalLight->Color.g; + DirectionalLightModule.attr("DirectionalLightColorB") = DirectionalLight->Color.b; // Get Local Dict @@ -426,9 +386,7 @@ bool ERS_CLASS_PythonInterpreterIntegration::ExecuteDirectionalLightScript(std:: // Write Back DirectionalLight Data double DirectionalLightPosX, DirectionalLightPosY, DirectionalLightPosZ; double DirectionalLightRotX, DirectionalLightRotY, DirectionalLightRotZ; - float DiffuseR, DiffuseG, DiffuseB; - float SpecularR, SpecularG, SpecularB; - float AmbientR, AmbientG, AmbientB; + float ColorR, ColorG, ColorB; try { DirectionalLightPosX = DirectionalLightModule.attr("DirectionalLightPosX").cast(); @@ -449,31 +407,14 @@ bool ERS_CLASS_PythonInterpreterIntegration::ExecuteDirectionalLightScript(std:: } try { - DiffuseR = DirectionalLightModule.attr("DirectionalLightDiffuseR").cast(); - DiffuseG = DirectionalLightModule.attr("DirectionalLightDiffuseG").cast(); - DiffuseB = DirectionalLightModule.attr("DirectionalLightDiffuseB").cast(); - DirectionalLight->Diffuse = glm::vec3(DiffuseR, DiffuseG, DiffuseB); + ColorR = DirectionalLightModule.attr("DirectionalLightColorR").cast(); + ColorG = DirectionalLightModule.attr("DirectionalLightColorG").cast(); + ColorB = DirectionalLightModule.attr("DirectionalLightColorB").cast(); + DirectionalLight->Color = glm::vec3(ColorR, ColorG, ColorB); } catch (pybind11::cast_error const&) { - ErrorMessageString->push_back("DirectionalLight Diffuse CAST_ERROR"); + ErrorMessageString->push_back("DirectionalLight Color CAST_ERROR"); } - try { - SpecularR = DirectionalLightModule.attr("DirectionalLightSpecularR").cast(); - SpecularG = DirectionalLightModule.attr("DirectionalLightSpecularG").cast(); - SpecularB = DirectionalLightModule.attr("DirectionalLightSpecularB").cast(); - DirectionalLight->Specular = glm::vec3(SpecularR, SpecularG, SpecularB); - } catch (pybind11::cast_error const&) { - ErrorMessageString->push_back("DirectionalLight Specular CAST_ERROR"); - } - - try { - AmbientR = DirectionalLightModule.attr("DirectionalLightAmbientR").cast(); - AmbientG = DirectionalLightModule.attr("DirectionalLightAmbientG").cast(); - AmbientB = DirectionalLightModule.attr("DirectionalLightAmbientB").cast(); - DirectionalLight->Ambient = glm::vec3(AmbientR, AmbientG, AmbientB); - } catch (pybind11::cast_error const&) { - ErrorMessageString->push_back("DirectionalLight Ambient CAST_ERROR"); - } // Return Status return true; @@ -497,21 +438,11 @@ bool ERS_CLASS_PythonInterpreterIntegration::ExecuteSpotLightScript(std::string SpotLightModule.attr("SpotLightRotY") = SpotLight->Rot.y; SpotLightModule.attr("SpotLightRotZ") = SpotLight->Rot.z; - SpotLightModule.attr("SpotLightDiffuseR") = SpotLight->Diffuse.r; - SpotLightModule.attr("SpotLightDiffuseG") = SpotLight->Diffuse.g; - SpotLightModule.attr("SpotLightDiffuseB") = SpotLight->Diffuse.b; + SpotLightModule.attr("SpotLightColorR") = SpotLight->Color.r; + SpotLightModule.attr("SpotLightColorG") = SpotLight->Color.g; + SpotLightModule.attr("SpotLightColorB") = SpotLight->Color.b; - SpotLightModule.attr("SpotLightSpecularR") = SpotLight->Specular.r; - SpotLightModule.attr("SpotLightSpecularG") = SpotLight->Specular.g; - SpotLightModule.attr("SpotLightSpecularB") = SpotLight->Specular.b; - - SpotLightModule.attr("SpotLightAmbientR") = SpotLight->Ambient.r; - SpotLightModule.attr("SpotLightAmbientG") = SpotLight->Ambient.g; - SpotLightModule.attr("SpotLightAmbientB") = SpotLight->Ambient.b; - - SpotLightModule.attr("SpotLightRolloffConstant") = SpotLight->RolloffConstant; - SpotLightModule.attr("SpotLightRolloffLinear") = SpotLight->RolloffLinear; - SpotLightModule.attr("SpotLightRolloffQuadratic") = SpotLight->RolloffQuadratic; + SpotLightModule.attr("SpotLightIntensity") = SpotLight->Intensity; SpotLightModule.attr("SpotLightCutoff") = SpotLight->CutOff; SpotLightModule.attr("SpotLightOuterCutoff") = SpotLight->OuterCutOff; @@ -586,9 +517,7 @@ bool ERS_CLASS_PythonInterpreterIntegration::ExecuteSpotLightScript(std::string // Write Back SpotLight Data double SpotLightPosX, SpotLightPosY, SpotLightPosZ; double SpotLightRotX, SpotLightRotY, SpotLightRotZ; - float DiffuseR, DiffuseG, DiffuseB; - float SpecularR, SpecularG, SpecularB; - float AmbientR, AmbientG, AmbientB; + float ColorR, ColorG, ColorB; try { SpotLightPosX = SpotLightModule.attr("SpotLightPosX").cast(); @@ -609,38 +538,18 @@ bool ERS_CLASS_PythonInterpreterIntegration::ExecuteSpotLightScript(std::string } try { - DiffuseR = SpotLightModule.attr("SpotLightDiffuseR").cast(); - DiffuseG = SpotLightModule.attr("SpotLightDiffuseG").cast(); - DiffuseB = SpotLightModule.attr("SpotLightDiffuseB").cast(); - SpotLight->Diffuse = glm::vec3(DiffuseR, DiffuseG, DiffuseB); - } catch (pybind11::cast_error const&) { - ErrorMessageString->push_back("SpotLight Diffuse CAST_ERROR"); - } - - try { - SpecularR = SpotLightModule.attr("SpotLightSpecularR").cast(); - SpecularG = SpotLightModule.attr("SpotLightSpecularG").cast(); - SpecularB = SpotLightModule.attr("SpotLightSpecularB").cast(); - SpotLight->Specular = glm::vec3(SpecularR, SpecularG, SpecularB); - } catch (pybind11::cast_error const&) { - ErrorMessageString->push_back("SpotLight Specular CAST_ERROR"); - } - - try { - AmbientR = SpotLightModule.attr("SpotLightAmbientR").cast(); - AmbientG = SpotLightModule.attr("SpotLightAmbientG").cast(); - AmbientB = SpotLightModule.attr("SpotLightAmbientB").cast(); - SpotLight->Ambient = glm::vec3(AmbientR, AmbientG, AmbientB); + ColorR = SpotLightModule.attr("SpotLightColorR").cast(); + ColorG = SpotLightModule.attr("SpotLightColorG").cast(); + ColorB = SpotLightModule.attr("SpotLightColorB").cast(); + SpotLight->Color = glm::vec3(ColorR, ColorG, ColorB); } catch (pybind11::cast_error const&) { - ErrorMessageString->push_back("SpotLight Ambient CAST_ERROR"); + ErrorMessageString->push_back("SpotLight Color CAST_ERROR"); } try { - SpotLight->RolloffConstant = SpotLightModule.attr("SpotLightRolloffConstant").cast(); - SpotLight->RolloffLinear = SpotLightModule.attr("SpotLightRolloffLinear").cast(); - SpotLight->RolloffQuadratic = SpotLightModule.attr("SpotLightRolloffQuadratic").cast(); + SpotLight->Intensity = SpotLightModule.attr("SpotLightIntensity").cast(); } catch (pybind11::cast_error const&) { - ErrorMessageString->push_back("SpotLight Rolloff CAST_ERROR"); + ErrorMessageString->push_back("SpotLight Intensity CAST_ERROR"); } diff --git a/Source/Core/Structures/ERS_STRUCT_Light/ERS_STRUCT_DirectionalLight.h b/Source/Core/Structures/ERS_STRUCT_Light/ERS_STRUCT_DirectionalLight.h index c694373b2b..d9af5971d4 100644 --- a/Source/Core/Structures/ERS_STRUCT_Light/ERS_STRUCT_DirectionalLight.h +++ b/Source/Core/Structures/ERS_STRUCT_Light/ERS_STRUCT_DirectionalLight.h @@ -20,9 +20,7 @@ struct ERS_STRUCT_DirectionalLight { std::vector AttachedScriptIndexes_; /** AttachedScriptIndexes_; /** AttachedScriptIndexes_; /**DirectionalLights[i]->Ambient[0]; - Output << YAML::Key << "AmbientGreen" << YAML::Value << InputScene->DirectionalLights[i]->Ambient[1]; - Output << YAML::Key << "AmbientBlue" << YAML::Value << InputScene->DirectionalLights[i]->Ambient[2]; - - Output << YAML::Key << "DiffuseRed" << YAML::Value << InputScene->DirectionalLights[i]->Diffuse[0]; - Output << YAML::Key << "DiffuseGreen" << YAML::Value << InputScene->DirectionalLights[i]->Diffuse[1]; - Output << YAML::Key << "DiffuseBlue" << YAML::Value << InputScene->DirectionalLights[i]->Diffuse[2]; - - Output << YAML::Key << "SpecularRed" << YAML::Value << InputScene->DirectionalLights[i]->Specular[0]; - Output << YAML::Key << "SpecularGreen" << YAML::Value << InputScene->DirectionalLights[i]->Specular[1]; - Output << YAML::Key << "SpecularBlue" << YAML::Value << InputScene->DirectionalLights[i]->Specular[2]; - + Output << YAML::Key << "ColorRed" << YAML::Value << InputScene->DirectionalLights[i]->Color[0]; + Output << YAML::Key << "ColorGreen" << YAML::Value << InputScene->DirectionalLights[i]->Color[1]; + Output << YAML::Key << "ColorBlue" << YAML::Value << InputScene->DirectionalLights[i]->Color[2]; Output << YAML::Key << "PosX" << YAML::Value << InputScene->DirectionalLights[i]->Pos[0]; Output << YAML::Key << "PosY" << YAML::Value << InputScene->DirectionalLights[i]->Pos[1]; @@ -152,17 +143,10 @@ std::string SceneWriter::ProcessScene(ERS_STRUCT_Scene* InputScene) { Output << YAML::Key << "AssetType" << YAML::Value << "PointLight"; - Output << YAML::Key << "AmbientRed" << YAML::Value << InputScene->PointLights[i]->Ambient[0]; - Output << YAML::Key << "AmbientGreen" << YAML::Value << InputScene->PointLights[i]->Ambient[1]; - Output << YAML::Key << "AmbientBlue" << YAML::Value << InputScene->PointLights[i]->Ambient[2]; - - Output << YAML::Key << "DiffuseRed" << YAML::Value << InputScene->PointLights[i]->Diffuse[0]; - Output << YAML::Key << "DiffuseGreen" << YAML::Value << InputScene->PointLights[i]->Diffuse[1]; - Output << YAML::Key << "DiffuseBlue" << YAML::Value << InputScene->PointLights[i]->Diffuse[2]; + Output << YAML::Key << "ColorRed" << YAML::Value << InputScene->PointLights[i]->Color[0]; + Output << YAML::Key << "ColorGreen" << YAML::Value << InputScene->PointLights[i]->Color[1]; + Output << YAML::Key << "ColorBlue" << YAML::Value << InputScene->PointLights[i]->Color[2]; - Output << YAML::Key << "SpecularRed" << YAML::Value << InputScene->PointLights[i]->Specular[0]; - Output << YAML::Key << "SpecularGreen" << YAML::Value << InputScene->PointLights[i]->Specular[1]; - Output << YAML::Key << "SpecularBlue" << YAML::Value << InputScene->PointLights[i]->Specular[2]; Output << YAML::Key << "PosX" << YAML::Value << InputScene->PointLights[i]->Pos[0]; @@ -170,9 +154,7 @@ std::string SceneWriter::ProcessScene(ERS_STRUCT_Scene* InputScene) { Output << YAML::Key << "PosZ" << YAML::Value << InputScene->PointLights[i]->Pos[2]; - Output << YAML::Key << "RolloffConstant" << YAML::Value << InputScene->PointLights[i]->RolloffConstant; - Output << YAML::Key << "RolloffLinear" << YAML::Value << InputScene->PointLights[i]->RolloffLinear; - Output << YAML::Key << "RolloffQuadratic" << YAML::Value << InputScene->PointLights[i]->RolloffQuadratic; + Output << YAML::Key << "Intensity" << YAML::Value << InputScene->PointLights[i]->Intensity; Output<SpotLights[i]->Ambient[0]; - Output << YAML::Key << "AmbientGreen" << YAML::Value << InputScene->SpotLights[i]->Ambient[1]; - Output << YAML::Key << "AmbientBlue" << YAML::Value << InputScene->SpotLights[i]->Ambient[2]; - - Output << YAML::Key << "DiffuseRed" << YAML::Value << InputScene->SpotLights[i]->Diffuse[0]; - Output << YAML::Key << "DiffuseGreen" << YAML::Value << InputScene->SpotLights[i]->Diffuse[1]; - Output << YAML::Key << "DiffuseBlue" << YAML::Value << InputScene->SpotLights[i]->Diffuse[2]; - - Output << YAML::Key << "SpecularRed" << YAML::Value << InputScene->SpotLights[i]->Specular[0]; - Output << YAML::Key << "SpecularGreen" << YAML::Value << InputScene->SpotLights[i]->Specular[1]; - Output << YAML::Key << "SpecularBlue" << YAML::Value << InputScene->SpotLights[i]->Specular[2]; + Output << YAML::Key << "ColorRed" << YAML::Value << InputScene->SpotLights[i]->Color[0]; + Output << YAML::Key << "ColorGreen" << YAML::Value << InputScene->SpotLights[i]->Color[1]; + Output << YAML::Key << "ColorBlue" << YAML::Value << InputScene->SpotLights[i]->Color[2]; Output << YAML::Key << "PosX" << YAML::Value << InputScene->SpotLights[i]->Pos[0]; @@ -220,9 +194,7 @@ std::string SceneWriter::ProcessScene(ERS_STRUCT_Scene* InputScene) { Output << YAML::Key << "RotZ" << YAML::Value << InputScene->SpotLights[i]->Rot[2]; - Output << YAML::Key << "RolloffConstant" << YAML::Value << InputScene->SpotLights[i]->RolloffConstant; - Output << YAML::Key << "RolloffLinear" << YAML::Value << InputScene->SpotLights[i]->RolloffLinear; - Output << YAML::Key << "RolloffQuadratic" << YAML::Value << InputScene->SpotLights[i]->RolloffQuadratic; + Output << YAML::Key << "Intensity" << YAML::Value << InputScene->SpotLights[i]->Intensity; Output << YAML::Key << "CutOff" << YAML::Value << InputScene->SpotLights[i]->CutOff; Output << YAML::Key << "OuterCutOff" << YAML::Value << InputScene->SpotLights[i]->OuterCutOff; diff --git a/Source/EditorAssets/Projects/DefaultProject/1.ERS b/Source/EditorAssets/Projects/DefaultProject/1.ERS index 1e3b9823c3..9e41bc3490 100644 --- a/Source/EditorAssets/Projects/DefaultProject/1.ERS +++ b/Source/EditorAssets/Projects/DefaultProject/1.ERS @@ -88,9 +88,9 @@ ShaderPrograms: FragmentID: 10035 18: Name: Viewport - VertexID: 10036 - FragmentID: 10037 + VertexID: 10040 + FragmentID: 10041 19: - Name: LightIcon + Name: _LightIcon VertexID: 10038 - FragmentID: 10039 \ No newline at end of file + FragmentID: 10039 diff --git a/Source/EditorAssets/Projects/DefaultProject/10037.ERS b/Source/EditorAssets/Projects/DefaultProject/10037.ERS deleted file mode 100644 index f42b78fccd..0000000000 --- a/Source/EditorAssets/Projects/DefaultProject/10037.ERS +++ /dev/null @@ -1,367 +0,0 @@ -#version 330 core - -// Set Outputs -out vec4 FragColor; - -// Set Inputs -in VS_OUT { - vec3 FragPos; - vec2 TexCoords; - mat3 TBN; - vec3 TangentViewPos; - vec3 TangentFragPos; - vec3 Normal; // Used when normal texture not present -} Object; - - - - -// Define Structs -struct STRUCT_DirectionalLight { - - vec3 Direction; - - // Light Color Parameters - vec3 Ambient; - vec3 Diffuse; - vec3 Specular; - -}; - -struct STRUCT_PointLight { - - // Physical Parameters - vec3 Position; - - // Light Color Parameters - vec3 Ambient; - vec3 Diffuse; - vec3 Specular; - - // Light Rolloff Parameters - float ConstantRolloff; - float LinearRolloff; - float QuadraticRolloff; - -}; - -struct STRUCT_SpotLight { - - // Physical Parameters - vec3 Position; - vec3 Direction; - - // Light Color Parameters - vec3 Ambient; - vec3 Diffuse; - vec3 Specular; - - // Light Rolloff Parameters - float ConstantRolloff; - float LinearRolloff; - float QuadraticRolloff; - - // Spotlight Parameters - float CutOff; - float OuterCutOff; - -}; - -struct STRUCT_SampledData { - - vec4 DiffuseTextureColor; - vec4 SpecularTextureColor; - vec4 NormalTextureColor; - vec4 HeightTextureColor; - vec4 EmissiveTextureColor; - vec4 OpacityTextureColor; - -}; - - - - - -// Get Metadata Params -uniform int FrameNumber; // Number of the frame, counts up from zero - -uniform float Time; // Time since program started in seconds -uniform float FrameTime; // Render Time Of The Frame - -uniform vec2 ViewportRes; // XY Resolution of the viewport -uniform vec3 CameraPosition; // Get Camera XYZ Position - - - -// Get Texture Info -uniform sampler2D texture_diffuse1; -uniform sampler2D texture_specular1; -uniform sampler2D texture_normals1; -uniform sampler2D texture_height1; -uniform sampler2D texture_emissive1; -uniform sampler2D texture_opacity1; -uniform float Shinyness; - - -uniform bool HasAmbient; -uniform bool HasAmbientOcclusion; -uniform bool HasBaseColor; -uniform bool HasDiffuse; -uniform bool HasDiffuseRoughness; -uniform bool HasDisplacement; -uniform bool HasEmissionColor; -uniform bool HasEmissive; -uniform bool HasHeight; -uniform bool HasLightmap; -uniform bool HasMetalness; -uniform bool HasNormalCamera; -uniform bool HasNormals; -uniform bool HasOpacity; -uniform bool HasReflection; -uniform bool HasShininess; -uniform bool HasSpecular; - - -// Get Lighting Info -uniform int NumberDirectionalLights; -uniform int NumberPointLights; -uniform int NumberSpotLights; -uniform STRUCT_DirectionalLight DirectionalLights[4]; -uniform STRUCT_PointLight PointLights[32]; -uniform STRUCT_SpotLight SpotLights[16]; - - -// Gamma Correction Info -uniform bool GammaCorrectionEnabled_; -uniform bool HDREnabled_; -uniform float Exposure_; -uniform float Gamma_; - - -// Declare Functions -vec4 CalculateDirectionalLight(STRUCT_DirectionalLight Light, STRUCT_SampledData SampledData, vec3 Normal, vec3 ViewDirection); -vec4 CalculatePointLight(STRUCT_PointLight Light, STRUCT_SampledData SampledData, vec3 Normal, vec3 FragPos, vec3 ViewDirection); -vec4 CalculateSpotLight(STRUCT_SpotLight Light, STRUCT_SampledData SampledData, vec3 Normal, vec3 FragPos, vec3 ViewDirection); - -vec4 GammaCorrectResult(vec4 Input, bool GammaEnabled); -vec4 GammaCorrectTexture(sampler2D Texture, bool GammaEnabled); - -STRUCT_SampledData SetSampledData(); - -void main() -{ - - // Lighting Sanity Check - if ((NumberDirectionalLights == 0) && (NumberPointLights == 0) && (NumberSpotLights == 0)) { - FragColor = vec4(0.8f); - return; - } - - // ---- Extract Texture Vectors, Create SampledData Struct ---- // - STRUCT_SampledData SampledData = SetSampledData(); - - vec3 Norm; - vec3 ViewDirection; - if (HasNormals) { - Norm = texture(texture_normals1, Object.TexCoords).rgb; - Norm = normalize(Norm * 2.0f - 1.0f); - ViewDirection = normalize(Object.TangentViewPos - Object.TangentFragPos); - } else { - Norm = normalize(Object.Normal); - ViewDirection = normalize(CameraPosition - Object.FragPos); - } - - - // ---- Calculate Lighting Contributions ---- // - vec4 Result = vec4(0.0f); - - // Calculate Directional Lights - for (int i = 0; i < NumberDirectionalLights; i++) { - Result += CalculateDirectionalLight(DirectionalLights[i], SampledData, Norm, ViewDirection); - } - - // Calculate Point Lights - for (int i = 0; i < NumberPointLights; i++) { - Result += CalculatePointLight(PointLights[i], SampledData, Norm, Object.FragPos, ViewDirection); - } - - // Calculate Spot Lights - for (int i = 0; i < NumberSpotLights; i++) { - Result += CalculateSpotLight(SpotLights[i], SampledData, Norm, Object.FragPos, ViewDirection); - } - - // Add Emissive Texture - if (HasEmissive) { - Result += SampledData.EmissiveTextureColor; - } - - // Multiply By Opacity - //if (HasOpacity) { - // Result.a = SampledData.OpacityTextureColor.r; - //} - - // Apply Gamma Correction - if (HDREnabled_) { - vec3 Mapped = vec3(1.0f) - exp(-Result.xyz * Exposure_); - FragColor = GammaCorrectResult(vec4(Mapped, 1.0f), GammaCorrectionEnabled_); - } else { - FragColor = GammaCorrectResult(Result, GammaCorrectionEnabled_); - } - -} - - - -STRUCT_SampledData SetSampledData() { - STRUCT_SampledData SampledData; - - SampledData.DiffuseTextureColor = GammaCorrectTexture(texture_diffuse1, GammaCorrectionEnabled_); - - // Handle Specular Textures - if (HasSpecular) { - SampledData.SpecularTextureColor = GammaCorrectTexture(texture_specular1, GammaCorrectionEnabled_); - } else { - SampledData.SpecularTextureColor = SampledData.DiffuseTextureColor; - } - - // Handle Normal Textures - if (HasNormals) { - SampledData.NormalTextureColor = texture(texture_normals1, Object.TexCoords); - } else { - SampledData.NormalTextureColor = vec4(0.0f); - } - - - SampledData.HeightTextureColor = texture(texture_height1, Object.TexCoords); - - // Handle Emissive Textures - if (HasEmissive) { - SampledData.EmissiveTextureColor = GammaCorrectTexture(texture_emissive1, GammaCorrectionEnabled_); - } else { - SampledData.EmissiveTextureColor = vec4(0.0f); - } - - // Handle Opacity Textures - if (HasEmissive) { - SampledData.OpacityTextureColor = texture(texture_opacity1, Object.TexCoords); - } else { - SampledData.OpacityTextureColor = vec4(0.0f); - } - - return SampledData; - -} - - -// Used To Enable Gamma Correction On The Output -vec4 GammaCorrectResult(vec4 Input, bool GammaEnabled) { - if (GammaEnabled) { - Input.rgb = pow(Input.rgb, vec3(1.0/Gamma_)); - } - return Input; -} - - -// Used To Make Sure Textures Aren't Too Bright -vec4 GammaCorrectTexture(sampler2D Texture, bool GammaEnabled) { - vec4 Color = texture(Texture, Object.TexCoords); - if (GammaEnabled) { - Color.rgb = pow(Color.rgb, vec3(Gamma_)); - } - return Color; -} - - -vec4 CalculateDirectionalLight(STRUCT_DirectionalLight Light, STRUCT_SampledData SampledData, vec3 Normal, vec3 ViewDirection) { - - vec3 LightDirectionVector = normalize(-Light.Direction); - vec3 ReflectionDirectionVector = reflect(-LightDirectionVector, Normal); - - // Diffuse/Specular Components - float Diffuse = max(dot(Normal, LightDirectionVector), 0.0f); - float Specular = pow(max(dot(ViewDirection, ReflectionDirectionVector), 0.0f), Shinyness); - - // Calculate Total Contribution From Components - vec4 AmbientComponent = vec4(Light.Ambient, 1.0f) * SampledData.DiffuseTextureColor; - vec4 DiffuseComponent = vec4(Light.Diffuse, 1.0f) * Diffuse * SampledData.DiffuseTextureColor; - vec4 SpecularComponent = vec4(Light.Specular, 1.0f) * Specular * SampledData.SpecularTextureColor; - - return (AmbientComponent + DiffuseComponent + SpecularComponent); - -} - -vec4 CalculatePointLight(STRUCT_PointLight Light, STRUCT_SampledData SampledData, vec3 Normal, vec3 FragPos, vec3 ViewDirection) { - - vec3 LightDirectionVector ; - if (HasNormals) { - LightDirectionVector = normalize(Object.TBN * Light.Position - Object.TangentFragPos); - } else { - LightDirectionVector = normalize(Light.Position - FragPos); - } - - vec3 ReflectionDirectionVector = reflect(-LightDirectionVector, Normal); - - // Diffuse/Specular Components - float Diffuse = max(dot(Normal, LightDirectionVector), 0.0f); - float Specular = pow(max(dot(ViewDirection, ReflectionDirectionVector), 0.0f), Shinyness); - - // Attenuate - float Distance = length(Light.Position - FragPos); - float Attenuation = 1.0f / (Light.ConstantRolloff + Light.LinearRolloff * Distance + Light.QuadraticRolloff * (Distance * Diffuse)); - - // Calculate Total Contribution From Components - vec4 AmbientComponent = vec4(Light.Ambient * Attenuation, 1.0f) * SampledData.DiffuseTextureColor; - vec4 DiffuseComponent = vec4(Light.Diffuse * Attenuation, 1.0f) * Diffuse * SampledData.DiffuseTextureColor; - vec4 SpecularComponent = vec4(Light.Specular * Attenuation, 1.0f) * Specular * SampledData.SpecularTextureColor; - - return (AmbientComponent + DiffuseComponent + SpecularComponent); - -} - -vec4 CalculateSpotLight(STRUCT_SpotLight Light, STRUCT_SampledData SampledData, vec3 Normal, vec3 FragPos, vec3 ViewDirection) { - - vec3 LightDirectionVector ; - if (HasNormals) { - LightDirectionVector = normalize(Object.TBN * Light.Position - Object.TangentFragPos); - } else { - LightDirectionVector = normalize(Light.Position - FragPos); - } - vec3 ReflectionDirectionVector = reflect(-LightDirectionVector, Normal); - - // Diffuse/Specular Components - float Diffuse = max(dot(Normal, LightDirectionVector), 0.0f); - float Specular = pow(max(dot(ViewDirection, ReflectionDirectionVector), 0.0f), Shinyness); - - // Calculate Attenuation - float Distance = length(Light.Position - FragPos); - float Attenuation = 1.0f / (Light.ConstantRolloff + Light.LinearRolloff * Distance + Light.QuadraticRolloff * (Distance * Diffuse)); - - // Calculate Spot Intensity - float Theta = dot(normalize(Light.Position - FragPos), normalize(-Light.Direction)); - float Epsilon = Light.CutOff - Light.OuterCutOff; - float Intensity = clamp((Theta - Light.OuterCutOff) / Epsilon, 0.0f, 1.0f); - - // Calculate Total Contribution From Components - vec4 AmbientComponent = vec4(Light.Ambient * Attenuation * Intensity, 1.0f) * SampledData.DiffuseTextureColor; - vec4 DiffuseComponent = vec4(Light.Diffuse * Attenuation * Intensity, 1.0f) * Diffuse * SampledData.DiffuseTextureColor; - vec4 SpecularComponent = vec4(Light.Specular * Attenuation * Intensity, 1.0f) * Specular * SampledData.SpecularTextureColor; - - return (AmbientComponent + DiffuseComponent + SpecularComponent); - -} - - - - - - - - - - - - - - - - diff --git a/Source/EditorAssets/Projects/DefaultProject/10036.ERS b/Source/EditorAssets/Projects/DefaultProject/10040.ERS similarity index 85% rename from Source/EditorAssets/Projects/DefaultProject/10036.ERS rename to Source/EditorAssets/Projects/DefaultProject/10040.ERS index 23f73d8983..c6c73c6983 100644 --- a/Source/EditorAssets/Projects/DefaultProject/10036.ERS +++ b/Source/EditorAssets/Projects/DefaultProject/10040.ERS @@ -12,6 +12,7 @@ out VS_OUT { vec3 FragPos; vec2 TexCoords; mat3 TBN; + vec3 WorldPos; vec3 TangentViewPos; vec3 TangentFragPos; vec3 Normal; // Used when no normal map is available; @@ -51,9 +52,10 @@ void main() Object.TBN = TBN; Object.TangentViewPos = TBN * CameraPosition; Object.TangentFragPos = TBN * Object.FragPos; - Object.Normal = mat3(transpose(inverse(model))) * aNormal; + Object.Normal = mat3(model) * aNormal; // mat3(transpose(inverse(model))) * aNormal; + Object.WorldPos = vec3(model*vec4(aPos, 1.0f)); - gl_Position = projection * view * model * vec4(aPos, 1.0f); + gl_Position = projection * view * vec4(Object.WorldPos, 1.0f); } @@ -73,4 +75,7 @@ void main() + + + diff --git a/Source/EditorAssets/Projects/DefaultProject/10041.ERS b/Source/EditorAssets/Projects/DefaultProject/10041.ERS new file mode 100644 index 0000000000..61480dbe53 --- /dev/null +++ b/Source/EditorAssets/Projects/DefaultProject/10041.ERS @@ -0,0 +1,482 @@ +#version 330 core + +// Set Outputs +out vec4 FragColor; + +// Set Inputs +in VS_OUT { + vec3 FragPos; + vec2 TexCoords; + mat3 TBN; + vec3 WorldPos; + vec3 TangentViewPos; + vec3 TangentFragPos; + vec3 Normal; // Used when normal texture not present +} Object; + + + + +// Define Structs +struct STRUCT_DirectionalLight { + + vec3 Direction; + + // Light Color Parameters + vec3 Ambient; + vec3 Diffuse; + vec3 Specular; + +}; + +struct STRUCT_PointLight { + + // Physical Parameters + vec3 Position; + + // Light Color Parameters + vec3 Color; + + // Light Rolloff Parameters + float Intensity; +}; + +struct STRUCT_SpotLight { + + // Physical Parameters + vec3 Position; + vec3 Direction; + + // Light Color Parameters + vec3 Color; + + // Light Rolloff Parameters + float Intensity; + + // Spotlight Parameters + float CutOff; + float OuterCutOff; + +}; + +struct STRUCT_SampledData { + + vec4 Albedo; + vec3 Normal; + vec3 Emissive; + float Metallic; + float Roughness; + float AO; + +}; + + + + + +// Get Metadata Params +uniform int FrameNumber; // Number of the frame, counts up from zero + +uniform float Time; // Time since program started in seconds +uniform float FrameTime; // Render Time Of The Frame + +uniform vec2 ViewportRes; // XY Resolution of the viewport +uniform vec3 CameraPosition; // Get Camera XYZ Position + + + +// Get Texture Info +uniform sampler2D texture_diffuse1; +uniform sampler2D texture_normals1; +uniform sampler2D texture_shininess1; +uniform sampler2D texture_emissive1; +uniform sampler2D texture_metalness1; +uniform sampler2D texture_ambientocclusion1; +uniform float Shinyness; + + +uniform bool HasAmbient; +uniform bool HasAmbientOcclusion; +uniform bool HasBaseColor; +uniform bool HasDiffuse; +uniform bool HasDiffuseRoughness; +uniform bool HasDisplacement; +uniform bool HasEmissionColor; +uniform bool HasEmissive; +uniform bool HasHeight; +uniform bool HasLightmap; +uniform bool HasMetalness; +uniform bool HasNormalCamera; +uniform bool HasNormals; +uniform bool HasOpacity; +uniform bool HasReflection; +uniform bool HasShininess; +uniform bool HasSpecular; + + +// Get Lighting Info +uniform int NumberDirectionalLights; +uniform int NumberPointLights; +uniform int NumberSpotLights; +uniform STRUCT_DirectionalLight DirectionalLights[4]; +uniform STRUCT_PointLight PointLights[32]; +uniform STRUCT_SpotLight SpotLights[16]; + + +// Gamma Correction Info +uniform bool GammaCorrectionEnabled_; +uniform bool HDREnabled_; +uniform float Exposure_; +uniform float Gamma_; + +const float PI = 3.14159265358979; + +vec3 GetNormalFromMap(sampler2D Normal) { + vec3 TangentNormal = texture(Normal, Object.TexCoords).xyz * 2.0f - 1.0f; + + vec3 Q1 = dFdx(Object.WorldPos); + vec3 Q2 = dFdy(Object.WorldPos); + vec2 st1 = dFdx(Object.TexCoords); + vec2 st2 = dFdy(Object.TexCoords); + + vec3 N = normalize(Object.Normal); + vec3 T = normalize(Q1*st2.t - Q2*st1.t); + vec3 B = -normalize(cross(N, T)); + mat3 TBN = mat3(T,B,N); + + return normalize(TBN * TangentNormal); + +} + + +float DistributionGGX(vec3 N, vec3 H, float Roughness) { + + float a = Roughness*Roughness; + float a2 = a*a; + float NdotH = max(dot(N,H), 0.0f); + float NdotH2 = NdotH*NdotH; + + float nom = a2; + float denom = (NdotH2 * (a2 - 1.0f) + 1.0f); + + return nom / denom; + +} +// ---------------------------------------------------------------------------- +float GeometrySchlickGGX(float NdotV, float roughness) +{ + float r = (roughness + 1.0); + float k = (r*r) / 8.0; + + float nom = NdotV; + float denom = NdotV * (1.0 - k) + k; + + return nom / denom; +} +// ---------------------------------------------------------------------------- +float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness) +{ + float NdotV = max(dot(N, V), 0.0); + float NdotL = max(dot(N, L), 0.0); + float ggx2 = GeometrySchlickGGX(NdotV, roughness); + float ggx1 = GeometrySchlickGGX(NdotL, roughness); + + return ggx1 * ggx2; +} +// ---------------------------------------------------------------------------- +vec3 FresnelSchlick(float cosTheta, vec3 F0) +{ + return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0); +} +// ---------------------------------------------------------------------------- + + + + + + +// Used To Enable Gamma Correction On The Output +vec4 GammaCorrectResult(vec4 Input, bool GammaEnabled) { + if (GammaEnabled) { + Input.rgb = pow(Input.rgb, vec3(1.0/Gamma_)); + } + return Input; +} + + +// Used To Make Sure Textures Aren't Too Bright +vec4 GammaCorrectTexture(sampler2D Texture, bool GammaEnabled) { + vec4 Color = texture(Texture, Object.TexCoords); + if (GammaEnabled) { + Color.rgb = pow(Color.rgb, vec3(Gamma_)); + } + return Color; +} + + + +/** + +vec4 CalculateDirectionalLight(STRUCT_DirectionalLight Light, STRUCT_SampledData SampledData, vec3 Normal, vec3 ViewDirection) { + + vec3 LightDirectionVector = normalize(-Light.Direction); + vec3 ReflectionDirectionVector = reflect(-LightDirectionVector, Normal); + + // Diffuse/Specular Components + float Diffuse = max(dot(Normal, LightDirectionVector), 0.0f); + float Specular = pow(max(dot(ViewDirection, ReflectionDirectionVector), 0.0f), Shinyness); + + // Calculate Total Contribution From Components + vec4 AmbientComponent = vec4(Light.Ambient, 1.0f) * SampledData.Albedo; + vec4 DiffuseComponent = vec4(Light.Diffuse, 1.0f) * Diffuse * SampledData.Albedo; + vec4 SpecularComponent = vec4(Light.Specular, 1.0f) * Specular * SampledData.Albedo; + + return (AmbientComponent + DiffuseComponent + SpecularComponent); + +} + +vec4 CalculatePointLight(STRUCT_PointLight Light, STRUCT_SampledData SampledData, vec3 Normal, vec3 FragPos, vec3 ViewDirection) { + + vec3 LightDirectionVector ; + if (HasNormals) { + LightDirectionVector = normalize(Object.TBN * Light.Position - Object.TangentFragPos); + } else { + LightDirectionVector = normalize(Light.Position - FragPos); + } + + vec3 ReflectionDirectionVector = reflect(-LightDirectionVector, Normal); + + // Diffuse/Specular Components + float Diffuse = max(dot(Normal, LightDirectionVector), 0.0f); + float Specular = pow(max(dot(ViewDirection, ReflectionDirectionVector), 0.0f), Shinyness); + + // Attenuate + float Distance = length(Light.Position - FragPos); + float Attenuation = 1.0f / (Light.ConstantRolloff + Light.LinearRolloff * Distance + Light.QuadraticRolloff * (Distance * Diffuse)); + + // Calculate Total Contribution From Components + vec4 AmbientComponent = vec4(Light.Ambient * Attenuation, 1.0f) * SampledData.Albedo; + vec4 DiffuseComponent = vec4(Light.Diffuse * Attenuation, 1.0f) * Diffuse * SampledData.Albedo; + vec4 SpecularComponent = vec4(Light.Specular * Attenuation, 1.0f) * Specular * SampledData.Albedo; + + return (AmbientComponent + DiffuseComponent + SpecularComponent); + +} + +vec4 CalculateSpotLight(STRUCT_SpotLight Light, STRUCT_SampledData SampledData, vec3 Normal, vec3 FragPos, vec3 ViewDirection ) { + + vec3 LightDirectionVector ; + if (HasNormals) { + LightDirectionVector = normalize(Object.TBN * Light.Position - Object.TangentFragPos); + } else { + LightDirectionVector = normalize(Light.Position - FragPos); + } + vec3 ReflectionDirectionVector = reflect(-LightDirectionVector, Normal); + + // Diffuse/Specular Components + float Diffuse = max(dot(Normal, LightDirectionVector), 0.0f); + float Specular = pow(max(dot(ViewDirection, ReflectionDirectionVector), 0.0f), Shinyness); + + // Calculate Attenuation + float Distance = length(Light.Position - FragPos); + float Attenuation = 1.0f / (Light.ConstantRolloff + Light.LinearRolloff * Distance + Light.QuadraticRolloff * (Distance * Diffuse)); + + // Calculate Spot Intensity + float Theta = dot(normalize(Light.Position - FragPos), normalize(-Light.Direction)); + float Epsilon = Light.CutOff - Light.OuterCutOff; + float Intensity = clamp((Theta - Light.OuterCutOff) / Epsilon, 0.0f, 1.0f); + + // Calculate Total Contribution From Components + vec4 AmbientComponent = vec4(Light.Ambient * Attenuation * Intensity, 1.0f) * SampledData.Albedo; + vec4 DiffuseComponent = vec4(Light.Diffuse * Attenuation * Intensity, 1.0f) * Diffuse * SampledData.Albedo; + vec4 SpecularComponent = vec4(Light.Specular * Attenuation * Intensity, 1.0f) * Specular * SampledData.Albedo; + + return (AmbientComponent + DiffuseComponent + SpecularComponent); + +} + + +**/ + +STRUCT_SampledData SetSampledData() { + STRUCT_SampledData SampledData; + + // Handle Albedo/Diffuse Textures + SampledData.Albedo = GammaCorrectTexture(texture_diffuse1, GammaCorrectionEnabled_); + + // Handle Metalness Textures + if (HasMetalness) { + SampledData.Metallic = texture2D(texture_metalness1, Object.TexCoords).r; + } else { + SampledData.Metallic = 0.0f; + } + + // Handle Normal Textures + if (HasNormals) { + SampledData.Normal = GetNormalFromMap(texture_normals1); + } else { + SampledData.Normal = vec3(0.5f, 0.5f, 1.0f); + } + + // Handle Shininess (Inverse Of Roughness) + if (HasShininess) { + SampledData.Roughness = 1.0f - texture2D(texture_shininess1, Object.TexCoords).r; + } else { + SampledData.Roughness = 0.5f; + } + + // Handle Emissive Textures + if (HasEmissive) { + SampledData.Emissive = GammaCorrectTexture(texture_emissive1, GammaCorrectionEnabled_).rgb; + } else { + SampledData.Emissive = vec3(0.0f); + } + + + return SampledData; + +} + + + +vec3 PBRPointLight(STRUCT_PointLight Light, vec3 ViewDir, vec3 Reflectance, STRUCT_SampledData Model) { + + // calculate per-light radiance + vec3 L = normalize(Light.Position - Object.WorldPos); + vec3 H = normalize(ViewDir + L); + float distance = length(Light.Position - Object.WorldPos); + float attenuation = 1.0 / (distance * distance); + vec3 radiance = Light.Color * Light.Intensity * attenuation; + + // Cook-Torrance BRDF + float NDF = DistributionGGX(Model.Normal, H, Model.Roughness); + float G = GeometrySmith(Model.Normal, ViewDir, L, Model.Roughness); + vec3 F = FresnelSchlick(max(dot(H, ViewDir), 0.0), Reflectance); + + vec3 numerator = NDF * G * F; + float denominator = 4.0 * max(dot(Model.Normal, ViewDir), 0.0) * max(dot(Model.Normal, L), 0.0) + 0.0001; // + 0.0001 to prevent divide by zero + vec3 specular = numerator / denominator; + + // kS is equal to Fresnel + vec3 kS = F; + // for energy conservation, the diffuse and specular light can't + // be above 1.0 (unless the surface emits light); to preserve this + // relationship the diffuse component (kD) should equal 1.0 - kS. + vec3 kD = vec3(1.0) - kS; + // multiply kD by the inverse metalness such that only non-metals + // have diffuse lighting, or a linear blend if partly metal (pure metals + // have no diffuse light). + kD *= 1.0 - Model.Metallic; + + // scale light by NdotL + float NdotL = max(dot(Model.Normal, L), 0.0); + + // add to outgoing radiance Lo + return (kD * Model.Albedo.rgb / PI + specular) * radiance * NdotL; // note that we already multiplied the BRDF by the Fresnel (kS) so we won't multiply by kS again + + +} + + +vec3 PBRSpotLight(STRUCT_SpotLight Light, vec3 ViewDir, vec3 Reflectance, STRUCT_SampledData Model) { + + vec3 LightDirectionVector ; + if (HasNormals) { + LightDirectionVector = normalize(Object.TBN * Light.Position - Object.TangentFragPos); + } else { + LightDirectionVector = normalize(Light.Position - Object.FragPos); + } + vec3 ReflectionDirectionVector = reflect(-LightDirectionVector, Object.Normal); + + // Calculate Spot Intensity + float Theta = dot(normalize(Light.Position - Object.FragPos), normalize(-Light.Direction)); + float Epsilon = Light.CutOff - Light.OuterCutOff; + float Intensity = clamp((Theta - Light.OuterCutOff) / Epsilon, 0.0f, 1.0f); + + + // calculate per-light radiance + vec3 L = normalize(Light.Position - Object.WorldPos); + vec3 H = normalize(ViewDir + L); + float distance = length(Light.Position - Object.WorldPos); + float attenuation = 1.0 / (distance * distance); + vec3 radiance = Light.Color * Light.Intensity * attenuation; + + // Cook-Torrance BRDF + float NDF = DistributionGGX(Model.Normal, H, Model.Roughness); + float G = GeometrySmith(Model.Normal, ViewDir, L, Model.Roughness); + vec3 F = FresnelSchlick(max(dot(H, ViewDir), 0.0), Reflectance); + + vec3 numerator = NDF * G * F; + float denominator = 4.0 * max(dot(Model.Normal, ViewDir), 0.0) * max(dot(Model.Normal, L), 0.0) + 0.0001; // + 0.0001 to prevent divide by zero + vec3 specular = numerator / denominator; + + // kS is equal to Fresnel + vec3 kS = F; + // for energy conservation, the diffuse and specular light can't + // be above 1.0 (unless the surface emits light); to preserve this + // relationship the diffuse component (kD) should equal 1.0 - kS. + vec3 kD = vec3(1.0) - kS; + // multiply kD by the inverse metalness such that only non-metals + // have diffuse lighting, or a linear blend if partly metal (pure metals + // have no diffuse light). + kD *= 1.0 - Model.Metallic; + + // scale light by NdotL + float NdotL = max(dot(Model.Normal, L), 0.0); + + // add to outgoing radiance Lo + return (kD * Model.Albedo.rgb / PI + specular) * radiance * NdotL * Intensity; // note that we already multiplied the BRDF by the Fresnel (kS) so we won't multiply by kS again + +} + + + + + +void main() { + + // Get Model Parameters + STRUCT_SampledData Model = SetSampledData(); + vec3 ViewDir = normalize(CameraPosition - Object.WorldPos); + + // calculate reflectance at normal incidence; if dia-electric (like plastic) use F0 + // of 0.04 and if it's a metal, use the albedo color as F0 (metallic workflow) + vec3 Reflectance = vec3(0.04); + Reflectance = mix(Reflectance, Model.Albedo.rgb, Model.Metallic); + + + // ---- Calculate Lighting Contributions ---- // + vec4 Lo = vec4(0.0f); + + // Calculate Point Lights + for (int i = 0; i < NumberPointLights; i++) { + Lo += vec4(PBRPointLight(PointLights[i], ViewDir, Reflectance, Model), 1.0f); + } + + // Calculate Spot Lights + for(int i = 0; i < NumberSpotLights; ++i) { + Lo += vec4(PBRSpotLight(SpotLights[i], ViewDir, Reflectance, Model), 1.0f); + } + + // ambient lighting (note that the next IBL tutorial will replace + // this ambient lighting with environment lighting). + vec4 Ambient = vec4(0.03) * Model.Albedo * Model.AO; + vec4 Color = Ambient + Lo; + + + // Add Emissive Texture + if (HasEmissive) { + Color.rgb += Model.Emissive; + } + + // Apply Gamma Correction + if (HDREnabled_) { + vec3 Mapped = vec3(1.0f) - exp(-Color.xyz * Exposure_); + FragColor = GammaCorrectResult(vec4(Mapped, 1.0f), GammaCorrectionEnabled_); + } else { + FragColor = GammaCorrectResult(Color, GammaCorrectionEnabled_); + } +} + + + diff --git a/Source/EditorAssets/Projects/DefaultProject/3.ERS b/Source/EditorAssets/Projects/DefaultProject/3.ERS index 4398be8fcd..9a7341b658 100644 --- a/Source/EditorAssets/Projects/DefaultProject/3.ERS +++ b/Source/EditorAssets/Projects/DefaultProject/3.ERS @@ -32,15 +32,9 @@ SceneData: 2: AssetName: Default Directional Light AssetType: DirectionalLight - AmbientRed: 0.25 - AmbientGreen: 0.25 - AmbientBlue: 0.25 - DiffuseRed: 0.25 - DiffuseGreen: 0.25 - DiffuseBlue: 0.25 - SpecularRed: 0.25 - SpecularGreen: 0.25 - SpecularBlue: 0.25 + ColorRed: 1.0 + ColorGreen: 1.0 + ColorBlue: 1.0 PosX: 0.0898500085 PosY: 1.15329742 PosZ: -0.723596871 @@ -50,41 +44,25 @@ SceneData: 3: AssetName: Default Point Light AssetType: PointLight - AmbientRed: 0.25 - AmbientGreen: 0.25 - AmbientBlue: 0.25 - DiffuseRed: 0.25 - DiffuseGreen: 0.25 - DiffuseBlue: 0.25 - SpecularRed: 0.25 - SpecularGreen: 0.25 - SpecularBlue: 0.25 + ColorRed: 1.0 + ColorGreen: 1.0 + ColorBlue: 1.0 PosX: -0.83369267 PosY: 0.582210124 PosZ: -0.533189774 - RolloffConstant: 1 - RolloffLinear: 0.0900000036 - RolloffQuadratic: 0.0320000015 + Intensity: 25 4: AssetName: Default Spot Light AssetType: SpotLight - AmbientRed: 0 - AmbientGreen: 0 - AmbientBlue: 0 - DiffuseRed: 0.25 - DiffuseGreen: 0.25 - DiffuseBlue: 1 - SpecularRed: 0.25 - SpecularGreen: 1 - SpecularBlue: 0.25 + ColorRed: 1.0 + ColorGreen: 1.0 + ColorBlue: 1.0 PosX: 0.993685424 PosY: 0.515645862 PosZ: -0.763120711 RotX: -156.130692 RotY: -44.4931717 RotZ: 141.395966 - RolloffConstant: 1 - RolloffLinear: 0.0900000036 - RolloffQuadratic: 0.0320000015 + Intensity: 25 CutOff: 0.970000029 - OuterCutOff: 0.959999979 \ No newline at end of file + OuterCutOff: 0.959999979