Skip to content

Commit

Permalink
Merge pull request #214 from carboncopies/154-add-shadow-maps
Browse files Browse the repository at this point in the history
154 add shadow maps
  • Loading branch information
datacrystals authored Jun 11, 2022
2 parents 9a24e79 + ed570d6 commit 0eb0c2d
Show file tree
Hide file tree
Showing 60 changed files with 2,279 additions and 1,028 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -142,6 +144,7 @@ target_link_libraries(${PROJECT_NAME}
ERS_STRUCT_HumanInputDeviceUtils
ERS_STRUCT_SystemUtils
ERS_STRUCT_ProjectUtils
ERS_STRUCT_RendererSettings

)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ void GUI_Menu_File::Draw() {
ShaderEditor_->Draw();



}
25 changes: 25 additions & 0 deletions Source/Core/Editor/Widgets/GUI_Widget_RenderingSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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];
}


}


Expand Down
3 changes: 3 additions & 0 deletions Source/Core/Editor/Widgets/GUI_Widget_RenderingSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class Widget_RenderingSettings {
ImVec4 ClearColor_ = ImVec4(0.2f, 0.2f, 0.2f, 1.0f); /**<Background Clearing Color */
bool OpenGLDrawLines_ = false; /**<Default Rendering Mode */

// Variables To Store Input Data
int DepthMapResolution_[2]; /**>Stores the value that the user is putting into the depth map input box*/


public:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Window_ShaderEditor::Window_ShaderEditor(ERS_STRUCT_SystemUtils* SystemUtils, ER


ShaderLoader_ = std::make_unique<ERS_CLASS_ShaderLoader>(SystemUtils_);
LivePreviewShader_ = std::make_shared<ERS_STRUCT_Shader>();




Expand Down Expand Up @@ -75,19 +75,19 @@ void Window_ShaderEditor::Draw() {

// If Just Enabled
if (Enabled_) {
LivePreviewShaderIndex_ = VisualRenderer_->Shaders_.size();
VisualRenderer_->Shaders_.push_back(std::make_unique<ERS_STRUCT_Shader>());
} 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);


}
Expand All @@ -101,7 +101,7 @@ void Window_ShaderEditor::Draw() {

DrawEditorWindow();
DrawToolsWindow();

}


Expand Down Expand Up @@ -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<ERS_STRUCT_Shader>();
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();

}

Expand Down
15 changes: 7 additions & 8 deletions Source/Core/Loader/ERS_ShaderLoader/ERS_CLASS_ShaderLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ ERS_CLASS_ShaderLoader::~ERS_CLASS_ShaderLoader() {

}

std::shared_ptr<ERS_STRUCT_Shader> 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<ERS_STRUCT_Shader> ShaderStruct = std::make_shared<ERS_STRUCT_Shader>();

if (LogBuild) {
SystemUtils_->Logger_->Log("Creating Vertex Shader Object", 3);
Expand All @@ -49,14 +47,13 @@ std::shared_ptr<ERS_STRUCT_Shader> ERS_CLASS_ShaderLoader::CreateShaderObject(co
SystemUtils_->Logger_->Log("Linked Shader Program", 4);
}

return ShaderStruct;

}

std::shared_ptr<ERS_STRUCT_Shader> 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<ERS_STRUCT_IOData> VertexData = std::make_unique<ERS_STRUCT_IOData>();
std::unique_ptr<ERS_STRUCT_IOData> FragmentData = std::make_unique<ERS_STRUCT_IOData>();
Expand All @@ -68,12 +65,14 @@ std::shared_ptr<ERS_STRUCT_Shader> ERS_CLASS_ShaderLoader::LoadShaderFromAsset(l


// Return Compiled Shader
std::shared_ptr<ERS_STRUCT_Shader> 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);



}
4 changes: 2 additions & 2 deletions Source/Core/Loader/ERS_ShaderLoader/ERS_CLASS_ShaderLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ERS_CLASS_ShaderLoader {
* @param FragmentText
* @return ERS_STRUCT_Shader
*/
std::shared_ptr<ERS_STRUCT_Shader> 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);


/**
Expand All @@ -63,7 +63,7 @@ class ERS_CLASS_ShaderLoader {
* @param FragmentID
* @return std::shared_ptr<ERS_STRUCT_Shader>
*/
std::shared_ptr<ERS_STRUCT_Shader> 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");



Expand Down
62 changes: 54 additions & 8 deletions Source/Core/Renderer/ERS_CLASS_RendererManager/RendererManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ERS_CLASS_ShaderLoader>(SystemUtils_);
for (int i = 0; (long)i < (long)ProjectUtils_->ProjectManager_->Project_.ShaderPrograms.size(); i++) {
VisualRenderer_->Shaders_.push_back(std::make_unique<ERS_STRUCT_Shader>());
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);
Expand Down Expand Up @@ -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);

Expand All @@ -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());
Expand Down Expand Up @@ -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);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <ERS_STRUCT_Camera.h>

#include <ERS_CLASS_ShaderLoader.h>
#include <ERS_CLASS_Framebuffer.h>
#include <GUI.h>

#include <ERS_ModelWriter.h>
Expand Down Expand Up @@ -52,7 +51,6 @@ class RendererManager {
std::unique_ptr<ERS_CLASS_VisualRenderer> VisualRenderer_; /**<Pointer To VisualRenderer Instance*/
GLFWwindow* Window_; /**<GLFW Window Instance*/
std::unique_ptr<ERS_CLASS_ShaderLoader> ShaderLoader_; /**<Pointer To Shader Loader Instnace*/
std::shared_ptr<ERS_CLASS_Framebuffer> FramebufferManager_; /**<Pointer To Framebuffer Manager Instnace*/
std::shared_ptr<ERS_STRUCT_Shader> Shader_; /**<ERS Shader Object (Main System Shader)*/
std::shared_ptr<GUISystem> GuiSystem_; /**<Instance of GUI System*/
std::unique_ptr<Cursors3D> Cursors3D_; /**<Setup 3D Cursor Class*/
Expand Down Expand Up @@ -90,6 +88,12 @@ class RendererManager {
*/
unsigned int LoadEditorIcon(const char* Path);

/**
* @brief This function gets the current opengl error status and if there's an issue it reports it into the log.
*
*/
void ReportOpenGLErrors();


public:

Expand Down
Loading

0 comments on commit 0eb0c2d

Please sign in to comment.