diff --git a/CMakeLists.txt b/CMakeLists.txt index 3daf65d0f1..edb19c165d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,6 +95,8 @@ add_subdirectory(${SRC_DIR}/Core/Structures/ERS_STRUCT_Light) add_subdirectory(${SRC_DIR}/Core/Structures/ERS_STRUCT_OpenGLDefaults) add_subdirectory(${SRC_DIR}/Core/Structures/ERS_STRUCT_SceneObject) add_subdirectory(${SRC_DIR}/Core/Structures/ERS_STRUCT_Script) +add_subdirectory(${SRC_DIR}/Core/Structures/ERS_STRUCT_DepthMap) +add_subdirectory(${SRC_DIR}/Core/Structures/ERS_STRUCT_RendererSettings) add_subdirectory(${SRC_DIR}/Core/Script/ERS_CLASS_PythonInterpreterIntegration) @@ -142,6 +144,7 @@ target_link_libraries(${PROJECT_NAME} ERS_STRUCT_HumanInputDeviceUtils ERS_STRUCT_SystemUtils ERS_STRUCT_ProjectUtils + ERS_STRUCT_RendererSettings ) diff --git a/Source/Core/Editor/MenuEntries/GUI_Menu_File/GUI_Menu_File.cpp b/Source/Core/Editor/MenuEntries/GUI_Menu_File/GUI_Menu_File.cpp index 575c398759..ca33b4b825 100644 --- a/Source/Core/Editor/MenuEntries/GUI_Menu_File/GUI_Menu_File.cpp +++ b/Source/Core/Editor/MenuEntries/GUI_Menu_File/GUI_Menu_File.cpp @@ -86,4 +86,5 @@ void GUI_Menu_File::Draw() { ShaderEditor_->Draw(); + } \ No newline at end of file diff --git a/Source/Core/Editor/Widgets/GUI_Widget_RenderingSettings.cpp b/Source/Core/Editor/Widgets/GUI_Widget_RenderingSettings.cpp index b47a00f204..4f281f06d2 100644 --- a/Source/Core/Editor/Widgets/GUI_Widget_RenderingSettings.cpp +++ b/Source/Core/Editor/Widgets/GUI_Widget_RenderingSettings.cpp @@ -9,6 +9,15 @@ Widget_RenderingSettings::Widget_RenderingSettings(ERS_STRUCT_SystemUtils* Syste SystemUtils_ = SystemUtils; SystemUtils_->Logger_->Log("Initializing Rendering Settings Widget", 5); + // Setup Default Values For Input Fields + SystemUtils_->Logger_->Log("Setting Up Default Renderer Setting Input Fields", 3); + + SystemUtils_->Logger_->Log("Copying Shadow Map Resolution", 2); + DepthMapResolution_[0] = SystemUtils_->RendererSettings_->ShadowMapX_; + DepthMapResolution_[1] = SystemUtils_->RendererSettings_->ShadowMapY_; + + + } Widget_RenderingSettings::~Widget_RenderingSettings() { @@ -89,6 +98,22 @@ void Widget_RenderingSettings::Draw() { //ImGui::Separator(); //ImGui::SliderInt("Viewport FOV", &Camera_, 1, 360) + // Handle Modifications To Renderer Settings + ImGui::Spacing(); + ImGui::Separator(); + ImGui::Spacing(); + bool Apply = false; + + + ImGui::InputInt2("Depth Map Resolution", DepthMapResolution_); + Apply = ImGui::Button("Apply"); + + if (Apply) { + SystemUtils_->RendererSettings_->ShadowMapX_ = DepthMapResolution_[0]; + SystemUtils_->RendererSettings_->ShadowMapY_ = DepthMapResolution_[1]; + } + + } diff --git a/Source/Core/Editor/Widgets/GUI_Widget_RenderingSettings.h b/Source/Core/Editor/Widgets/GUI_Widget_RenderingSettings.h index 1a1528ce84..ba3c2ea3df 100644 --- a/Source/Core/Editor/Widgets/GUI_Widget_RenderingSettings.h +++ b/Source/Core/Editor/Widgets/GUI_Widget_RenderingSettings.h @@ -32,6 +32,9 @@ class Widget_RenderingSettings { ImVec4 ClearColor_ = ImVec4(0.2f, 0.2f, 0.2f, 1.0f); /**Stores the value that the user is putting into the depth map input box*/ + public: diff --git a/Source/Core/Editor/Windows/GUI_Window_ShaderEditor/GUI_Window_ShaderEditor.cpp b/Source/Core/Editor/Windows/GUI_Window_ShaderEditor/GUI_Window_ShaderEditor.cpp index 895a1eba0b..47fba7071f 100644 --- a/Source/Core/Editor/Windows/GUI_Window_ShaderEditor/GUI_Window_ShaderEditor.cpp +++ b/Source/Core/Editor/Windows/GUI_Window_ShaderEditor/GUI_Window_ShaderEditor.cpp @@ -21,7 +21,7 @@ Window_ShaderEditor::Window_ShaderEditor(ERS_STRUCT_SystemUtils* SystemUtils, ER ShaderLoader_ = std::make_unique(SystemUtils_); - LivePreviewShader_ = std::make_shared(); + @@ -75,19 +75,19 @@ void Window_ShaderEditor::Draw() { // If Just Enabled if (Enabled_) { - LivePreviewShaderIndex_ = VisualRenderer_->Shaders_.size(); + VisualRenderer_->Shaders_.push_back(std::make_unique()); } else { // Set Any Viewports Shaders To 0 Who Are Using This Shader for (int i = 0; (long)i < (long)VisualRenderer_->Viewports_.size(); i++) { - if (VisualRenderer_->Viewports_[i]->ShaderIndex == LivePreviewShaderIndex_) { + if (VisualRenderer_->Viewports_[i]->ShaderIndex == (int)(VisualRenderer_->Shaders_.size() - 1)) { VisualRenderer_->Viewports_[i]->ShaderIndex = 0; } } // Remove Shader From List - VisualRenderer_->Shaders_.erase(LivePreviewShaderIndex_); + VisualRenderer_->Shaders_.erase(VisualRenderer_->Shaders_.begin() + VisualRenderer_->Shaders_.size() - 1); } @@ -101,7 +101,7 @@ void Window_ShaderEditor::Draw() { DrawEditorWindow(); DrawToolsWindow(); - + } @@ -257,58 +257,35 @@ void Window_ShaderEditor::DrawEditorWindow() { void Window_ShaderEditor::DrawToolsWindow() { - bool CompileVisible = ImGui::Begin("Shader Tools", &Enabled_); - - // Compile Shader Object - std::string VertexText = Editors_[0]->GetText(); - std::string FragmentText = Editors_[1]->GetText(); - - LivePreviewShader_->~ERS_STRUCT_Shader(); - LivePreviewShader_ = std::make_shared(); - std::string VertexLog = LivePreviewShader_->CompileVertexShader(VertexText.c_str()); - std::string FragmentLog = LivePreviewShader_->CompileFragmentShader(FragmentText.c_str()); - LivePreviewShader_->CreateShaderProgram(); - bool ShaderCompiled = LivePreviewShader_->MakeActive(); - LivePreviewShader_->SetInt("texture_diffuse1", 0); - LivePreviewShader_->DisplayName = "Preview Shader"; - LivePreviewShader_->InternalName = "Preview Shader"; - - - // If Autopreview, Update Shader - if (ShaderCompiled) { - VisualRenderer_->SetShader(LivePreviewShader_, LivePreviewShaderIndex_); - } - - - // Extract Shader Log - std::string ShaderLog; - if (Mode_ == 0) { - ShaderLog = VertexLog; - } else if (Mode_ == 1) { - ShaderLog = FragmentLog; - } - - if (ShaderLog == "") { - ShaderLog = "No errors detected."; - } - - - // Set Default Window Size - ImGui::SetWindowSize(ImVec2(600,400), ImGuiCond_FirstUseEver); - + bool CompileVisible = ImGui::Begin("Compiler Log", &Enabled_); + + // Compile Shader Object + std::string VertexText = Editors_[0]->GetText(); + std::string FragmentText = Editors_[1]->GetText(); + VisualRenderer_->Shaders_[VisualRenderer_->Shaders_.size() - 1]->ResetProgram(); + std::string VertexLog = VisualRenderer_->Shaders_[VisualRenderer_->Shaders_.size() - 1]->CompileVertexShader(VertexText.c_str()); + std::string FragmentLog = VisualRenderer_->Shaders_[VisualRenderer_->Shaders_.size() - 1]->CompileFragmentShader(FragmentText.c_str()); + VisualRenderer_->Shaders_[VisualRenderer_->Shaders_.size() - 1]->CreateShaderProgram(); + VisualRenderer_->Shaders_[VisualRenderer_->Shaders_.size() - 1]->DisplayName = "Preview Shader"; + VisualRenderer_->Shaders_[VisualRenderer_->Shaders_.size() - 1]->InternalName = "Preview Shader"; + + // Extract Shader Log + std::string ShaderLog; + if (Mode_ == 0) { + ShaderLog = VertexLog; + } else if (Mode_ == 1) { + ShaderLog = FragmentLog; + } + // Set Default Window Size + ImGui::SetWindowSize(ImVec2(600,400), ImGuiCond_FirstUseEver); if (CompileVisible) { - // Draw Log ImGui::BeginChild("Shader Log"); ImGui::TextWrapped("%s", ShaderLog.c_str()); ImGui::EndChild(); - } - - - - ImGui::End(); + ImGui::End(); } diff --git a/Source/Core/Loader/ERS_ShaderLoader/ERS_CLASS_ShaderLoader.cpp b/Source/Core/Loader/ERS_ShaderLoader/ERS_CLASS_ShaderLoader.cpp index a90640bedc..b6524d23ca 100644 --- a/Source/Core/Loader/ERS_ShaderLoader/ERS_CLASS_ShaderLoader.cpp +++ b/Source/Core/Loader/ERS_ShaderLoader/ERS_CLASS_ShaderLoader.cpp @@ -18,14 +18,12 @@ ERS_CLASS_ShaderLoader::~ERS_CLASS_ShaderLoader() { } -std::shared_ptr ERS_CLASS_ShaderLoader::CreateShaderObject(const char* VertexText, const char* FragmentText, bool LogBuild) { +void ERS_CLASS_ShaderLoader::CreateShaderObject(const char* VertexText, const char* FragmentText, ERS_STRUCT_Shader* ShaderStruct, bool LogBuild) { if (LogBuild) { SystemUtils_->Logger_->Log("Creating Shader Object", 5); } - // Create Shader - std::shared_ptr ShaderStruct = std::make_shared(); if (LogBuild) { SystemUtils_->Logger_->Log("Creating Vertex Shader Object", 3); @@ -49,14 +47,13 @@ std::shared_ptr ERS_CLASS_ShaderLoader::CreateShaderObject(co SystemUtils_->Logger_->Log("Linked Shader Program", 4); } - return ShaderStruct; } -std::shared_ptr ERS_CLASS_ShaderLoader::LoadShaderFromAsset(long VertexID, long FragmentID, std::string ShaderName) { +void ERS_CLASS_ShaderLoader::LoadShaderFromAsset(long VertexID, long FragmentID, ERS_STRUCT_Shader* ShaderStruct, std::string ShaderName) { // Load Shaders From Disk Into RAM - SystemUtils_->Logger_->Log("Loading Shaders From Asset ID", 5); + SystemUtils_->Logger_->Log(std::string("Loading Shaders From Asset IDs ") + std::to_string(VertexID) + std::string(", ") + std::to_string(FragmentID), 5); std::unique_ptr VertexData = std::make_unique(); std::unique_ptr FragmentData = std::make_unique(); @@ -68,12 +65,14 @@ std::shared_ptr ERS_CLASS_ShaderLoader::LoadShaderFromAsset(l // Return Compiled Shader - std::shared_ptr ShaderStruct = CreateShaderObject(VertexText.c_str(), FragmentText.c_str()); + CreateShaderObject(VertexText.c_str(), FragmentText.c_str(), ShaderStruct); ShaderStruct->VertexID = VertexID; ShaderStruct->FragmentID = FragmentID; ShaderStruct->DisplayName = ShaderName; ShaderStruct->InternalName = ShaderName; - return ShaderStruct; + + SystemUtils_->Logger_->Log(std::string("Loaded Shader '") + ShaderName + std::string("'"), 5); + } \ No newline at end of file diff --git a/Source/Core/Loader/ERS_ShaderLoader/ERS_CLASS_ShaderLoader.h b/Source/Core/Loader/ERS_ShaderLoader/ERS_CLASS_ShaderLoader.h index 362c55f18c..728c361057 100644 --- a/Source/Core/Loader/ERS_ShaderLoader/ERS_CLASS_ShaderLoader.h +++ b/Source/Core/Loader/ERS_ShaderLoader/ERS_CLASS_ShaderLoader.h @@ -53,7 +53,7 @@ class ERS_CLASS_ShaderLoader { * @param FragmentText * @return ERS_STRUCT_Shader */ - std::shared_ptr CreateShaderObject(const char* VertexText, const char* FragmentText, bool LogBuild = true); + void CreateShaderObject(const char* VertexText, const char* FragmentText, ERS_STRUCT_Shader* ShaderStruct, bool LogBuild = true); /** @@ -63,7 +63,7 @@ class ERS_CLASS_ShaderLoader { * @param FragmentID * @return std::shared_ptr */ - std::shared_ptr LoadShaderFromAsset(long VertexID, long FragmentID, std::string ShaderName = "Untitled Shader"); + void LoadShaderFromAsset(long VertexID, long FragmentID, ERS_STRUCT_Shader* ShaderStruct, std::string ShaderName = "Untitled Shader"); diff --git a/Source/Core/Renderer/ERS_CLASS_RendererManager/RendererManager.cpp b/Source/Core/Renderer/ERS_CLASS_RendererManager/RendererManager.cpp index 691fa0c58d..b68f65740e 100644 --- a/Source/Core/Renderer/ERS_CLASS_RendererManager/RendererManager.cpp +++ b/Source/Core/Renderer/ERS_CLASS_RendererManager/RendererManager.cpp @@ -30,19 +30,19 @@ RendererManager::RendererManager(ERS_STRUCT_SystemUtils* SystemUtils, ERS_STRUCT LoadEditorData(); VisualRenderer_->SetOpenGLDefaults(OpenGLDefaults_.get()); - // Debugging test, to see if this fixes the access violations - glEnable(GL_TEXTURE_2D); + // Setup Shaders ShaderLoader_ = std::make_unique(SystemUtils_); for (int i = 0; (long)i < (long)ProjectUtils_->ProjectManager_->Project_.ShaderPrograms.size(); i++) { + VisualRenderer_->Shaders_.push_back(std::make_unique()); + ERS_STRUCT_Shader* Shader = VisualRenderer_->Shaders_[VisualRenderer_->Shaders_.size()-1].get(); + long VertexShaderID = ProjectUtils_->ProjectManager_->Project_.ShaderPrograms[i].VertexID; long FragmentShaderID = ProjectUtils_->ProjectManager_->Project_.ShaderPrograms[i].FragmentID; std::string ShaderName = ProjectUtils_->ProjectManager_->Project_.ShaderPrograms[i].Name; - Shader_ = ShaderLoader_->LoadShaderFromAsset(VertexShaderID, FragmentShaderID, ShaderName); - Shader_->MakeActive(SystemUtils_->Logger_.get()); - Shader_->SetInt("texture_diffuse1", 0); - VisualRenderer_->SetShader(Shader_, i); + ShaderLoader_->LoadShaderFromAsset(VertexShaderID, FragmentShaderID, Shader, ShaderName); + } int DefaultShader = ProjectUtils_->ProjectManager_->Project_.DefaultShaderProgram; VisualRenderer_->SetDefaultShader(DefaultShader); @@ -132,8 +132,8 @@ void RendererManager::InitializeGLFW() { // Initialize GLFW glfwInit(); - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); @@ -157,10 +157,25 @@ void RendererManager::InitializeGLFW() { glfwMakeContextCurrent(Window_); glfwSwapInterval(0); + + + // Setup GLAD + if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { + SystemUtils_->Logger_->Log("Failed To Initialize GLAD", 10); + } + + // Setup OpenGL For Blending (For Transparency Issues) + glEnable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + + } void RendererManager::UpdateLoop(float DeltaTime) { + // Log Any Issues + ReportOpenGLErrors(); + // Update Window Title std::string SceneTitle = ProjectUtils_->ProjectManager_->Project_.ProjectName + std::string(" - BrainGenix-ERS"); glfwSetWindowTitle(Window_, SceneTitle.c_str()); @@ -205,4 +220,35 @@ void RendererManager::UpdateLoop(float DeltaTime) { } +} + +void RendererManager::ReportOpenGLErrors() { + + // Get Current Errors + GLint GLErrorStatus = glGetError(); + + if (GLErrorStatus != GL_NO_ERROR) { + + std::string ErrorMeaning = "Unknown"; + if (GLErrorStatus == GL_INVALID_ENUM) { + ErrorMeaning = "GL_INVALID_ENUM"; + } else if (GLErrorStatus == GL_INVALID_VALUE) { + ErrorMeaning = "GL_INVALID_VALUE"; + } else if (GLErrorStatus == GL_INVALID_OPERATION) { + ErrorMeaning = "GL_INVALID_OPERATION"; + } else if (GLErrorStatus == GL_STACK_OVERFLOW) { + ErrorMeaning = "GL_STACK_OVERFLOW"; + } else if (GLErrorStatus == GL_STACK_UNDERFLOW) { + ErrorMeaning = "GL_STACK_UNDERFLOW"; + } else if (GLErrorStatus == GL_OUT_OF_MEMORY) { + ErrorMeaning = "GL_OUT_OF_MEMORY"; + } else if (GLErrorStatus == GL_INVALID_FRAMEBUFFER_OPERATION) { + ErrorMeaning = "GL_INVALID_FRAMEBUFFER_OPERATION"; + } + + std::string ErrorMessage = std::string("OpenGL Context Reporting Error '") + std::to_string(GLErrorStatus) + std::string("' (") + ErrorMeaning + std::string(")"); + SystemUtils_->Logger_->Log(ErrorMessage, 9); + + } + } \ No newline at end of file diff --git a/Source/Core/Renderer/ERS_CLASS_RendererManager/RendererManager.h b/Source/Core/Renderer/ERS_CLASS_RendererManager/RendererManager.h index e3a2a0cca8..05ff3b1ca1 100644 --- a/Source/Core/Renderer/ERS_CLASS_RendererManager/RendererManager.h +++ b/Source/Core/Renderer/ERS_CLASS_RendererManager/RendererManager.h @@ -22,7 +22,6 @@ #include #include -#include #include #include @@ -52,7 +51,6 @@ class RendererManager { std::unique_ptr VisualRenderer_; /** ShaderLoader_; /** FramebufferManager_; /** Shader_; /** GuiSystem_; /** Cursors3D_; /** + + +ERS_CLASS_DepthMaps::ERS_CLASS_DepthMaps(ERS_STRUCT_SystemUtils* SystemUtils, ERS_STRUCT_ProjectUtils* ProjectUtils, ERS_CLASS_MeshRenderer* Renderer) { + + SystemUtils_ = SystemUtils; + ProjectUtils_ = ProjectUtils; + Renderer_ = Renderer; + + SystemUtils_->Logger_->Log("Initializing Viewport Overlay Subsystem", 5); + + // Create Array Texture For Depth Maps + RegenerateDepthMapTextureArray(1, 2048, 2048); + + +} + +ERS_CLASS_DepthMaps::~ERS_CLASS_DepthMaps() { + + SystemUtils_->Logger_->Log("Viewport Overlay Subsystem Destructor Invoked", 6); + +} + +bool ERS_CLASS_DepthMaps::RegenerateDepthMapTextureArray(int NumberOfTextures, int Width, int Height, bool LogEnabled) { + + + SystemUtils_->Logger_->Log( + std::string("Generating Depth Map Texture Array Of ") + std::to_string(NumberOfTextures) + + std::string(" Textures, With Width Of ") + std::to_string(Width) + + std::string(" Pixels, And Height Of ") + std::to_string(Height) + + std::string(" Pixels") + , 5, LogEnabled); + + // Check If Already Texture, If So, Delete So We Can Overwrite it + SystemUtils_->Logger_->Log("Checking If Texture Array Already Exists", 4, LogEnabled); + bool TextureAlreadyExists = glIsTexture(DepthTextureArrayID_); + if (TextureAlreadyExists) { + SystemUtils_->Logger_->Log("Array ID Already In Use, Freeing First", 3, LogEnabled); + glDeleteTextures(1, &DepthTextureArrayID_); + } else { + SystemUtils_->Logger_->Log("Array ID Not Already In Use", 3, LogEnabled); + } + + // Handle The Creation Of A New Texture Array + SystemUtils_->Logger_->Log("Setting Up Texture Array Metadata", 3, LogEnabled); + DepthTextureArrayWidth_ = Width; + DepthTextureArrayHeight_ = Height; + DepthTextureNumTextures_ = NumberOfTextures; + + SystemUtils_->Logger_->Log("Setting Up Texture Array OpenGL Parameters", 4, LogEnabled); + glGenTextures(1, &DepthTextureArrayID_); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D_ARRAY, DepthTextureArrayID_); + + + // ** THIS CAUSES A SEGFAULT FOR SOME REASON...? NOT SURE WHY, SO USING WORKAROUND BELOW ** + // glTextureStorage3D(GL_TEXTURE_2D_ARRAY, + // 0, // Number OF Mipmaps, Note that we're not using mipmaps so this is set to 1 + // GL_DEPTH_COMPONENT16, // Storage Format, Using Depth Format Here As We're Setting Up A Depth Map + // Width, Height, // Width and Height, Pretty Self Explanitory + // NumberOfTextures // Total Number Of Textures In The Array + // ); + + glTexImage3D(GL_TEXTURE_2D_ARRAY, + 0, // Current 'mipmap level', We're not using these so 0 is fine + GL_DEPTH_COMPONENT24, // Storage Format, Using Depth Format Here As We're Setting Up A Depth Map + Width, Height, // Width and Height, Pretty Self Explanitory + NumberOfTextures, // Total Number Of Textures In The Array + 0, // Border, we're not using this + GL_DEPTH_COMPONENT, // Tells opengl what kind of data we're storing in this texture + GL_FLOAT, // tells opengl how to store the data + NULL // if we were loading an image in, we could then pass the data in here, but we're not so this is left as null + ); + + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + float BorderColor[] = {1.0f, 1.0f, 1.0f, 1.0f}; + glTexParameterfv(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BORDER_COLOR, BorderColor); + SystemUtils_->Logger_->Log("Depth Map Texture Array Initialization Complete", 4, LogEnabled); + + + // Update Allocation Array + SystemUtils_->Logger_->Log("Checking Depth Map Texture Array Allocation Array", 3, LogEnabled); + unsigned long SizeOfAllocationArray = DepthMapTexturesAlreadyAllocated_.size(); + if (SizeOfAllocationArray > (unsigned int)NumberOfTextures) { + SystemUtils_->Logger_->Log("Downsizing Array To Match Target Number Of Textures", 4, LogEnabled); + DepthMapTexturesAlreadyAllocated_.erase(DepthMapTexturesAlreadyAllocated_.begin() + NumberOfTextures, DepthMapTexturesAlreadyAllocated_.end()); + } else if (SizeOfAllocationArray < (unsigned int)NumberOfTextures) { + SystemUtils_->Logger_->Log("Upsizing Array To Match Target Number Of Textures", 4, LogEnabled); + for (unsigned int i = 0; i < NumberOfTextures - SizeOfAllocationArray; i++) { + DepthMapTexturesAlreadyAllocated_.push_back(-1); + } + } + SystemUtils_->Logger_->Log("Done Updating/Checking Allocation Array", 3, LogEnabled); + + + // Rebind Any Framebuffers + SystemUtils_->Logger_->Log("Rebinding Framebuffer Objects Depth Textures", 4, LogEnabled); + for (unsigned int i = 0; i < DepthMapTexturesAlreadyAllocated_.size(); i++) { + + long ID = DepthMapTexturesAlreadyAllocated_[i]; + + // Check If Valid ID + if (glIsFramebuffer(ID)) { + + // If Valid, Rebind + SystemUtils_->Logger_->Log(std::string("Rebinding Framebuffer '") + std::to_string(ID) + std::string("' To Texture At Index '") + std::to_string(i) + std::string("'"), 4, LogEnabled); + glBindFramebuffer(GL_FRAMEBUFFER, ID); + glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, DepthTextureArrayID_, 0, i); + + } else if (ID != -1) { + SystemUtils_->Logger_->Log("Framebuffer Object Is Invalid, Removing From Allocation Table", 4, LogEnabled); + DepthMapTexturesAlreadyAllocated_[i] = -1; + } + + } + + return true; + +} + +bool ERS_CLASS_DepthMaps::FreeDepthMapIndex(unsigned int Index) { + + // Sanity Check + if (Index > DepthMapTexturesAlreadyAllocated_.size() - 1) { + return false; // Indicate Failure, Out Of Range + } + + // DeAllocate From Array + DepthMapTexturesAlreadyAllocated_[Index] = -1; + return true; + +} + +unsigned int ERS_CLASS_DepthMaps::AllocateDepthMapIndex(unsigned int FramebufferObjectID) { + + // If Enough Textures Exist, Find One + SystemUtils_->Logger_->Log("Allocating Depth Map Texture Array Index", 5); + for (unsigned int i = 0; i < DepthMapTexturesAlreadyAllocated_.size(); i++) { + if (DepthMapTexturesAlreadyAllocated_[i] == -1) { + SystemUtils_->Logger_->Log(std::string("Allocated Depth Map Texture Array Index: ") + std::to_string(i), 5); + DepthMapTexturesAlreadyAllocated_[i] = FramebufferObjectID; + return i; + } + } + + // IF Not, Batch Allocate More + SystemUtils_->Logger_->Log("Depth Map Texture Array Full, Regenerating With More Textures", 5); + int StartSize = DepthMapTexturesAlreadyAllocated_.size(); + RegenerateDepthMapTextureArray(StartSize + DepthMapAllocationChunkSize_, DepthTextureArrayWidth_, DepthTextureArrayHeight_); + SystemUtils_->Logger_->Log(std::string("Finished Updating Depth Map Array, Allocating Depth Map Texture Array Index: ") + std::to_string(StartSize + DepthMapAllocationChunkSize_), 5); + + return StartSize + 1; + +} + +ERS_STRUCT_DepthMap ERS_CLASS_DepthMaps::GenerateDepthMap(bool LogEnable) { + + + SystemUtils_->Logger_->Log(std::string("Creating Depth Map With Resolution Of ") + std::to_string(DepthTextureArrayWidth_) + std::string("x") + std::to_string(DepthTextureArrayHeight_), 5, LogEnable); + + // Setup Struct + ERS_STRUCT_DepthMap Output; + + // Generate FBO + SystemUtils_->Logger_->Log("Generating Framebuffer Object", 4, LogEnable); + glGenFramebuffers(1, &Output.FrameBufferObjectID); + SystemUtils_->Logger_->Log("Generated Framebuffer Object", 3, LogEnable); + + // Allocate Depth Map Texture ID + Output.DepthMapTextureIndex = AllocateDepthMapIndex(Output.FrameBufferObjectID); + + // Attach Depth Map Texture To Framebuffer + SystemUtils_->Logger_->Log(std::string("Attaching Depth Map Texture To Framebuffer Texture '") + std::to_string(Output.DepthMapTextureIndex) + std::string("'"), 4, LogEnable); + glBindFramebuffer(GL_FRAMEBUFFER, Output.FrameBufferObjectID); + glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, DepthTextureArrayID_, 0, Output.DepthMapTextureIndex); + glDrawBuffer(GL_NONE); + glReadBuffer(GL_NONE); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + SystemUtils_->Logger_->Log("Finished Attaching Texture To Framebuffer", 3, LogEnable); + + + Output.Initialized = true; + + // Return Output + return Output; + +} + +void ERS_CLASS_DepthMaps::CheckSettings() { + + // Check Depth Maps + bool NeedsToUpdate = true; + + if (SystemUtils_->RendererSettings_->ShadowMapX_ != DepthTextureArrayWidth_) { + DepthTextureArrayWidth_ = SystemUtils_->RendererSettings_->ShadowMapX_; + } else if (SystemUtils_->RendererSettings_->ShadowMapX_ != DepthTextureArrayHeight_) { + DepthTextureArrayHeight_ = SystemUtils_->RendererSettings_->ShadowMapY_; + } else { + NeedsToUpdate = false; + } + + if (NeedsToUpdate) { + RegenerateDepthMapTextureArray(DepthTextureNumTextures_, DepthTextureArrayWidth_, DepthTextureArrayHeight_); + } + +} + +void ERS_CLASS_DepthMaps::UpdateDepthMap(ERS_STRUCT_DepthMap* Target, ERS_STRUCT_Shader* DepthShader, glm::vec3 Pos, glm::vec3 Rot, bool Orthogonal, glm::mat4* LightSpaceMatrix) { + + + // Check Settings + CheckSettings(); + + // Setup Variables + ERS_STRUCT_Scene* TargetScene = ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_].get(); + glm::mat4 ObjectProjection, ObjectView, ObjectSpace; + float NearPlane = 0.1f, FarPlane = 15.0f; + + // Calculate Project, View, Space Matrices + if (Orthogonal) { + ObjectProjection = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, NearPlane, FarPlane); // ortho models directional light source + } else { + float AspectRatio = DepthTextureArrayWidth_ / DepthTextureArrayHeight_; + ObjectProjection = glm::perspective(glm::radians(110.0f), AspectRatio, NearPlane, FarPlane); // Perspective models regular light source + } + + // Re-Do Rotation + glm::vec3 XYZRotation = ERS_FUNCTION_ConvertRotationToFrontVector(Rot); + + glm::vec3 Front = glm::normalize(XYZRotation); + ObjectView = glm::lookAt(Pos, Pos+Front, glm::vec3(0.0f, 1.0f, 0.0f)); // Pos+Front + ObjectSpace = ObjectProjection * ObjectView; + + // Render With Depth Shader + DepthShader->MakeActive(); + DepthShader->SetMat4("LightSpaceMatrix", ObjectSpace); + + if (LightSpaceMatrix != nullptr) { + *LightSpaceMatrix = ObjectSpace; + } + + glViewport(0, 0, DepthTextureArrayWidth_, DepthTextureArrayHeight_); + glBindFramebuffer(GL_FRAMEBUFFER, Target->FrameBufferObjectID); + + + glClear(GL_DEPTH_BUFFER_BIT); + glActiveTexture(GL_TEXTURE0); + Renderer_->RenderSceneNoTextures(TargetScene, DepthShader); + + glBindFramebuffer(GL_FRAMEBUFFER, 0); + + +} + +void ERS_CLASS_DepthMaps::UpdateDepthMaps(ERS_STRUCT_Shader* DepthShader) { + + + // Fix Offset (Peter Panning) + glCullFace(GL_FRONT); + + // Get Active Scene + ERS_STRUCT_Scene* ActiveScene = ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_].get(); + + // Handle Directional Lights + for (unsigned int i = 0; i < ActiveScene->DirectionalLights.size(); i++) { + + // Extract Struct + ERS_STRUCT_DirectionalLight* Light = ActiveScene->DirectionalLights[i].get(); + + // Check If Light Has DepthMap + if (!Light->DepthMap.Initialized) { + Light->DepthMap = GenerateDepthMap(); + } + + // Render To Depth Map + glm::mat4* LightSpaceMatrix = new glm::mat4(); + UpdateDepthMap(&Light->DepthMap, DepthShader, Light->Pos, Light->Rot, true, LightSpaceMatrix); + Light->LightSpaceMatrix = *LightSpaceMatrix; + + } + + // Handle Spot Lights + for (unsigned int i = 0; i < ActiveScene->SpotLights.size(); i++) { + + // Extract Struct + ERS_STRUCT_SpotLight* Light = ActiveScene->SpotLights[i].get(); + + // Check If Light Has DepthMap + if (!Light->DepthMap.Initialized) { + Light->DepthMap = GenerateDepthMap(); + } + + // Render To Depth Map + glm::mat4* LightSpaceMatrix = new glm::mat4(); + UpdateDepthMap(&Light->DepthMap, DepthShader, Light->Pos, Light->Rot, true, LightSpaceMatrix); + Light->LightSpaceMatrix = *LightSpaceMatrix; + + } + + // Handle Point Lights + for (unsigned int i = 0; i < ActiveScene->PointLights.size(); i++) { + + // Extract Struct + ERS_STRUCT_PointLight* Light = ActiveScene->PointLights[i].get(); + + // Check If Light Has DepthMap + if (!Light->DepthMap.Initialized) { + Light->DepthMap = GenerateDepthMap(); + } + + // Render To Depth Map + glm::mat4* LightSpaceMatrix = new glm::mat4(); + UpdateDepthMap(&Light->DepthMap, DepthShader, Light->Pos, Light->Pos, true, LightSpaceMatrix); // set this to false later, debugging + Light->LightSpaceMatrix = *LightSpaceMatrix; + + } + + + // Return To Normal Culling + glCullFace(GL_BACK); + +} \ No newline at end of file diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_DepthMaps.h b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_DepthMaps.h new file mode 100644 index 0000000000..1a0809a62e --- /dev/null +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_DepthMaps.h @@ -0,0 +1,161 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#pragma once + + +// Standard Libraries (BG convention: use <> instead of "") +#include +#include +#include + +// Third-Party Libraries (BG convention: use <> instead of "") +#include +#include +#include +#include + +#include +#include + + +// Internal Libraries (BG convention: use <> instead of "") +#include +#include + +#include + +#include +#include +#include +#include + +#include + +/** + * @brief This class renders any ui/overlay info onto the viewport as requested by the viewport struct. + * + */ +class ERS_CLASS_DepthMaps { + +private: + + ERS_STRUCT_SystemUtils* SystemUtils_; /** DepthMapTexturesAlreadyAllocated_; /** DepthMapTextureIndex_; /** AssociatedDepthMapFramebufferIndex_; /** - - - -ERS_CLASS_Framebuffer::ERS_CLASS_Framebuffer(ERS_CLASS_LoggingSystem* Logger, ERS_CLASS_ShaderLoader* ShaderLoader, float Width, float Height) { - - Logger_ = Logger; - ShaderLoader_ = ShaderLoader; - Logger_->Log("Initializing Framebuffer Manager", 5); - - Logger_->Log("Loading Screen Shaders", 5); - ScreenShader_ = *ShaderLoader_->LoadShaderFromAsset(100, 101); - - Logger_->Log("Making Screen Shaders Active", 3); - ScreenShader_.MakeActive(); - ScreenShader_.SetInt("screenTexture", 0); - - Logger_->Log("Generating Screen Quad VAO", 4); - glGenVertexArrays(1, &ScreenQuadVAO_); - - Logger_->Log("Generating Screen Quad VBO", 4); - glGenBuffers(1, &ScreenQuadVBO_); - - - // Framebuffer manager Quads - float QuadVertices[] = { - - // Positions // Texture Coordinates - -1.0f, 1.0f, 0.0f, 1.0f, - -1.0f, -1.0f, 0.0f, 0.0f, - 1.0f, -1.0f, 1.0f, 0.0f, - - -1.0f, 1.0f, 0.0f, 1.0f, - 1.0f, -1.0f, 1.0f, 0.0f, - 1.0f, 1.0f, 1.0f, 1.0f - }; - glBindVertexArray(ScreenQuadVAO_); - glBindBuffer(GL_ARRAY_BUFFER, ScreenQuadVBO_); - glBufferData(GL_ARRAY_BUFFER, sizeof(QuadVertices), &QuadVertices, GL_STATIC_DRAW); - - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4*sizeof(float), (void*)0); - glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4*sizeof(float), (void*)(2*sizeof(float))); - - - // Create Framebuffer - Logger_->Log("Creating Framebuffer Object", 4); - glGenFramebuffers(1, &FramebufferObject_); - - // Bind To Framebuffer - Logger_->Log("Binding To Framebuffer Object", 4); - glBindFramebuffer(GL_FRAMEBUFFER, FramebufferObject_); - - // Create RenderTexture - Logger_->Log("Creating Render Texture", 4); - glGenTextures(1, &RenderTexture_); - glBindTexture(GL_TEXTURE_2D, RenderTexture_); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, Width, Height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); // NOTE: THIS MUST HAPPEN ON RESIZE! - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - - // Attach Texture To Framebuffer - Logger_->Log("Attaching Texture To Framebuffer", 4); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, RenderTexture_, 0); - - // Create Render Buffer - Logger_->Log("Creating Render Buffer Object", 5); - glGenRenderbuffers(1, &RenderBufferObject_); - glBindRenderbuffer(GL_RENDERBUFFER, RenderBufferObject_); - - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, Width, Height); // RESIZE THIS WITH THE WINDOW! - - // Attach Renderbuffer to Depth And Stencil Attachment - Logger_->Log("Attaching Render Buffer Object To Depth Stencil", 5); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, RenderBufferObject_); - - - // Check Framebuffer Status - if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { - - // Log Error - Logger_->Log("Failed To Initialize Framebuffer", 9); - } - - - // Bind To Framebuffer - Logger_->Log("Binding To Framebuffer", 5); - glBindFramebuffer(GL_FRAMEBUFFER, 0); - - - -} - -ERS_CLASS_Framebuffer::~ERS_CLASS_Framebuffer() { - - Logger_->Log("Framebuffer Manager Destructor Called", 6); - - Logger_->Log("Destroying Framebuffer Object", 5); - glDeleteFramebuffers(1, &FramebufferObject_); - - Logger_->Log("Destroying Screen Quad VAO/VBO", 4); - glDeleteVertexArrays(1, &ScreenQuadVAO_); - glDeleteBuffers(1, &ScreenQuadVBO_); - -} - - -void ERS_CLASS_Framebuffer::StartFramebufferRenderPass() { - - // Bind To Framebuffer - glBindFramebuffer(GL_FRAMEBUFFER, FramebufferObject_); - glEnable(GL_DEPTH_TEST); - - -} - - -void ERS_CLASS_Framebuffer::StartScreenRenderPass() { - - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glDisable(GL_DEPTH_TEST); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - - glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - - // Use ScreenShader - ScreenShader_.MakeActive(); - - // Render Quad - glBindVertexArray(ScreenQuadVAO_); - glBindTexture(GL_TEXTURE_2D, RenderTexture_); - glDrawArrays(GL_TRIANGLES, 0, 6); - -} - -void ERS_CLASS_Framebuffer::ResizeFramebuffer(int Width, int Height) { - - // Update Render Color Buffer Size - glBindTexture(GL_TEXTURE_2D, RenderTexture_); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, Width, Height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); - - // Update RBO Size - glBindRenderbuffer(GL_RENDERBUFFER, RenderBufferObject_); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, Width, Height); - -} \ No newline at end of file diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_Framebuffer.h b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_Framebuffer.h deleted file mode 100644 index 684376ad7c..0000000000 --- a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_Framebuffer.h +++ /dev/null @@ -1,88 +0,0 @@ -//======================================================================// -// This file is part of the BrainGenix-ERS Environment Rendering System // -//======================================================================// - -#pragma once - - -// Standard Libraries (BG convention: use <> instead of "") - - -// Third-Party Libraries (BG convention: use <> instead of "") -#include - -#include - -#include - - -// Internal Libraries (BG convention: use <> instead of "") -#include -#include -#include - - - -/** - * @brief Class to create/renderto/destruy framebuffer object. - * - */ -class ERS_CLASS_Framebuffer { - - -private: - - ERS_CLASS_LoggingSystem* Logger_; /** -ERS_CLASS_Grid::ERS_CLASS_Grid(ERS_STRUCT_SystemUtils* SystemUtils, std::shared_ptr GridShader) { +ERS_CLASS_Grid::ERS_CLASS_Grid(ERS_STRUCT_SystemUtils* SystemUtils, ERS_STRUCT_Shader* GridShader) { SystemUtils_ = SystemUtils; GridShader_ = GridShader; diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_Grid.h b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_Grid.h index 7aa24f6c8c..b5287f2a95 100644 --- a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_Grid.h +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_Grid.h @@ -26,7 +26,7 @@ class ERS_CLASS_Grid { private: ERS_STRUCT_SystemUtils* SystemUtils_; /** GridShader_; /** GridShader); + ERS_CLASS_Grid(ERS_STRUCT_SystemUtils* SystemUtils, ERS_STRUCT_Shader* GridShader); /** * @brief Destroy the ers class grid object diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_InputProcessor.h b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_InputProcessor.h index f90e410a03..ed77aa5a26 100644 --- a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_InputProcessor.h +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_InputProcessor.h @@ -14,7 +14,6 @@ // Internal Libraries (BG convention: use <> instead of "") #include #include -#include /** @@ -30,7 +29,6 @@ class ERS_CLASS_InputProcessor { float LastX = 400; /** LightIconRendererShader) { +ERS_CLASS_LightIconRenderer::ERS_CLASS_LightIconRenderer(ERS_STRUCT_OpenGLDefaults* Defaults, ERS_STRUCT_SystemUtils* SystemUtils, ERS_STRUCT_Shader* LightIconRendererShader) { SystemUtils_ = SystemUtils; @@ -90,7 +90,7 @@ void ERS_CLASS_LightIconRenderer::Draw(ERS_STRUCT_Camera* Camera, ERS_CLASS_Scen //LightIconRendererShader_->SetVec3("BillboardRotation", SceneManager->Scenes_[SceneManager->ActiveScene_]->PointLights[i]->Pos); - glUniform1i(glGetUniformLocation(LightIconRendererShader_->ShaderProgram, "IconTexture"), 0); + glUniform1i(glGetUniformLocation(LightIconRendererShader_->ShaderProgram_, "IconTexture"), 0); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, OpenGLDefaults_->PointLightTexture_); @@ -128,7 +128,7 @@ void ERS_CLASS_LightIconRenderer::Draw(ERS_STRUCT_Camera* Camera, ERS_CLASS_Scen LightIconRendererShader_->SetVec3("BillboardPosition", LightPosition); LightIconRendererShader_->SetVec3("BillboardRotation", LampRotation); - glUniform1i(glGetUniformLocation(LightIconRendererShader_->ShaderProgram, "IconTexture"), 0); + glUniform1i(glGetUniformLocation(LightIconRendererShader_->ShaderProgram_, "IconTexture"), 0); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, OpenGLDefaults_->DirectionalLightTexture_); @@ -166,7 +166,7 @@ void ERS_CLASS_LightIconRenderer::Draw(ERS_STRUCT_Camera* Camera, ERS_CLASS_Scen LightIconRendererShader_->SetVec3("BillboardPosition", LightPosition); LightIconRendererShader_->SetVec3("BillboardRotation", LampRotation); - glUniform1i(glGetUniformLocation(LightIconRendererShader_->ShaderProgram, "IconTexture"), 0); + glUniform1i(glGetUniformLocation(LightIconRendererShader_->ShaderProgram_, "IconTexture"), 0); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, OpenGLDefaults_->SpotLightTexture_); diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_LightIconRenderer.h b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_LightIconRenderer.h index 58601c58f9..a3cb405a16 100644 --- a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_LightIconRenderer.h +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_LightIconRenderer.h @@ -31,7 +31,7 @@ class ERS_CLASS_LightIconRenderer { ERS_STRUCT_SystemUtils* SystemUtils_; /** LightIconRendererShader_; /** LightIconRendererShader); + ERS_CLASS_LightIconRenderer(ERS_STRUCT_OpenGLDefaults* Defaults, ERS_STRUCT_SystemUtils* SystemUtils, ERS_STRUCT_Shader* LightIconRendererShader); /** * @brief Destroy the ers class grid object diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_MeshRenderer.cpp b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_MeshRenderer.cpp index ba11aab771..3e216d9a2c 100644 --- a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_MeshRenderer.cpp +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_MeshRenderer.cpp @@ -20,7 +20,7 @@ ERS_CLASS_MeshRenderer::~ERS_CLASS_MeshRenderer() { } -void ERS_CLASS_MeshRenderer::RenderScene(ERS_STRUCT_Scene* Scene, ERS_STRUCT_OpenGLDefaults* OpenGLDefaults, std::shared_ptr Shader) { +void ERS_CLASS_MeshRenderer::RenderScene(ERS_STRUCT_Scene* Scene, ERS_STRUCT_OpenGLDefaults* OpenGLDefaults, ERS_STRUCT_Shader* Shader) { ERS_FUNCTION_UpdateMeshTransparency(Scene); @@ -30,26 +30,14 @@ void ERS_CLASS_MeshRenderer::RenderScene(ERS_STRUCT_Scene* Scene, ERS_STRUCT_Ope // Draw All Opaque Meshes for (unsigned long i = 0; i < OpaqueMeshes.size(); i++) { - glBindTexture(GL_TEXTURE_2D, OpenGLDefaults->DefaultTexture_); - glActiveTexture(OpenGLDefaults->DefaultTexture_); ERS_FUNCTION_DrawMesh(OpaqueMeshes[i], OpenGLDefaults, Shader); } - - - // Disable Depth Filtering - //glDisable(GL_DEPTH_TEST); - // Render Transparent Meshes In Right Order for (unsigned long i = 0; i < TransparentMeshes.size(); i++) { - glBindTexture(GL_TEXTURE_2D, OpenGLDefaults->DefaultTexture_); - glActiveTexture(OpenGLDefaults->DefaultTexture_); ERS_FUNCTION_DrawMesh(TransparentMeshes[i], OpenGLDefaults, Shader); } - // Enable Depth Filtering - //glEnable(GL_DEPTH_TEST); - // TODO: Update rendering process // should be based around the idea that the models are used to get the meshes to be rendered @@ -68,4 +56,26 @@ void ERS_CLASS_MeshRenderer::RenderScene(ERS_STRUCT_Scene* Scene, ERS_STRUCT_Ope // then remove the mesh draw function and put it into here so that it's more consoldiated and self-explanitory // then maybe move the renderer code into it's own namespace? +} + + +void ERS_CLASS_MeshRenderer::RenderSceneNoTextures(ERS_STRUCT_Scene* Scene, ERS_STRUCT_Shader* Shader) { + + ERS_FUNCTION_UpdateMeshTransparency(Scene); + + // Sort Into Pesh Categories + std::vector OpaqueMeshes; + std::vector TransparentMeshes; + ERS_FUNCTION_MeshTransparencySort(&OpaqueMeshes, &TransparentMeshes, Scene); + + // Draw All Opaque Meshes + for (unsigned long i = 0; i < OpaqueMeshes.size(); i++) { + ERS_FUNCTION_DrawMeshNoTextures(OpaqueMeshes[i], Shader); + } + for (unsigned long i = 0; i < TransparentMeshes.size(); i++) { + ERS_FUNCTION_DrawMeshNoTextures(TransparentMeshes[i], Shader); + } + + // ToDO: Make It So That The Transparency Of The Mesh Is Taken Into Account, Rather Than Being completely Bypassed Like It Is Now. + } \ No newline at end of file diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_MeshRenderer.h b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_MeshRenderer.h index 444723a04e..5da5dfda21 100644 --- a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_MeshRenderer.h +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_MeshRenderer.h @@ -24,13 +24,13 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include @@ -80,7 +80,14 @@ class ERS_CLASS_MeshRenderer { * @param OpenGLDefaults * @param Shader */ - void RenderScene(ERS_STRUCT_Scene* Scene, ERS_STRUCT_OpenGLDefaults* OpenGLDefaults, std::shared_ptr Shader); + void RenderScene(ERS_STRUCT_Scene* Scene, ERS_STRUCT_OpenGLDefaults* OpenGLDefaults, ERS_STRUCT_Shader* Shader); + + /** + * @brief Render the scene without textures (used to generate depth maps) + * + * @param Scene + */ + void RenderSceneNoTextures(ERS_STRUCT_Scene* Scene, ERS_STRUCT_Shader* Shader); }; \ No newline at end of file diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_ShadowMaps.cpp b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_ShadowMaps.cpp new file mode 100644 index 0000000000..b3ebc0b134 --- /dev/null +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_ShadowMaps.cpp @@ -0,0 +1,36 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#include + + +ERS_CLASS_ShadowMaps::ERS_CLASS_ShadowMaps(ERS_STRUCT_SystemUtils* SystemUtils, ERS_STRUCT_ProjectUtils* ProjectUtils, ERS_CLASS_MeshRenderer* Renderer) { + + SystemUtils_ = SystemUtils; + ProjectUtils_ = ProjectUtils; + Renderer_ = Renderer; + + SystemUtils_->Logger_->Log("Initializing Shadow Map Subsystem", 5); + ERS_CLASS_DepthMaps_ = std::make_unique(SystemUtils_, ProjectUtils_, Renderer_); + + +} + +ERS_CLASS_ShadowMaps::~ERS_CLASS_ShadowMaps() { + + SystemUtils_->Logger_->Log("Viewport Overlay Subsystem Destructor Invoked", 6); + +} + + +void ERS_CLASS_ShadowMaps::UpdateShadowMaps(ERS_STRUCT_Shader* DepthMapShader) { + + // Update All Depth Maps + ERS_CLASS_DepthMaps_->UpdateDepthMaps(DepthMapShader); + + + // Provide Depth Map Textures + + +} \ No newline at end of file diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_ShadowMaps.h b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_ShadowMaps.h new file mode 100644 index 0000000000..da6c7c869e --- /dev/null +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_ShadowMaps.h @@ -0,0 +1,84 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#pragma once + + +// Standard Libraries (BG convention: use <> instead of "") +#include +#include +#include + +// Third-Party Libraries (BG convention: use <> instead of "") +#include +#include +#include +#include + +#include +#include + + +// Internal Libraries (BG convention: use <> instead of "") +#include +#include +#include + +#include +#include +#include +#include + + + +/** + * @brief This class renders any ui/overlay info onto the viewport as requested by the viewport struct. + * + */ +class ERS_CLASS_ShadowMaps { + +private: + + ERS_STRUCT_SystemUtils* SystemUtils_; /** ERS_CLASS_DepthMaps_; /** + + +ERS_CLASS_ViewportMenu::ERS_CLASS_ViewportMenu(ERS_STRUCT_SystemUtils* SystemUtils, ERS_STRUCT_ProjectUtils* ProjectUtils, double* GameStartTime, bool* IsEditorMode, std::vector>* Shaders) { + + SystemUtils_ = SystemUtils; + ProjectUtils_ = ProjectUtils; + GameStartTime_ = GameStartTime; + IsEditorMode_ = IsEditorMode; + Shaders_ = Shaders; + + SystemUtils_->Logger_->Log("Initializing Viewport Menu Subsystem", 5); + +} + + +ERS_CLASS_ViewportMenu::~ERS_CLASS_ViewportMenu() { + + SystemUtils_->Logger_->Log("Viewport Menu Subsystem Destructor Invoked", 6); + +} + + +void ERS_CLASS_ViewportMenu::DrawMenu(ERS_STRUCT_Viewport* Viewport) { + + + // Menu Bar + if (ImGui::BeginMenuBar()) { + + + // Viewport Cube Controls + if (ImGui::BeginMenu("Controls")) { + + // Draw Controls + ImGui::MenuItem("Scene Info Overlay", nullptr, &Viewport->ShowSceneInfo_); + ImGui::MenuItem("System Resources Overlay", nullptr, &Viewport->ShowResourceInfo_); + ImGui::MenuItem("Loading Time Overlay", nullptr, &Viewport->ShowLoadingTimeInfo_); + ImGui::MenuItem("Light Debug Overlay", nullptr, &Viewport->ShowLightInfo_); + + ImGui::Separator(); + + ImGui::MenuItem("Rotation Indicator", nullptr, &Viewport->ShowCube); + ImGui::MenuItem("Gizmo", nullptr, &Viewport->GizmoEnabled); + ImGui::MenuItem("Grid", nullptr, &Viewport->GridEnabled); + ImGui::MenuItem("Light Icons", nullptr, &Viewport->LightIcons); + + ImGui::Separator(); + + ImGui::MenuItem("Gamma Correction", nullptr, &Viewport->GammaCorrection); + ImGui::MenuItem("HDR", nullptr, &Viewport->HDREnabled_); + + + ImGui::EndMenu(); + } + + + // Shader Control Menu + if(ImGui::BeginMenu("Shader")) { + + // Draw Selectable Menu Showing Active Viewport Shader + for (int i = 0; (long)i < (long)Shaders_->size(); i++) { + + if (strcmp((*Shaders_)[i]->DisplayName.substr(0, 1).c_str(), "_")) { + if (ImGui::Selectable((*Shaders_)[i]->DisplayName.c_str(), i == Viewport->ShaderIndex)) { + Viewport->ShaderIndex = i; + } + } + + } + + ImGui::EndMenu(); + } + + // Grid Control Menu + if (ImGui::BeginMenu("Grid")) { + + // Grid Scale Submenu + if (ImGui::BeginMenu("Scale")) { + + if (ImGui::MenuItem("0.0625 Units", nullptr, (Viewport->Grid->GridSize_ == 0.00125f))) { + Viewport->Grid->GridSize_ = 0.00125f; + } + + if (ImGui::MenuItem("0.125 Units", nullptr, (Viewport->Grid->GridSize_ == 0.0025f))) { + Viewport->Grid->GridSize_ = 0.0025f; + } + + if (ImGui::MenuItem("0.25 Units", nullptr, (Viewport->Grid->GridSize_ == 0.005f))) { + Viewport->Grid->GridSize_ = 0.005f; + } + + if (ImGui::MenuItem("0.5 Units", nullptr, (Viewport->Grid->GridSize_ == 0.01f))) { + Viewport->Grid->GridSize_ = 0.01f; + } + + if (ImGui::MenuItem("1 Unit", nullptr, (Viewport->Grid->GridSize_ == 0.02f))) { + Viewport->Grid->GridSize_ = 0.02f; + } + + if (ImGui::MenuItem("2.5 Units", nullptr, (Viewport->Grid->GridSize_ == 0.05f))) { + Viewport->Grid->GridSize_ = 0.05f; + } + + if (ImGui::MenuItem("5 Units", nullptr, (Viewport->Grid->GridSize_ == 0.1f))) { + Viewport->Grid->GridSize_ = 0.1f; + } + + ImGui::EndMenu(); + } + + // Line Thickness Submenu + if (ImGui::BeginMenu("Line Thickness")) { + + if (ImGui::MenuItem("0.5%", nullptr, (Viewport->Grid->GridLineThickness_ == 0.005f))) { + Viewport->Grid->GridLineThickness_ = 0.005f; + } + + if (ImGui::MenuItem("1%", nullptr, (Viewport->Grid->GridLineThickness_ == 0.01f))) { + Viewport->Grid->GridLineThickness_ = 0.01f; + } + + if (ImGui::MenuItem("2%", nullptr, (Viewport->Grid->GridLineThickness_ == 0.02f))) { + Viewport->Grid->GridLineThickness_ = 0.02f; + } + + if (ImGui::MenuItem("3%", nullptr, (Viewport->Grid->GridLineThickness_ == 0.03f))) { + Viewport->Grid->GridLineThickness_ = 0.03f; + } + + if (ImGui::MenuItem("4%", nullptr, (Viewport->Grid->GridLineThickness_ == 0.04f))) { + Viewport->Grid->GridLineThickness_ = 0.04f; + } + + ImGui::EndMenu(); + } + + // Color Scheme + if (ImGui::BeginMenu("Colors")) { + + // Base Color + if (ImGui::BeginMenu("Base")) { + + + if (ImGui::MenuItem("White")) { + Viewport->Grid->GridColor_ = glm::vec3(1.0f); + } + + if (ImGui::MenuItem("Light Grey")) { + Viewport->Grid->GridColor_ = glm::vec3(0.75f); + } + + if (ImGui::MenuItem("Grey")) { + Viewport->Grid->GridColor_ = glm::vec3(0.5f); + } + + if (ImGui::MenuItem("Dark Grey")) { + Viewport->Grid->GridColor_ = glm::vec3(0.25f); + } + + if (ImGui::MenuItem("Very Dark Grey")) { + Viewport->Grid->GridColor_ = glm::vec3(0.1f); + } + + if (ImGui::MenuItem("Black")) { + Viewport->Grid->GridColor_ = glm::vec3(0.0f); + } + + ImGui::EndMenu(); + } + + // X Axis Color + if (ImGui::BeginMenu("X Axis")) { + + + if (ImGui::MenuItem("Red")) { + Viewport->Grid->GridColorX_ = glm::vec3(1.0f, 0.0f, 0.0f); + } + + if (ImGui::MenuItem("Green")) { + Viewport->Grid->GridColorX_ = glm::vec3(0.0f, 1.0f, 0.0f); + } + + if (ImGui::MenuItem("Blue")) { + Viewport->Grid->GridColorX_ = glm::vec3(0.0f, 0.0f, 1.0f); + } + + if (ImGui::MenuItem("Dark Grey")) { + Viewport->Grid->GridColorX_ = glm::vec3(0.25f); + } + + if (ImGui::MenuItem("Very Dark Grey")) { + Viewport->Grid->GridColorX_ = glm::vec3(0.1f); + } + + if (ImGui::MenuItem("Black")) { + Viewport->Grid->GridColorX_ = glm::vec3(0.0f); + } + + ImGui::EndMenu(); + } + + + // Z Axis Color + if (ImGui::BeginMenu("Z Axis")) { + + + if (ImGui::MenuItem("Red")) { + Viewport->Grid->GridColorZ_ = glm::vec3(1.0f, 0.0f, 0.0f); + } + + if (ImGui::MenuItem("Green")) { + Viewport->Grid->GridColorZ_ = glm::vec3(0.0f, 1.0f, 0.0f); + } + + if (ImGui::MenuItem("Blue")) { + Viewport->Grid->GridColorZ_ = glm::vec3(0.0f, 0.0f, 1.0f); + } + + if (ImGui::MenuItem("Dark Grey")) { + Viewport->Grid->GridColorZ_ = glm::vec3(0.25f); + } + + if (ImGui::MenuItem("Very Dark Grey")) { + Viewport->Grid->GridColorZ_ = glm::vec3(0.1f); + } + + if (ImGui::MenuItem("Black")) { + Viewport->Grid->GridColorZ_ = glm::vec3(0.0f); + } + + ImGui::EndMenu(); + } + + + ImGui::EndMenu(); + } + + + ImGui::EndMenu(); + } + + // Add Items Menu + if (ImGui::BeginMenu("Add")) { + + if (ImGui::BeginMenu("Light")) { + + if (ImGui::MenuItem("Point Light")) { + ProjectUtils_->SceneManager_->AddPointLight(); + } + + if (ImGui::MenuItem("Spot Light")) { + ProjectUtils_->SceneManager_->AddSpotLight(); + } + + if (ImGui::MenuItem("Directional Light")) { + ProjectUtils_->SceneManager_->AddDirectionalLight(); + } + + ImGui::EndMenu(); + } + + if (ImGui::MenuItem("Script")) { + + ERS_STRUCT_Script NewScript; + NewScript.AssetID = SystemUtils_->ERS_IOSubsystem_->AllocateAssetID(); + NewScript.Code_ = "# ERS Script\n"; + NewScript.Name_ = "Untitled Script"; + ProjectUtils_->ProjectManager_->Project_.Scripts.push_back(NewScript); + + } + + + ImGui::EndMenu(); + } + + // Grid Snapping Control Menu + if (ImGui::BeginMenu("Grid Snapping")) { + + if (ImGui::BeginMenu("Translation")) { + + if (ImGui::MenuItem("Disabled", nullptr, (Viewport->GridSnapAmountTranslate_ == 0.0f))) { + Viewport->GridSnapAmountTranslate_ = 0.0f; + } + + ImGui::Separator(); + + if (ImGui::MenuItem("0.1", nullptr, (Viewport->GridSnapAmountTranslate_ == 0.1f))) { + Viewport->GridSnapAmountTranslate_ = 0.1f; + } + if (ImGui::MenuItem("0.25", nullptr, (Viewport->GridSnapAmountTranslate_ == 0.25f))) { + Viewport->GridSnapAmountTranslate_ = 0.25f; + } + if (ImGui::MenuItem("0.5", nullptr, (Viewport->GridSnapAmountTranslate_ == 0.5f))) { + Viewport->GridSnapAmountTranslate_ = 0.5f; + } + if (ImGui::MenuItem("0.75", nullptr, (Viewport->GridSnapAmountTranslate_ == 0.75f))) { + Viewport->GridSnapAmountTranslate_ = 0.75f; + } + if (ImGui::MenuItem("1.0", nullptr, (Viewport->GridSnapAmountTranslate_ == 1.0f))) { + Viewport->GridSnapAmountTranslate_ = 1.0f; + } + + ImGui::EndMenu(); + } + + + if (ImGui::BeginMenu("Rotate")) { + + if (ImGui::MenuItem("Disabled", nullptr, (Viewport->GridSnapAmountRotate_ == 0.0f))) { + Viewport->GridSnapAmountRotate_ = 0.0f; + } + + ImGui::Separator(); + + if (ImGui::MenuItem("1", nullptr, (Viewport->GridSnapAmountRotate_ == 1.0f))) { + Viewport->GridSnapAmountRotate_ = 1.0f; + } + if (ImGui::MenuItem("5", nullptr, (Viewport->GridSnapAmountRotate_ == 5.0f))) { + Viewport->GridSnapAmountRotate_ = 5.0f; + } + if (ImGui::MenuItem("10", nullptr, (Viewport->GridSnapAmountRotate_ == 10.0f))) { + Viewport->GridSnapAmountRotate_ = 10.0f; + } + if (ImGui::MenuItem("25", nullptr, (Viewport->GridSnapAmountRotate_ == 25.0f))) { + Viewport->GridSnapAmountRotate_ = 25.0f; + } + if (ImGui::MenuItem("45", nullptr, (Viewport->GridSnapAmountRotate_ == 45.0f))) { + Viewport->GridSnapAmountRotate_ = 45.0f; + } + if (ImGui::MenuItem("90", nullptr, (Viewport->GridSnapAmountRotate_ == 90.0f))) { + Viewport->GridSnapAmountRotate_ = 90.0f; + } + + ImGui::EndMenu(); + } + + + + if (ImGui::BeginMenu("Scale")) { + + if (ImGui::MenuItem("Disabled", nullptr, (Viewport->GridSnapAmountScale_ == 0.0f))) { + Viewport->GridSnapAmountScale_ = 0.0f; + } + + ImGui::Separator(); + + if (ImGui::MenuItem("0.1", nullptr, (Viewport->GridSnapAmountScale_ == 0.1f))) { + Viewport->GridSnapAmountScale_ = 0.1f; + } + if (ImGui::MenuItem("0.25", nullptr, (Viewport->GridSnapAmountScale_ == 0.25f))) { + Viewport->GridSnapAmountScale_ = 0.25f; + } + if (ImGui::MenuItem("0.5", nullptr, (Viewport->GridSnapAmountScale_ == 0.5f))) { + Viewport->GridSnapAmountScale_ = 0.5f; + } + if (ImGui::MenuItem("0.75", nullptr, (Viewport->GridSnapAmountScale_ == 0.75f))) { + Viewport->GridSnapAmountScale_ = 0.75f; + } + if (ImGui::MenuItem("1.0", nullptr, (Viewport->GridSnapAmountScale_ == 1.0f))) { + Viewport->GridSnapAmountScale_ = 1.0f; + } + + ImGui::EndMenu(); + } + + + ImGui::EndMenu(); + } + + // Game Control Menu + if (ImGui::BeginMenu("Run")) { + + // Run Option + if (ImGui::MenuItem("Run With Editor", "F5")) { + *IsEditorMode_ = false; + *GameStartTime_ = glfwGetTime(); + } + + // Stop Option + if (ImGui::MenuItem("Stop", "Escape")) { + *IsEditorMode_ = !IsEditorMode_; + } + + ImGui::EndMenu(); + } + + ImGui::EndMenuBar(); + } + + + // Keybinds + if (ImGui::IsKeyPressed(GLFW_KEY_F5)) { + *IsEditorMode_ = false; + *GameStartTime_ = glfwGetTime(); + } + if (ImGui::IsKeyPressed(GLFW_KEY_ESCAPE)) { + *IsEditorMode_ = true; + } + + +} \ No newline at end of file diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_ViewportMenu.h b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_ViewportMenu.h new file mode 100644 index 0000000000..446ecd31b7 --- /dev/null +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_ViewportMenu.h @@ -0,0 +1,73 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#pragma once + + +// Standard Libraries (BG convention: use <> instead of "") +#include +#include +#include + +// Third-Party Libraries (BG convention: use <> instead of "") +#include +#include +#include +#include + +#include +#include + + +// Internal Libraries (BG convention: use <> instead of "") +#include + +#include + +#include +#include +#include + + + +/** + * @brief This class renders any ui/Menu info onto the viewport as requested by the viewport struct. + * + */ +class ERS_CLASS_ViewportMenu { + +private: + + ERS_STRUCT_SystemUtils* SystemUtils_; /**>* Shaders_; /**>* Shaders); + + /** + * @brief Destroy the ers class viewportMenu object + * + */ + ~ERS_CLASS_ViewportMenu(); + + /** + * @brief Draw the Menu on the viewport pointer passed in. + * + * @param Viewport + */ + void DrawMenu(ERS_STRUCT_Viewport* Viewport); + +}; \ No newline at end of file diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_ViewportOverlay.cpp b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_ViewportOverlay.cpp new file mode 100644 index 0000000000..5da8b6ba54 --- /dev/null +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_ViewportOverlay.cpp @@ -0,0 +1,157 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#include + + +ERS_CLASS_ViewportOverlay::ERS_CLASS_ViewportOverlay(ERS_STRUCT_SystemUtils* SystemUtils, ERS_STRUCT_ProjectUtils* ProjectUtils) { + + SystemUtils_ = SystemUtils; + ProjectUtils_ = ProjectUtils; + + SystemUtils_->Logger_->Log("Initializing Viewport Overlay Subsystem", 5); + +} + + +ERS_CLASS_ViewportOverlay::~ERS_CLASS_ViewportOverlay() { + + SystemUtils_->Logger_->Log("Viewport Overlay Subsystem Destructor Invoked", 6); + +} + + +void ERS_CLASS_ViewportOverlay::DrawOverlay(ERS_STRUCT_Viewport* Viewport) { + + + // Draw Scene Info Overlay + if (Viewport->ShowSceneInfo_) { + + // Generate Info + unsigned long NumModels = ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_]->Models.size(); + unsigned long NumVerts = 0; + unsigned long NumIndices = 0; + unsigned long NumTextures = 0; + unsigned long TotalModels = 0; + unsigned long InstancedModels = 0; + + for (unsigned long i = 0; i < NumModels; i++) { + if (ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_]->Models[i]->Enabled) { + NumVerts += ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_]->Models[i]->TotalVertices_; + NumIndices += ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_]->Models[i]->TotalIndices_; + NumTextures += ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_]->Models[i]->OpenGLTextureIDs_.size(); + TotalModels ++; + if (!ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_]->Models[i]->IsTemplateModel) { + InstancedModels++; + } + } + } + + std::string SceneMessage = std::string("Scene: ") + std::to_string(TotalModels) + std::string(" Models (") + std::to_string(InstancedModels) + + std::string(" Instanced Models, ") + std::to_string(TotalModels - InstancedModels) + std::string(" Template Models), ") + std::to_string(NumVerts) + + std::string(" Verts, ") + std::to_string(NumIndices) + std::string(" Indices, ") + std::to_string(NumTextures) + std::string(" Textures"); + + ImGui::TextColored(ImVec4(0.25f, 1.0f, 0.25f, 1.0f), "%s", SceneMessage.c_str()); + + + } + + + // Show System Resources Info Overlay + if (Viewport->ShowResourceInfo_) { + + // Generate Info + unsigned long NumModels = ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_]->Models.size(); + unsigned long InMemoryVerts = 0; + unsigned long InMemoryIndices = 0; + + for (unsigned long i = 0; i < NumModels; i++) { + if (ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_]->Models[i]->IsTemplateModel) { + InMemoryVerts += ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_]->Models[i]->TotalVertices_; + InMemoryIndices += ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_]->Models[i]->TotalIndices_; + } + } + + + std::string ResourcesMessages = std::to_string(InMemoryVerts) + std::string(" Verts In Memory, ") + std::to_string(InMemoryIndices) + std::string(" Indices In Memory"); + ImGui::TextColored(ImVec4(0.25f, 1.0f, 0.25f, 1.0f), "%s", ResourcesMessages.c_str()); + + } + + // Show Loading Time Info Overlay + if (Viewport->ShowLoadingTimeInfo_) { + + // Generate Info + unsigned long NumModels = ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_]->Models.size(); + double LongestLoadingTime = 0; + double ShortestLoadingTime = 65535; + double AverageLoadingTime = 0; + + for (unsigned long i = 0; i < NumModels; i++) { + if (ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_]->Models[i]->TotalLoadingTime_ > LongestLoadingTime) { + LongestLoadingTime = ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_]->Models[i]->TotalLoadingTime_; + } + if (ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_]->Models[i]->TotalLoadingTime_ < ShortestLoadingTime && ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_]->Models[i]->TotalLoadingTime_ != 0.0f) { + ShortestLoadingTime = ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_]->Models[i]->TotalLoadingTime_; + } + AverageLoadingTime += ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_]->Models[i]->TotalLoadingTime_; + } + + AverageLoadingTime /= NumModels; + + std::string LoadingTimeMessage = std::string("Asset Loading Times | Average: ") + std::to_string(AverageLoadingTime) + std::string(" Seconds, Shortest: ") + std::to_string(ShortestLoadingTime) + std::string(" Seconds, Longest: ") + std::to_string(LongestLoadingTime) + std::string(" Seconds"); + ImGui::TextColored(ImVec4(0.25f, 1.0f, 0.25f, 1.0f), "%s", LoadingTimeMessage.c_str()); + + } + + // Show/Hide Light Debug Info Overlay + if (Viewport->ShowLightInfo_) { + + + // Initialize + ERS_STRUCT_Scene* ActiveScene = ProjectUtils_->SceneManager_->Scenes_[ProjectUtils_->SceneManager_->ActiveScene_].get(); + + // Get Lighting Information + unsigned int NumDirectionalDepthMaps = 0; + unsigned int NumSpotDepthMaps = 0; + unsigned int NumPointDepthMaps = 0; + + unsigned int NumDirectionalLights = 0; + unsigned int NumSpotLights = 0; + unsigned int NumPointLights = 0; + + for (unsigned int i = 0; i < ActiveScene->DirectionalLights.size(); i++) { + if (ActiveScene->DirectionalLights[i]->DepthMap.Initialized) { + NumDirectionalDepthMaps++; + } + NumDirectionalLights++; + } + + for (unsigned int i = 0; i < ActiveScene->SpotLights.size(); i++) { + if (ActiveScene->SpotLights[i]->DepthMap.Initialized) { + NumSpotDepthMaps++; + } + NumSpotLights++; + } + + for (unsigned int i = 0; i < ActiveScene->PointLights.size(); i++) { + if (ActiveScene->PointLights[i]->DepthMap.Initialized) { + NumPointDepthMaps++; + } + NumPointLights++; + } + + std::string LabelText = std::to_string(NumDirectionalLights) + std::string(" Directional Lights (") + std::to_string(NumDirectionalDepthMaps) + + std::string(" Have Depth Maps) ") + std::to_string(NumSpotLights) + std::string(" Spot Lights (") + std::to_string(NumSpotDepthMaps) + + std::string(" Have Depth Maps) ") + std::to_string(NumPointLights) + std::string(" Point Lights (") + std::to_string(NumPointDepthMaps) + + std::string(" Have Depth Maps)"); + ImGui::TextColored(ImVec4(0.25f, 1.0f, 0.25f, 1.0f), "%s", LabelText.c_str()); + + + } + + + + +} \ No newline at end of file diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_ViewportOverlay.h b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_ViewportOverlay.h new file mode 100644 index 0000000000..9e0bcc8838 --- /dev/null +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_ViewportOverlay.h @@ -0,0 +1,68 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#pragma once + + +// Standard Libraries (BG convention: use <> instead of "") +#include +#include +#include + +// Third-Party Libraries (BG convention: use <> instead of "") +#include +#include +#include +#include + +#include +#include + + +// Internal Libraries (BG convention: use <> instead of "") +#include + +#include + +#include +#include +#include + + + +/** + * @brief This class renders any ui/overlay info onto the viewport as requested by the viewport struct. + * + */ +class ERS_CLASS_ViewportOverlay { + +private: + + ERS_STRUCT_SystemUtils* SystemUtils_; /**Logger_->Log("Initializing OpenGL", 5); - InitializeOpenGL(); - SystemUtils_->Logger_->Log("Initializing MeshRenderer Class", 5); MeshRenderer_ = std::make_unique(SystemUtils_); + SystemUtils_->Logger_->Log("Initializing Viewport Overlay Subsystem", 5); + ViewportOverlay_ = std::make_unique(SystemUtils_, ProjectUtils_); + + SystemUtils_->Logger_->Log("Initializing Viewport Menu Subsystem", 5); + ViewportMenu_ = std::make_unique(SystemUtils_, ProjectUtils_, &GameStartTime_, &IsEditorMode_, &Shaders_); + + ShadowMaps_ = std::make_unique(SystemUtils_, ProjectUtils_, MeshRenderer_.get()); // DEFAULT MODES, CHANGE THIS LATER! -------------------------------- IsEditorMode_ = true; @@ -45,30 +49,12 @@ ERS_CLASS_VisualRenderer::~ERS_CLASS_VisualRenderer() { } -void ERS_CLASS_VisualRenderer::SetShader(std::shared_ptr Shader, int ID) { - - Shaders_[ID] = Shader; - -} void ERS_CLASS_VisualRenderer::SetDefaultShader(int ShaderID) { DefaultShader_ = ShaderID; } -void ERS_CLASS_VisualRenderer::InitializeOpenGL() { - - // Setup GLAD - if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { - SystemUtils_->Logger_->Log("Failed To Initialize GLAD", 10); - } - - // Setup OpenGL For Blending (For Transparency Issues) - glEnable(GL_DEPTH_TEST); - glEnable(GL_BLEND); - -} - void ERS_CLASS_VisualRenderer::SetOpenGLDefaults(ERS_STRUCT_OpenGLDefaults* Defaults) { OpenGLDefaults_ = Defaults; @@ -77,7 +63,8 @@ void ERS_CLASS_VisualRenderer::SetOpenGLDefaults(ERS_STRUCT_OpenGLDefaults* Defa void ERS_CLASS_VisualRenderer::UpdateViewports(float DeltaTime, ERS_CLASS_SceneManager* SceneManager) { - + // Set Depth Shader For Shadow System + DepthMapShader_ = Shaders_[ERS_FUNCTION_FindShaderByName(std::string("_DepthMap"), &Shaders_)].get(); // Close Any Viewports That Aren't All Open @@ -92,6 +79,9 @@ void ERS_CLASS_VisualRenderer::UpdateViewports(float DeltaTime, ERS_CLASS_SceneM } + // Generate Shadows + //DepthMapShader_ = Shaders_[ERS_FUNCTION_FindShaderByName(std::string("Preview Shader"), &Shaders_)].get(); + ShadowMaps_->UpdateShadowMaps(DepthMapShader_); // Setup Vars @@ -285,8 +275,7 @@ void ERS_CLASS_VisualRenderer::UpdateViewport(int Index, ERS_CLASS_SceneManager* if (ImGui::IsKeyPressed(GLFW_KEY_GRAVE_ACCENT)) { Viewports_[Index]->MenuEnabled = !Viewports_[Index]->MenuEnabled; } - DrawViewportMenu(Index, SceneManager); - + ViewportMenu_->DrawMenu(Viewports_[Index].get()); // Calculate Window Position @@ -378,7 +367,8 @@ void ERS_CLASS_VisualRenderer::UpdateViewport(int Index, ERS_CLASS_SceneManager* Shaders_[ShaderIndex]->SetFloat("Exposure_", Viewports_[Index]->Exposure_); Shaders_[ShaderIndex]->SetFloat("Gamma_", Viewports_[Index]->Gamma_); - + + // Update Cursor If Selection Changed if (SceneManager->Scenes_[SceneManager->ActiveScene_]->HasSelectionChanged && DrawCursor) { @@ -424,9 +414,21 @@ void ERS_CLASS_VisualRenderer::UpdateViewport(int Index, ERS_CLASS_SceneManager* + + + + glUniform1i(glGetUniformLocation(Shaders_[ShaderIndex]->ShaderProgram_, "DepthMapArray"), 8); + glActiveTexture(GL_TEXTURE8); + glBindTexture(GL_TEXTURE_2D_ARRAY, ShadowMaps_->ERS_CLASS_DepthMaps_->DepthTextureArrayID_); + + + // Render - //SceneManager->Render(OpenGLDefaults_, Shaders_[ShaderIndex]); - MeshRenderer_->RenderScene(SceneManager->Scenes_[SceneManager->ActiveScene_].get(), OpenGLDefaults_, Shaders_[ShaderIndex]); + + //MeshRenderer_->RenderSceneNoTextures(SceneManager->Scenes_[SceneManager->ActiveScene_].get(), Shaders_[ShaderIndex].get()); + MeshRenderer_->RenderScene(SceneManager->Scenes_[SceneManager->ActiveScene_].get(), OpenGLDefaults_, Shaders_[ShaderIndex].get()); + + if (Viewports_[Index]->GridEnabled) { Viewports_[Index]->Grid->DrawGrid(view, projection, Viewports_[Index]->Camera->Position_); } @@ -482,11 +484,11 @@ void ERS_CLASS_VisualRenderer::UpdateViewport(int Index, ERS_CLASS_SceneManager* } - DrawViewportOverlay(Index, SceneManager); + ViewportOverlay_->DrawOverlay(Viewports_[Index].get()); } - + ImGui::End(); } @@ -529,20 +531,6 @@ void ERS_CLASS_VisualRenderer::CreateViewport() { } -long ERS_CLASS_VisualRenderer::FindShaderIndex(std::string Name) { - - long Index = 0; - for (unsigned long i = 0; i < Shaders_.size(); i++) { - if (Shaders_[i]->InternalName == Name) { - Index = i; - break; - } - } - - return Index; - -} - void ERS_CLASS_VisualRenderer::CreateViewport(std::string ViewportName) { @@ -557,8 +545,8 @@ void ERS_CLASS_VisualRenderer::CreateViewport(std::string ViewportName) { // Populate Viewport Struct 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->Grid = std::make_unique(SystemUtils_, Shaders_[ERS_FUNCTION_FindShaderByName(std::string("_Grid"), &Shaders_)].get()); + Viewport->LightIconRenderer = std::make_unique(OpenGLDefaults_, SystemUtils_, Shaders_[ERS_FUNCTION_FindShaderByName(std::string("_LightIcon"), &Shaders_)].get()); //Set TO Shader 19 For Billboard Shader, Temp. Disabled As It Doesn't Work ATM Viewport->Name = ViewportName; Viewport->Width = 1; @@ -568,11 +556,11 @@ void ERS_CLASS_VisualRenderer::CreateViewport(std::string ViewportName) { Viewport->Enabled = std::make_unique(true); + // Create Input Processor SystemUtils_->Logger_->Log("Creating New Input Processor", 4); Viewport->Processor = std::make_unique(Viewport->Camera.get(), Window_); - // Create Framebuffer unsigned int FramebufferObject; SystemUtils_->Logger_->Log("Creating Framebuffer Object", 4); @@ -644,7 +632,7 @@ void ERS_CLASS_VisualRenderer::UpdateShader(int ShaderIndex, float DeltaTime, in // Get Pointer to Shader - std::shared_ptr ActiveShader = Shaders_[ShaderIndex]; + ERS_STRUCT_Shader* ActiveShader = Shaders_[ShaderIndex].get(); // Set Metadata Params float Time = glfwGetTime(); @@ -684,9 +672,13 @@ void ERS_CLASS_VisualRenderer::UpdateShader(int ShaderIndex, float DeltaTime, in std::string UniformName = std::string("DirectionalLights[") + std::to_string(i) + std::string("]"); - ActiveShader->SetVec3((UniformName + std::string(".Direction")).c_str(), ActiveScene->DirectionalLights[i]->Rot); + // Re-Do Rotation + ActiveShader->SetVec3((UniformName + std::string(".Direction")).c_str(), ERS_FUNCTION_ConvertRotationToFrontVector(ActiveScene->DirectionalLights[i]->Rot)); ActiveShader->SetVec3((UniformName + std::string(".Color")).c_str(), ActiveScene->DirectionalLights[i]->Color); ActiveShader->SetFloat((UniformName + std::string(".Intensity")).c_str(), ActiveScene->DirectionalLights[i]->Intensity); + + ActiveShader->SetInt((UniformName + std::string(".DepthMapIndex")).c_str(), ActiveScene->DirectionalLights[i]->DepthMap.DepthMapTextureIndex); + ActiveShader->SetMat4((UniformName + std::string(".LightSpaceMatrix")).c_str(), ActiveScene->DirectionalLights[i]->LightSpaceMatrix); } @@ -701,6 +693,9 @@ void ERS_CLASS_VisualRenderer::UpdateShader(int ShaderIndex, float DeltaTime, in ActiveShader->SetFloat((UniformName + std::string(".Intensity")).c_str(), ActiveScene->PointLights[i]->Intensity); ActiveShader->SetVec3((UniformName + std::string(".Color")).c_str(), ActiveScene->PointLights[i]->Color); + ActiveShader->SetInt((UniformName + std::string(".DepthMapIndex")).c_str(), ActiveScene->PointLights[i]->DepthMap.DepthMapTextureIndex); + ActiveShader->SetMat4((UniformName + std::string(".LightSpaceMatrix")).c_str(), ActiveScene->PointLights[i]->LightSpaceMatrix); + } @@ -711,484 +706,25 @@ void ERS_CLASS_VisualRenderer::UpdateShader(int ShaderIndex, float DeltaTime, in std::string UniformName = std::string("SpotLights[") + std::to_string(i) + std::string("]"); + // Re-Do Rotation 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->SetVec3((UniformName + std::string(".Direction")).c_str(), ERS_FUNCTION_ConvertRotationToFrontVector(ActiveScene->SpotLights[i]->Rot)); 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(".Color")).c_str(), ActiveScene->SpotLights[i]->Color); - } - - - - ActiveShader->SetFloat("Shinyness", 32.0f); - - -} - -void ERS_CLASS_VisualRenderer::DrawViewportMenu(int Index, ERS_CLASS_SceneManager* SceneManager) { - - // Menu Bar - if (ImGui::BeginMenuBar()) { - - - // Viewport Cube Controls - if (ImGui::BeginMenu("Controls")) { - - // Draw Controls - ImGui::MenuItem("Scene Info Overlay", nullptr, &Viewports_[Index]->ShowSceneInfo_); - ImGui::MenuItem("System Resources Overlay", nullptr, &Viewports_[Index]->ShowResourceInfo_); - ImGui::MenuItem("Loading Time Overlay", nullptr, &Viewports_[Index]->ShowLoadingTimeInfo_); - - ImGui::Separator(); - - ImGui::MenuItem("Rotation Indicator", nullptr, &Viewports_[Index]->ShowCube); - ImGui::MenuItem("Gizmo", nullptr, &Viewports_[Index]->GizmoEnabled); - ImGui::MenuItem("Grid", nullptr, &Viewports_[Index]->GridEnabled); - ImGui::MenuItem("Light Icons", nullptr, &Viewports_[Index]->LightIcons); - - ImGui::Separator(); - - ImGui::MenuItem("Gamma Correction", nullptr, &Viewports_[Index]->GammaCorrection); - ImGui::MenuItem("HDR", nullptr, &Viewports_[Index]->HDREnabled_); - - - ImGui::EndMenu(); - } - - - // Shader Control Menu - if(ImGui::BeginMenu("Shader")) { - - // Draw Selectable Menu Showing Active Viewport Shader - for (int i = 0; (long)i < (long)Shaders_.size(); i++) { - - if (strcmp(Shaders_[i]->DisplayName.substr(0, 1).c_str(), "_")) { - if (ImGui::Selectable(Shaders_[i]->DisplayName.c_str(), i == Viewports_[Index]->ShaderIndex)) { - Viewports_[Index]->ShaderIndex = i; - } - } - - } - - ImGui::EndMenu(); - } - - // Grid Control Menu - if (ImGui::BeginMenu("Grid")) { - - // Grid Scale Submenu - if (ImGui::BeginMenu("Scale")) { - - if (ImGui::MenuItem("0.0625 Units", nullptr, (Viewports_[Index]->Grid->GridSize_ == 0.00125f))) { - Viewports_[Index]->Grid->GridSize_ = 0.00125f; - } - - if (ImGui::MenuItem("0.125 Units", nullptr, (Viewports_[Index]->Grid->GridSize_ == 0.0025f))) { - Viewports_[Index]->Grid->GridSize_ = 0.0025f; - } - - if (ImGui::MenuItem("0.25 Units", nullptr, (Viewports_[Index]->Grid->GridSize_ == 0.005f))) { - Viewports_[Index]->Grid->GridSize_ = 0.005f; - } - - if (ImGui::MenuItem("0.5 Units", nullptr, (Viewports_[Index]->Grid->GridSize_ == 0.01f))) { - Viewports_[Index]->Grid->GridSize_ = 0.01f; - } - - if (ImGui::MenuItem("1 Unit", nullptr, (Viewports_[Index]->Grid->GridSize_ == 0.02f))) { - Viewports_[Index]->Grid->GridSize_ = 0.02f; - } - - if (ImGui::MenuItem("2.5 Units", nullptr, (Viewports_[Index]->Grid->GridSize_ == 0.05f))) { - Viewports_[Index]->Grid->GridSize_ = 0.05f; - } - - if (ImGui::MenuItem("5 Units", nullptr, (Viewports_[Index]->Grid->GridSize_ == 0.1f))) { - Viewports_[Index]->Grid->GridSize_ = 0.1f; - } - - ImGui::EndMenu(); - } - - // Line Thickness Submenu - if (ImGui::BeginMenu("Line Thickness")) { - - if (ImGui::MenuItem("0.5%", nullptr, (Viewports_[Index]->Grid->GridLineThickness_ == 0.005f))) { - Viewports_[Index]->Grid->GridLineThickness_ = 0.005f; - } - - if (ImGui::MenuItem("1%", nullptr, (Viewports_[Index]->Grid->GridLineThickness_ == 0.01f))) { - Viewports_[Index]->Grid->GridLineThickness_ = 0.01f; - } - - if (ImGui::MenuItem("2%", nullptr, (Viewports_[Index]->Grid->GridLineThickness_ == 0.02f))) { - Viewports_[Index]->Grid->GridLineThickness_ = 0.02f; - } - - if (ImGui::MenuItem("3%", nullptr, (Viewports_[Index]->Grid->GridLineThickness_ == 0.03f))) { - Viewports_[Index]->Grid->GridLineThickness_ = 0.03f; - } - - if (ImGui::MenuItem("4%", nullptr, (Viewports_[Index]->Grid->GridLineThickness_ == 0.04f))) { - Viewports_[Index]->Grid->GridLineThickness_ = 0.04f; - } - - ImGui::EndMenu(); - } - - // Color Scheme - if (ImGui::BeginMenu("Colors")) { - - // Base Color - if (ImGui::BeginMenu("Base")) { - - - if (ImGui::MenuItem("White")) { - Viewports_[Index]->Grid->GridColor_ = glm::vec3(1.0f); - } - - if (ImGui::MenuItem("Light Grey")) { - Viewports_[Index]->Grid->GridColor_ = glm::vec3(0.75f); - } - - if (ImGui::MenuItem("Grey")) { - Viewports_[Index]->Grid->GridColor_ = glm::vec3(0.5f); - } - - if (ImGui::MenuItem("Dark Grey")) { - Viewports_[Index]->Grid->GridColor_ = glm::vec3(0.25f); - } - - if (ImGui::MenuItem("Very Dark Grey")) { - Viewports_[Index]->Grid->GridColor_ = glm::vec3(0.1f); - } - - if (ImGui::MenuItem("Black")) { - Viewports_[Index]->Grid->GridColor_ = glm::vec3(0.0f); - } - - ImGui::EndMenu(); - } - - // X Axis Color - if (ImGui::BeginMenu("X Axis")) { - - - if (ImGui::MenuItem("Red")) { - Viewports_[Index]->Grid->GridColorX_ = glm::vec3(1.0f, 0.0f, 0.0f); - } - - if (ImGui::MenuItem("Green")) { - Viewports_[Index]->Grid->GridColorX_ = glm::vec3(0.0f, 1.0f, 0.0f); - } - - if (ImGui::MenuItem("Blue")) { - Viewports_[Index]->Grid->GridColorX_ = glm::vec3(0.0f, 0.0f, 1.0f); - } - - if (ImGui::MenuItem("Dark Grey")) { - Viewports_[Index]->Grid->GridColorX_ = glm::vec3(0.25f); - } - - if (ImGui::MenuItem("Very Dark Grey")) { - Viewports_[Index]->Grid->GridColorX_ = glm::vec3(0.1f); - } - - if (ImGui::MenuItem("Black")) { - Viewports_[Index]->Grid->GridColorX_ = glm::vec3(0.0f); - } - - ImGui::EndMenu(); - } - - // Z Axis Color - if (ImGui::BeginMenu("Z Axis")) { - - - if (ImGui::MenuItem("Red")) { - Viewports_[Index]->Grid->GridColorZ_ = glm::vec3(1.0f, 0.0f, 0.0f); - } - - if (ImGui::MenuItem("Green")) { - Viewports_[Index]->Grid->GridColorZ_ = glm::vec3(0.0f, 1.0f, 0.0f); - } - - if (ImGui::MenuItem("Blue")) { - Viewports_[Index]->Grid->GridColorZ_ = glm::vec3(0.0f, 0.0f, 1.0f); - } - - if (ImGui::MenuItem("Dark Grey")) { - Viewports_[Index]->Grid->GridColorZ_ = glm::vec3(0.25f); - } - - if (ImGui::MenuItem("Very Dark Grey")) { - Viewports_[Index]->Grid->GridColorZ_ = glm::vec3(0.1f); - } - - if (ImGui::MenuItem("Black")) { - Viewports_[Index]->Grid->GridColorZ_ = glm::vec3(0.0f); - } - - ImGui::EndMenu(); - } - - - ImGui::EndMenu(); - } - - - ImGui::EndMenu(); - } - - - // Add Items Menu - if (ImGui::BeginMenu("Add")) { - - if (ImGui::BeginMenu("Light")) { - - if (ImGui::MenuItem("Point Light")) { - SceneManager->AddPointLight(); - } - - if (ImGui::MenuItem("Spot Light")) { - SceneManager->AddSpotLight(); - } - - if (ImGui::MenuItem("Directional Light")) { - SceneManager->AddDirectionalLight(); - } - - ImGui::EndMenu(); - } - - if (ImGui::MenuItem("Script")) { - - ERS_STRUCT_Script NewScript; - NewScript.AssetID = SystemUtils_->ERS_IOSubsystem_->AllocateAssetID(); - NewScript.Code_ = "# ERS Script\n"; - NewScript.Name_ = "Untitled Script"; - ProjectUtils_->ProjectManager_->Project_.Scripts.push_back(NewScript); - - } - - - ImGui::EndMenu(); - } - - - // Grid Snapping Control Menu - if (ImGui::BeginMenu("Grid Snapping")) { - - if (ImGui::BeginMenu("Translation")) { - - if (ImGui::MenuItem("Disabled", nullptr, (Viewports_[Index]->GridSnapAmountTranslate_ == 0.0f))) { - Viewports_[Index]->GridSnapAmountTranslate_ = 0.0f; - } - - ImGui::Separator(); - - if (ImGui::MenuItem("0.1", nullptr, (Viewports_[Index]->GridSnapAmountTranslate_ == 0.1f))) { - Viewports_[Index]->GridSnapAmountTranslate_ = 0.1f; - } - if (ImGui::MenuItem("0.25", nullptr, (Viewports_[Index]->GridSnapAmountTranslate_ == 0.25f))) { - Viewports_[Index]->GridSnapAmountTranslate_ = 0.25f; - } - if (ImGui::MenuItem("0.5", nullptr, (Viewports_[Index]->GridSnapAmountTranslate_ == 0.5f))) { - Viewports_[Index]->GridSnapAmountTranslate_ = 0.5f; - } - if (ImGui::MenuItem("0.75", nullptr, (Viewports_[Index]->GridSnapAmountTranslate_ == 0.75f))) { - Viewports_[Index]->GridSnapAmountTranslate_ = 0.75f; - } - if (ImGui::MenuItem("1.0", nullptr, (Viewports_[Index]->GridSnapAmountTranslate_ == 1.0f))) { - Viewports_[Index]->GridSnapAmountTranslate_ = 1.0f; - } - - ImGui::EndMenu(); - } - - - if (ImGui::BeginMenu("Rotate")) { - - if (ImGui::MenuItem("Disabled", nullptr, (Viewports_[Index]->GridSnapAmountRotate_ == 0.0f))) { - Viewports_[Index]->GridSnapAmountRotate_ = 0.0f; - } - - ImGui::Separator(); - - if (ImGui::MenuItem("1", nullptr, (Viewports_[Index]->GridSnapAmountRotate_ == 1.0f))) { - Viewports_[Index]->GridSnapAmountRotate_ = 1.0f; - } - if (ImGui::MenuItem("5", nullptr, (Viewports_[Index]->GridSnapAmountRotate_ == 5.0f))) { - Viewports_[Index]->GridSnapAmountRotate_ = 5.0f; - } - if (ImGui::MenuItem("10", nullptr, (Viewports_[Index]->GridSnapAmountRotate_ == 10.0f))) { - Viewports_[Index]->GridSnapAmountRotate_ = 10.0f; - } - if (ImGui::MenuItem("25", nullptr, (Viewports_[Index]->GridSnapAmountRotate_ == 25.0f))) { - Viewports_[Index]->GridSnapAmountRotate_ = 25.0f; - } - if (ImGui::MenuItem("45", nullptr, (Viewports_[Index]->GridSnapAmountRotate_ == 45.0f))) { - Viewports_[Index]->GridSnapAmountRotate_ = 45.0f; - } - if (ImGui::MenuItem("90", nullptr, (Viewports_[Index]->GridSnapAmountRotate_ == 90.0f))) { - Viewports_[Index]->GridSnapAmountRotate_ = 90.0f; - } - - ImGui::EndMenu(); - } - - - - if (ImGui::BeginMenu("Scale")) { - - if (ImGui::MenuItem("Disabled", nullptr, (Viewports_[Index]->GridSnapAmountScale_ == 0.0f))) { - Viewports_[Index]->GridSnapAmountScale_ = 0.0f; - } - - ImGui::Separator(); - - if (ImGui::MenuItem("0.1", nullptr, (Viewports_[Index]->GridSnapAmountScale_ == 0.1f))) { - Viewports_[Index]->GridSnapAmountScale_ = 0.1f; - } - if (ImGui::MenuItem("0.25", nullptr, (Viewports_[Index]->GridSnapAmountScale_ == 0.25f))) { - Viewports_[Index]->GridSnapAmountScale_ = 0.25f; - } - if (ImGui::MenuItem("0.5", nullptr, (Viewports_[Index]->GridSnapAmountScale_ == 0.5f))) { - Viewports_[Index]->GridSnapAmountScale_ = 0.5f; - } - if (ImGui::MenuItem("0.75", nullptr, (Viewports_[Index]->GridSnapAmountScale_ == 0.75f))) { - Viewports_[Index]->GridSnapAmountScale_ = 0.75f; - } - if (ImGui::MenuItem("1.0", nullptr, (Viewports_[Index]->GridSnapAmountScale_ == 1.0f))) { - Viewports_[Index]->GridSnapAmountScale_ = 1.0f; - } - - ImGui::EndMenu(); - } - - - ImGui::EndMenu(); - } - - // Game Control Menu - if (ImGui::BeginMenu("Run")) { - - // Run Option - if (ImGui::MenuItem("Run With Editor", "F5")) { - IsEditorMode_ = false; - GameStartTime_ = glfwGetTime(); - } - - // Stop Option - if (ImGui::MenuItem("Stop", "Escape")) { - IsEditorMode_ = !IsEditorMode_; - } - - ImGui::EndMenu(); - } - - ImGui::EndMenuBar(); - } - - - // Keybinds - if (ImGui::IsKeyPressed(GLFW_KEY_F5)) { - IsEditorMode_ = false; - GameStartTime_ = glfwGetTime(); - } - if (ImGui::IsKeyPressed(GLFW_KEY_ESCAPE)) { - IsEditorMode_ = true; - } - -} - -void ERS_CLASS_VisualRenderer::DrawViewportOverlay(int Index, ERS_CLASS_SceneManager* SceneManager) { - - // Draw Scene Info Overlay - if (Viewports_[Index]->ShowSceneInfo_) { - - // Generate Info - unsigned long NumModels = SceneManager->Scenes_[SceneManager->ActiveScene_]->Models.size(); - unsigned long NumVerts = 0; - unsigned long NumIndices = 0; - unsigned long NumTextures = 0; - unsigned long TotalModels = 0; - unsigned long InstancedModels = 0; - - for (unsigned long i = 0; i < NumModels; i++) { - if (SceneManager->Scenes_[SceneManager->ActiveScene_]->Models[i]->Enabled) { - NumVerts += SceneManager->Scenes_[SceneManager->ActiveScene_]->Models[i]->TotalVertices_; - NumIndices += SceneManager->Scenes_[SceneManager->ActiveScene_]->Models[i]->TotalIndices_; - NumTextures += SceneManager->Scenes_[SceneManager->ActiveScene_]->Models[i]->OpenGLTextureIDs_.size(); - TotalModels ++; - if (!SceneManager->Scenes_[SceneManager->ActiveScene_]->Models[i]->IsTemplateModel) { - InstancedModels++; - } - } - } - - std::string SceneMessage = std::string("Scene: ") + std::to_string(TotalModels) + std::string(" Models (") + std::to_string(InstancedModels) - + std::string(" Instanced Models, ") + std::to_string(TotalModels - InstancedModels) + std::string(" Template Models), ") + std::to_string(NumVerts) - + std::string(" Verts, ") + std::to_string(NumIndices) + std::string(" Indices, ") + std::to_string(NumTextures) + std::string(" Textures"); - - ImGui::TextColored(ImVec4(0.25f, 1.0f, 0.25f, 1.0f), "%s", SceneMessage.c_str()); - - - } - - - // Show System Resources Info Overlay - if (Viewports_[Index]->ShowResourceInfo_) { - - // Generate Info - unsigned long NumModels = SceneManager->Scenes_[SceneManager->ActiveScene_]->Models.size(); - unsigned long InMemoryVerts = 0; - unsigned long InMemoryIndices = 0; - - for (unsigned long i = 0; i < NumModels; i++) { - if (SceneManager->Scenes_[SceneManager->ActiveScene_]->Models[i]->IsTemplateModel) { - InMemoryVerts += SceneManager->Scenes_[SceneManager->ActiveScene_]->Models[i]->TotalVertices_; - InMemoryIndices += SceneManager->Scenes_[SceneManager->ActiveScene_]->Models[i]->TotalIndices_; - } - } - - - std::string ResourcesMessages = std::to_string(InMemoryVerts) + std::string(" Verts In Memory, ") + std::to_string(InMemoryIndices) + std::string(" Indices In Memory"); - ImGui::TextColored(ImVec4(0.25f, 1.0f, 0.25f, 1.0f), "%s", ResourcesMessages.c_str()); - - } - - // Show Loading Time Info Overlay - if (Viewports_[Index]->ShowLoadingTimeInfo_) { - - // Generate Info - unsigned long NumModels = SceneManager->Scenes_[SceneManager->ActiveScene_]->Models.size(); - double LongestLoadingTime = 0; - double ShortestLoadingTime = 65535; - double AverageLoadingTime = 0; - - for (unsigned long i = 0; i < NumModels; i++) { - if (SceneManager->Scenes_[SceneManager->ActiveScene_]->Models[i]->TotalLoadingTime_ > LongestLoadingTime) { - LongestLoadingTime = SceneManager->Scenes_[SceneManager->ActiveScene_]->Models[i]->TotalLoadingTime_; - } - if (SceneManager->Scenes_[SceneManager->ActiveScene_]->Models[i]->TotalLoadingTime_ < ShortestLoadingTime && SceneManager->Scenes_[SceneManager->ActiveScene_]->Models[i]->TotalLoadingTime_ != 0.0f) { - ShortestLoadingTime = SceneManager->Scenes_[SceneManager->ActiveScene_]->Models[i]->TotalLoadingTime_; - } - AverageLoadingTime += SceneManager->Scenes_[SceneManager->ActiveScene_]->Models[i]->TotalLoadingTime_; - } - - AverageLoadingTime /= NumModels; - - std::string LoadingTimeMessage = std::string("Asset Loading Times | Average: ") + std::to_string(AverageLoadingTime) + std::string(" Seconds, Shortest: ") + std::to_string(ShortestLoadingTime) + std::string(" Seconds, Longest: ") + std::to_string(LongestLoadingTime) + std::string(" Seconds"); - ImGui::TextColored(ImVec4(0.25f, 1.0f, 0.25f, 1.0f), "%s", LoadingTimeMessage.c_str()); + ActiveShader->SetInt((UniformName + std::string(".DepthMapIndex")).c_str(), ActiveScene->SpotLights[i]->DepthMap.DepthMapTextureIndex); + ActiveShader->SetMat4((UniformName + std::string(".LightSpaceMatrix")).c_str(), ActiveScene->SpotLights[i]->LightSpaceMatrix); + } + ActiveShader->SetFloat("Shinyness", 32.0f); } + diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_VisualRenderer.h b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_VisualRenderer.h index 01f7bf0487..92acd91a10 100644 --- a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_VisualRenderer.h +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_CLASS_VisualRenderer.h @@ -24,10 +24,12 @@ #include #include #include -#include #include #include #include +#include +#include +#include #include #include @@ -43,6 +45,8 @@ #include #include +#include +#include /** * @brief Handles viewport creation/deletion/rendering/updating. @@ -54,18 +58,25 @@ class ERS_CLASS_VisualRenderer { GLFWwindow *Window_; /** ShadowMaps_; /** MeshRenderer_; /** ViewportOverlay_; /** ViewportMenu_; /**> Viewports_; /**Pointer to struct of viewports*/ - std::map> Shaders_; /**> Shaders_; /** Shader, int ID); - + /** * @brief Set the Default Shader by index * diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_ConvertRotationToFrontVector.cpp b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_ConvertRotationToFrontVector.cpp new file mode 100644 index 0000000000..f4a9744b10 --- /dev/null +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_ConvertRotationToFrontVector.cpp @@ -0,0 +1,17 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#include + + +glm::vec3 ERS_FUNCTION_ConvertRotationToFrontVector(glm::vec3 Rotation) { + + glm::mat4 RotMatrix; + RotMatrix = glm::rotate(RotMatrix, glm::radians(Rotation[2]), glm::vec3(0, 0, 1)); + RotMatrix = glm::rotate(RotMatrix, glm::radians(Rotation[1]), glm::vec3(0, 1, 0)); + RotMatrix = glm::rotate(RotMatrix, glm::radians(Rotation[0]), glm::vec3(1, 0, 0)); + + return glm::vec3(RotMatrix[2][0], RotMatrix[2][1], RotMatrix[2][2]); + +} \ No newline at end of file diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_ConvertRotationToFrontVector.h b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_ConvertRotationToFrontVector.h new file mode 100644 index 0000000000..a564a9e87f --- /dev/null +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_ConvertRotationToFrontVector.h @@ -0,0 +1,25 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#pragma once + + +// Standard Libraries (BG convention: use <> instead of "") +#include +#include + +// Third-Party Libraries (BG convention: use <> instead of "") +#include +#include + +// Internal Libraries (BG convention: use <> instead of "") + + +/** + * @brief Converts the passed in rotation to the front vector. + * + * @param Rotation + * @return glm::vec3 + */ +glm::vec3 ERS_FUNCTION_ConvertRotationToFrontVector(glm::vec3 Rotation); \ No newline at end of file diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMesh.cpp b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMesh.cpp index ff7cb8d5f4..90198f398c 100644 --- a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMesh.cpp +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMesh.cpp @@ -5,7 +5,7 @@ #include -void ERS_FUNCTION_DrawMesh(ERS_STRUCT_Mesh* Mesh, ERS_STRUCT_OpenGLDefaults* OpenGLDefaults, std::shared_ptr Shader) { +void ERS_FUNCTION_DrawMesh(ERS_STRUCT_Mesh* Mesh, ERS_STRUCT_OpenGLDefaults* OpenGLDefaults, ERS_STRUCT_Shader* Shader) { Shader->SetMat4("model", Mesh->ModelMatrix); @@ -21,7 +21,7 @@ void ERS_FUNCTION_DrawMesh(ERS_STRUCT_Mesh* Mesh, ERS_STRUCT_OpenGLDefaults* Ope // Reset All Textures To Defaults - unsigned int ShaderProgram = Shader->ShaderProgram; + unsigned int ShaderProgram = Shader->ShaderProgram_; unsigned int ResetTexID = OpenGLDefaults->DefaultTexture_; ERS_FUNCTION_ResetMeshTexture("texture_ambient_occlusion1", 1, ShaderProgram, ResetTexID); ERS_FUNCTION_ResetMeshTexture("texture_diffuse1", 2, ShaderProgram, ResetTexID); @@ -72,25 +72,21 @@ void ERS_FUNCTION_DrawMesh(ERS_STRUCT_Mesh* Mesh, ERS_STRUCT_OpenGLDefaults* Ope Number = std::to_string(EmissiveHandle++); Type = 4; HasEmissive = true; - } else if(Name == "texture_height") { - Number = std::to_string(HeightHandle++); - Type = 5; - HasHeight = true; } else if(Name == "texture_metalness") { Number = std::to_string(MetalnessHandle++); - Type = 6; + Type = 5; HasMetalness = true; } else if(Name == "texture_normals") { Number = std::to_string(NormalsHandle++); - Type = 7; + Type = 6; HasNormals = true; } else if(Name == "texture_shininess") { Number = std::to_string(ShininessHandle++); - Type = 8; + Type = 7; HasShininess = true; } - glUniform1i(glGetUniformLocation(Shader->ShaderProgram, (Name + Number).c_str()), Type); + glUniform1i(glGetUniformLocation(Shader->ShaderProgram_, (Name + Number).c_str()), Type); // Bind Texture glActiveTexture(GL_TEXTURE0 + Type); @@ -98,6 +94,8 @@ void ERS_FUNCTION_DrawMesh(ERS_STRUCT_Mesh* Mesh, ERS_STRUCT_OpenGLDefaults* Ope } + + // Set Uniforms Shader->SetBool("HasAmbientOcclusion", HasAmbientOcclusion); Shader->SetBool("HasDiffuse", HasDiffuse); diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMesh.h b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMesh.h index 6d4f4b3d8c..c823265541 100644 --- a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMesh.h +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMesh.h @@ -28,4 +28,4 @@ * @param OpenGLDefaults * @param Shader */ -void ERS_FUNCTION_DrawMesh(ERS_STRUCT_Mesh* Mesh, ERS_STRUCT_OpenGLDefaults* OpenGLDefaults, std::shared_ptr Shader); \ No newline at end of file +void ERS_FUNCTION_DrawMesh(ERS_STRUCT_Mesh* Mesh, ERS_STRUCT_OpenGLDefaults* OpenGLDefaults, ERS_STRUCT_Shader* Shader); \ No newline at end of file diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMeshNoTextures.cpp b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMeshNoTextures.cpp new file mode 100644 index 0000000000..0776e622a1 --- /dev/null +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMeshNoTextures.cpp @@ -0,0 +1,118 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#include + + +void ERS_FUNCTION_DrawMeshNoTextures(ERS_STRUCT_Mesh* Mesh, ERS_STRUCT_Shader* Shader) { + + Shader->SetMat4("model", Mesh->ModelMatrix); + + // unsigned int AmbientOcclusionHandle = 1; + // unsigned int DiffuseHandle = 1; + // unsigned int DisplacementHandle = 1; + // unsigned int EmissiveHandle = 1; + // unsigned int HeightHandle = 1; + // unsigned int MetalnessHandle = 1; + // unsigned int NormalsHandle = 1; + // unsigned int ShininessHandle = 1; + + + + // // Reset All Textures To Defaults + // unsigned int ShaderProgram = Shader->ShaderProgram; + // unsigned int ResetTexID = OpenGLDefaults->DefaultTexture_; + // ERS_FUNCTION_ResetMeshTexture("texture_ambient_occlusion1", 1, ShaderProgram, ResetTexID); + // ERS_FUNCTION_ResetMeshTexture("texture_diffuse1", 2, ShaderProgram, ResetTexID); + // ERS_FUNCTION_ResetMeshTexture("texture_displacement1", 3, ShaderProgram, ResetTexID); + // ERS_FUNCTION_ResetMeshTexture("texture_emissive1", 4, ShaderProgram, ResetTexID); + // ERS_FUNCTION_ResetMeshTexture("texture_height1", 5, ShaderProgram, ResetTexID); + // ERS_FUNCTION_ResetMeshTexture("texture_metalness1", 6, ShaderProgram, ResetTexID); + // ERS_FUNCTION_ResetMeshTexture("texture_normals1", 7, ShaderProgram, ResetTexID); + // ERS_FUNCTION_ResetMeshTexture("texture_shininess1", 8, ShaderProgram, ResetTexID); + + + + // bool HasAmbientOcclusion = false; + // bool HasDiffuse = false; + // bool HasDisplacement = false; + // bool HasEmissive = false; + // bool HasHeight = false; + // bool HasMetalness = false; + // bool HasNormals = false; + // bool HasShininess = false; + + + // // Iterate Through Textures + // for (unsigned int i = 0; i < Mesh->TextureIDs.size(); i++) { + + // // Set To Proper Texture + // glActiveTexture(GL_TEXTURE0 + i); + + // // Get Texture Number + // std::string Number; + // std::string Name = Mesh->TextureNames[i]; + // int Type = 0; + + // // Detect Type + // if(Name == "texture_ambient_occlusion") { + // Number = std::to_string(AmbientOcclusionHandle++); + // Type = 1; + // HasAmbientOcclusion = true; + // } else if(Name == "texture_diffuse") { + // Number = std::to_string(DiffuseHandle++); + // Type = 2; + // HasDiffuse = true; + // } else if(Name == "texture_displacement") { + // Number = std::to_string(DisplacementHandle++); + // Type = 3; + // HasDisplacement = true; + // } else if(Name == "texture_emissive") { + // Number = std::to_string(EmissiveHandle++); + // Type = 4; + // HasEmissive = true; + // } else if(Name == "texture_height") { + // Number = std::to_string(HeightHandle++); + // Type = 5; + // HasHeight = true; + // } else if(Name == "texture_metalness") { + // Number = std::to_string(MetalnessHandle++); + // Type = 6; + // HasMetalness = true; + // } else if(Name == "texture_normals") { + // Number = std::to_string(NormalsHandle++); + // Type = 7; + // HasNormals = true; + // } else if(Name == "texture_shininess") { + // Number = std::to_string(ShininessHandle++); + // Type = 8; + // HasShininess = true; + // } + + // glUniform1i(glGetUniformLocation(Shader->ShaderProgram, (Name + Number).c_str()), Type); + + // // Bind Texture + // glActiveTexture(GL_TEXTURE0 + Type); + // glBindTexture(GL_TEXTURE_2D, Mesh->TextureIDs[i]); + + // } + + // // Set Uniforms + // Shader->SetBool("HasAmbientOcclusion", HasAmbientOcclusion); + // Shader->SetBool("HasDiffuse", HasDiffuse); + // Shader->SetBool("HasDisplacement", HasDisplacement); + // Shader->SetBool("HasEmissive", HasEmissive); + // Shader->SetBool("HasHeight", HasHeight); + // Shader->SetBool("HasMetalness", HasMetalness); + // Shader->SetBool("HasNormals", HasNormals); + // Shader->SetBool("HasShininess", HasShininess); + + + + // Draw Mesh + glBindVertexArray(Mesh->VAO); + glDrawElements(GL_TRIANGLES, Mesh->NumberIndices, GL_UNSIGNED_INT, 0); + glBindVertexArray(0); + +} \ No newline at end of file diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMeshNoTextures.h b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMeshNoTextures.h new file mode 100644 index 0000000000..b4d00b1c95 --- /dev/null +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_DrawMeshNoTextures.h @@ -0,0 +1,29 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#pragma once + + +// Standard Libraries (BG convention: use <> instead of "") +#include +#include + +// Third-Party Libraries (BG convention: use <> instead of "") + +// Internal Libraries (BG convention: use <> instead of "") +#include + +#include + +#include +#include + + + +/** + * @brief Draws the mesh passed in. + * + * @param Mesh + */ +void ERS_FUNCTION_DrawMeshNoTextures(ERS_STRUCT_Mesh* Mesh, ERS_STRUCT_Shader* Shader); \ No newline at end of file diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_FindShaderByName.cpp b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_FindShaderByName.cpp new file mode 100644 index 0000000000..182a92c006 --- /dev/null +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_FindShaderByName.cpp @@ -0,0 +1,20 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#include + + +unsigned int ERS_FUNCTION_FindShaderByName(std::string Name, std::vector>* Shaders) { + + long Index = 0; + for (unsigned long i = 0; i < Shaders->size(); i++) { + if ((*Shaders)[i]->InternalName == Name) { + Index = i; + break; + } + } + + return Index; + +} \ No newline at end of file diff --git a/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_FindShaderByName.h b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_FindShaderByName.h new file mode 100644 index 0000000000..58a68911b6 --- /dev/null +++ b/Source/Core/Renderer/ERS_CLASS_VisualRenderer/ERS_FUNCTION_FindShaderByName.h @@ -0,0 +1,26 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#pragma once + + +// Standard Libraries (BG convention: use <> instead of "") +#include +#include +#include + +// Third-Party Libraries (BG convention: use <> instead of "") + +// Internal Libraries (BG convention: use <> instead of "") +#include + + +/** + * @brief Returns the index of a shader with a name that matches the input name. + * Will return 0 if the shader cannot be found. + * + * @param Name + * @param Shaders + */ +unsigned int ERS_FUNCTION_FindShaderByName(std::string Name, std::vector>* Shaders); \ No newline at end of file diff --git a/Source/Core/Structures/ERS_STRUCT_DepthMap/CMakeLists.txt b/Source/Core/Structures/ERS_STRUCT_DepthMap/CMakeLists.txt new file mode 100644 index 0000000000..2426576564 --- /dev/null +++ b/Source/Core/Structures/ERS_STRUCT_DepthMap/CMakeLists.txt @@ -0,0 +1,28 @@ +######################################################################## +# This file is part of the BrainGenix-ERS Environment Rendering System # +######################################################################## + + +# Create Library (Name Should Be Parent Dir Name) +add_library(ERS_STRUCT_DepthMap + + # Add Source Files (.cpp) + "ERS_STRUCT_DepthMap.cpp" + + # Add Header Files (.h) + "ERS_STRUCT_DepthMap.h" + + ${BACKWARD_ENABLE} + ) + +# Link 3rd Party Libs +target_link_libraries(ERS_STRUCT_DepthMap + ) + +# Link Internal Libs +target_link_libraries(ERS_STRUCT_DepthMap + ) + + +target_include_directories(ERS_STRUCT_DepthMap PUBLIC ./) +set_target_properties(ERS_STRUCT_DepthMap PROPERTIES LINKER_LANGUAGE CXX) \ No newline at end of file diff --git a/Source/Core/Structures/ERS_STRUCT_DepthMap/ERS_STRUCT_DepthMap.cpp b/Source/Core/Structures/ERS_STRUCT_DepthMap/ERS_STRUCT_DepthMap.cpp new file mode 100644 index 0000000000..5335b21c8e --- /dev/null +++ b/Source/Core/Structures/ERS_STRUCT_DepthMap/ERS_STRUCT_DepthMap.cpp @@ -0,0 +1,5 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#include \ No newline at end of file diff --git a/Source/Core/Structures/ERS_STRUCT_DepthMap/ERS_STRUCT_DepthMap.h b/Source/Core/Structures/ERS_STRUCT_DepthMap/ERS_STRUCT_DepthMap.h new file mode 100644 index 0000000000..da860dfc4c --- /dev/null +++ b/Source/Core/Structures/ERS_STRUCT_DepthMap/ERS_STRUCT_DepthMap.h @@ -0,0 +1,31 @@ +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#pragma once + +// Standard Libraries (BG convention: use <> instead of "") +#include + +// Third-Party Libraries (BG convention: use <> instead of "") + +// Internal Libraries (BG convention: use <> instead of "") + + +/** + * @brief This struct stores the opengl ids for a full depth map 'object'. + * Ie: the FBO id, Texture ID, etc. + * + * Please Note: The depth maps are managed by 'ERS_CLASS_DepthMaps' not the light itself. + * The depth maps are created and rendered-to by that class. + * + */ +struct ERS_STRUCT_DepthMap { + + unsigned int FrameBufferObjectID; /** // Internal Libraries (BG convention: use <> instead of "") +#include struct ERS_STRUCT_DirectionalLight { @@ -26,4 +27,8 @@ struct ERS_STRUCT_DirectionalLight { glm::vec3 Pos; /** // Internal Libraries (BG convention: use <> instead of "") +#include struct ERS_STRUCT_PointLight { @@ -27,4 +28,9 @@ struct ERS_STRUCT_PointLight { glm::vec3 Pos; /** // Internal Libraries (BG convention: use <> instead of "") +#include struct ERS_STRUCT_SpotLight { @@ -31,4 +32,9 @@ struct ERS_STRUCT_SpotLight { glm::vec3 Pos; /** \ No newline at end of file diff --git a/Source/Core/Structures/ERS_STRUCT_RendererSettings/ERS_STRUCT_RendererSettings.h b/Source/Core/Structures/ERS_STRUCT_RendererSettings/ERS_STRUCT_RendererSettings.h new file mode 100644 index 0000000000..d5cd22191b --- /dev/null +++ b/Source/Core/Structures/ERS_STRUCT_RendererSettings/ERS_STRUCT_RendererSettings.h @@ -0,0 +1,33 @@ +// ToDO: then add to project struct, then update project loader/writer with this info. Then check trello board for other related tasks like live ediitng. + + +//======================================================================// +// This file is part of the BrainGenix-ERS Environment Rendering System // +//======================================================================// + +#pragma once + +// Standard Libraries (BG convention: use <> instead of "") +#include + +// Third-Party Libraries (BG convention: use <> instead of "") + +// Internal Libraries (BG convention: use <> instead of "") + + + +/** + * @brief Struct containing renderer settings. + * + */ +struct ERS_STRUCT_RendererSettings { + + // Shadow Map Settings + int ShadowMapX_ = 2048; + int ShadowMapY_ = 2048; + + + // Indicate If Settings Have Changed + bool HaveSettingsChanged_ = false; + +}; \ No newline at end of file diff --git a/Source/Core/Structures/ERS_STRUCT_Shader/ERS_STRUCT_Shader.cpp b/Source/Core/Structures/ERS_STRUCT_Shader/ERS_STRUCT_Shader.cpp index 37fd80fd3f..8c9e9e26e1 100644 --- a/Source/Core/Structures/ERS_STRUCT_Shader/ERS_STRUCT_Shader.cpp +++ b/Source/Core/Structures/ERS_STRUCT_Shader/ERS_STRUCT_Shader.cpp @@ -6,10 +6,28 @@ #include +ERS_STRUCT_Shader::ERS_STRUCT_Shader() { + + ShaderProgram_ = 0; + VertexShader = 0; + FragmentShader = 0; + + VertexID = 0; + FragmentID = 0; +} + ERS_STRUCT_Shader::~ERS_STRUCT_Shader() { // Deallocate Shader Program - glDeleteProgram(ShaderProgram); + glUseProgram(0); + glDeleteProgram(ShaderProgram_); + +} + + +void ERS_STRUCT_Shader::ResetProgram() { + + glDeleteProgram(ShaderProgram_); } @@ -34,8 +52,7 @@ std::string ERS_STRUCT_Shader::CompileVertexShader(const char* VertexText, ERS_C } } - // Update Vars - _VertexShaderInitialized = true; + return ErrorMessage; } @@ -43,7 +60,6 @@ std::string ERS_STRUCT_Shader::CompileVertexShader(const char* VertexText, ERS_C std::string ERS_STRUCT_Shader::CompileFragmentShader(const char* FragmentText, ERS_CLASS_LoggingSystem* Logger) { // Compile The Fragment Shader Text Into A Binary - std::string ErrorMessage; FragmentShader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(FragmentShader, 1, &FragmentText, NULL); @@ -52,6 +68,7 @@ std::string ERS_STRUCT_Shader::CompileFragmentShader(const char* FragmentText, E // Report Compilation Status int FragmentSuccess; char FragmentInfoLog[65535]; + std::string ErrorMessage; glGetShaderiv(FragmentShader, GL_COMPILE_STATUS, &FragmentSuccess); if (!FragmentSuccess) { glGetShaderInfoLog(FragmentShader, 65535, NULL, FragmentInfoLog); @@ -61,8 +78,6 @@ std::string ERS_STRUCT_Shader::CompileFragmentShader(const char* FragmentText, E } } - // Update Vars - _FragmentShaderInitialized = true; return ErrorMessage; } @@ -70,47 +85,38 @@ std::string ERS_STRUCT_Shader::CompileFragmentShader(const char* FragmentText, E std::string ERS_STRUCT_Shader::CreateShaderProgram(ERS_CLASS_LoggingSystem* Logger) { - // Check That Vertex And Fragment Shaders Are Initialized - std::string ErrorMessage; - if (!_VertexShaderInitialized || !_FragmentShaderInitialized) { - if (Logger != nullptr) { - Logger->Log("Vertex/Fragment Shader Compile Error", 8); - } - } - // Create Shader Program - ShaderProgram = glCreateProgram(); + ShaderProgram_ = glCreateProgram(); // Attach Shaders To Program - glAttachShader(ShaderProgram, VertexShader); - glAttachShader(ShaderProgram, FragmentShader); + glAttachShader(ShaderProgram_, VertexShader); + glAttachShader(ShaderProgram_, FragmentShader); // Link Program - glLinkProgram(ShaderProgram); + glLinkProgram(ShaderProgram_); // Get Link Status int Success; - glGetProgramiv(ShaderProgram, GL_LINK_STATUS, &Success); + std::string ErrorMessage; + glGetProgramiv(ShaderProgram_, GL_LINK_STATUS, &Success); if (!Success) { char InfoLog[65535]; - glGetProgramInfoLog(ShaderProgram, 65535, NULL, InfoLog); + glGetProgramInfoLog(ShaderProgram_, 65535, NULL, InfoLog); ErrorMessage = std::string(InfoLog); if (Logger != nullptr) { Logger->Log("Shader Link Error: " + std::string(InfoLog), 8); } - } else { - _ShaderProgramInitialized = true; } - // Free RAM + glDetachShader(ShaderProgram_, VertexShader); glDeleteShader(VertexShader); + + glDetachShader(ShaderProgram_, FragmentShader); glDeleteShader(FragmentShader); - // Set State Of Vertex/Fragment Shaders To Uninit - _VertexShaderInitialized = false; - _FragmentShaderInitialized = false; + // Return Status @@ -118,16 +124,9 @@ std::string ERS_STRUCT_Shader::CreateShaderProgram(ERS_CLASS_LoggingSystem* Logg } -bool ERS_STRUCT_Shader::MakeActive(ERS_CLASS_LoggingSystem* Logger) { - - if ((!_ShaderProgramInitialized)) { - if (Logger != nullptr) { - Logger->Log("Shader Not Yet Initialized", 8); - } - return false; - } +bool ERS_STRUCT_Shader::MakeActive() { - glUseProgram(ShaderProgram); + glUseProgram(ShaderProgram_); return true; } @@ -137,56 +136,56 @@ bool ERS_STRUCT_Shader::MakeActive(ERS_CLASS_LoggingSystem* Logger) { // ------------------------------------------------------------------------ void ERS_STRUCT_Shader::SetBool(const std::string &name, bool value) const { - glUniform1i(glGetUniformLocation(ShaderProgram, name.c_str()), (int)value); + glUniform1i(glGetUniformLocation(ShaderProgram_, name.c_str()), (int)value); } // ------------------------------------------------------------------------ void ERS_STRUCT_Shader::SetInt(const std::string &name, int value) const { - glUniform1i(glGetUniformLocation(ShaderProgram, name.c_str()), value); + glUniform1i(glGetUniformLocation(ShaderProgram_, name.c_str()), value); } void ERS_STRUCT_Shader::SetFloat(const std::string &name, float value) const { - glUniform1f(glGetUniformLocation(ShaderProgram, name.c_str()), value); + glUniform1f(glGetUniformLocation(ShaderProgram_, name.c_str()), value); } // ------------------------------------------------------------------------ void ERS_STRUCT_Shader::SetVec2(const std::string &name, const glm::vec2 &value) const { - glUniform2fv(glGetUniformLocation(ShaderProgram, name.c_str()), 1, &value[0]); + glUniform2fv(glGetUniformLocation(ShaderProgram_, name.c_str()), 1, &value[0]); } void ERS_STRUCT_Shader::SetVec2(const std::string &name, float x, float y) const { - glUniform2f(glGetUniformLocation(ShaderProgram, name.c_str()), x, y); + glUniform2f(glGetUniformLocation(ShaderProgram_, name.c_str()), x, y); } // ------------------------------------------------------------------------ void ERS_STRUCT_Shader::SetVec3(const std::string &name, const glm::vec3 &value) const { - glUniform3fv(glGetUniformLocation(ShaderProgram, name.c_str()), 1, &value[0]); + glUniform3fv(glGetUniformLocation(ShaderProgram_, name.c_str()), 1, &value[0]); } void ERS_STRUCT_Shader::SetVec3(const std::string &name, float x, float y, float z) const { - glUniform3f(glGetUniformLocation(ShaderProgram, name.c_str()), x, y, z); + glUniform3f(glGetUniformLocation(ShaderProgram_, name.c_str()), x, y, z); } // ------------------------------------------------------------------------ void ERS_STRUCT_Shader::SetVec4(const std::string &name, const glm::vec4 &value) const { - glUniform4fv(glGetUniformLocation(ShaderProgram, name.c_str()), 1, &value[0]); + glUniform4fv(glGetUniformLocation(ShaderProgram_, name.c_str()), 1, &value[0]); } void ERS_STRUCT_Shader::SetVec4(const std::string &name, float x, float y, float z, float w) { - glUniform4f(glGetUniformLocation(ShaderProgram, name.c_str()), x, y, z, w); + glUniform4f(glGetUniformLocation(ShaderProgram_, name.c_str()), x, y, z, w); } // ------------------------------------------------------------------------ void ERS_STRUCT_Shader::SetMat2(const std::string &name, const glm::mat2 &mat) const { - glUniformMatrix2fv(glGetUniformLocation(ShaderProgram, name.c_str()), 1, GL_FALSE, &mat[0][0]); + glUniformMatrix2fv(glGetUniformLocation(ShaderProgram_, name.c_str()), 1, GL_FALSE, &mat[0][0]); } // ------------------------------------------------------------------------ void ERS_STRUCT_Shader::SetMat3(const std::string &name, const glm::mat3 &mat) const { - glUniformMatrix3fv(glGetUniformLocation(ShaderProgram, name.c_str()), 1, GL_FALSE, &mat[0][0]); + glUniformMatrix3fv(glGetUniformLocation(ShaderProgram_, name.c_str()), 1, GL_FALSE, &mat[0][0]); } // ------------------------------------------------------------------------ void ERS_STRUCT_Shader::SetMat4(const std::string &name, const glm::mat4 &mat) const { - glUniformMatrix4fv(glGetUniformLocation(ShaderProgram, name.c_str()), 1, GL_FALSE, &mat[0][0]); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgram_, name.c_str()), 1, GL_FALSE, &mat[0][0]); } diff --git a/Source/Core/Structures/ERS_STRUCT_Shader/ERS_STRUCT_Shader.h b/Source/Core/Structures/ERS_STRUCT_Shader/ERS_STRUCT_Shader.h index 72fb61b35b..06118cd720 100644 --- a/Source/Core/Structures/ERS_STRUCT_Shader/ERS_STRUCT_Shader.h +++ b/Source/Core/Structures/ERS_STRUCT_Shader/ERS_STRUCT_Shader.h @@ -31,7 +31,7 @@ struct ERS_STRUCT_Shader { - unsigned int ShaderProgram; /** instead of "") #include +#include +#include + +#include #include #include #include -#include -#include + + @@ -28,15 +32,18 @@ struct ERS_STRUCT_SystemUtils { - std::unique_ptr Logger_; /** LocalSystemConfiguration_; /** SystemShouldRun_; /** Logger_; /** ERS_IOSubsystem_; /** ERS_ModelWriter_; /** SystemShouldRun_; /** FramerateManager_; /** ERS_CLASS_HardwareInformation_; /** ERS_CLASS_PythonInterpreterIntegration_; /** RendererSettings_; /** LogMessages_; /** pcfDepth ? 1.0 : 0.0; + } + } + shadow /= (SampleSize*2)*(SampleSize*2); + + return shadow; + +} + + +float ShadowPCFRandom(float Bias, vec3 ProjCoords, int Index, float CurrentDepth, int SampleSize) { + + float shadow = 0.0f; + vec2 texelSize = 1.0f / textureSize(DepthMapArray, 0).xy; + + for(int x = -SampleSize; x <= SampleSize; ++x) + { + for(int y = -SampleSize; y <= SampleSize; ++y) + { + vec2 TexCoords2D = ProjCoords.xy + (vec2(x, y) * texelSize); + int index = int(16.0f*random(floor(gl_FragCoord.yxz*1000.0f), x*y))%16; + float pcfDepth = texture(DepthMapArray, vec3(TexCoords2D + PoissonDisk[index]/700.0f, Index)).r; + //pcfDepth = texture(DepthMapArray, vec3(TexCoords2D, Index)).r; + shadow += CurrentDepth - Bias > pcfDepth ? 1.0f : 0.0f; + + + + } + } + shadow /= (SampleSize*2)*(SampleSize*2); + + + return shadow; +} + + + + +float ShadowCalculation(mat4 LightSpaceMatrix, vec3 LightPos, int Index) +{ + vec4 fragPosLightSpace = LightSpaceMatrix * vec4(Object.FragPos, 1.0f); + + // perform perspective divide + vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w; + // transform to [0,1] range + projCoords = projCoords * 0.5f + 0.5; + + + // get closest depth value from light's perspective (using [0,1] range fragPosLight as coords) + float closestDepth = texture(DepthMapArray, vec3(projCoords.xy, Index)).r; + // get depth of current fragment from light's perspective + float currentDepth = projCoords.z; + // check whether current frag pos is in shadow + vec3 LightDir = normalize(LightPos - Object.FragPos); + float Bias = max(0.00 * (1.0 - dot(Object.Normal, LightDir)), 0.005); + + + //float Shadow = currentDepth - Bias > closestDepth ? 1.0 : 0.0; + + + //float Shadow = 0.0f; + + /** + + // Sample the shadow map 4 times + for (int i=0;i<4;i++){ + // use either : + // - Always the same samples. + // Gives a fixed pattern in the shadow, but no noise + int index = i; + // - A random sample, based on the pixel's screen location. + // No banding, but the shadow moves with the camera, which looks weird. + // int index = int(16.0*random(gl_FragCoord.xyy, i))%16; + // - A random sample, based on the pixel's position in world space. + // The position is rounded to the millimeter to avoid too much aliasing + //int index = int(16.0*random(floor(Position_worldspace.xyz*1000.0), i))%16; + + // being fully in the shadow will eat up 4*0.2 = 0.8 + // 0.2 potentially remain, which is quite dark. + Shadow += (1.0-texture(DepthMapArray, vec3(projCoords.xy + PoissonDisk[index]/700.0, Index)));//(ShadowCoord.z-bias)/ShadowCoord.w) )); + } + + + **/ + + + + float Shadow = ShadowPCFRandom(Bias, projCoords, Index, currentDepth, 1); + + + + + + + if (projCoords.z > 1.0) { + Shadow = 0.0f; + } + + if (Shadow > 1.0f) { + Shadow = 1.0f; + } else if (Shadow < 0.0f) { + Shadow = 0.0f; + } + + + + + + return 1.0f - Shadow; +} + + + + vec3 GetNormalFromMap(sampler2D Normal) { // Ensure That Textures Are Present/Valid, If Not, Provide Fallback @@ -294,8 +440,8 @@ vec3 PBRPointLight(STRUCT_PointLight Light, vec3 ViewDir, vec3 Reflectance, STRU kD *= 1.0 - Model.Metallic; // scale light by NdotL - float NdotL = max(dot(Model.Normal, L), 0.0); - + 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 @@ -415,27 +561,27 @@ void main() { // ---- Calculate Lighting Contributions ---- // - vec4 Lo = vec4(0.0f); + vec3 Lo = vec3(0.0f); // Calculate Directional Lights for (int i = 0; i < NumberDirectionalLights; i++) { - Lo += vec4(PBRDirectionalLight(DirectionalLights[i], ViewDir, Reflectance, Model), 1.0f); + Lo += PBRDirectionalLight(DirectionalLights[i], ViewDir, Reflectance, Model) * ShadowCalculation(DirectionalLights[i].LightSpaceMatrix, DirectionalLights[i].Direction, DirectionalLights[i].DepthMapIndex); } // Calculate Point Lights for (int i = 0; i < NumberPointLights; i++) { - Lo += vec4(PBRPointLight(PointLights[i], ViewDir, Reflectance, Model), 1.0f); + Lo += PBRPointLight(PointLights[i], ViewDir, Reflectance, Model);// * (1.0f - ShadowCalculation(PointLights[i].LightSpaceMatrix, PointLights[i].Position, PointLights[i].DepthMapIndex)); } // Calculate Spot Lights for(int i = 0; i < NumberSpotLights; ++i) { - Lo += vec4(PBRSpotLight(SpotLights[i], ViewDir, Reflectance, Model), 1.0f); + Lo += PBRSpotLight(SpotLights[i], ViewDir, Reflectance, Model); } // 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; + vec4 Color = Ambient + vec4(Lo, Model.Albedo.a); // Add Emissive Texture @@ -450,6 +596,10 @@ void main() { } else { FragColor = GammaCorrectResult(Color, GammaCorrectionEnabled_); } + + + + //FragColor = vec4(vec3(1.0f - ShadowCalculation(Object.FragPosLightSpace, DirectionalLights[0].Direction)), 1.0f); } @@ -460,5 +610,3 @@ void main() { - - diff --git a/Source/EditorAssets/Projects/DefaultProject/10042.ERS b/Source/EditorAssets/Projects/DefaultProject/10042.ERS new file mode 100644 index 0000000000..5bd2733cc9 --- /dev/null +++ b/Source/EditorAssets/Projects/DefaultProject/10042.ERS @@ -0,0 +1,10 @@ +#version 330 core +layout (location = 0) in vec3 aPos; + +uniform mat4 LightSpaceMatrix; +uniform mat4 model; + +void main() +{ + gl_Position = LightSpaceMatrix * model * vec4(aPos, 1.0); +} diff --git a/Source/EditorAssets/Projects/DefaultProject/10043.ERS b/Source/EditorAssets/Projects/DefaultProject/10043.ERS new file mode 100644 index 0000000000..0ba553608d --- /dev/null +++ b/Source/EditorAssets/Projects/DefaultProject/10043.ERS @@ -0,0 +1,6 @@ +#version 330 core + +void main() +{ + // gl_FragDepth = gl_FragCoord.z; +} diff --git a/Source/Main.cpp b/Source/Main.cpp index fa804be8fa..c2668ff2aa 100644 --- a/Source/Main.cpp +++ b/Source/Main.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include @@ -105,6 +106,8 @@ int main() { SystemUtils->Logger_.get() ); + SystemUtils->RendererSettings_ = std::make_unique(); + // Create ProjectUtils Struct SystemUtils->Logger_->Log("Setting Up Project Utilities Structure", 3);