denoise only on last image when rendering

This commit is contained in:
2025-02-15 23:51:18 +01:00
parent 0544bc3a0f
commit 99965ae243
5 changed files with 30 additions and 16 deletions

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/22 16:29:26 by tomoron #+# #+# */ /* Created: 2025/01/22 16:29:26 by tomoron #+# #+# */
/* Updated: 2025/02/05 17:24:37 by tomoron ### ########.fr */ /* Updated: 2025/02/15 22:46:36 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -25,6 +25,7 @@ extern "C" {
class Scene; class Scene;
class Window; class Window;
class Shader; class Shader;
class ShaderProgram;
typedef struct s_pathPoint typedef struct s_pathPoint
{ {
@ -38,7 +39,7 @@ class Renderer
public: public:
Renderer(Scene *scene, Window *win, Arguments &args); Renderer(Scene *scene, Window *win, Arguments &args);
void update(GLuint &texture); void update(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
void renderImgui(void); void renderImgui(void);
int rendering(void) const; int rendering(void) const;
@ -66,7 +67,7 @@ class Renderer
void initRender(); void initRender();
void fillGoodCodecList(std::vector<AVCodecID> &lst); void fillGoodCodecList(std::vector<AVCodecID> &lst);
void updateAvailableCodecs(int mode, AVCodecID id); void updateAvailableCodecs(int mode, AVCodecID id);
void addImageToRender(GLuint &texture); void addImageToRender(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
void endRender(void); void endRender(void);

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */ /* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/13 16:15:41 by TheRed #+# #+# */ /* Created: 2024/10/13 16:15:41 by TheRed #+# #+# */
/* Updated: 2025/02/04 16:46:37 by tomoron ### ########.fr */ /* Updated: 2025/02/15 22:54:27 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -47,8 +47,9 @@ class Window
bool &getAccumulate(void); bool &getAccumulate(void);
void setFrameCount(int nb); void setFrameCount(int nb);
bool isRendering();
void rendererUpdate(GLuint &texture); void rendererUpdate(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
private: private:
GLFWwindow *_window; GLFWwindow *_window;
Scene *_scene; Scene *_scene;

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */ /* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/27 14:51:49 by TheRed #+# #+# */ /* Created: 2024/09/27 14:51:49 by TheRed #+# #+# */
/* Updated: 2025/02/14 18:26:34 by tomoron ### ########.fr */ /* Updated: 2025/02/15 22:54:52 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -66,7 +66,7 @@ int main(int argc, char **argv)
window.updateDeltaTime(); window.updateDeltaTime();
updateDataOnGPU(scene, buffers); updateDataOnGPU(scene, buffers);
window.rendererUpdate(textures[0]); window.rendererUpdate(textures, denoising_program);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@ -86,7 +86,7 @@ int main(int argc, char **argv)
raytracing_program.dispathCompute((WIDTH + 15) / 16, (HEIGHT + 15) / 16, 1); raytracing_program.dispathCompute((WIDTH + 15) / 16, (HEIGHT + 15) / 16, 1);
if (scene.getDenoise().enabled) if (scene.getDenoise().enabled && !window.isRendering())
shaderDenoise(denoising_program, scene.getDenoise(), textures); shaderDenoise(denoising_program, scene.getDenoise(), textures);
window.imGuiNewFrame(); window.imGuiNewFrame();

View File

@ -6,12 +6,14 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */ /* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/22 16:34:53 by tomoron #+# #+# */ /* Created: 2025/01/22 16:34:53 by tomoron #+# #+# */
/* Updated: 2025/02/13 19:03:34 by ycontre ### ########.fr */ /* Updated: 2025/02/15 22:51:54 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "RT.hpp" #include "RT.hpp"
void shaderDenoise(ShaderProgram &denoising_program, GPUDenoise &denoise, std::vector<GLuint> textures);
Renderer::Renderer(Scene *scene, Window *win, Arguments &args) Renderer::Renderer(Scene *scene, Window *win, Arguments &args)
{ {
std::string *renderPath; std::string *renderPath;
@ -300,7 +302,7 @@ void Renderer::initRender(void)
SWS_BILINEAR, nullptr, nullptr, nullptr); SWS_BILINEAR, nullptr, nullptr, nullptr);
} }
void Renderer::addImageToRender(GLuint &texture) void Renderer::addImageToRender(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram)
{ {
std::vector<float> image(WIDTH * HEIGHT * 4); std::vector<float> image(WIDTH * HEIGHT * 4);
@ -308,7 +310,10 @@ void Renderer::addImageToRender(GLuint &texture)
long int videoFrameOffset; long int videoFrameOffset;
long int outputImageOffset; long int outputImageOffset;
glBindTexture(GL_TEXTURE_2D, texture);
if(_scene->getDenoise().enabled)
shaderDenoise(denoisingProgram, _scene->getDenoise(), textures);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, image.data()); glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, image.data());
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
@ -403,7 +408,7 @@ void Renderer::addPoint(float time)
_path.insert(pos, newPoint); _path.insert(pos, newPoint);
} }
void Renderer::update(GLuint &texture) void Renderer::update(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram)
{ {
double curTime; double curTime;
@ -424,7 +429,7 @@ void Renderer::update(GLuint &texture)
if(!_testMode) if(!_testMode)
{ {
addImageToRender(texture); addImageToRender(textures, denoisingProgram);
_frameCount++; _frameCount++;
} }
makeMovement(curTime - _curSplitStart, curTime); makeMovement(curTime - _curSplitStart, curTime);

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */ /* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/13 16:16:24 by TheRed #+# #+# */ /* Created: 2024/10/13 16:16:24 by TheRed #+# #+# */
/* Updated: 2025/02/06 02:57:16 by tomoron ### ########.fr */ /* Updated: 2025/02/15 22:54:33 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -160,6 +160,7 @@ void Window::display()
glfwSwapBuffers(_window); glfwSwapBuffers(_window);
} }
void Window::pollEvents() void Window::pollEvents()
{ {
this->process_input(); this->process_input();
@ -167,14 +168,20 @@ void Window::pollEvents()
glfwPollEvents(); glfwPollEvents();
} }
bool Window::shouldClose() bool Window::shouldClose()
{ {
return glfwWindowShouldClose(_window) || _renderer->shouldClose(); return glfwWindowShouldClose(_window) || _renderer->shouldClose();
} }
void Window::rendererUpdate(GLuint &texture) bool Window::isRendering()
{ {
_renderer->update(texture); return (_renderer->rendering());
}
void Window::rendererUpdate(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram)
{
_renderer->update(textures, denoisingProgram);
} }
void Window::imGuiNewFrame() void Window::imGuiNewFrame()