From 5b0b916c561f602723b9ae80f5462a7939b652a1 Mon Sep 17 00:00:00 2001 From: Julian T Date: Thu, 13 Aug 2020 20:06:29 +0200 Subject: Pathtracing working with defuse and emissive lighting --- app/rendercoord.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'app/rendercoord.cpp') diff --git a/app/rendercoord.cpp b/app/rendercoord.cpp index f9fc9f8..9c59acd 100644 --- a/app/rendercoord.cpp +++ b/app/rendercoord.cpp @@ -5,12 +5,13 @@ #include -uint32_t colorToUint32(Color &c) { - c.clamp(); +uint32_t colorToUint32(const Color &c) { + Color cnew = Color(c); + cnew.clamp(); return (0xFF << 24) + - (c.r() << 16) + - (c.g() << 8) + - c.b(); + (cnew.r() << 16) + + (cnew.g() << 8) + + cnew.b(); } // Run by main thread @@ -27,12 +28,19 @@ void RenderThread::run() { while (1) { // Wait for work m_work.acquire(); + m_render.m_sampler.seed(100); - for (unsigned x = 0; x < m_render.m_width; x++) { - for (unsigned y = 0; y < m_render.m_height; y++) { - auto c = m_render.render(m_render.m_width - x, m_render.m_height - y); - m_writebuffer[x + y * m_render.m_height] = - static_cast(colorToUint32(c)); + // Very expensive, but necesary to get live rendering + Color *sum = new Color[m_render.m_width * m_render.m_height]; + + for (unsigned sample = 1; sample < m_samples+1; sample++) { + for (unsigned x = 0; x < m_render.m_width; x++) { + for (unsigned y = 0; y < m_render.m_height; y++) { + auto index = x + y * m_render.m_height; + sum[index] += m_render.render(m_render.m_width - x, m_render.m_height - y, 1); + + m_writebuffer[index] = colorToUint32(sum[index] / sample); + } } } @@ -64,7 +72,7 @@ RenderCoordinator::RenderCoordinator(QObject *parent, DrawWidget &target, Render QObject::connect(&m_worker, &RenderThread::done, this, &RenderCoordinator::workerDone); - m_worker.render(target.m_drawbuffer, 1); + m_worker.render(target.m_drawbuffer, 100); } -- cgit v1.2.3