Skip to content

Commit

Permalink
Fix bug in cube display, clean up comments, clarify and tighten READM…
Browse files Browse the repository at this point in the history
…E.md
  • Loading branch information
ehainesnv committed Aug 28, 2019
1 parent 27a0cc8 commit 94bf1af
Show file tree
Hide file tree
Showing 33 changed files with 140 additions and 169 deletions.
62 changes: 32 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ This tutorial was created to accompany the 2019 Siggraph course on
https://drive.google.com/open?id=1_IYHwAZ4EoMcDmS0TknP-TZd7Cwmab_I ).

The aim of this repo is to serve as a "tutorial" in how to set
up a full Scene - i.e.,, OptiX Context, Module, Programs, Pipeline,
up a full Scene - i.e., OptiX Context, Module, Programs, Pipeline,
Shader Binding Table (SBT), Accel Struct (AS), Build Inputs, Texture
Samplers, etc., in the newly introduced OptiX 7.

To do this, this repo intentionally does not provide *one* example
that has the final code, but instead is split into 10 smaller
examples, each of which modifies and extends the previous one,
hopefully in a way that it is relatively easy to spot the differences
(i.e.,, to spot what exactly had to be added to go from "A" to "B").
(i.e., to spot what exactly had to be added to go from "A" to "B").

Note this tutorial does (intentionally) not end in a overwhelming
wow-factor full-featured renderer - it's aim is to *only* help you get
Expand All @@ -27,16 +27,15 @@ out of the box in both Linux and Windows. However, I assume it's safe
to expect that some one or other bug has crept in somewhere that I
haven't found yet. If you do find one, please feel free to let me know
via email or bug report, or send a push request, so others will be
spared from finding it again. Of course, any other feedback is
welcome, too!
spared from finding it again. Any other feedback is welcome, too!


# Building the Code

This code was intentionally written with minimal dependencies,
requiring pretty much only CMake (as a build system), your favorite
compiler (tested with Visual Studio under Windows, and GCC under
Linux), and of course the OptiX 7 SDK (including CUDA 10.1 and the
requiring only CMake (as a build system), your favorite
compiler (tested with Visual Studio 2017 under Windows, and GCC under
Linux), and the OptiX 7 SDK (including CUDA 10.1 and the
most recent NVIDIA developer driver).

## Dependencies
Expand All @@ -55,8 +54,8 @@ most recent NVIDIA developer driver).
`export OptiX_INSTALL_DIR=<wherever you installed OptiX 7.0 SDK>`
- on windows, the installer should automatically put it into the right directory

The literally only *external* library we use is GLFW for windowing, and
even this one we actually build on the fly under Windows, so installing
The only *external* library we use is GLFW for windowing, and
even this one we build on the fly under Windows, so installing
it is required only under Linux.

Detailed steps below:
Expand Down Expand Up @@ -97,7 +96,7 @@ Detailed steps below:
- Open `CMake GUI` from your start menu
- point "source directory" to the downloaded source directory
- point "build directory" to <source directory>/build (agree to create this directory when prompted)
- click 'configure', then specify the generator as Visual Studio 15 2017, and the Optional platform as x64. If CUDA, SDK, and compiler are all properly installed this should enable the 'generate' button. If not, make sure all dependencies are properly installed, "clear cache", and re-configure.
- click 'configure', then specify the generator as Visual Studio 2017 (Version 15), and the Optional platform as x64. If CUDA, SDK, and compiler are all properly installed this should enable the 'generate' button. If not, make sure all dependencies are properly installed, "clear cache", and re-configure.
- click 'generate' (this creates a visual studio project and solutions)
- click 'open project' (this should open the project in visual studio)

Expand Down Expand Up @@ -128,11 +127,11 @@ in a console window, e.g., run `build\Debug\ex01_helloOptix.exe`
## Example 2: First Pipeline Setup and Raygen Program

This is the first "real" OptiX example, and maybe somewhat
surprisingly, the biggest "step" in all of the examples.
surprisingly, the biggest "step" in all the examples.

The actual raygen program that this example launches is actually
very(!) small, and pretty much trivial; and there are no other programs,
not even geometry, nor a single ray being traced... but to launch
very (!) small, and pretty much trivial; and there are no other programs,
not even geometry, nor a single ray being traced ... but to launch
this simple raygen program we nevertheless have to go through the
entire process of creating Modules, Programs, and, in particular, a
valid "Shader Binding Table" (SBT), before we can launch our little
Expand All @@ -148,9 +147,8 @@ On the upside: Once this initial setup is done, everything will get
Rendering to files is nice and well, but *probably* you want to
eventually do some online rendering; so this example moves the
previous raygen example into a 3D viewer window (created and run using
GLFW). For now this viewer just displays the rendered images (i.e.,,
nothing changes from frame to frame); I'm going to add some user
interaction after Siggraph is over.
GLFW). For now this viewer just displays the rendered images, with no
user interaction.

![Same Raygen example, in GLFL Window (Linux)](./example03_inGLFWindow/ex03-linux.png)
![Same Raygen example, in GLFL Window (Windows)](./example03_inGLFWindow/ex03-windows.png)
Expand All @@ -163,17 +161,18 @@ real geometry.

This example introduces how to create some Triangle Mesh Geometry (in
this example, two simple, hardcoded, cubes), how to build an
Acceleration structure over this "BuildInput", and how to trace rays
against. To do this it also needs to introduce a simple camera model.
Acceleration Structure over this "BuildInput", and how to trace rays
against it. To do this we also need to introduce a simple camera model.

![First Triangle Mesh and Accel Struct](./example04_firstTriangleMesh/ex04.png)

## Example 5: First Shader Binding Table (SBT) Data

The earlier examples *created* an SBT (they had to, else they couldn't
have executed any OptiX launch); but didn't actually put any data into
have executed any OptiX launch), but didn't actually put any data into
the SBT. This example introduces how to do that, by putting just some
simple constant per-object color into the mesh's SBT entry.
simple constant per-object color into the mesh's SBT entry, then shading
it based on the surface normal's angle to the view ray.

![First SBT Data](./example05_firstSBTData/ex05.png)

Expand Down Expand Up @@ -204,21 +203,21 @@ suddenly starts to take shape:
## Example 8: Adding Textures via CUDA Texture Objects

This example shows how to create and set up CUDA texture objects on
the host, host to pass those to the device via the SBT, and how to use
the host, with the host passing those to the device via the SBT, and how to use
those texture objects on the device. This one will take a bit of time
to load in Debug - it's worth the wait!
to load in Debug - it's worth the wait! Or simply build and run in Release.

![Adding Textures](./example08_addingTextures/ex08.png)

## Example 9: Adding a second ray type: Shadows

This is the last example that focusses on host-side setup, in this
This is the last example that focuses on host-side setup, in this
case adding a second ray type (for shadow rays), which also requires
to change the way the SBT is being built.
changing the way the SBT is being built.

This sample also shows how to shoot secondary rays (the shadow rays)
in device programs, how to use an any-hit program for the shadow rays,
how to call *optixTerminateRay* from within an anyhit program, and how
how to call *optixTerminateRay* from within an any-hit program, and how
to use the optixTrace call's SBT index/offset values to specify the
ray type.

Expand All @@ -232,19 +231,22 @@ example can now start to focus more on the "ray tracing 101" style
additions that focus what rays to trace to add certain rendering
effects.

This simple example intentionally only adds soft shadows from area lights, but extending this to add reflections, refraction, diffuse bounces, better material models/BRDFs, etc., show from now on be rather straightforward.
This simple example intentionally only adds soft shadows from area
lights, but extending this to add reflections, refraction, diffuse
bounces, better material models/BRDFs, etc., should from now on be
straightforward.

Please feel free to play with adding these examples... and share what
Please feel free to play with adding these examples ... and share what
you did!

![Soft Shadows](./example10_softShadows/ex10.png)

## Example 11: It's up to you ...

From here on, there are multiple different avenues of how to add to
this very simple viewer, both in terms of visual features,
performance, kind and complexity of geometry, etc. In no particular
order, and just to serve as an inspiration:
this simple viewer, in terms of visual features, performance, kind
and complexity of geometry, etc. In no particular order, and just
to serve as inspiration:

- Performance
- Multi-GPU
Expand Down
2 changes: 1 addition & 1 deletion example01_helloOptix/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/*! \namespace osc - Optix Siggraph Course */
namespace osc {

/*! helper function that initializes optix, and checks for errors */
/*! helper function that initializes optix and checks for errors */
void initOptix()
{
// -------------------------------------------------------
Expand Down
18 changes: 9 additions & 9 deletions example02_pipelineAndRayGen/SampleRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace osc {
int objectID;
};

/*! constructor - performs asll setup, inlucuding initializing
/*! constructor - performs all setup, including initializing
optix, creates module, pipeline, programs, SBT, etc. */
SampleRenderer::SampleRenderer()
{
Expand Down Expand Up @@ -83,7 +83,7 @@ namespace osc {
std::cout << GDT_TERMINAL_DEFAULT;
}

/*! helper function that initializes optix, and checks for errors */
/*! helper function that initializes optix and checks for errors */
void SampleRenderer::initOptix()
{
std::cout << "#osc: initializing optix..." << std::endl;
Expand Down Expand Up @@ -125,7 +125,7 @@ namespace osc {
CUDA_CHECK(StreamCreate(&stream));

cudaGetDeviceProperties(&deviceProps, deviceID);
std::cout << "#osc: running on device device: " << deviceProps.name << std::endl;
std::cout << "#osc: running on device: " << deviceProps.name << std::endl;

CUresult cuRes = cuCtxGetCurrent(&cudaContext);
if( cuRes != CUDA_SUCCESS )
Expand Down Expand Up @@ -175,7 +175,7 @@ namespace osc {



/*! does all setup for the raygen program(s) we are going to use */
/*! does all setup for the raygen program(s) we are going to use */
void SampleRenderer::createRaygenPrograms()
{
// we do a single ray gen program in this example:
Expand All @@ -200,7 +200,7 @@ namespace osc {
if (sizeof_log > 1) PRINT(log);
}

/*! does all setup for the miss program(s) we are going to use */
/*! does all setup for the miss program(s) we are going to use */
void SampleRenderer::createMissPrograms()
{
// we do a single ray gen program in this example:
Expand All @@ -225,7 +225,7 @@ namespace osc {
if (sizeof_log > 1) PRINT(log);
}

/*! does all setup for the hitgroup program(s) we are going to use */
/*! does all setup for the hitgroup program(s) we are going to use */
void SampleRenderer::createHitgroupPrograms()
{
// for this simple example, we set up a single hit group
Expand Down Expand Up @@ -330,7 +330,7 @@ namespace osc {

// we don't actually have any objects in this example, but let's
// create a dummy one so the SBT doesn't have any null pointers
// (which the sanity checks in compilation would compain about)
// (which the sanity checks in compilation would complain about)
int numObjects = 1;
std::vector<HitgroupRecord> hitgroupRecords;
for (int i=0;i<numObjects;i++) {
Expand All @@ -354,7 +354,7 @@ namespace osc {
// sanity check: make sure we launch only after first resize is
// already done:
if (launchParams.fbSize.x == 0) return;

launchParamsBuffer.upload(&launchParams,1);
launchParams.frameID++;

Expand Down Expand Up @@ -382,7 +382,7 @@ namespace osc {
// resize our cuda frame buffer
colorBuffer.resize(newSize.x*newSize.y*sizeof(uint32_t));

// update the launch paramters that we'll pass to the optix
// update the launch parameters that we'll pass to the optix
// launch:
launchParams.fbSize = newSize;
launchParams.colorBuffer = (uint32_t*)colorBuffer.d_ptr;
Expand Down
4 changes: 2 additions & 2 deletions example02_pipelineAndRayGen/SampleRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace osc {
// publicly accessible interface
// ------------------------------------------------------------------
public:
/*! constructor - performs asll setup, inlucuding initializing
/*! constructor - performs all setup, including initializing
optix, creates module, pipeline, programs, SBT, etc. */
SampleRenderer();

Expand All @@ -50,7 +50,7 @@ namespace osc {
// internal helper functions
// ------------------------------------------------------------------

/*! helper function that initializes optix, and checks for errors */
/*! helper function that initializes optix and checks for errors */
void initOptix();

/*! creates and configures a optix device context (in this simple
Expand Down
16 changes: 8 additions & 8 deletions example03_inGLFWindow/SampleRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace osc {
int objectID;
};

/*! constructor - performs asll setup, inlucuding initializing
/*! constructor - performs all setup, including initializing
optix, creates module, pipeline, programs, SBT, etc. */
SampleRenderer::SampleRenderer()
{
Expand Down Expand Up @@ -83,7 +83,7 @@ namespace osc {
std::cout << GDT_TERMINAL_DEFAULT;
}

/*! helper function that initializes optix, and checks for errors */
/*! helper function that initializes optix and checks for errors */
void SampleRenderer::initOptix()
{
std::cout << "#osc: initializing optix..." << std::endl;
Expand Down Expand Up @@ -125,7 +125,7 @@ namespace osc {
CUDA_CHECK(StreamCreate(&stream));

cudaGetDeviceProperties(&deviceProps, deviceID);
std::cout << "#osc: running on device device: " << deviceProps.name << std::endl;
std::cout << "#osc: running on device: " << deviceProps.name << std::endl;

CUresult cuRes = cuCtxGetCurrent(&cudaContext);
if( cuRes != CUDA_SUCCESS )
Expand Down Expand Up @@ -175,7 +175,7 @@ namespace osc {



/*! does all setup for the raygen program(s) we are going to use */
/*! does all setup for the raygen program(s) we are going to use */
void SampleRenderer::createRaygenPrograms()
{
// we do a single ray gen program in this example:
Expand All @@ -200,7 +200,7 @@ namespace osc {
if (sizeof_log > 1) PRINT(log);
}

/*! does all setup for the miss program(s) we are going to use */
/*! does all setup for the miss program(s) we are going to use */
void SampleRenderer::createMissPrograms()
{
// we do a single ray gen program in this example:
Expand All @@ -225,7 +225,7 @@ namespace osc {
if (sizeof_log > 1) PRINT(log);
}

/*! does all setup for the hitgroup program(s) we are going to use */
/*! does all setup for the hitgroup program(s) we are going to use */
void SampleRenderer::createHitgroupPrograms()
{
// for this simple example, we set up a single hit group
Expand Down Expand Up @@ -330,7 +330,7 @@ namespace osc {

// we don't actually have any objects in this example, but let's
// create a dummy one so the SBT doesn't have any null pointers
// (which the sanity checks in compilation would compain about)
// (which the sanity checks in compilation would complain about)
int numObjects = 1;
std::vector<HitgroupRecord> hitgroupRecords;
for (int i=0;i<numObjects;i++) {
Expand Down Expand Up @@ -382,7 +382,7 @@ namespace osc {
// resize our cuda frame buffer
colorBuffer.resize(newSize.x*newSize.y*sizeof(uint32_t));

// update the launch paramters that we'll pass to the optix
// update the launch parameters that we'll pass to the optix
// launch:
launchParams.fbSize = newSize;
launchParams.colorBuffer = (uint32_t*)colorBuffer.d_ptr;
Expand Down
4 changes: 2 additions & 2 deletions example03_inGLFWindow/SampleRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace osc {
// publicly accessible interface
// ------------------------------------------------------------------
public:
/*! constructor - performs asll setup, inlucuding initializing
/*! constructor - performs all setup, including initializing
optix, creates module, pipeline, programs, SBT, etc. */
SampleRenderer();

Expand All @@ -50,7 +50,7 @@ namespace osc {
// internal helper functions
// ------------------------------------------------------------------

/*! helper function that initializes optix, and checks for errors */
/*! helper function that initializes optix and checks for errors */
void initOptix();

/*! creates and configures a optix device context (in this simple
Expand Down
Loading

0 comments on commit 94bf1af

Please sign in to comment.