+ | Renderer working

This commit is contained in:
TheRedShip
2025-02-14 18:11:33 +01:00
parent 583e15685a
commit a704a1fd76
7 changed files with 57 additions and 40 deletions

View File

@ -38,7 +38,7 @@ class Renderer
public: public:
Renderer(Scene *scene, Window *win, Arguments &args); Renderer(Scene *scene, Window *win, Arguments &args);
void update(Shader &shader); void update(GLuint &texture);
void renderImgui(void); void renderImgui(void);
int rendering(void) const; int rendering(void) const;
@ -66,7 +66,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(Shader &shader); void addImageToRender(GLuint &texture);
void endRender(void); void endRender(void);

View File

@ -48,7 +48,7 @@ class Window
void setFrameCount(int nb); void setFrameCount(int nb);
void rendererUpdate(Shader &shader); void rendererUpdate(GLuint &texture);
private: private:
GLFWwindow *_window; GLFWwindow *_window;
Scene *_scene; Scene *_scene;

View File

@ -1,4 +1,4 @@
#if 0 #if SHADER_DEBUG
#include "shaders/debug.glsl" #include "shaders/debug.glsl"
#else #else
#include "shaders/raytracing.glsl" #include "shaders/raytracing.glsl"

View File

@ -132,21 +132,31 @@ struct Stats
#include "shaders/intersect.glsl" #include "shaders/intersect.glsl"
int traceRay(Ray ray) hitInfo traceScene(Ray ray)
{ {
int num_hit; hitInfo hit;
hit.t = 1e30;
hit.obj_index = -1;
num_hit = 0;
for (int i = 0; i < u_objectsNum; i++) for (int i = 0; i < u_objectsNum; i++)
{ {
GPUObject obj = objects[i]; GPUObject obj = objects[i];
hitInfo temp_hit; hitInfo temp_hit;
if (intersect(ray, obj, temp_hit))
num_hit++; if (intersect(ray, obj, temp_hit) && temp_hit.t < hit.t)
{
hit.t = temp_hit.t;
hit.obj_index = i;
hit.obj_type = obj.type;
hit.mat_index = obj.mat_index;
hit.position = temp_hit.position;
hit.normal = temp_hit.normal;
}
} }
return (num_hit); return (hit);
} }
hitInfo traceBVH(Ray ray, GPUBvhData bvh_data, inout Stats stats) hitInfo traceBVH(Ray ray, GPUBvhData bvh_data, inout Stats stats)
@ -272,12 +282,23 @@ Ray initRay(vec2 uv)
return (Ray(origin, ray_direction, (1.0 / ray_direction))); return (Ray(origin, ray_direction, (1.0 / ray_direction)));
} }
hitInfo trace(Ray ray, inout Stats stats)
{
hitInfo hitBVH;
hitInfo hitScene;
hitInfo hit;
hitBVH = traverseBVHs(ray, stats);
hitScene = traceScene(ray);
return (hitBVH.t < hitScene.t ? hitBVH : hitScene);
}
vec3 debugColor(vec2 uv) vec3 debugColor(vec2 uv)
{ {
Ray ray = initRay(uv); Ray ray = initRay(uv);
Stats stats = Stats(0, 0); Stats stats = Stats(0, 0);
hitInfo hit = traverseBVHs(ray, stats); hitInfo hit = trace(ray, stats);
float box_display = float(stats.box_count) / float(debug.box_treshold); float box_display = float(stats.box_count) / float(debug.box_treshold);
float triangle_display = float(stats.triangle_count) / float(debug.triangle_treshold); float triangle_display = float(stats.triangle_count) / float(debug.triangle_treshold);

View File

@ -64,9 +64,11 @@ int main(int argc, char **argv)
while (!window.shouldClose()) while (!window.shouldClose())
{ {
window.updateDeltaTime(); window.updateDeltaTime();
glClear(GL_COLOR_BUFFER_BIT);
updateDataOnGPU(scene, buffers); updateDataOnGPU(scene, buffers);
window.rendererUpdate(textures[0]);
glClear(GL_COLOR_BUFFER_BIT);
raytracing_program.use(); raytracing_program.use();
raytracing_program.set_int("u_frameCount", window.getFrameCount()); raytracing_program.set_int("u_frameCount", window.getFrameCount());

View File

@ -300,15 +300,17 @@ void Renderer::initRender(void)
SWS_BILINEAR, nullptr, nullptr, nullptr); SWS_BILINEAR, nullptr, nullptr, nullptr);
} }
void Renderer::addImageToRender(Shader &shader) void Renderer::addImageToRender(GLuint &texture)
{ {
std::vector<float> image; std::vector<float> image(WIDTH * HEIGHT * 4);
AVPacket *pkt; AVPacket *pkt;
long int videoFrameOffset; long int videoFrameOffset;
long int outputImageOffset; long int outputImageOffset;
(void) shader; glBindTexture(GL_TEXTURE_2D, texture);
// image = shader.getOutputImage(); glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, image.data());
glBindTexture(GL_TEXTURE_2D, 0);
for (int x = 0; x < WIDTH; x++) for (int x = 0; x < WIDTH; x++)
{ {
@ -401,7 +403,7 @@ void Renderer::addPoint(float time)
_path.insert(pos, newPoint); _path.insert(pos, newPoint);
} }
void Renderer::update(Shader &shader) void Renderer::update(GLuint &texture)
{ {
double curTime; double curTime;
@ -422,7 +424,7 @@ void Renderer::update(Shader &shader)
if(!_testMode) if(!_testMode)
{ {
addImageToRender(shader); addImageToRender(texture);
_frameCount++; _frameCount++;
} }
makeMovement(curTime - _curSplitStart, curTime); makeMovement(curTime - _curSplitStart, curTime);

View File

@ -172,9 +172,9 @@ bool Window::shouldClose()
return glfwWindowShouldClose(_window) || _renderer->shouldClose(); return glfwWindowShouldClose(_window) || _renderer->shouldClose();
} }
void Window::rendererUpdate(Shader &shader) void Window::rendererUpdate(GLuint &texture)
{ {
_renderer->update(shader); _renderer->update(texture);
} }
void Window::imGuiNewFrame() void Window::imGuiNewFrame()
@ -253,7 +253,7 @@ void Window::imGuiRender(ShaderProgram &raytracing_program)
if (ImGui::CollapsingHeader("Fog")) if (ImGui::CollapsingHeader("Fog"))
{ {
if (ImGui::Checkbox("Enable", (bool *)(&_scene->getVolume().enabled))) if (ImGui::Checkbox("Enable##0", (bool *)(&_scene->getVolume().enabled)))
{ {
raytracing_program.set_define("FOG", std::to_string(_scene->getVolume().enabled)); raytracing_program.set_define("FOG", std::to_string(_scene->getVolume().enabled));
raytracing_program.reloadShaders(); raytracing_program.reloadShaders();
@ -279,9 +279,7 @@ void Window::imGuiRender(ShaderProgram &raytracing_program)
if (ImGui::CollapsingHeader("Denoiser")) if (ImGui::CollapsingHeader("Denoiser"))
{ {
ImGui::PushID(0); ImGui::Checkbox("Enable##1", (bool *)(&_scene->getDenoise().enabled));
ImGui::Checkbox("Enable", (bool *)(&_scene->getDenoise().enabled));
ImGui::Separator(); ImGui::Separator();
if (ImGui::SliderInt("Pass", &_scene->getDenoise().pass, 0, 8)) if (ImGui::SliderInt("Pass", &_scene->getDenoise().pass, 0, 8))
_scene->getDenoise().pass = (_scene->getDenoise().pass / 2) * 2; // make sure it's even _scene->getDenoise().pass = (_scene->getDenoise().pass / 2) * 2; // make sure it's even
@ -289,15 +287,11 @@ void Window::imGuiRender(ShaderProgram &raytracing_program)
ImGui::SliderFloat("Color diff", &_scene->getDenoise().c_phi, 0.0f, 1.0f); 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("Position diff", &_scene->getDenoise().p_phi, 0.0f, 1.0f);
ImGui::SliderFloat("Normal diff", &_scene->getDenoise().n_phi, 0.0f, 1.0f); ImGui::SliderFloat("Normal diff", &_scene->getDenoise().n_phi, 0.0f, 1.0f);
ImGui::PopID();
} }
if (ImGui::CollapsingHeader("Debug")) if (ImGui::CollapsingHeader("Debug"))
{ {
ImGui::PushID(0); if (ImGui::Checkbox("Enable##2", (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.set_define("DEBUG", std::to_string(_scene->getDebug().enabled));
raytracing_program.reloadShaders(); raytracing_program.reloadShaders();
@ -307,8 +301,6 @@ void Window::imGuiRender(ShaderProgram &raytracing_program)
has_changed |= ImGui::SliderInt("Debug mode", &_scene->getDebug().mode, 0, 2); 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("Box treshold", &_scene->getDebug().box_treshold, 1, 2000);
has_changed |= ImGui::SliderInt("Triangle treshold", &_scene->getDebug().triangle_treshold, 1, 2000); has_changed |= ImGui::SliderInt("Triangle treshold", &_scene->getDebug().triangle_treshold, 1, 2000);
ImGui::PopID();
} }
@ -356,9 +348,9 @@ int Window::getPixelisation(void)
if (mouse || movement) if (mouse || movement)
{ {
if(_fps < 60 && _pixelisation < 16) if(_fps < 30 && _pixelisation < 16)
_pixelisation++; _pixelisation++;
if(_fps > 120 && _pixelisation > 0) if(_fps > 60 && _pixelisation > 0)
_pixelisation--; _pixelisation--;
} }
else if(_pixelisation) else if(_pixelisation)