~ | Fixing fog lighting acne and denoising not clearing

This commit is contained in:
TheRedShip
2025-03-09 16:01:03 +01:00
committed by tomoron
parent debfa4ea7d
commit ac47d587e6
4 changed files with 12 additions and 7 deletions

View File

@ -39,7 +39,7 @@ class Window
static void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods);
void imGuiNewFrame();
void imGuiRender(ShaderProgram &raytracing_program);
void imGuiRender(ShaderProgram &raytracing_program, std::vector<GLuint> &textures);
GLFWwindow *getWindow(void) const;
float getFps(void) const;

View File

@ -84,7 +84,7 @@ vec3 sampleSphereLight(vec3 position, GPUObject obj, int light_index, GPUMateria
}
float cos_theta = max(0.0, -dot(light_dir, normalize(sample_point - obj.position)));
return mat.emission * mat.color / (light_dist * light_dist) * cos_theta / (4.0 * M_PI * (obj.radius / 2.0) * (obj.radius / 2.0));
return mat.emission * mat.color / max(light_dist * light_dist, 1.0) * cos_theta / (4.0 * M_PI * (obj.radius / 2.0) * (obj.radius / 2.0));
}
vec3 sampleQuadLight(vec3 position, GPUObject obj, int light_index, GPUMaterial mat, inout uint rng_state)
@ -123,8 +123,8 @@ vec3 sampleQuadLight(vec3 position, GPUObject obj, int light_index, GPUMaterial
float area = length(crossQuad);
float pdf = 1.0 / area;
float cos_theta = max(0.0, dot(obj.normal, -light_dir));
return mat.emission * mat.color / (light_dist * light_dist) * pdf;
// float cos_theta = max(0.0, dot(obj.normal, -light_dir));
return mat.emission * mat.color / max(light_dist * light_dist, 1.);
}
vec3 sampleLights(in vec3 position, inout uint rng_state)

View File

@ -100,7 +100,7 @@ int main(int argc, char **argv)
render_program.use();
drawScreenTriangle(VAO, textures[window.getOutputTexture()], render_program.getProgram());
window.imGuiRender(raytracing_program);
window.imGuiRender(raytracing_program, textures);
window.display();
window.pollEvents();

View File

@ -200,7 +200,7 @@ void Window::imGuiNewFrame()
ImGui::NewFrame();
}
void Window::imGuiRender(ShaderProgram &raytracing_program)
void Window::imGuiRender(ShaderProgram &raytracing_program, std::vector<GLuint> &textures)
{
bool has_changed = false;
@ -298,7 +298,12 @@ void Window::imGuiRender(ShaderProgram &raytracing_program)
if (ImGui::CollapsingHeader("Denoiser"))
{
ImGui::Checkbox("Enable##1", (bool *)(&_scene->getDenoise().enabled));
if (ImGui::Checkbox("Enable##1", (bool *)(&_scene->getDenoise().enabled)))
{
//clear denoising texture
glClearTexImage(textures[3], 0, GL_RGBA, GL_FLOAT, nullptr);
glClearTexImage(textures[4], 0, GL_RGBA, GL_FLOAT, nullptr);
}
ImGui::Separator();
if (ImGui::SliderInt("Pass", &_scene->getDenoise().pass, 0, 8))
_scene->getDenoise().pass = (_scene->getDenoise().pass / 2) * 2; // make sure it's even