Skip to content

Commit

Permalink
Merge pull request #11 from kakol20/rgb-rays
Browse files Browse the repository at this point in the history
Rgb rays
  • Loading branch information
kakol20 authored Aug 14, 2022
2 parents 00e7f59 + 9c15bc4 commit e300621
Show file tree
Hide file tree
Showing 25 changed files with 7,132 additions and 9,165 deletions.
Binary file modified renders/debugScene/denoiser.blend
Binary file not shown.
1,760 changes: 880 additions & 880 deletions renders/debugScene/log_albedo.txt

Large diffs are not rendered by default.

1,760 changes: 880 additions & 880 deletions renders/debugScene/log_color.txt

Large diffs are not rendered by default.

1,760 changes: 880 additions & 880 deletions renders/debugScene/log_emission.txt

Large diffs are not rendered by default.

1,760 changes: 880 additions & 880 deletions renders/debugScene/log_normal.txt

Large diffs are not rendered by default.

Binary file modified renders/debugScene/render_a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified renders/debugScene/render_c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified renders/debugScene/render_denoised.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified renders/debugScene/render_e.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified renders/debugScene/render_n.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions renders/debugScene/runTime.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Elapsed time in seconds: 93.0372s
Elapsed time in minutes: 1.55062min
Elapsed time in seconds: 232.207s
Elapsed time in minutes: 3.87011min
Binary file modified renders/original/denoiser.blend
Binary file not shown.
2,282 changes: 881 additions & 1,401 deletions renders/original/log_albedo.txt

Large diffs are not rendered by default.

2,282 changes: 881 additions & 1,401 deletions renders/original/log_color.txt

Large diffs are not rendered by default.

2,282 changes: 881 additions & 1,401 deletions renders/original/log_emission.txt

Large diffs are not rendered by default.

2,282 changes: 881 additions & 1,401 deletions renders/original/log_normal.txt

Large diffs are not rendered by default.

Binary file modified renders/original/render_a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified renders/original/render_c.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified renders/original/render_n.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions renders/original/runTime.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Elapsed time in seconds: 1064.04s
Elapsed time in minutes: 17.734min
Elapsed time in seconds: 1632.31s
Elapsed time in minutes: 27.2051min
6 changes: 3 additions & 3 deletions settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ renderScale=1
# ----- RENDER SETTINGS -----
rayDepth=8
threads=12
maxSamples=128
minSamples=32
maxSamples=32
minSamples=8
noiseThreshold=0.01
tileSize=32
# color, normal, albedo, emission or all
renderMode=all
# original or debug
scene=debug
scene=original

# ----- CAMERA SETTINGS -----
blurStrength=0.1
Expand Down
7 changes: 6 additions & 1 deletion src/misc/Random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ Float Random::RandomFloat(const Float& min, const Float& max) {
Float random = Float(Random::RandomUInt());
random /= std::numeric_limits<unsigned int>::max();
return (random * (max - min)) + min;
}
}

int Random::RandomInt(const int& min, const int& max) {
int distance = (max - min) + 1;
return (Random::RandomUInt() % distance) + min;
}
1 change: 1 addition & 0 deletions src/misc/Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Random {
static unsigned int RandomUInt(const unsigned int& bitCount = 32);

static Float RandomFloat(const Float& min = 0, const Float& max = 1);
static int RandomInt(const int& min, const int& max);
};

#endif // !RANDOM_H
105 changes: 73 additions & 32 deletions src/raytracing/Raytracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,35 +535,74 @@ void Raytracing::Render(const int& minX, const int& minY, const int& maxX, const
Vector3D previous(0);
Vector3D totalDiff(0);

size_t samplesOffset = (size_t)Float::Round(Random::RandomFloat(0, (int)m_blueNoise.Size())).ToInt();
//size_t redOffset = (size_t)Float::Round(Random::RandomFloat(0, (int)m_blueNoise.Size())).ToInt();
size_t sampleOffset = (size_t)Random::RandomInt(0, (int)m_blueNoise.Size());

for (int s = 0; s < maxSamples; s++) {
//Float u = x / Float(imageWidth - 1);
//Float v = y / Float(imageHeight - 1);

Float u = x;
Float v = y;
Float redU = x - 1;
Float redV = y;
Float greenU = x;
Float greenV = y;
Float blueU = x + 1;
Float blueV = y;

if (s < (int)m_blueNoise.Size()) {
size_t index = s + samplesOffset;
size_t index = s + sampleOffset;
Vector3D sample = m_blueNoise[index];
u += sample.GetX();
v += sample.GetY();
redU += sample.GetX();
redV += sample.GetY();

greenU += sample.GetX();
greenV += sample.GetY();

blueU += sample.GetX();
blueV += sample.GetY();
}
else {
u += Random::RandomFloat();
v += Random::RandomFloat();
redU += Random::RandomFloat();
redV += Random::RandomFloat();

greenU = redU + 1;
greenV = redV;

blueU = greenU + 1;
blueV = greenV;
}

u /= Float(imageWidth - 1);
v /= Float(imageHeight - 1);
redU /= Float(imageWidth - 1);
redV /= Float(imageHeight - 1);

greenU /= Float(imageWidth - 1);
greenV /= Float(imageHeight - 1);

blueU /= Float(imageWidth - 1);
blueV /= Float(imageHeight - 1);

Vector3D redRayColor;

Ray ray = m_camera.GetRay(u, v);
Vector3D rayColor = RayColor(ray, maxDepth);
if (m_settings["renderMode"] != "normal") {
Ray ray = m_camera.GetRay(redU, redV);
redRayColor = RayColor(ray, maxDepth, Vector3D(1, 0, 0));

ray = m_camera.GetRay(greenU, greenV);
Vector3D greenRayColor = RayColor(ray, maxDepth, Vector3D(0, 1, 0));

ray = m_camera.GetRay(blueU, blueV);
Vector3D blueRayColor = RayColor(ray, maxDepth, Vector3D(0, 0, 1));

redRayColor += greenRayColor + blueRayColor;
}
else {
Ray ray = m_camera.GetRay(greenU, greenV);
redRayColor = RayColor(ray, maxDepth, Vector3D(1, 1, 1));
}

if (count > 0) {
Vector3D difference;
difference = previous - (rayColor * 255);
difference = previous - (redRayColor * 255);
difference = Vector3D::Abs(difference);
totalDiff += difference;

Expand All @@ -576,16 +615,16 @@ void Raytracing::Render(const int& minX, const int& minY, const int& maxX, const

if (belowThreshold) {
count++;
pixelCol += rayColor;
pixelCol += redRayColor;

break;
}
}
}

previous = rayColor * 255;
previous = redRayColor * 255;
count++;
pixelCol += rayColor;
pixelCol += redRayColor;
}

if (count <= 0) count = 1;
Expand All @@ -599,7 +638,7 @@ void Raytracing::Render(const int& minX, const int& minY, const int& maxX, const
}
}

Vector3D Raytracing::RayColor(Ray& ray, const int& depth) {
Vector3D Raytracing::RayColor(Ray& ray, const int& depth, const Vector3D& initialRayCol) {
if (depth <= 0) return Vector3D(Float::NearZero);

// check for object hit
Expand All @@ -612,25 +651,29 @@ Vector3D Raytracing::RayColor(Ray& ray, const int& depth) {

rec.GetMat()->Scatter(ray, rec, attentuation, scattered, normal, absorb, transparent, emission);

attentuation *= initialRayCol;

if (m_settings["renderMode"] == "color") {
if (absorb || emission) {
return attentuation;
}
else if (transparent) {
Ray continueRay(rec.GetPoint(), ray.GetDir());
return RayColor(continueRay, depth - 1);
return RayColor(continueRay, depth - 1, initialRayCol);
}
else {
return attentuation * RayColor(scattered, depth - 1);
//return attentuation * RayColor(scattered, depth - 1);
if (attentuation.NearZero()) return attentuation;
return attentuation * RayColor(scattered, depth - 1, initialRayCol);
}
}
else if (m_settings["renderMode"] == "normal") {
if (transparent) {
Ray continueRay(rec.GetPoint(), ray.GetDir());
return RayColor(continueRay, depth - 1);
return RayColor(continueRay, depth - 1, initialRayCol);
}
else {
return (normal + Vector3D::One) / 2;
return ((normal + Vector3D::One) / 2) * initialRayCol;
}
}
else if (m_settings["renderMode"] == "albedo") {
Expand All @@ -653,11 +696,11 @@ Vector3D Raytracing::RayColor(Ray& ray, const int& depth) {
if (m_settings["renderMode"] == "color" || m_settings["renderMode"] == "albedo") {
if (m_settings["scene"] == "original") {
Float t = 0.5 * (unitDir.GetY() + 1);
return (Vector3D::One * (1 - t)) + (Vector3D(0.5, 0.7, 1) * t);
return ((Vector3D::One * (1 - t)) + (Vector3D(0.5, 0.7, 1) * t)) * initialRayCol;
}
else {
Vector3D uv = unitDir.UVSphere();
uv -= Vector3D(1, 0, 0);
uv *= Vector3D(-1, 0, 0);

Float u = uv.GetX() * m_background.GetWidth();
Float v = uv.GetY() * m_background.GetHeight();
Expand All @@ -667,12 +710,13 @@ Vector3D Raytracing::RayColor(Ray& ray, const int& depth) {

Vector3D rgb(r, g, b);
rgb /= 255;
rgb *= initialRayCol;

return rgb * m_bgStrength;
}
}
else if (m_settings["renderMode"] == "normal") {
return ((unitDir * -1) + Vector3D::One) / 2;
return (((unitDir * -1) + Vector3D::One) / 2) * initialRayCol;
}
else if (m_settings["renderMode"] == "emission") {
return Vector3D::Zero;
Expand Down Expand Up @@ -775,7 +819,7 @@ void Raytracing::OriginalScene() {
}
else {
m_matMap[matID] = new Glass(Vector3D::One, 0, 1.5);
}
}

m_renderedObjects.push_back(new Sphere(0.2, m_matMap[matID], Vector3D::One, center));
}
Expand Down Expand Up @@ -819,8 +863,8 @@ void Raytracing::DebugScene() {
min = data[i];
minIndex = i;
}
}
}
}

Float r, g, b;
m_background.GetColor(0.5, 0.5, r, g, b);
Expand Down Expand Up @@ -850,16 +894,13 @@ void Raytracing::DebugScene() {

// ----- OBJECTS -----



m_matMap["diffuse"] = new Diffuse(Vector3D(1, Float::NearZero, Float::NearZero));
m_matMap["unshaded"] = new Unshaded(Vector3D(1, 1, Float::NearZero));
m_matMap["metallic"] = new Metal(Vector3D(Float::NearZero, 1, Float::NearZero), 0.1, 1.45);
m_matMap["glass"] = new Glass(Vector3D(Float::NearZero, Float::NearZero, 1), 0.1, 1.45);

m_matMap["ground"] = new Diffuse(Vector3D(0.5, 0.5, 0.5));


// objects

m_renderedObjects.push_back(new Sphere(1, m_matMap["diffuse"], Vector3D::Zero, Vector3D(-3.15, 1, 0)));
Expand Down Expand Up @@ -966,10 +1007,10 @@ void Raytracing::ShowProgress() {
else {
output += oof::reset_formatting();
output += (char)176u;
}
}
}
}
}
}

FastWrite::Write(output);

Expand All @@ -983,7 +1024,7 @@ void Raytracing::ShowProgress() {
"\nProgress: " + std::to_string(m_tilesRendered));

#endif // ENABLE_LOGGING
}
}

void Raytracing::ShuffleTiles() {
size_t i = m_tiles.size() - 1;
Expand Down
2 changes: 1 addition & 1 deletion src/raytracing/Raytracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Raytracing {
void Render(const int& minX, const int& minY, const int& maxX, const int& maxY);

bool RayHitObject(Ray& ray, const Float& t_min, const Float& t_max, HitRec& rec);
Vector3D RayColor(Ray& ray, const int& depth);
Vector3D RayColor(Ray& ray, const int& depth, const Vector3D& initialRayCol = Vector3D::One);

// ----- INITIALISING SCENES -----

Expand Down

0 comments on commit e300621

Please sign in to comment.