Updated Shader with more functions

This commit is contained in:
OusmBlueNinja 2024-12-31 15:45:24 -06:00
parent 35bc1b0796
commit b6aa69210f
5 changed files with 65 additions and 28 deletions

View File

@ -0,0 +1,5 @@
#version 330 core
void main()
{
// No color output; only depth is recorded
}

10
assets/shaders/Depth.vert Normal file
View File

@ -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);
}

View File

@ -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

View File

@ -61,7 +61,8 @@ Shader::Shader(const char* vertexPath, const char* fragmentPath)
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
@ -73,7 +74,8 @@ Shader::Shader(const char* vertexPath, const char* fragmentPath)
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
@ -86,7 +88,8 @@ Shader::Shader(const char* vertexPath, const char* fragmentPath)
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);
}

View File

@ -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