diff --git a/assets/shaders/Depth.frag b/assets/shaders/Depth.frag new file mode 100644 index 0000000..83dc7ef --- /dev/null +++ b/assets/shaders/Depth.frag @@ -0,0 +1,5 @@ +#version 330 core +void main() +{ + // No color output; only depth is recorded +} diff --git a/assets/shaders/Depth.vert b/assets/shaders/Depth.vert new file mode 100644 index 0000000..bca281a --- /dev/null +++ b/assets/shaders/Depth.vert @@ -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/imgui.ini b/imgui.ini index 080ebd5..a4f3207 100644 --- a/imgui.ini +++ b/imgui.ini @@ -1,6 +1,6 @@ [Window][DockSpace] Pos=0,0 -Size=1920,1177 +Size=1280,720 Collapsed=0 [Window][Debug##Default] @@ -68,26 +68,26 @@ Size=1920,1177 Collapsed=0 [Window][Inspector##InspectorWindow] -Pos=1536,27 -Size=376,1142 +Pos=896,27 +Size=376,685 Collapsed=0 DockId=0x00000016,0 [Window][Editor##EditorWindow] Pos=332,27 -Size=1202,776 +Size=562,319 Collapsed=0 DockId=0x00000017,0 [Window][Performance##performance] -Pos=8,761 -Size=322,408 +Pos=8,468 +Size=322,244 Collapsed=0 DockId=0x0000001C,0 [Window][Logger##logger] -Pos=332,805 -Size=1202,364 +Pos=332,348 +Size=562,364 Collapsed=0 DockId=0x00000019,0 @@ -105,7 +105,7 @@ DockId=0x0000000F,0 [Window][Scene Window##SceneWindow] Pos=8,27 -Size=322,732 +Size=322,439 Collapsed=0 DockId=0x0000001B,0 @@ -121,6 +121,12 @@ Size=599,364 Collapsed=0 DockId=0x0000001A,0 +[Window][Depth Map Debug] +Pos=332,805 +Size=1202,364 +Collapsed=0 +DockId=0x00000019,1 + [Table][0xE9E836E4,4] Column 0 Weight=1.2999 Column 1 Weight=1.0439 @@ -128,7 +134,7 @@ Column 2 Weight=0.6474 Column 3 Weight=1.0088 [Docking][Data] -DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=8,50 Size=1904,1142 Split=X Selected=0xF7365A5A +DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=42,84 Size=1264,685 Split=X Selected=0xF7365A5A DockNode ID=0x00000013 Parent=0x14621557 SizeRef=322,1142 Split=Y Selected=0x818D04BB DockNode ID=0x0000001B Parent=0x00000013 SizeRef=264,456 HiddenTabBar=1 Selected=0x1D5D92B6 DockNode ID=0x0000001C Parent=0x00000013 SizeRef=264,254 HiddenTabBar=1 Selected=0x818D04BB diff --git a/src/Rendering/Shader.cpp b/src/Rendering/Shader.cpp index 1ceb098..43f3bc2 100644 --- a/src/Rendering/Shader.cpp +++ b/src/Rendering/Shader.cpp @@ -8,7 +8,7 @@ // Constructor implementations Shader::Shader() : ID(0) {} -Shader::Shader(const char* vertexPath, const char* fragmentPath) +Shader::Shader(const char *vertexPath, const char *fragmentPath) { // 1. Retrieve the vertex/fragment source code from filePath std::string vertexCode; @@ -17,19 +17,19 @@ Shader::Shader(const char* vertexPath, const char* fragmentPath) std::ifstream fShaderFile; // Ensure ifstream objects can throw exceptions - vShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit); - fShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit); + vShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit); + fShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit); - try + try { // Open files vShaderFile.open(vertexPath); fShaderFile.open(fragmentPath); std::stringstream vShaderStream, fShaderStream; - + // Read file's buffer contents into streams vShaderStream << vShaderFile.rdbuf(); - fShaderStream << fShaderFile.rdbuf(); + fShaderStream << fShaderFile.rdbuf(); // Close file handlers vShaderFile.close(); @@ -37,15 +37,15 @@ Shader::Shader(const char* vertexPath, const char* fragmentPath) // Convert stream into string vertexCode = vShaderStream.str(); - fragmentCode = fShaderStream.str(); + fragmentCode = fShaderStream.str(); } - catch (std::ifstream::failure& e) + catch (std::ifstream::failure &e) { std::cerr << "ERROR::SHADER::FILE_NOT_SUCCESSFULLY_READ: " << e.what() << std::endl; } - const char* vShaderCode = vertexCode.c_str(); - const char * fShaderCode = fragmentCode.c_str(); + const char *vShaderCode = vertexCode.c_str(); + const char *fShaderCode = fragmentCode.c_str(); // 2. Compile shaders GLuint vertex, fragment; @@ -58,10 +58,11 @@ Shader::Shader(const char* vertexPath, const char* fragmentPath) glCompileShader(vertex); // Print compile errors if any glGetShaderiv(vertex, GL_COMPILE_STATUS, &success); - if(!success) + if (!success) { glGetShaderInfoLog(vertex, 512, NULL, infoLog); - std::cerr << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl; + std::cerr << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" + << infoLog << std::endl; } // Fragment Shader @@ -70,10 +71,11 @@ Shader::Shader(const char* vertexPath, const char* fragmentPath) glCompileShader(fragment); // Print compile errors if any glGetShaderiv(fragment, GL_COMPILE_STATUS, &success); - if(!success) + if (!success) { glGetShaderInfoLog(fragment, 512, NULL, infoLog); - std::cerr << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << std::endl; + std::cerr << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" + << infoLog << std::endl; } // Shader Program @@ -83,10 +85,11 @@ Shader::Shader(const char* vertexPath, const char* fragmentPath) glLinkProgram(ID); // Print linking errors if any glGetProgramiv(ID, GL_LINK_STATUS, &success); - if(!success) + if (!success) { glGetProgramInfoLog(ID, 512, NULL, infoLog); - std::cerr << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog << std::endl; + std::cerr << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" + << infoLog << std::endl; } // Delete the shaders as they're linked into our program now and no longer necessary @@ -143,3 +146,14 @@ void Shader::SetMat4(const std::string &name, const glm::mat4 &mat) const glUseProgram(ID); // Ensure the shader program is active glUniformMatrix4fv(GetUniformLocation(name), 1, GL_FALSE, glm::value_ptr(mat)); } +void Shader::SetVec3(const std::string &name, const glm::vec3 &value) const +{ + glUseProgram(ID); // Ensure the shader program is active + glUniform3fv(glGetUniformLocation(ID, name.c_str()), 1, &value[0]); +} + +void Shader::SetSampler2D(const std::string &name, int textureUnit) const +{ + glUseProgram(ID); // Ensure the shader program is active + glUniform1i(glGetUniformLocation(ID, name.c_str()), textureUnit); +} diff --git a/src/Rendering/Shader.h b/src/Rendering/Shader.h index 9bfdfe7..e2c872e 100644 --- a/src/Rendering/Shader.h +++ b/src/Rendering/Shader.h @@ -3,7 +3,7 @@ #include #include -#include // or appropriate OpenGL headers +#include // or appropriate OpenGL headers #include // For glm::mat4 class Shader @@ -13,7 +13,7 @@ public: // Constructors Shader(); - Shader(const char* vertexPath, const char* fragmentPath); + Shader(const char *vertexPath, const char *fragmentPath); ~Shader(); // Destructor to clean up shader program // Use/activate the shader @@ -24,6 +24,8 @@ public: void SetFloat(const std::string &name, float value) const; void SetBool(const std::string &name, bool value) const; void SetMat4(const std::string &name, const glm::mat4 &mat) const; // For setting 4x4 matrices + void SetSampler2D(const std::string &name, int textureUnit) const; + void SetVec3(const std::string &name, const glm::vec3 &value) const; private: // Caching uniform locations for performance