~ | Pass system shader

This commit is contained in:
TheRedShip
2025-02-07 23:32:52 +01:00
parent 47bf193752
commit cbc2550d78
5 changed files with 76 additions and 43 deletions

View File

@ -61,11 +61,12 @@ void printWithLineNumbers(const char *str)
std::cout << lineNumber++ << ": " << line << std::endl;
}
Shader::Shader(std::string vertexPath, std::string fragmentPath, std::string computePath)
Shader::Shader(std::string vertexPath, std::string fragmentPath, std::string computePath, std::string denoisingPath)
{
const char *vertexCode = loadFileWithIncludes(vertexPath);
const char *fragmentCode = loadFileWithIncludes(fragmentPath);
const char *computeCode = loadFileWithIncludes(computePath);
const char *denoisingCode = loadFileWithIncludes(denoisingPath);
// printWithLineNumbers(computeCode);
@ -89,6 +90,13 @@ Shader::Shader(std::string vertexPath, std::string fragmentPath, std::string com
glCompileShader(_compute);
checkCompileErrors(_compute);
_denoising = glCreateShader(GL_COMPUTE_SHADER);
glShaderSource(_denoising, 1, &denoisingCode, NULL);
glCompileShader(_denoising);
checkCompileErrors(_denoising);
}
Shader::~Shader(void)
@ -98,15 +106,14 @@ Shader::~Shader(void)
glDeleteShader(_compute);
glDeleteProgram(_program);
glDeleteProgram(_program_compute);
glDeleteProgram(_denoising);
}
void Shader::attach(void)
{
_program = glCreateProgram();
_program_compute = glCreateProgram();
glProgramParameteri(_program_compute, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
glProgramParameteri(_program, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
_program_denoising = glCreateProgram();
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
@ -114,10 +121,14 @@ void Shader::attach(void)
glAttachShader(_program, _vertex);
glAttachShader(_program, _fragment);
glAttachShader(_program_compute, _compute);
glAttachShader(_program_denoising, _denoising);
glLinkProgram(_program);
glLinkProgram(_program_compute);
glLinkProgram(_program_denoising);
glGenTextures(1, &_output_texture);
glBindTexture(GL_TEXTURE_2D, _output_texture);
@ -196,6 +207,20 @@ void Shader::drawTriangles()
glDrawArrays(GL_TRIANGLES, 0, _size * 3);
}
void Shader::flipOutputDenoising(bool pass)
{
if (pass)
{
glBindImageTexture(0, _output_texture, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA32F);
glBindImageTexture(2, _denoising_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);
}
else
{
glBindImageTexture(0, _denoising_texture, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA32F);
glBindImageTexture(2, _output_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);
}
}
void Shader::set_int(const std::string &name, int value) const
{
glUniform1i(glGetUniformLocation(_program_compute, name.c_str()), value);
@ -252,6 +277,11 @@ GLuint Shader::getProgramCompute(void) const
return (_program_compute);
}
GLuint Shader::getProgramComputeDenoising(void) const
{
return (_program_denoising);
}
std::vector<float> Shader::getOutputImage(void)
{
std::vector<float> res(WIDTH * HEIGHT * 4);