mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
~ | Pass system shader
This commit is contained in:
16
srcs/RT.cpp
16
srcs/RT.cpp
@ -21,7 +21,7 @@ int main(int argc, char **argv)
|
||||
if (scene.fail())
|
||||
return (1);
|
||||
Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 0, args);
|
||||
Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl");
|
||||
Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl", "shaders/denoising.glsl");
|
||||
// Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl");
|
||||
|
||||
|
||||
@ -141,6 +141,20 @@ int main(int argc, char **argv)
|
||||
glDispatchCompute((WIDTH + 15) / 16, (HEIGHT + 15) / 16, 1);
|
||||
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
|
||||
|
||||
//
|
||||
glUseProgram(shader.getProgramComputeDenoising());
|
||||
glUniform2fv(glGetUniformLocation(shader.getProgramComputeDenoising(), "u_resolution"), 1, glm::value_ptr(glm::vec2(WIDTH, HEIGHT)));
|
||||
|
||||
for (int pass = 0; pass < 1; ++pass)
|
||||
{
|
||||
shader.flipOutputDenoising(pass % 2 == 0);
|
||||
|
||||
glDispatchCompute((WIDTH + 15) / 16, (HEIGHT + 15) / 16, 1);
|
||||
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
|
||||
}
|
||||
shader.flipOutputDenoising(true);
|
||||
//
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
window.imGuiNewFrame();
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user