Skip to content

Latest commit

 

History

History
85 lines (45 loc) · 3.92 KB

README.md

File metadata and controls

85 lines (45 loc) · 3.92 KB

Spike

.NET Core Path Tracer

Spike is a C# .NET Core 2.0 path tracer with multithreading and SIMD, including a bit of code to create abstract art.

The sample image below is 4K with a bounce count of 8 and a sample count per pixel of 1024. It took approixmately 4 hours to render on my machine.

Light Box

This is a simple prototype and isn't physically accurate, but the code is clean and it's fun to play around with.

Getting Started

Spike is a simple console app, but it should be relatively easy to refactor into a separate assembly.

It its default state, the console app will generate 10 4K abstract art images and save them to the Png directory.

The images only use 8 samples per pixel and take appoximately 5 minutes a piece on my machine.

Abstract

Abstract

Abstract

Rendering your own scene

The first step is to create an instance of PathTracerScene.

You'll need to assign a PathTracerCamera to your scene and the PathTracerTriangles you want to render. You'll also need to assign PathTracerMaterial instances to your triangles and the BackgroundMaterial property of your scene.

A material has a Color property and an IsLight property. Materials also include properties for Gloss and Reflectivity. Colors with alpha values are supported.

After you create your scene you'll want to set some rendering options. These options include Width, Height, BounceCount, PixelSampleRate, SamplesPerPixel, MaxDegreeOfParallelism, and FrameCount (for animations). You can also include a delegate for displaying progress. ConsolePercentageDisplay will write this information to the console.

Next, you'll want to create a frame recorder. Simply create an instance of PngPathTracerFrameRecorder or create your own.

Finally create an instance of PathTracerEngine and call Render, passing in your scene, options, and frame recorder.

Render Modes

The PathTracerOptions class has a RenderMode that accepts a PathTracerRenderMode enum. These are great for debugging purposes. Sample images are listed below.

PathTracer

PathTracer

Color

Color

Depth

Depth

Normals

Normals

PureReflections

PureReflections

RandomReflections

RandomReflections

ActualReflections

ActualReflections

AmbientOcclusion

AmbientOcclusion

DistanceTraveled

DistanceTraveled

Tips and tricks

  • Use a PathTracerScene.BackgroundMaterial with PathTracerMaterial.IsLight set to true for ambient light.
  • Use the PathTracerScene.Animation delegate to animate your scene between frames.
  • Use PathTracerSceneGenerator to generate abstract art or the test scene shown above.
  • Use the PathTracerOptions.Shaders delegate list to apply per-pixel effects to your rendered image.