mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
+ | Imgui denoise
This commit is contained in:
34
srcs/RT.cpp
34
srcs/RT.cpp
@ -141,21 +141,28 @@ 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 < 4; ++pass)
|
||||
GPUDenoise denoise = scene.getDenoise();
|
||||
if (denoise.enabled)
|
||||
{
|
||||
shader.flipOutputDenoising(pass % 2 == 0);
|
||||
glUseProgram(shader.getProgramComputeDenoising());
|
||||
|
||||
glUniform1i(glGetUniformLocation(shader.getProgramComputeDenoising(), "u_pass"), pass);
|
||||
|
||||
glDispatchCompute((WIDTH + 15) / 16, (HEIGHT + 15) / 16, 1);
|
||||
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
|
||||
glUniform2fv(glGetUniformLocation(shader.getProgramComputeDenoising(), "u_resolution"), 1, glm::value_ptr(glm::vec2(WIDTH, HEIGHT)));
|
||||
glUniform1f(glGetUniformLocation(shader.getProgramComputeDenoising(), "u_c_phi"), denoise.c_phi);
|
||||
glUniform1f(glGetUniformLocation(shader.getProgramComputeDenoising(), "u_p_phi"), denoise.p_phi);
|
||||
glUniform1f(glGetUniformLocation(shader.getProgramComputeDenoising(), "u_n_phi"), denoise.n_phi);
|
||||
|
||||
for (int pass = 0; pass < denoise.pass ; ++pass)
|
||||
{
|
||||
shader.flipOutputDenoising(pass % 2 == 0);
|
||||
|
||||
glUniform1i(glGetUniformLocation(shader.getProgramComputeDenoising(), "u_pass"), pass);
|
||||
|
||||
glDispatchCompute((WIDTH + 15) / 16, (HEIGHT + 15) / 16, 1);
|
||||
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
|
||||
}
|
||||
shader.flipOutputDenoising(true);
|
||||
}
|
||||
shader.flipOutputDenoising(true);
|
||||
//
|
||||
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
@ -168,6 +175,9 @@ int main(int argc, char **argv)
|
||||
|
||||
window.display();
|
||||
window.pollEvents();
|
||||
|
||||
glClearTexImage(shader.getNormalTexture(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
glClearTexImage(shader.getPositionTexture(), 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
}
|
||||
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
|
@ -100,6 +100,7 @@ int Camera::portalTeleport(Scene *scene, float delta_time)
|
||||
|
||||
if (distance_portal <= distance_future_pos && glm::dot(glm::normalize(future_pos - _position), obj.normal) > 0.0f)
|
||||
{
|
||||
std::cout << "Teleportation" << std::endl;
|
||||
GPUObject linked_portal = scene->getObjectData()[obj.radius];
|
||||
|
||||
glm::mat4 portal_transform = linked_portal.transform * glm::inverse(obj.transform);
|
||||
|
@ -33,6 +33,11 @@ Scene::Scene(std::string &name)
|
||||
_gpu_debug.triangle_treshold = 1;
|
||||
_gpu_debug.box_treshold = 1;
|
||||
|
||||
_gpu_denoise.enabled = 0;
|
||||
_gpu_denoise.pass = 0;
|
||||
_gpu_denoise.c_phi = 0.1f;
|
||||
_gpu_denoise.p_phi = 0.1f;
|
||||
_gpu_denoise.n_phi = 0.1f;
|
||||
|
||||
if (!file.is_open())
|
||||
{
|
||||
@ -364,6 +369,11 @@ GPUDebug &Scene::getDebug()
|
||||
return (_gpu_debug);
|
||||
}
|
||||
|
||||
GPUDenoise &Scene::getDenoise()
|
||||
{
|
||||
return (_gpu_denoise);
|
||||
}
|
||||
|
||||
std::vector<GPUBvhData> &Scene::getBvhData()
|
||||
{
|
||||
return (_gpu_bvh_data);
|
||||
|
@ -300,6 +300,16 @@ GLuint Shader::getProgramComputeDenoising(void) const
|
||||
return (_program_denoising);
|
||||
}
|
||||
|
||||
GLuint Shader::getNormalTexture(void) const
|
||||
{
|
||||
return (_normal_texture);
|
||||
}
|
||||
|
||||
GLuint Shader::getPositionTexture(void) const
|
||||
{
|
||||
return (_position_texture);
|
||||
}
|
||||
|
||||
std::vector<float> Shader::getOutputImage(void)
|
||||
{
|
||||
std::vector<float> res(WIDTH * HEIGHT * 4);
|
||||
|
@ -272,17 +272,37 @@ void Window::imGuiRender()
|
||||
has_changed = true;
|
||||
}
|
||||
|
||||
if (ImGui::CollapsingHeader("Denoiser"))
|
||||
{
|
||||
ImGui::PushID(0);
|
||||
|
||||
ImGui::Checkbox("Enable", (bool *)(&_scene->getDenoise().enabled));
|
||||
ImGui::Separator();
|
||||
if (ImGui::SliderInt("Pass", &_scene->getDenoise().pass, 0, 8))
|
||||
_scene->getDenoise().pass = (_scene->getDenoise().pass / 2) * 2; // make sure it's even
|
||||
|
||||
ImGui::SliderFloat("Color diff", &_scene->getDenoise().c_phi, 0.0f, 1.0f);
|
||||
ImGui::SliderFloat("Position diff", &_scene->getDenoise().p_phi, 0.0f, 1.0f);
|
||||
ImGui::SliderFloat("Normal diff", &_scene->getDenoise().n_phi, 0.0f, 1.0f);
|
||||
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
if (ImGui::CollapsingHeader("Debug"))
|
||||
{
|
||||
ImGui::PushID(0);
|
||||
|
||||
has_changed |= ImGui::Checkbox("Enable", (bool *)(&_scene->getDebug().enabled));
|
||||
ImGui::Separator();
|
||||
has_changed |= ImGui::SliderInt("Debug mode", &_scene->getDebug().mode, 0, 2);
|
||||
has_changed |= ImGui::SliderInt("Box treshold", &_scene->getDebug().box_treshold, 1, 2000);
|
||||
has_changed |= ImGui::SliderInt("Triangle treshold", &_scene->getDebug().triangle_treshold, 1, 2000);
|
||||
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
_renderer->renderImgui();;
|
||||
|
||||
_renderer->renderImgui();
|
||||
|
||||
ImGui::End();
|
||||
|
||||
|
Reference in New Issue
Block a user