diff options
author | Julian T <julian@jtle.dk> | 2020-08-13 20:06:29 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2020-08-13 20:06:29 +0200 |
commit | 5b0b916c561f602723b9ae80f5462a7939b652a1 (patch) | |
tree | 6ee419f0dd1649b2c329585551f06a555a631db8 /app/rendercoord.cpp | |
parent | 690b72664ca8d471f5c117f6ed87aeae2de0a208 (diff) |
Pathtracing working with defuse and emissive lighting
Diffstat (limited to 'app/rendercoord.cpp')
-rw-r--r-- | app/rendercoord.cpp | 30 |
1 files changed, 19 insertions, 11 deletions
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 <render.hpp> -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<QRgb>(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); } |