Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

Commit

Permalink
Commit blob of documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathonracz committed Apr 10, 2018
1 parent e95e18c commit 0c9add5
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 12 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# jtracer

**jtracer** is a C++ raytracer capable of running either on the CPU (multithreaded or non-multithreaded) or as an Apple Metal compute kernel.

The raytracer was originally based on the implementation guide given by Peter Shirley's excellent ebook [Ray Tracing In One Weekend](https://www.amazon.com/Ray-Tracing-Weekend-Minibooks-Book-ebook/). The algorithms were modified to make the raytracer non-allocating (i.e. non stack based) by using color/light accumulators with a single ray object to trace through the scene.

The implementation found in [`jtracer/Trace`](jtracer/Trace) is designed to be extremely portable. It is a header-only implementation of a general GPU-compute compatible raytracer from a per-pixel standpoint given a set of scene parameters (in this case, a bunch of spheres). In theory, it should work in an OpenCL C++ or CUDA environment with little modification - likely just some system-specific definitions in [`JTTypes.h`](jtracer/Trace/JTTypes.h).

The frontend is written in Objective-C++. It is tested with Xcode 9.3 under macOS 10.13.4. The UI is extremely simple - all options are hardcoded within the app. On startup the main window will display two views: the top is a GPU-compute render via Metal, and the bottom is a multicore CPU render scheduled by `libdispatch` (Grand Central Dispatch). Below is a screenshot:

<img src="https://github.com/jonathonracz/jtracer/blob/master/screenshot.png?raw=true" alt="Screenshot, as described above.">
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
1 change: 1 addition & 0 deletions jtracer/JTRenderState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ - (id)init {
_uniformsInternal->spheres[0].materialParams.albedo = make_float3(1.0f, 0.0f, 0.0f);
_uniformsInternal->spheres[0].materialParams.roughness = 0.0f;
_uniformsInternal->spheres[0].materialParams.reflectivity = 1.0f;
_uniformsInternal->spheres[0].materialParams.transparency = 1.0f;

_uniformsInternal->spheres[1].materialParams.albedo = make_float3(0.0f, 1.0f, 0.0f);
_uniformsInternal->spheres[1].materialParams.roughness = 0.25f;
Expand Down
2 changes: 1 addition & 1 deletion jtracer/JTRenderViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ - (void)viewDidLoad {

- (void)renderViews:(JTDisplayLink *)sender {
[_renderState update:_displayLink.timestamp];
//[self.metalRenderer render:_renderState sender:_displayLink];
[self.metalRenderer render:_renderState sender:_displayLink];
[self.cgRenderer render:_renderState sender:_displayLink];
}

Expand Down
27 changes: 17 additions & 10 deletions jtracer/Trace/JTBSDF.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,23 @@ inline float3 scatter(JT_THREAD PRNG& random, JT_THREAD const Parameters& params

float3 scattered = make_float3(0.0f, 0.0f, 0.0f);

float3 reflection = Math::reflect(incident, normal);
float3 diffuse = random.generateInUnitSphere();
// Make sure the diffuse ray is actually a reflection - i.e. leaving the
// object.
if (dot(diffuse, normal) < 0)
diffuse *= -1.0f;

// TODO: This may be better off as a slerp so there isn't a lopsided
// resolution between the center and edges of the interpolation...
scattered = Math::lerp(reflection, diffuse, params.roughness);
//if (isReflection)
{
float3 reflection = Math::reflect(incident, normal);
float3 diffuse = random.generateInUnitSphere();
// Make sure the diffuse ray is actually a reflection - i.e. leaving the
// object.
if (dot(diffuse, normal) < 0)
diffuse *= -1.0f;

// TODO: This may be better off as a slerp so there isn't a lopsided
// resolution between the center and edges of the interpolation...
scattered = Math::lerp(reflection, diffuse, params.roughness);
}
//else
{
// Refraction
}

assert(!equal(scattered, make_float3(0.0f, 0.0f, 0.0f)));

Expand Down
2 changes: 1 addition & 1 deletion jtracer/Trace/JTPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Path
{
}

float3 trace(JT_THREAD Ray ray)
float3 trace(Ray ray)
{
Sphere::HitRecord hitRecord;

Expand Down
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0c9add5

Please sign in to comment.