Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Image_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 32 additions & 1 deletion PathTracer/src/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void Renderer::OnResize(uint32_t width, uint32_t height) {
return;

finalImage->Resize(width, height);

}
else {
finalImage = std::make_shared<Walnut::Image>(width, height, Walnut::ImageFormat::RGBA);
Expand All @@ -37,6 +38,18 @@ void Renderer::OnResize(uint32_t width, uint32_t height) {

delete[] accumulationData;
accumulationData = new glm::vec4[width * height];

imageHorizontalIterator.resize(width);
imageVerticalIterator.resize(height);

for (uint32_t i = 0; i < width; i++)
{
imageHorizontalIterator[i] = i;
}
for (uint32_t i = 0; i < height; i++)
{
imageVerticalIterator[i] = i;
}
}

void Renderer::Render(const Scene& scene, const Camera& camera) {
Expand All @@ -47,6 +60,24 @@ void Renderer::Render(const Scene& scene, const Camera& camera) {
if (frameIndex == 1)
memset(accumulationData, 0, finalImage->GetHeight() * finalImage->GetWidth() * sizeof(glm::vec4));

#define M_T 1
#if M_T 1
std::for_each(std::execution::par, imageVerticalIterator.begin(), imageVerticalIterator.end(),
[this](uint32_t y) {
std::for_each(std::execution::par, imageHorizontalIterator.begin(), imageHorizontalIterator.end(),
[this, y](uint32_t x) {
glm::vec4 color = RayGeneration(x, y);

accumulationData[x + y * finalImage->GetWidth()] += color;

glm::vec4 accumulatedColor = accumulationData[x + y * finalImage->GetWidth()];
accumulatedColor /= (float)frameIndex;
accumulatedColor = glm::clamp(accumulatedColor, glm::vec4(0.0f), glm::vec4(1.0f));

m_ImageData[x + finalImage->GetWidth() * y] = Utilities::ConvertToRGBA(accumulatedColor);
});
});
#else
for (uint32_t y = 0; y < finalImage->GetHeight(); y++)
{
for (uint32_t x = 0; x < finalImage->GetWidth(); x++) {
Expand All @@ -63,7 +94,7 @@ void Renderer::Render(const Scene& scene, const Camera& camera) {

}
}

#endif

finalImage->SetData(m_ImageData);

Expand Down
5 changes: 4 additions & 1 deletion PathTracer/src/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Walnut/Random.h"
#include "Camera.h"
#include "Ray.h"
#include <execution>
#include "Scene.h"


Expand All @@ -13,7 +14,7 @@ class Renderer {
public:

struct Settings {
bool Accumulate = false;
bool Accumulate = true;
};
Renderer() = default;

Expand Down Expand Up @@ -45,6 +46,8 @@ class Renderer {
std::shared_ptr<Walnut::Image> finalImage;
glm::vec4 RayGeneration(uint32_t x, uint32_t y);

std::vector<uint32_t> imageHorizontalIterator, imageVerticalIterator;

const Scene* activeScene = nullptr;
const Camera* activeCamera = nullptr;

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
### Path Tracer

#### Images:

![](file:///C:/Users/moham/Documents/GitHub/Vulkan-Based-Path-Tracer/Image_01.png)