Git Product home page Git Product logo

apress / ray-tracing-gems Goto Github PK

View Code? Open in Web Editor NEW
954.0 35.0 108.0 137.27 MB

Source Code for "Ray Tracing Gems: High-Quality and Real-Time Rendering with DXR and Other APIs" by Eric Haines and Tomas Akenine-Möller

Home Page: https://www.apress.com/us/book/9781484244265

License: MIT License

Cuda 0.57% HLSL 0.83% C++ 20.44% Mathematica 2.74% C 49.57% GLSL 0.01% Makefile 0.01% CMake 2.37% CSS 0.34% HTML 21.31% JavaScript 0.42% Objective-C 1.29% Less 0.09%

ray-tracing-gems's Introduction

Apress Source Code

This repository accompanies Ray Tracing Gems: High-Quality and Real-Time Rendering with DXR and Other APIs by Eric Haines and Tomas Akenine-M�ller (Apress, 2019).

See http://raytracinggems.com for further information about the book.

Cover image

Download or clone the files as a zip using the green button in the upper right, or clone the repository to your machine using Git with https://github.com/Apress/ray-tracing-gems.git

Note that code with a *.cu or *.cuh suffix is written in CUDA. The various CUDA functions can be found in this set of reference pages. Code with an *.hlsl suffix is in the High Level Shading Language, with its function reference here.

Releases

Errata for the book is available.

Release v1.0 corresponds to the code in the published book, with three corrections to Chapter 16:

Page 226: "float SampleLinear( float a, float b ) {" should have a "float u" parameter for the random variable, i.e., "float SampleLinear( float u, float a, float b ) {"

Page 235, file ConcentricSquareMapping.cpp: The case "a == 0 && b == 0" is not handled and can result in division by 0; above line 3 add "if (b == 0) b = 1;"

Page 242, file PhongDistribution.cpp: Line 1 of the code at the top, change "1+s" to "2+s"

Contributions

See the file Contributing.md for more information on how you can contribute to this repository.

License

All code here is released under the MIT License, copyright 2019 NVIDIA Corporation, unless otherwise noted within an individual chapter's files. This license reads as follows:

Copyright 2019 NVIDIA Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ray-tracing-gems's People

Contributors

erich666 avatar jessicavakili avatar pierremoreau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ray-tracing-gems's Issues

May be mistake in codes

I found that in the source file which addressed at ray-tracing-gems/Ch_11_Automatic_Handling_of_Materials_in_Nested_Volumes/push.cpp may have a mistake. The index variable used at line 14 as prev_same is an index of the stack, not an index of the scene materials. So, I think the variable prev_same should be change to stack[prev_same].material_idx.Just like the following codes:

line 14 if (material[material_idx] == material[prev_same]) { => if (material[material_idx] == material[stack[prev_same].material_idx]) {

It was also used at line 26 but in right form:
line 26 if ((material[stack[idx].material_idx] != material[material_idx]) &&

Minor mistake in code sample

In section 16.4.2.3 Hierarchical Transformation (p233), the first code sample is missing a curly braces between line 8 and 9 to close off the else statement:

 1 node = root;
 2 while (!node.isLeaf) {
 3     if (u < node.probLeft) {
 4         u /= node.probLeft;
 5         node = node.left;
 6     } else {
 7         u /= (1.0 - node.probLeft);
 8         node = node.right;
 9 }
10 // Ok. We have found a leaf with the correct probability!

Should be:

 1 node = root;
 2 while (!node.isLeaf) {
 3     if (u < node.probLeft) {
 4         u /= node.probLeft;
 5         node = node.left;
 6     } else {
 7         u /= (1.0 - node.probLeft);
 8         node = node.right;
 9     }                                 <<<<<<<<<<<<<<<<<<<<< Missing this
10 }
11 // Ok. We have found a leaf with the correct probability!

chapter 27, the introduction of Listing 27-2 is wrong

The introduction of Listing 27-2:

Listing 27-2.This closest-hit shader code snippet skips shading of transparent surfaces when the incident ray has crossed through a user-defined maximum number of transparent surfaces, proceeding instead by shooting a transmission ray and continuing as though there had been no ray/surface intersection

is same as that of Listing 27-4:

Listing 27-4. This closest-hit shader code snippet skips the shading of transparent surfaces when the incident ray has crossed through a user-defned maximum number of transparent surfaces, proceeding instead by shooting a transmission ray and continuing as though there had been no ray/surface intersection.

and I believe the former is wrong.
I didn't see this mistake in the errata and I have checked version 1.5, 4/29/2019, it's still there.

Source missing?

Greetings I am interested in the implementation of Ch. 14 (Ch_14_Ray-Guided_Volumetric_Water_Caustics_in_Single_Scattering_Media_with_DXR), but it seems that the source code is missing. I can only find dll, exe & media files.

GL Texture memory leak in Chapter 28: Ray Tracing Inhomogeneous Volumes

There is a potential GL texture memory leak in the code. It generates a new texture object each frame (line 459-462).

Solution:
Two additions in the code should do it :)

  1. Add the following code after line 431
kernel_params.iteration = 0;

//allocate texture once
glBindTexture(GL_TEXTURE_2D, display_tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
  1. Replace glTexImage2D and parameter setting calls (lines 459-462) with the following glTexSubImage2D call,
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0,0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, NULL);

Chapter 15.3 code for sample variance equation - possible bug

Hi, very minor thing but I'm looking at http://raytracinggems.com/unofficial_RayTracingGems_v1.7.pdf and the last line code for estimate_sample_variance() seems incorrect.

The code is:

1 float estimate_sample_variance(float samples[], int n) {
2     float sum = 0, sum_sq = 0;
3     for (int i = 0; i < n; ++i) {
4         sum += samples[i];
5         sum_sq += samples[i] * samples[i];
6     }
7     return sum_sq / (n * (n - 1))) -
8     sum * sum / ((n - 1) * n * n);
9 }

in lines 7 & 8 there is an additional ')' but the formula also appears wrong - it should be return sum_sq / (n - 1) - sum * sum / ((n - 1) * n); ( or return (sum_sq - sum * sum / n) / (n - 1); )? (or I might be missing something :) )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.