mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | Renderer working
This commit is contained in:
@ -38,7 +38,7 @@ class Renderer
|
||||
public:
|
||||
Renderer(Scene *scene, Window *win, Arguments &args);
|
||||
|
||||
void update(Shader &shader);
|
||||
void update(GLuint &texture);
|
||||
void renderImgui(void);
|
||||
|
||||
int rendering(void) const;
|
||||
@ -66,7 +66,7 @@ class Renderer
|
||||
void initRender();
|
||||
void fillGoodCodecList(std::vector<AVCodecID> &lst);
|
||||
void updateAvailableCodecs(int mode, AVCodecID id);
|
||||
void addImageToRender(Shader &shader);
|
||||
void addImageToRender(GLuint &texture);
|
||||
void endRender(void);
|
||||
|
||||
|
||||
|
@ -48,7 +48,7 @@ class Window
|
||||
|
||||
void setFrameCount(int nb);
|
||||
|
||||
void rendererUpdate(Shader &shader);
|
||||
void rendererUpdate(GLuint &texture);
|
||||
private:
|
||||
GLFWwindow *_window;
|
||||
Scene *_scene;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#if 0
|
||||
#if SHADER_DEBUG
|
||||
#include "shaders/debug.glsl"
|
||||
#else
|
||||
#include "shaders/raytracing.glsl"
|
||||
|
@ -132,21 +132,31 @@ struct Stats
|
||||
|
||||
#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++)
|
||||
{
|
||||
GPUObject obj = objects[i];
|
||||
|
||||
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)
|
||||
@ -272,12 +282,23 @@ Ray initRay(vec2 uv)
|
||||
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)
|
||||
{
|
||||
Ray ray = initRay(uv);
|
||||
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 triangle_display = float(stats.triangle_count) / float(debug.triangle_treshold);
|
||||
|
@ -64,9 +64,11 @@ int main(int argc, char **argv)
|
||||
while (!window.shouldClose())
|
||||
{
|
||||
window.updateDeltaTime();
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
updateDataOnGPU(scene, buffers);
|
||||
window.rendererUpdate(textures[0]);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
raytracing_program.use();
|
||||
raytracing_program.set_int("u_frameCount", window.getFrameCount());
|
||||
|
@ -300,15 +300,17 @@ void Renderer::initRender(void)
|
||||
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;
|
||||
long int videoFrameOffset;
|
||||
long int outputImageOffset;
|
||||
|
||||
(void) shader;
|
||||
// image = shader.getOutputImage();
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, image.data());
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
for (int x = 0; x < WIDTH; x++)
|
||||
{
|
||||
@ -401,7 +403,7 @@ void Renderer::addPoint(float time)
|
||||
_path.insert(pos, newPoint);
|
||||
}
|
||||
|
||||
void Renderer::update(Shader &shader)
|
||||
void Renderer::update(GLuint &texture)
|
||||
{
|
||||
double curTime;
|
||||
|
||||
@ -422,7 +424,7 @@ void Renderer::update(Shader &shader)
|
||||
|
||||
if(!_testMode)
|
||||
{
|
||||
addImageToRender(shader);
|
||||
addImageToRender(texture);
|
||||
_frameCount++;
|
||||
}
|
||||
makeMovement(curTime - _curSplitStart, curTime);
|
||||
|
@ -172,9 +172,9 @@ bool Window::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()
|
||||
@ -253,7 +253,7 @@ void Window::imGuiRender(ShaderProgram &raytracing_program)
|
||||
|
||||
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.reloadShaders();
|
||||
@ -279,9 +279,7 @@ void Window::imGuiRender(ShaderProgram &raytracing_program)
|
||||
|
||||
if (ImGui::CollapsingHeader("Denoiser"))
|
||||
{
|
||||
ImGui::PushID(0);
|
||||
|
||||
ImGui::Checkbox("Enable", (bool *)(&_scene->getDenoise().enabled));
|
||||
ImGui::Checkbox("Enable##1", (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
|
||||
@ -289,15 +287,11 @@ void Window::imGuiRender(ShaderProgram &raytracing_program)
|
||||
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);
|
||||
|
||||
if (ImGui::Checkbox("Enable", (bool *)(&_scene->getDebug().enabled)))
|
||||
if (ImGui::Checkbox("Enable##2", (bool *)(&_scene->getDebug().enabled)))
|
||||
{
|
||||
raytracing_program.set_define("DEBUG", std::to_string(_scene->getDebug().enabled));
|
||||
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("Box treshold", &_scene->getDebug().box_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(_fps < 60 && _pixelisation < 16)
|
||||
if(_fps < 30 && _pixelisation < 16)
|
||||
_pixelisation++;
|
||||
if(_fps > 120 && _pixelisation > 0)
|
||||
if(_fps > 60 && _pixelisation > 0)
|
||||
_pixelisation--;
|
||||
}
|
||||
else if(_pixelisation)
|
||||
|
Reference in New Issue
Block a user