This repository has been archived by the owner on Oct 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor path tracing code into a new class
- Loading branch information
1 parent
cf2f2e0
commit e95e18c
Showing
9 changed files
with
115 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
xcuserdata | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// JTPath.h | ||
// jtracer | ||
// | ||
// Created by Jonathon Racz on 1/19/18. | ||
// Copyright © 2018 jonathonracz. All rights reserved. | ||
// | ||
|
||
#pragma once | ||
|
||
#include "JTTypes.h" | ||
#include "JTRay.h" | ||
#include "JTBackgroundGradient.h" | ||
|
||
namespace jt | ||
{ | ||
|
||
class Path | ||
{ | ||
public: | ||
Path(JT_THREAD PRNG& _random, JT_THREAD const BackgroundGradient& _background, JT_THREAD const SphereList& _sphereList) : | ||
random(_random), background(_background), sphereList(_sphereList) | ||
{ | ||
} | ||
|
||
float3 trace(JT_THREAD Ray ray) | ||
{ | ||
Sphere::HitRecord hitRecord; | ||
|
||
uint64 numBounces = 0; | ||
float3 colorAccumulator = make_float3(0.0f, 0.0f, 0.0f); | ||
float reflection = 1.0f; | ||
float currentIOR = 1.0f; | ||
|
||
float3 finalRayColor = make_float3(0.0f, 0.0f, 0.0f); | ||
bool finalColorComputed = false; | ||
|
||
do | ||
{ | ||
bool didHit = sphereList.hitTest(ray, hitRecord, 0.001f); | ||
if (didHit && reflection > 0.0f) | ||
{ | ||
numBounces++; | ||
colorAccumulator += hitRecord.materialParams.albedo; | ||
reflection *= hitRecord.materialParams.reflectivity; // TODO: Fresnel-based reflection | ||
float3 incident = normalize(ray.directionAtOrigin()); | ||
float3 scattered = BSDF::scatter(random, hitRecord.materialParams, incident, hitRecord.normal); | ||
float3 target = hitRecord.p + (hitRecord.normal * 0.5f) + scattered; | ||
ray = Ray(hitRecord.p, target - hitRecord.p); | ||
} | ||
else | ||
{ | ||
float3 lightColor = background.color(ray); | ||
if (numBounces > 0) | ||
finalRayColor = lightColor * (colorAccumulator / numBounces) * reflection; | ||
else | ||
finalRayColor = lightColor; | ||
|
||
finalColorComputed = true; | ||
} | ||
} | ||
while (!finalColorComputed); | ||
|
||
return finalRayColor; | ||
} | ||
|
||
private: | ||
JT_THREAD PRNG& random; | ||
JT_THREAD const BackgroundGradient& background; | ||
JT_THREAD const SphereList& sphereList; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters