diff --git a/README.md b/README.md index 4e3af72..686b4a6 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ Terry Sun; Arch Linux, Intel i5-4670, GTX 750 A CUDA-accelerated path tracer: a global-illumination renderer. +![](img/main-10000.png) + ## Features ### Materials @@ -17,8 +19,14 @@ The pathtracer supports the following material surfaces: * specular/reflective (perfect and imperfect): light reflects perfectly off the surface; or, light takes an imperfect reflected directly using the [Phong BRDF][gpu-specular]. -* refractive (using [Schlick's Approximation][wiki-schlick] to blend reflective - and refractive light bounces): glass, water +* refractive (using [Schlick's Approximation][wiki-schlick] of the Fresnel + effect to blend reflective and refractive light bounces). + +![](img/specular-5000.png) +![](img/refract-5000.png) + +*(Left: specular exponent 200; specular exponent 25)* +*(Right: indices of refraction 1.31 (water ice), 1.7 (impure glass))* [gpu-specular]: http://http.developer.nvidia.com/GPUGems3/gpugems3_ch20.html [wiki-schlick]: https://en.wikipedia.org/wiki/Schlick%27s_approximation @@ -30,30 +38,81 @@ of rays shot from the camera. DOF is defined with a focal distance from the camera, at which objects are perfectly in focus, and an aperture radius, defining the amount of variance added to each ray. -![](img/nodof.png) -![](img/dof05.png) -![](img/dof03.png) +![](img/dof-none-5000.png) +![](img/dof04-5000.png) + +*(no DOF; DOF with distance 5.5, aperture 0.4; 5000 iterations each)* ### Antialiasing Camera rays are shot from the camera's position in the direction of a pixel. -Antialiasing jitters the target of the ray within a pixel. +Antialiasing jitters the target of the ray within a pixel. This is a brief +computation that happens once per pixel per iteration; it has little impact on +performance. + +![](img/aa-none-5000.png) +![](img/aa-5000.png) + +*(note antialiasing along cube, light, and wall corners)* + +### Texture mapping + +Textures can be read in to define diffuse colors for a material. + +For spheres, polar coordinates *phi* and *theta* are used as the UV coordinates, +wrapping a texture across a sphere. For cubes, polar coordinates are calculated +relative to the cube face; each face of the cube has an identical copy of the +texture. + +For both texture and normal mapping: add a small amount of complexity to the +intersection tesitng code in order to output UV coordinates. Most of the cost, +if any, would come from additional memory requirements (access into global +memory when reading the texture). -[TODO: picture] +![](img/uv1-5000.png) +![](img/uv2-5000.png) + +### Normal mapping + +Textures can be read in to define ray-bounce surface normals (superceding normal +vectors generated by the geometry intersection). + +Combining the two above effects: + +![](img/globe-texture-5000.png) +![](img/globe-normal-5000.png) +![](img/globe-both-5000.png) + +*(normal map only; texture map only; texture and normal map)* ### Stream compaction. -Shared-memory work-efficient stream compaction. +This pathtracer uses `thrust::remove_if` to perform stream compaction on dead +rays. -[TODO: analysis] +I also implemented a [GPU-shared-memory, work-efficient stream compaction +algorithm][p2-shared-mem]. Unfortunately I couldn't integrate that into this +project -- I suspect there are memory errors when I translated the stream +compaction to handle pathtracing structs rather than integer values. -### Texture mapping + [p2-shared-mem]: https://github.com/terrynsun/CIS565-P2-Stream-Compaction + +w. stream compaction +500 iterations, w. back wall: 61.30s +500 iterations, w/o. back wall: 61.76 -[TODO: picture(s)] +w/o. stream compaction +500 iterations, w. back wall: 47.95 +500 iterations, w/o. back wall: 47.84 -### Bump mapping +With - without stream compaction +Open box: +Closed box: -[TODO: picture(s)] +Small light: +Large light: + +[TODO: analysis] ## Run @@ -104,7 +163,6 @@ MATERIAL (material ID) //material header RGB (float r) (float g) (float b) //diffuse color SPECX (float specx) //specular exponent SPECRGB (float r) (float g) (float b) //specular color -REFR (bool refr) //refractivity flag, 0 for no, 1 for yes REFRIOR (float ior) //index of refraction for Fresnel effects EMITTANCE (float emittance) //the emittance of the material; >0 is a light source TEXTURE (int textureid) //texture corresponding to diffuse coloring diff --git a/img/aa-5000.png b/img/aa-5000.png new file mode 100644 index 0000000..b3cd2f8 Binary files /dev/null and b/img/aa-5000.png differ diff --git a/img/aa-none-5000.png b/img/aa-none-5000.png new file mode 100644 index 0000000..c9fc817 Binary files /dev/null and b/img/aa-none-5000.png differ diff --git a/img/dof-none-5000.png b/img/dof-none-5000.png new file mode 100644 index 0000000..acc7a26 Binary files /dev/null and b/img/dof-none-5000.png differ diff --git a/img/dof03.png b/img/dof03.png deleted file mode 100644 index 5ae5d77..0000000 Binary files a/img/dof03.png and /dev/null differ diff --git a/img/dof04-5000.png b/img/dof04-5000.png new file mode 100644 index 0000000..9c84d2f Binary files /dev/null and b/img/dof04-5000.png differ diff --git a/img/dof05.png b/img/dof05.png deleted file mode 100644 index 0de820c..0000000 Binary files a/img/dof05.png and /dev/null differ diff --git a/img/globe-both-5000.png b/img/globe-both-5000.png new file mode 100644 index 0000000..f5188a7 Binary files /dev/null and b/img/globe-both-5000.png differ diff --git a/img/globe-normal-5000.png b/img/globe-normal-5000.png new file mode 100644 index 0000000..0baefce Binary files /dev/null and b/img/globe-normal-5000.png differ diff --git a/img/globe-texture-5000.png b/img/globe-texture-5000.png new file mode 100644 index 0000000..04adc9e Binary files /dev/null and b/img/globe-texture-5000.png differ diff --git a/img/main-10000.png b/img/main-10000.png new file mode 100644 index 0000000..9240049 Binary files /dev/null and b/img/main-10000.png differ diff --git a/img/nodof.png b/img/nodof.png deleted file mode 100644 index ba3e43d..0000000 Binary files a/img/nodof.png and /dev/null differ diff --git a/img/refract-5000.png b/img/refract-5000.png new file mode 100644 index 0000000..365d969 Binary files /dev/null and b/img/refract-5000.png differ diff --git a/img/specular-5000.png b/img/specular-5000.png new file mode 100644 index 0000000..14c54e0 Binary files /dev/null and b/img/specular-5000.png differ diff --git a/img/uv1-5000.png b/img/uv1-5000.png new file mode 100644 index 0000000..7310d7f Binary files /dev/null and b/img/uv1-5000.png differ diff --git a/img/uv2-5000.png b/img/uv2-5000.png new file mode 100644 index 0000000..6505364 Binary files /dev/null and b/img/uv2-5000.png differ diff --git a/scenes/aa.txt b/scenes/aa.txt new file mode 100644 index 0000000..7649087 --- /dev/null +++ b/scenes/aa.txt @@ -0,0 +1,100 @@ +// Camera +CAMERA +RES 100 100 +FOVY 45 +ITERATIONS 5000 +DEPTH 8 +FILE aa +DOF -1 -1 +EYE 0 8 2.5 +VIEW 0 0 -1 +UP 0 1 0 + +// ---------------------- Materials ---------------------- \\ + +// Emissive material (light) +MATERIAL 0 +RGB 1 1 1 +EMITTANCE 2 + +// Diffuse white +MATERIAL 1 +RGB .98 .98 .98 + +// Diffuse orange +MATERIAL 2 +RGB 0.85 .5 .3 + +// Diffuse purple +MATERIAL 3 +RGB 0.55 .55 .85 + +// Textured +MATERIAL 4 +RGB .35 .75 .35 + +// ---------------------- Objects ---------------------- \\ + +// Ceiling light +OBJECT 0 +cube +material 0 +TRANS 0 10 0 +ROTAT 0 0 0 +SCALE 6 .3 6 + +// Floor +OBJECT 1 +cube +material 1 +TRANS 0 0 0 +ROTAT 0 0 0 +SCALE 10 0.1 10 + +// Ceiling +OBJECT 2 +cube +material 1 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE 0.1 10 10 + +// Back wall +OBJECT 3 +cube +material 1 +TRANS 0 5 -5 +ROTAT 0 90 0 +SCALE 0.1 10 10 + +// Front wall +OBJECT 4 +cube +material 1 +TRANS 0 5 5 +ROTAT 0 90 0 +SCALE 0.1 10 10 + +// Left wall +OBJECT 5 +cube +material 2 +TRANS -5 5 0 +ROTAT 0 0 0 +SCALE 0.1 10 10 + +// Right wall +OBJECT 6 +cube +material 3 +TRANS 5 5 0 +ROTAT 0 0 0 +SCALE 0.1 10 10 + +// White textured +OBJECT 7 +cube +material 4 +TRANS 0 6 -1.5 +ROTAT 0 15 25 +SCALE 3 3 3 diff --git a/scenes/cornell.txt b/scenes/cornell.txt index 3921d88..73b72bb 100644 --- a/scenes/cornell.txt +++ b/scenes/cornell.txt @@ -1,10 +1,10 @@ // Camera CAMERA -RES 800 800 +RES 350 350 FOVY 45 -ITERATIONS 500 +ITERATIONS 5000 DEPTH 8 -FILE cornell +FILE specular DOF -1 -1 EYE 0.0 5 4.5 VIEW 0 0 -1 @@ -21,29 +21,35 @@ EMITTANCE 3 MATERIAL 1 RGB .98 .98 .98 -// Diffuse red +// Diffuse orange MATERIAL 2 -RGB .85 .35 .35 +RGB 0.85 .5 .3 -// Diffuse green +// Diffuse purple MATERIAL 3 -RGB .35 .85 .35 +RGB 0.55 .55 .85 -// Specular yellow +// Globe textured MATERIAL 4 -RGB 0.4 0.4 0 -SPECEX 50 -SPECRGB 1 1 1 +RGB .85 .35 .35 -// Refractive green +// Perfect specular MATERIAL 5 -RGB 0.0 0.8 0.8 -REFR 1 -REFRIOR 1.5 +RGB .3 .3 .3 +SPECRGB .8 .8 .8 +SPECEX 0 -// Diffuse orange +// Imperfect specular MATERIAL 6 -RGB .8 .8 0 +RGB .3 .3 .3 +SPECRGB .8 .8 .8 +SPECEX 20 + +// Less imperfect specular +MATERIAL 7 +RGB .3 .3 .3 +SPECRGB .8 .8 .8 +SPECEX 100 // ---------------------- Objects ---------------------- \\ @@ -103,18 +109,34 @@ TRANS 5 5 0 ROTAT 0 0 0 SCALE 0.1 10 10 -// Specular Yellow +// Reddish OBJECT 7 sphere material 4 -TRANS -2 6 -1 +TRANS 0 2.5 -2.5 ROTAT 0 0 0 SCALE 3 3 3 -// Glass sphere +// Imperfect specular OBJECT 8 sphere material 6 -TRANS 0 2 -1.5 +TRANS -3 4.5 -0.5 +ROTAT 0 0 0 +SCALE 3 3 3 + +// Imperfect specular +OBJECT 9 +sphere +material 7 +TRANS 3 4.5 -0.5 +ROTAT 0 0 0 +SCALE 3 3 3 + +// Perfect specular +OBJECT 10 +sphere +material 5 +TRANS 0 5.5 -3.5 ROTAT 0 0 0 SCALE 3 3 3 diff --git a/scenes/dof.txt b/scenes/dof.txt index 194fd05..aa8b7a5 100644 --- a/scenes/dof.txt +++ b/scenes/dof.txt @@ -5,7 +5,7 @@ FOVY 45 ITERATIONS 5000 DEPTH 8 FILE dof -DOF -1 -1 +DOF 5.5 0.4 EYE 0.0 5 4.5 VIEW 0 0 -1 UP 0 1 0 diff --git a/scenes/globe.txt b/scenes/globe.txt new file mode 100644 index 0000000..c63288b --- /dev/null +++ b/scenes/globe.txt @@ -0,0 +1,105 @@ +// Camera +CAMERA +RES 800 800 +FOVY 45 +ITERATIONS 5000 +DEPTH 8 +FILE globe +DOF -1 -1 +EYE 0.0 5 4.5 +VIEW 0 0 -1 +UP 0 1 0 + +// ---------------------- Materials ---------------------- \\ + +TEXTURE textures/globe-normal.png + +TEXTURE textures/globe-texture.jpg + +// Emissive material (light) +MATERIAL 0 +RGB 1 1 1 +EMITTANCE 2 + +// Diffuse white +MATERIAL 1 +RGB .98 .98 .98 + +// Diffuse orange +MATERIAL 2 +RGB 0.85 .5 .3 + +// Diffuse purple +MATERIAL 3 +RGB 0.55 .55 .85 + +// Textured +MATERIAL 4 +RGB .85 .85 .85 +TEXTURE 1 + +// ---------------------- Objects ---------------------- \\ + +// Ceiling light +OBJECT 0 +cube +material 0 +TRANS 0 10 0 +ROTAT 0 0 0 +SCALE 6 .3 6 + +// Floor +OBJECT 1 +cube +material 1 +TRANS 0 0 0 +ROTAT 0 0 0 +SCALE 10 0.1 10 + +// Ceiling +OBJECT 2 +cube +material 1 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE 0.1 10 10 + +// Back wall +OBJECT 3 +cube +material 1 +TRANS 0 5 -5 +ROTAT 0 90 0 +SCALE 0.1 10 10 + +// Front wall +OBJECT 4 +cube +material 1 +TRANS 0 5 5 +ROTAT 0 90 0 +SCALE 0.1 10 10 + +// Left wall +OBJECT 5 +cube +material 2 +TRANS -5 5 0 +ROTAT 0 0 0 +SCALE 0.1 10 10 + +// Right wall +OBJECT 6 +cube +material 3 +TRANS 5 5 0 +ROTAT 0 0 0 +SCALE 0.1 10 10 + +// White textured +OBJECT 7 +sphere +material 4 +TRANS 0 4 -1.5 +ROTAT 35 0 0 +SCALE 5 5 5 diff --git a/scenes/main.txt b/scenes/main.txt new file mode 100644 index 0000000..1ee2719 --- /dev/null +++ b/scenes/main.txt @@ -0,0 +1,163 @@ +// Camera +CAMERA +RES 700 700 +FOVY 45 +ITERATIONS 1000 +DEPTH 8 +FILE timing +DOF -1 -1 +EYE 0.0 5 4.5 +VIEW 0 0 -1 +UP 0 1 0 + +// ---------------------- Materials ---------------------- \\ + +TEXTURE textures/globe-normal.png + +TEXTURE textures/globe-texture.jpg + +// Emissive material (light) +MATERIAL 0 +RGB 1 1 1 +EMITTANCE 3 + +// Diffuse white +MATERIAL 1 +RGB .98 .98 .98 + +// Diffuse orange +MATERIAL 2 +RGB 0.85 .5 .3 + +// Diffuse purple +MATERIAL 3 +RGB 0.55 .55 .85 + +// Globe textured +MATERIAL 4 +NORMAL 0 +TEXTURE 1 + +// Perfect specular +MATERIAL 5 +RGB .3 .3 .3 +SPECRGB .8 .8 .8 +SPECEX 0 + +// Imperfect specular +MATERIAL 6 +RGB .3 .3 .3 +SPECRGB .8 .8 .8 +SPECEX 30 + +// Refractive (ice) +MATERIAL 7 +RGB 1 1 1 +SPECRGB .8 .8 .8 +SPECEX 50 +IOR 1.31 + +// Refractive (glass) +MATERIAL 8 +RGB 1 1 1 +SPECRGB .8 .8 .8 +SPECEX 50 +IOR 1.7 + +// ---------------------- Objects ---------------------- \\ + +// Ceiling light +OBJECT 0 +cube +material 0 +TRANS 0 10 0 +ROTAT 0 0 0 +SCALE 6 .3 6 + +// Floor +OBJECT 1 +cube +material 1 +TRANS 0 0 0 +ROTAT 0 0 0 +SCALE 10 0.1 10 + +// Ceiling +OBJECT 2 +cube +material 1 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE 0.1 10 10 + +// Back wall +OBJECT 3 +cube +material 1 +TRANS 0 5 -5 +ROTAT 0 90 0 +SCALE 0.1 10 10 + +// Front wall +OBJECT 4 +cube +material 1 +TRANS 0 5 5 +ROTAT 0 90 0 +SCALE 0.1 10 10 + +// Left wall +OBJECT 5 +cube +material 2 +TRANS -5 5 0 +ROTAT 0 0 0 +SCALE 0.1 10 10 + +// Right wall +OBJECT 6 +cube +material 3 +TRANS 5 5 0 +ROTAT 0 0 0 +SCALE 0.1 10 10 + +// Globe textured +OBJECT 7 +sphere +material 4 +TRANS 0 4.5 -2.5 +ROTAT 45 25 0 +SCALE 3 3 3 + +// Perfect specular +OBJECT 8 +sphere +material 5 +TRANS -3 4.5 -1.5 +ROTAT 0 0 0 +SCALE 3 3 3 + +// Imperfect specular +OBJECT 9 +sphere +material 6 +TRANS 3 4.5 -1.5 +ROTAT 0 0 0 +SCALE 3 3 3 + +// Bottom left refractive +OBJECT 10 +sphere +material 7 +TRANS -1.5 2 -2 +ROTAT 0 0 0 +SCALE 2.5 2.5 2.5 + +// Bottom right refractive +OBJECT 11 +sphere +material 8 +TRANS 1.5 2 -2 +ROTAT 0 0 0 +SCALE 2.5 2.5 2.5 diff --git a/scenes/mats.txt b/scenes/refr.txt similarity index 72% rename from scenes/mats.txt rename to scenes/refr.txt index 30b7207..7e5490b 100644 --- a/scenes/mats.txt +++ b/scenes/refr.txt @@ -2,7 +2,7 @@ CAMERA RES 500 500 FOVY 45 -ITERATIONS 2000 +ITERATIONS 5000 DEPTH 8 FILE cornell DOF -1 -1 @@ -12,6 +12,8 @@ UP 0 1 0 // ---------------------- Materials ---------------------- \\ +TEXTURE textures/checkerboard.jpg + // Emissive material (light) MATERIAL 0 RGB 1 1 1 @@ -41,26 +43,23 @@ RGB .3 .3 .3 SPECRGB 1 1 1 SPECEX 200 -// Refractive +// Textured MATERIAL 6 -RGB 1 1 1 -SPECRGB .8 .8 .8 -SPECEX 200 -IOR 1 +TEXTURE 0 -// Refractive +// Refractive (ice) MATERIAL 7 RGB 1 1 1 SPECRGB .8 .8 .8 -SPECEX 200 -IOR 3 +SPECEX 50 +IOR 1.31 -// Refractive +// Refractive (glass) MATERIAL 8 RGB 1 1 1 SPECRGB .8 .8 .8 -SPECEX 200 -IOR 5 +SPECEX 50 +IOR 1.7 // ---------------------- Objects ---------------------- \\ @@ -120,42 +119,18 @@ TRANS 5 5 0 ROTAT 0 0 0 SCALE 0.1 10 10 -// Left reflective -OBJECT 7 -sphere -material 4 -TRANS -1.25 4 -2 -ROTAT 0 0 0 -SCALE .1 .1 .1 - -// Right reflective -OBJECT 8 -sphere -material 5 -TRANS 1.25 4 -2 -ROTAT 0 0 0 -SCALE .1 .1 .1 - -// Bottom middle refractive -OBJECT 9 -sphere -material 6 -TRANS 0 1.5 -2 -ROTAT 0 0 0 -SCALE 2.5 2.5 2.5 - // Bottom left refractive -OBJECT 10 +OBJECT 7 sphere material 7 -TRANS -2.5 1.5 -2 +TRANS -2.5 2 -2 ROTAT 0 0 0 -SCALE 2.5 2.5 2.5 +SCALE 3 3 3 // Bottom right refractive -OBJECT 11 +OBJECT 8 sphere material 8 -TRANS 2.5 1.5 -2 +TRANS 2.5 2 -2 ROTAT 0 0 0 -SCALE 2.5 2.5 2.5 +SCALE 3 3 3 diff --git a/scenes/texture.txt b/scenes/texture.txt index 73284f4..ddb6ffd 100644 --- a/scenes/texture.txt +++ b/scenes/texture.txt @@ -1,6 +1,6 @@ // Camera CAMERA -RES 500 500 +RES 350 350 FOVY 45 ITERATIONS 5000 DEPTH 8 @@ -95,8 +95,8 @@ SCALE 0.1 10 10 // Yellow textured OBJECT 7 -sphere +cube material 4 -TRANS 0 4 -1.5 -ROTAT 45 0 0 -SCALE 5 5 5 +TRANS 0 4.5 -1.5 +ROTAT 25 25 0 +SCALE 4 4 4 diff --git a/textures/globe-normal.png b/textures/globe-normal.png new file mode 100644 index 0000000..1e1b01f Binary files /dev/null and b/textures/globe-normal.png differ diff --git a/textures/globe-texture.jpg b/textures/globe-texture.jpg new file mode 100644 index 0000000..9d1829b Binary files /dev/null and b/textures/globe-texture.jpg differ