+ | Define system + denoising back

This commit is contained in:
TheRedShip
2025-02-13 23:18:04 +01:00
parent 9b8da6ebd8
commit 4ddacdaadd
14 changed files with 376 additions and 319 deletions

View File

@ -16,12 +16,12 @@
#include <stdlib.h>
#include <string.h>
const char *loadFileWithIncludes(const std::string& path)
std::stringstream loadFileWithIncludes(const std::string& path)
{
std::ifstream file(path);
if (!file.is_open()) {
std::cerr << "Failed to open file: " << path << std::endl;
return "";
return std::stringstream();
}
std::stringstream fileContent;
@ -36,7 +36,7 @@ const char *loadFileWithIncludes(const std::string& path)
if (start != std::string::npos && end != std::string::npos && end > start)
{
std::string includePath = line.substr(start + 1, end - start - 1);
std::string includedContent = loadFileWithIncludes(includePath);
std::string includedContent = loadFileWithIncludes(includePath).str();
fileContent << includedContent << "\n";
}
}
@ -44,7 +44,7 @@ const char *loadFileWithIncludes(const std::string& path)
fileContent << line << "\n";
}
return strdup(fileContent.str().c_str());
return fileContent;
}
@ -78,10 +78,16 @@ void Shader::compile()
{
_shader_id = glCreateShader(_type);
const char *shader_code = loadFileWithIncludes(_file_path);
// printWithLineNumbers(shader_code);
std::string shader_code = loadFileWithIncludes(_file_path).str();
glShaderSource(_shader_id, 1, &shader_code, NULL);
for (auto &define : _defines)
shader_code = "#define SHADER_" + define.first + " " + define.second + "\n" + shader_code;
shader_code = "#version 430\n" + shader_code;
const char *shader_code_cstr = shader_code.c_str();
// printWithLineNumbers(shader_code_cstr);
glShaderSource(_shader_id, 1, &shader_code_cstr, NULL);
glCompileShader(_shader_id);
this->checkCompileErrors();
@ -106,6 +112,11 @@ void Shader::checkCompileErrors()
}
}
void Shader::setDefine(const std::string &name, const std::string &value)
{
_defines[name] = value;
}
GLuint Shader::getShader(void) const
{
return (_shader_id);

View File

@ -115,6 +115,12 @@ void ShaderProgram::set_textures(std::map<std::string, std::vector<GLuint>> text
}
}
void ShaderProgram::set_define(const std::string &name, const std::string &value)
{
for (Shader *shader : _shaders)
shader->setDefine(name, value);
}
GLuint ShaderProgram::getProgram(void) const
{
return (_program);

View File

@ -184,7 +184,7 @@ void Window::imGuiNewFrame()
ImGui::NewFrame();
}
void Window::imGuiRender()
void Window::imGuiRender(ShaderProgram &raytracing_program)
{
bool has_changed = false;
@ -253,7 +253,12 @@ void Window::imGuiRender()
if (ImGui::CollapsingHeader("Fog"))
{
has_changed |= ImGui::Checkbox("Enable", (bool *)(&_scene->getVolume().enabled));
if (ImGui::Checkbox("Enable", (bool *)(&_scene->getVolume().enabled)))
{
raytracing_program.set_define("FOG", std::to_string(_scene->getVolume().enabled));
raytracing_program.reloadShaders();
has_changed = true;
}
ImGui::Separator();
if (ImGui::SliderFloat("Absorption", &_scene->getVolume().sigma_a.x, 0., 0.1))
@ -292,7 +297,12 @@ void Window::imGuiRender()
{
ImGui::PushID(0);
has_changed |= ImGui::Checkbox("Enable", (bool *)(&_scene->getDebug().enabled));
if (ImGui::Checkbox("Enable", (bool *)(&_scene->getDebug().enabled)))
{
raytracing_program.set_define("DEBUG", std::to_string(_scene->getDebug().enabled));
raytracing_program.reloadShaders();
has_changed = true;
}
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);