diff --git a/README.md b/README.md index 110697c..181caee 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,91 @@ CUDA Path Tracer ================ - +![](./results/title.jpg) **University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 3** -* (TODO) YOUR NAME HERE -* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab) +* Jiawei Wang +* Tested on: Windows 10, i7-6700 @ 2.60GHz 16.0GB, GTX 970M 3072MB (Personal) +## Results: +___ +![](./results/010.gif) + +### Final Path Tracer: +___ +***3507 Samples | 800 x 800*** +![](./results/test1.2017-10-01_06-21-18z.3507samp.png "3507 samples/ cornell") +### Detailed Features: +___ +* **Anti-Aliasing**: Realized by Stochastic *Sampled Antialiasing*, just jitter a little bit when create Camera ray, this will cause a little blur on the image, which can solve the aliasing problems.
+ Here is the results: (left: `without anti-aliasing`, right: `with anti-aliasing`) +
+
+ +* **Depth Of Field**: Realized by jittering around pixel. See at [PBRT 6.2.3]
+  Here is the results:
+ (left: `lens_radius = 0.5`, right: `lens_radius = 1.0`)
+
+ (left: `focal_length = 9`, right: `focal_length = 19`)
+
+ +* **Refraction(Frensel Effect)**: Frensel Effect requires not only the refration effect, but also the reflection effect. This is realized by generate a random value for each sample and use this value comparing with the **dot product** to decide whether this sample is counted as a reflection sample.
+  Here is the results: (left: `no reflection`, right: `both reflection and refraction`)
+
+ You can see that the right one is more realistic, 'cause the ball reflects the light on the celling.
+ +* **Motion blur**: Realized by jittering ray of different iterations between the `transition_start` to the `transition_end`, which can generate an effect like followings:
+
+ +* **Direct light**: In this project, I only implemented the most basic direct light, make the ray direction to the ligths when the `ray.remainning bounce == 1`, and then average the color of them.
+ Here is the results: (left: `no direct light`, right: `direct light`)
+
+ +* **Arbitrary Mesh Loading**: Used `tiny_obj` tools to load the obj file and `glm::intersectRayTriangle` function to do the intersection test.
+ Here is the results:
+
+ (left: **Flat Shading**, right: **Smooth Shading**)
+
+ **Smooth Shading** is realized by interpolating the normal on each pixel using the vertex normals.
+ +## Optimization and Performance Analysis: +___ +### Stream Compaction +* Instead of using one thread to run a whole path, we use one thread to run one bounce of the path. +* This will optimize the "waitting situation", for example, path1 bounces more than 10 times and path2 only bounces once, in that case, even though the path2 is finished but it has to wait until the other paths like path2 to finish and then it can finished its thread.This situation will happen all the time, which will cause lots of meaningless stalls of the threads +* We can realize this by maintaining a *Thread Pool*, and use *Stream compaction* to delete the terminated rays. +* I didn't finish the version without the Stream compaction, so I couldn't present an exact comparison here. But according to the explanation above, we could know that the *Stream Compaction* can reduce the time of stalls while it will increase the time of compaction operations. +* Therefore, it's easy to get the conclusion that: At first, the method without *Stream Compaction* is faster. But with the increment of the `max_bounce_time`, the time of stalls will be longer, the advantage of *Stream Compaction* will be more obvious, and when the `max_bounce_time` is big enough, the *Stream Compaction* is faster and will be much faster after that. +* When the scene is closed, which means no ray can get out of the "box", the *Stream Compaction* may not be that good. Because in this case, every ray has to intersect with a geometry in the scene. Only the path hit the light can terminate before it reaches its max_bounce, so the time of stalls is much shorter, and the *Stream Compaction* may be not a good choice +### Caching First Bounce +* We have to take lots of samples to get the final image, and each iteration we need to generate the rays from camera at first. However, the rays from the camera are the same of each iteration, which means the intersections, the paths information, like origin and direction are also the same of each iteration. +* Therefore, we can cache these information of the first iteration and reuse in the following iterations. +* Here is the comparision results: +![](./results/plot1.JPG) +![](./results/form1.JPG) +* We can see that the caching does make the path tracing faster. +* **Warning**: When we turn on the `Anti-Aliasing`, `Montion Blur`, `Depth Of Field`, we couldn't cach the camera ray anymore. Because they have to generate different camera rays(`Anti-Aliasing`,`Depth Of Field`) or get different intersections(`Motion Blur`) every iteration. -### (TODO: Your README) +### Sorting the Materials +* Although one thread is dealing with one bounce right now, there are still some "waitting situation" will happen. Because each bounce is dealing with diffrent materials and different materials have different time to run, which will cause some meanless stalls for the threads in the same block. +* The solution is that we can sort the paths according to their materials before we do the shading, this will enable the threads next to each other has the same time to run, which can reduce the stalls. +* We can use **Radix Sort** to sort the materials +* Here are the comparisions between the sorted and unsorted methods: +![](./results/form2.JPG) +* The Results show that the sorted method is much more slower than our expectations, I think there may be 3 reasons as following: + * firstly, the number of materials is not large enough, which means the original continuity is good enough, and we just waste our time on the sorting. + * secondly, the complexity of the calculation of the materials shading is not high enough, which means the difference between the computation time of different materials is very small. + * thirdly, we didn't take advantage of the using of shared memory, because materials are continuous, we can store the material related data on the shared memory, which will save lots of time on memory accessing. + +### Bounding Box +* When we are compute intersections with a complex mesh, we can compute if the ray hit the bounding box first. Because checking intersection with box is much more faster than checking every triangles of the mesh. +* Here are the comparision results between the methods without bbox and with bbox: +![](./results/plot3.JPG) +![](./results/form3.JPG) +* The improvement of the using of bounding box is remarkble. -*DO NOT* leave the README to the last minute! It is a crucial part of the -project, and we will not be able to grade you without a good README. +## Third Party Code +* `ConcentricSampleDisk(float u1, float u2)`: this function is to compute a random point on a circle, which take 2 random floats between 0 to 1 as inputs.
+Reference: PBRT source code https://www.dartdocs.org/documentation/dartray/0.0.1/core/ConcentricSampleDisk.html +* `tiny_obj_loader`: a third party library to load obj files.
+Reference: http://syoyo.github.io/tinyobjloader/ +* Thanks for Kaixiang Miao(TA), do the color gather inside of the shading function instead of `finalGather` diff --git a/external/include/tiny_obj_loader.h b/external/include/tiny_obj_loader.h new file mode 100644 index 0000000..6f0515b --- /dev/null +++ b/external/include/tiny_obj_loader.h @@ -0,0 +1,2063 @@ +/* +The MIT License (MIT) + +Copyright (c) 2012-2017 Syoyo Fujita and many contributors. + +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. +*/ + +// +// version 1.0.8 : Fix parsing `g` tag just after `usemtl`(#138) +// version 1.0.7 : Support multiple tex options(#126) +// version 1.0.6 : Add TINYOBJLOADER_USE_DOUBLE option(#124) +// version 1.0.5 : Ignore `Tr` when `d` exists in MTL(#43) +// version 1.0.4 : Support multiple filenames for 'mtllib'(#112) +// version 1.0.3 : Support parsing texture options(#85) +// version 1.0.2 : Improve parsing speed by about a factor of 2 for large +// files(#105) +// version 1.0.1 : Fixes a shape is lost if obj ends with a 'usemtl'(#104) +// version 1.0.0 : Change data structure. Change license from BSD to MIT. +// + +// +// Use this in *one* .cc +// #define TINYOBJLOADER_IMPLEMENTATION +// #include "tiny_obj_loader.h" +// + +#ifndef TINY_OBJ_LOADER_H_ +#define TINY_OBJ_LOADER_H_ + +#include +#include +#include + +namespace tinyobj { + +// https://en.wikipedia.org/wiki/Wavefront_.obj_file says ... +// +// -blendu on | off # set horizontal texture blending +// (default on) +// -blendv on | off # set vertical texture blending +// (default on) +// -boost real_value # boost mip-map sharpness +// -mm base_value gain_value # modify texture map values (default +// 0 1) +// # base_value = brightness, +// gain_value = contrast +// -o u [v [w]] # Origin offset (default +// 0 0 0) +// -s u [v [w]] # Scale (default +// 1 1 1) +// -t u [v [w]] # Turbulence (default +// 0 0 0) +// -texres resolution # texture resolution to create +// -clamp on | off # only render texels in the clamped +// 0-1 range (default off) +// # When unclamped, textures are +// repeated across a surface, +// # when clamped, only texels which +// fall within the 0-1 +// # range are rendered. +// -bm mult_value # bump multiplier (for bump maps +// only) +// +// -imfchan r | g | b | m | l | z # specifies which channel of the file +// is used to +// # create a scalar or bump texture. +// r:red, g:green, +// # b:blue, m:matte, l:luminance, +// z:z-depth.. +// # (the default for bump is 'l' and +// for decal is 'm') +// bump -imfchan r bumpmap.tga # says to use the red channel of +// bumpmap.tga as the bumpmap +// +// For reflection maps... +// +// -type sphere # specifies a sphere for a "refl" +// reflection map +// -type cube_top | cube_bottom | # when using a cube map, the texture +// file for each +// cube_front | cube_back | # side of the cube is specified +// separately +// cube_left | cube_right + +#ifdef TINYOBJLOADER_USE_DOUBLE +//#pragma message "using double" +typedef double real_t; +#else +//#pragma message "using float" +typedef float real_t; +#endif + +typedef enum { + TEXTURE_TYPE_NONE, // default + TEXTURE_TYPE_SPHERE, + TEXTURE_TYPE_CUBE_TOP, + TEXTURE_TYPE_CUBE_BOTTOM, + TEXTURE_TYPE_CUBE_FRONT, + TEXTURE_TYPE_CUBE_BACK, + TEXTURE_TYPE_CUBE_LEFT, + TEXTURE_TYPE_CUBE_RIGHT +} texture_type_t; + +typedef struct { + texture_type_t type; // -type (default TEXTURE_TYPE_NONE) + real_t sharpness; // -boost (default 1.0?) + real_t brightness; // base_value in -mm option (default 0) + real_t contrast; // gain_value in -mm option (default 1) + real_t origin_offset[3]; // -o u [v [w]] (default 0 0 0) + real_t scale[3]; // -s u [v [w]] (default 1 1 1) + real_t turbulence[3]; // -t u [v [w]] (default 0 0 0) + // int texture_resolution; // -texres resolution (default = ?) TODO + bool clamp; // -clamp (default false) + char imfchan; // -imfchan (the default for bump is 'l' and for decal is 'm') + bool blendu; // -blendu (default on) + bool blendv; // -blendv (default on) + real_t bump_multiplier; // -bm (for bump maps only, default 1.0) +} texture_option_t; + +typedef struct { + std::string name; + + real_t ambient[3]; + real_t diffuse[3]; + real_t specular[3]; + real_t transmittance[3]; + real_t emission[3]; + real_t shininess; + real_t ior; // index of refraction + real_t dissolve; // 1 == opaque; 0 == fully transparent + // illumination model (see http://www.fileformat.info/format/material/) + int illum; + + int dummy; // Suppress padding warning. + + std::string ambient_texname; // map_Ka + std::string diffuse_texname; // map_Kd + std::string specular_texname; // map_Ks + std::string specular_highlight_texname; // map_Ns + std::string bump_texname; // map_bump, map_Bump, bump + std::string displacement_texname; // disp + std::string alpha_texname; // map_d + std::string reflection_texname; // refl + + texture_option_t ambient_texopt; + texture_option_t diffuse_texopt; + texture_option_t specular_texopt; + texture_option_t specular_highlight_texopt; + texture_option_t bump_texopt; + texture_option_t displacement_texopt; + texture_option_t alpha_texopt; + texture_option_t reflection_texopt; + + // PBR extension + // http://exocortex.com/blog/extending_wavefront_mtl_to_support_pbr + real_t roughness; // [0, 1] default 0 + real_t metallic; // [0, 1] default 0 + real_t sheen; // [0, 1] default 0 + real_t clearcoat_thickness; // [0, 1] default 0 + real_t clearcoat_roughness; // [0, 1] default 0 + real_t anisotropy; // aniso. [0, 1] default 0 + real_t anisotropy_rotation; // anisor. [0, 1] default 0 + real_t pad0; + std::string roughness_texname; // map_Pr + std::string metallic_texname; // map_Pm + std::string sheen_texname; // map_Ps + std::string emissive_texname; // map_Ke + std::string normal_texname; // norm. For normal mapping. + + texture_option_t roughness_texopt; + texture_option_t metallic_texopt; + texture_option_t sheen_texopt; + texture_option_t emissive_texopt; + texture_option_t normal_texopt; + + int pad2; + + std::map unknown_parameter; +} material_t; + +typedef struct { + std::string name; + + std::vector intValues; + std::vector floatValues; + std::vector stringValues; +} tag_t; + +// Index struct to support different indices for vtx/normal/texcoord. +// -1 means not used. +typedef struct { + int vertex_index; + int normal_index; + int texcoord_index; +} index_t; + +typedef struct { + std::vector indices; + std::vector num_face_vertices; // The number of vertices per + // face. 3 = polygon, 4 = quad, + // ... Up to 255. + std::vector material_ids; // per-face material ID + std::vector tags; // SubD tag +} mesh_t; + +typedef struct { + std::string name; + mesh_t mesh; +} shape_t; + +// Vertex attributes +typedef struct { + std::vector vertices; // 'v' + std::vector normals; // 'vn' + std::vector texcoords; // 'vt' +} attrib_t; + +typedef struct callback_t_ { + // W is optional and set to 1 if there is no `w` item in `v` line + void (*vertex_cb)(void *user_data, real_t x, real_t y, real_t z, real_t w); + void (*normal_cb)(void *user_data, real_t x, real_t y, real_t z); + + // y and z are optional and set to 0 if there is no `y` and/or `z` item(s) in + // `vt` line. + void (*texcoord_cb)(void *user_data, real_t x, real_t y, real_t z); + + // called per 'f' line. num_indices is the number of face indices(e.g. 3 for + // triangle, 4 for quad) + // 0 will be passed for undefined index in index_t members. + void (*index_cb)(void *user_data, index_t *indices, int num_indices); + // `name` material name, `material_id` = the array index of material_t[]. -1 + // if + // a material not found in .mtl + void (*usemtl_cb)(void *user_data, const char *name, int material_id); + // `materials` = parsed material data. + void (*mtllib_cb)(void *user_data, const material_t *materials, + int num_materials); + // There may be multiple group names + void (*group_cb)(void *user_data, const char **names, int num_names); + void (*object_cb)(void *user_data, const char *name); + + callback_t_() + : vertex_cb(NULL), + normal_cb(NULL), + texcoord_cb(NULL), + index_cb(NULL), + usemtl_cb(NULL), + mtllib_cb(NULL), + group_cb(NULL), + object_cb(NULL) {} +} callback_t; + +class MaterialReader { + public: + MaterialReader() {} + virtual ~MaterialReader(); + + virtual bool operator()(const std::string &matId, + std::vector *materials, + std::map *matMap, + std::string *err) = 0; +}; + +class MaterialFileReader : public MaterialReader { + public: + explicit MaterialFileReader(const std::string &mtl_basedir) + : m_mtlBaseDir(mtl_basedir) {} + virtual ~MaterialFileReader() {} + virtual bool operator()(const std::string &matId, + std::vector *materials, + std::map *matMap, std::string *err); + + private: + std::string m_mtlBaseDir; +}; + +class MaterialStreamReader : public MaterialReader { + public: + explicit MaterialStreamReader(std::istream &inStream) + : m_inStream(inStream) {} + virtual ~MaterialStreamReader() {} + virtual bool operator()(const std::string &matId, + std::vector *materials, + std::map *matMap, std::string *err); + + private: + std::istream &m_inStream; +}; + +/// Loads .obj from a file. +/// 'attrib', 'shapes' and 'materials' will be filled with parsed shape data +/// 'shapes' will be filled with parsed shape data +/// Returns true when loading .obj become success. +/// Returns warning and error message into `err` +/// 'mtl_basedir' is optional, and used for base directory for .mtl file. +/// In default(`NULL'), .mtl file is searched from an application's working +/// directory. +/// 'triangulate' is optional, and used whether triangulate polygon face in .obj +/// or not. +bool LoadObj(attrib_t *attrib, std::vector *shapes, + std::vector *materials, std::string *err, + const char *filename, const char *mtl_basedir = NULL, + bool triangulate = true); + +/// Loads .obj from a file with custom user callback. +/// .mtl is loaded as usual and parsed material_t data will be passed to +/// `callback.mtllib_cb`. +/// Returns true when loading .obj/.mtl become success. +/// Returns warning and error message into `err` +/// See `examples/callback_api/` for how to use this function. +bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback, + void *user_data = NULL, + MaterialReader *readMatFn = NULL, + std::string *err = NULL); + +/// Loads object from a std::istream, uses GetMtlIStreamFn to retrieve +/// std::istream for materials. +/// Returns true when loading .obj become success. +/// Returns warning and error message into `err` +bool LoadObj(attrib_t *attrib, std::vector *shapes, + std::vector *materials, std::string *err, + std::istream *inStream, MaterialReader *readMatFn = NULL, + bool triangulate = true); + +/// Loads materials into std::map +void LoadMtl(std::map *material_map, + std::vector *materials, std::istream *inStream, + std::string *warning); + +} // namespace tinyobj + +#endif // TINY_OBJ_LOADER_H_ + +#ifdef TINYOBJLOADER_IMPLEMENTATION +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace tinyobj { + +MaterialReader::~MaterialReader() {} + +struct vertex_index { + int v_idx, vt_idx, vn_idx; + vertex_index() : v_idx(-1), vt_idx(-1), vn_idx(-1) {} + explicit vertex_index(int idx) : v_idx(idx), vt_idx(idx), vn_idx(idx) {} + vertex_index(int vidx, int vtidx, int vnidx) + : v_idx(vidx), vt_idx(vtidx), vn_idx(vnidx) {} +}; + +struct tag_sizes { + tag_sizes() : num_ints(0), num_reals(0), num_strings(0) {} + int num_ints; + int num_reals; + int num_strings; +}; + +struct obj_shape { + std::vector v; + std::vector vn; + std::vector vt; +}; + +// See +// http://stackoverflow.com/questions/6089231/getting-std-ifstream-to-handle-lf-cr-and-crlf +static std::istream &safeGetline(std::istream &is, std::string &t) { + t.clear(); + + // The characters in the stream are read one-by-one using a std::streambuf. + // That is faster than reading them one-by-one using the std::istream. + // Code that uses streambuf this way must be guarded by a sentry object. + // The sentry object performs various tasks, + // such as thread synchronization and updating the stream state. + + std::istream::sentry se(is, true); + std::streambuf *sb = is.rdbuf(); + + if (se) { + for (;;) { + int c = sb->sbumpc(); + switch (c) { + case '\n': + return is; + case '\r': + if (sb->sgetc() == '\n') sb->sbumpc(); + return is; + case EOF: + // Also handle the case when the last line has no line ending + if (t.empty()) is.setstate(std::ios::eofbit); + return is; + default: + t += static_cast(c); + } + } + } + + return is; +} + +#define IS_SPACE(x) (((x) == ' ') || ((x) == '\t')) +#define IS_DIGIT(x) \ + (static_cast((x) - '0') < static_cast(10)) +#define IS_NEW_LINE(x) (((x) == '\r') || ((x) == '\n') || ((x) == '\0')) + +// Make index zero-base, and also support relative index. +static inline bool fixIndex(int idx, int n, int *ret) { + if (!ret) { + return false; + } + + if (idx > 0) { + (*ret) = idx - 1; + return true; + } + + if (idx == 0) { + // zero is not allowed according to the spec. + return false; + } + + if (idx < 0) { + (*ret) = n + idx; // negative value = relative + return true; + } + + return false; // never reach here. +} + +static inline std::string parseString(const char **token) { + std::string s; + (*token) += strspn((*token), " \t"); + size_t e = strcspn((*token), " \t\r"); + s = std::string((*token), &(*token)[e]); + (*token) += e; + return s; +} + +static inline int parseInt(const char **token) { + (*token) += strspn((*token), " \t"); + int i = atoi((*token)); + (*token) += strcspn((*token), " \t\r"); + return i; +} + +// Tries to parse a floating point number located at s. +// +// s_end should be a location in the string where reading should absolutely +// stop. For example at the end of the string, to prevent buffer overflows. +// +// Parses the following EBNF grammar: +// sign = "+" | "-" ; +// END = ? anything not in digit ? +// digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; +// integer = [sign] , digit , {digit} ; +// decimal = integer , ["." , integer] ; +// float = ( decimal , END ) | ( decimal , ("E" | "e") , integer , END ) ; +// +// Valid strings are for example: +// -0 +3.1417e+2 -0.0E-3 1.0324 -1.41 11e2 +// +// If the parsing is a success, result is set to the parsed value and true +// is returned. +// +// The function is greedy and will parse until any of the following happens: +// - a non-conforming character is encountered. +// - s_end is reached. +// +// The following situations triggers a failure: +// - s >= s_end. +// - parse failure. +// +static bool tryParseDouble(const char *s, const char *s_end, double *result) { + if (s >= s_end) { + return false; + } + + double mantissa = 0.0; + // This exponent is base 2 rather than 10. + // However the exponent we parse is supposed to be one of ten, + // thus we must take care to convert the exponent/and or the + // mantissa to a * 2^E, where a is the mantissa and E is the + // exponent. + // To get the final double we will use ldexp, it requires the + // exponent to be in base 2. + int exponent = 0; + + // NOTE: THESE MUST BE DECLARED HERE SINCE WE ARE NOT ALLOWED + // TO JUMP OVER DEFINITIONS. + char sign = '+'; + char exp_sign = '+'; + char const *curr = s; + + // How many characters were read in a loop. + int read = 0; + // Tells whether a loop terminated due to reaching s_end. + bool end_not_reached = false; + + /* + BEGIN PARSING. + */ + + // Find out what sign we've got. + if (*curr == '+' || *curr == '-') { + sign = *curr; + curr++; + } else if (IS_DIGIT(*curr)) { /* Pass through. */ + } else { + goto fail; + } + + // Read the integer part. + end_not_reached = (curr != s_end); + while (end_not_reached && IS_DIGIT(*curr)) { + mantissa *= 10; + mantissa += static_cast(*curr - 0x30); + curr++; + read++; + end_not_reached = (curr != s_end); + } + + // We must make sure we actually got something. + if (read == 0) goto fail; + // We allow numbers of form "#", "###" etc. + if (!end_not_reached) goto assemble; + + // Read the decimal part. + if (*curr == '.') { + curr++; + read = 1; + end_not_reached = (curr != s_end); + while (end_not_reached && IS_DIGIT(*curr)) { + static const double pow_lut[] = { + 1.0, 0.1, 0.01, 0.001, 0.0001, 0.00001, 0.000001, 0.0000001, + }; + const int lut_entries = sizeof pow_lut / sizeof pow_lut[0]; + + // NOTE: Don't use powf here, it will absolutely murder precision. + mantissa += static_cast(*curr - 0x30) * + (read < lut_entries ? pow_lut[read] : std::pow(10.0, -read)); + read++; + curr++; + end_not_reached = (curr != s_end); + } + } else if (*curr == 'e' || *curr == 'E') { + } else { + goto assemble; + } + + if (!end_not_reached) goto assemble; + + // Read the exponent part. + if (*curr == 'e' || *curr == 'E') { + curr++; + // Figure out if a sign is present and if it is. + end_not_reached = (curr != s_end); + if (end_not_reached && (*curr == '+' || *curr == '-')) { + exp_sign = *curr; + curr++; + } else if (IS_DIGIT(*curr)) { /* Pass through. */ + } else { + // Empty E is not allowed. + goto fail; + } + + read = 0; + end_not_reached = (curr != s_end); + while (end_not_reached && IS_DIGIT(*curr)) { + exponent *= 10; + exponent += static_cast(*curr - 0x30); + curr++; + read++; + end_not_reached = (curr != s_end); + } + exponent *= (exp_sign == '+' ? 1 : -1); + if (read == 0) goto fail; + } + +assemble: + *result = (sign == '+' ? 1 : -1) * + (exponent ? std::ldexp(mantissa * std::pow(5.0, exponent), exponent) + : mantissa); + return true; +fail: + return false; +} + +static inline real_t parseReal(const char **token, double default_value = 0.0) { + (*token) += strspn((*token), " \t"); + const char *end = (*token) + strcspn((*token), " \t\r"); + double val = default_value; + tryParseDouble((*token), end, &val); + real_t f = static_cast(val); + (*token) = end; + return f; +} + +static inline void parseReal2(real_t *x, real_t *y, const char **token, + const double default_x = 0.0, + const double default_y = 0.0) { + (*x) = parseReal(token, default_x); + (*y) = parseReal(token, default_y); +} + +static inline void parseReal3(real_t *x, real_t *y, real_t *z, + const char **token, const double default_x = 0.0, + const double default_y = 0.0, + const double default_z = 0.0) { + (*x) = parseReal(token, default_x); + (*y) = parseReal(token, default_y); + (*z) = parseReal(token, default_z); +} + +static inline void parseV(real_t *x, real_t *y, real_t *z, real_t *w, + const char **token, const double default_x = 0.0, + const double default_y = 0.0, + const double default_z = 0.0, + const double default_w = 1.0) { + (*x) = parseReal(token, default_x); + (*y) = parseReal(token, default_y); + (*z) = parseReal(token, default_z); + (*w) = parseReal(token, default_w); +} + +static inline bool parseOnOff(const char **token, bool default_value = true) { + (*token) += strspn((*token), " \t"); + const char *end = (*token) + strcspn((*token), " \t\r"); + + bool ret = default_value; + if ((0 == strncmp((*token), "on", 2))) { + ret = true; + } else if ((0 == strncmp((*token), "off", 3))) { + ret = false; + } + + (*token) = end; + return ret; +} + +static inline texture_type_t parseTextureType( + const char **token, texture_type_t default_value = TEXTURE_TYPE_NONE) { + (*token) += strspn((*token), " \t"); + const char *end = (*token) + strcspn((*token), " \t\r"); + texture_type_t ty = default_value; + + if ((0 == strncmp((*token), "cube_top", strlen("cube_top")))) { + ty = TEXTURE_TYPE_CUBE_TOP; + } else if ((0 == strncmp((*token), "cube_bottom", strlen("cube_bottom")))) { + ty = TEXTURE_TYPE_CUBE_BOTTOM; + } else if ((0 == strncmp((*token), "cube_left", strlen("cube_left")))) { + ty = TEXTURE_TYPE_CUBE_LEFT; + } else if ((0 == strncmp((*token), "cube_right", strlen("cube_right")))) { + ty = TEXTURE_TYPE_CUBE_RIGHT; + } else if ((0 == strncmp((*token), "cube_front", strlen("cube_front")))) { + ty = TEXTURE_TYPE_CUBE_FRONT; + } else if ((0 == strncmp((*token), "cube_back", strlen("cube_back")))) { + ty = TEXTURE_TYPE_CUBE_BACK; + } else if ((0 == strncmp((*token), "sphere", strlen("sphere")))) { + ty = TEXTURE_TYPE_SPHERE; + } + + (*token) = end; + return ty; +} + +static tag_sizes parseTagTriple(const char **token) { + tag_sizes ts; + + ts.num_ints = atoi((*token)); + (*token) += strcspn((*token), "/ \t\r"); + if ((*token)[0] != '/') { + return ts; + } + (*token)++; + + ts.num_reals = atoi((*token)); + (*token) += strcspn((*token), "/ \t\r"); + if ((*token)[0] != '/') { + return ts; + } + (*token)++; + + ts.num_strings = atoi((*token)); + (*token) += strcspn((*token), "/ \t\r") + 1; + + return ts; +} + +// Parse triples with index offsets: i, i/j/k, i//k, i/j +static bool parseTriple(const char **token, int vsize, int vnsize, int vtsize, + vertex_index *ret) { + if (!ret) { + return false; + } + + vertex_index vi(-1); + + if (!fixIndex(atoi((*token)), vsize, &(vi.v_idx))) { + return false; + } + + (*token) += strcspn((*token), "/ \t\r"); + if ((*token)[0] != '/') { + (*ret) = vi; + return true; + } + (*token)++; + + // i//k + if ((*token)[0] == '/') { + (*token)++; + if (!fixIndex(atoi((*token)), vnsize, &(vi.vn_idx))) { + return false; + } + (*token) += strcspn((*token), "/ \t\r"); + (*ret) = vi; + return true; + } + + // i/j/k or i/j + if (!fixIndex(atoi((*token)), vtsize, &(vi.vt_idx))) { + return false; + } + + (*token) += strcspn((*token), "/ \t\r"); + if ((*token)[0] != '/') { + (*ret) = vi; + return true; + } + + // i/j/k + (*token)++; // skip '/' + if (!fixIndex(atoi((*token)), vnsize, &(vi.vn_idx))) { + return false; + } + (*token) += strcspn((*token), "/ \t\r"); + + (*ret) = vi; + + return true; +} + +// Parse raw triples: i, i/j/k, i//k, i/j +static vertex_index parseRawTriple(const char **token) { + vertex_index vi(static_cast(0)); // 0 is an invalid index in OBJ + + vi.v_idx = atoi((*token)); + (*token) += strcspn((*token), "/ \t\r"); + if ((*token)[0] != '/') { + return vi; + } + (*token)++; + + // i//k + if ((*token)[0] == '/') { + (*token)++; + vi.vn_idx = atoi((*token)); + (*token) += strcspn((*token), "/ \t\r"); + return vi; + } + + // i/j/k or i/j + vi.vt_idx = atoi((*token)); + (*token) += strcspn((*token), "/ \t\r"); + if ((*token)[0] != '/') { + return vi; + } + + // i/j/k + (*token)++; // skip '/' + vi.vn_idx = atoi((*token)); + (*token) += strcspn((*token), "/ \t\r"); + return vi; +} + +static bool ParseTextureNameAndOption(std::string *texname, + texture_option_t *texopt, + const char *linebuf, const bool is_bump) { + // @todo { write more robust lexer and parser. } + bool found_texname = false; + std::string texture_name; + + // Fill with default value for texopt. + if (is_bump) { + texopt->imfchan = 'l'; + } else { + texopt->imfchan = 'm'; + } + texopt->bump_multiplier = 1.0f; + texopt->clamp = false; + texopt->blendu = true; + texopt->blendv = true; + texopt->sharpness = 1.0f; + texopt->brightness = 0.0f; + texopt->contrast = 1.0f; + texopt->origin_offset[0] = 0.0f; + texopt->origin_offset[1] = 0.0f; + texopt->origin_offset[2] = 0.0f; + texopt->scale[0] = 1.0f; + texopt->scale[1] = 1.0f; + texopt->scale[2] = 1.0f; + texopt->turbulence[0] = 0.0f; + texopt->turbulence[1] = 0.0f; + texopt->turbulence[2] = 0.0f; + texopt->type = TEXTURE_TYPE_NONE; + + const char *token = linebuf; // Assume line ends with NULL + + while (!IS_NEW_LINE((*token))) { + token += strspn(token, " \t"); // skip space + if ((0 == strncmp(token, "-blendu", 7)) && IS_SPACE((token[7]))) { + token += 8; + texopt->blendu = parseOnOff(&token, /* default */ true); + } else if ((0 == strncmp(token, "-blendv", 7)) && IS_SPACE((token[7]))) { + token += 8; + texopt->blendv = parseOnOff(&token, /* default */ true); + } else if ((0 == strncmp(token, "-clamp", 6)) && IS_SPACE((token[6]))) { + token += 7; + texopt->clamp = parseOnOff(&token, /* default */ true); + } else if ((0 == strncmp(token, "-boost", 6)) && IS_SPACE((token[6]))) { + token += 7; + texopt->sharpness = parseReal(&token, 1.0); + } else if ((0 == strncmp(token, "-bm", 3)) && IS_SPACE((token[3]))) { + token += 4; + texopt->bump_multiplier = parseReal(&token, 1.0); + } else if ((0 == strncmp(token, "-o", 2)) && IS_SPACE((token[2]))) { + token += 3; + parseReal3(&(texopt->origin_offset[0]), &(texopt->origin_offset[1]), + &(texopt->origin_offset[2]), &token); + } else if ((0 == strncmp(token, "-s", 2)) && IS_SPACE((token[2]))) { + token += 3; + parseReal3(&(texopt->scale[0]), &(texopt->scale[1]), &(texopt->scale[2]), + &token, 1.0, 1.0, 1.0); + } else if ((0 == strncmp(token, "-t", 2)) && IS_SPACE((token[2]))) { + token += 3; + parseReal3(&(texopt->turbulence[0]), &(texopt->turbulence[1]), + &(texopt->turbulence[2]), &token); + } else if ((0 == strncmp(token, "-type", 5)) && IS_SPACE((token[5]))) { + token += 5; + texopt->type = parseTextureType((&token), TEXTURE_TYPE_NONE); + } else if ((0 == strncmp(token, "-imfchan", 8)) && IS_SPACE((token[8]))) { + token += 9; + token += strspn(token, " \t"); + const char *end = token + strcspn(token, " \t\r"); + if ((end - token) == 1) { // Assume one char for -imfchan + texopt->imfchan = (*token); + } + token = end; + } else if ((0 == strncmp(token, "-mm", 3)) && IS_SPACE((token[3]))) { + token += 4; + parseReal2(&(texopt->brightness), &(texopt->contrast), &token, 0.0, 1.0); + } else { + // Assume texture filename + size_t len = strcspn(token, " \t\r"); // untile next space + texture_name = std::string(token, token + len); + token += len; + + token += strspn(token, " \t"); // skip space + + found_texname = true; + } + } + + if (found_texname) { + (*texname) = texture_name; + return true; + } else { + return false; + } +} + +static void InitMaterial(material_t *material) { + material->name = ""; + material->ambient_texname = ""; + material->diffuse_texname = ""; + material->specular_texname = ""; + material->specular_highlight_texname = ""; + material->bump_texname = ""; + material->displacement_texname = ""; + material->reflection_texname = ""; + material->alpha_texname = ""; + for (int i = 0; i < 3; i++) { + material->ambient[i] = 0.f; + material->diffuse[i] = 0.f; + material->specular[i] = 0.f; + material->transmittance[i] = 0.f; + material->emission[i] = 0.f; + } + material->illum = 0; + material->dissolve = 1.f; + material->shininess = 1.f; + material->ior = 1.f; + + material->roughness = 0.f; + material->metallic = 0.f; + material->sheen = 0.f; + material->clearcoat_thickness = 0.f; + material->clearcoat_roughness = 0.f; + material->anisotropy_rotation = 0.f; + material->anisotropy = 0.f; + material->roughness_texname = ""; + material->metallic_texname = ""; + material->sheen_texname = ""; + material->emissive_texname = ""; + material->normal_texname = ""; + + material->unknown_parameter.clear(); +} + +static bool exportFaceGroupToShape( + shape_t *shape, const std::vector > &faceGroup, + const std::vector &tags, const int material_id, + const std::string &name, bool triangulate) { + if (faceGroup.empty()) { + return false; + } + + // Flatten vertices and indices + for (size_t i = 0; i < faceGroup.size(); i++) { + const std::vector &face = faceGroup[i]; + + vertex_index i0 = face[0]; + vertex_index i1(-1); + vertex_index i2 = face[1]; + + size_t npolys = face.size(); + + if (triangulate) { + // Polygon -> triangle fan conversion + for (size_t k = 2; k < npolys; k++) { + i1 = i2; + i2 = face[k]; + + index_t idx0, idx1, idx2; + idx0.vertex_index = i0.v_idx; + idx0.normal_index = i0.vn_idx; + idx0.texcoord_index = i0.vt_idx; + idx1.vertex_index = i1.v_idx; + idx1.normal_index = i1.vn_idx; + idx1.texcoord_index = i1.vt_idx; + idx2.vertex_index = i2.v_idx; + idx2.normal_index = i2.vn_idx; + idx2.texcoord_index = i2.vt_idx; + + shape->mesh.indices.push_back(idx0); + shape->mesh.indices.push_back(idx1); + shape->mesh.indices.push_back(idx2); + + shape->mesh.num_face_vertices.push_back(3); + shape->mesh.material_ids.push_back(material_id); + } + } else { + for (size_t k = 0; k < npolys; k++) { + index_t idx; + idx.vertex_index = face[k].v_idx; + idx.normal_index = face[k].vn_idx; + idx.texcoord_index = face[k].vt_idx; + shape->mesh.indices.push_back(idx); + } + + shape->mesh.num_face_vertices.push_back( + static_cast(npolys)); + shape->mesh.material_ids.push_back(material_id); // per face + } + } + + shape->name = name; + shape->mesh.tags = tags; + + return true; +} + +// Split a string with specified delimiter character. +// http://stackoverflow.com/questions/236129/split-a-string-in-c +static void SplitString(const std::string &s, char delim, + std::vector &elems) { + std::stringstream ss; + ss.str(s); + std::string item; + while (std::getline(ss, item, delim)) { + elems.push_back(item); + } +} + +void LoadMtl(std::map *material_map, + std::vector *materials, std::istream *inStream, + std::string *warning) { + // Create a default material anyway. + material_t material; + InitMaterial(&material); + + // Issue 43. `d` wins against `Tr` since `Tr` is not in the MTL specification. + bool has_d = false; + bool has_tr = false; + + std::stringstream ss; + + std::string linebuf; + while (inStream->peek() != -1) { + safeGetline(*inStream, linebuf); + + // Trim trailing whitespace. + if (linebuf.size() > 0) { + linebuf = linebuf.substr(0, linebuf.find_last_not_of(" \t") + 1); + } + + // Trim newline '\r\n' or '\n' + if (linebuf.size() > 0) { + if (linebuf[linebuf.size() - 1] == '\n') + linebuf.erase(linebuf.size() - 1); + } + if (linebuf.size() > 0) { + if (linebuf[linebuf.size() - 1] == '\r') + linebuf.erase(linebuf.size() - 1); + } + + // Skip if empty line. + if (linebuf.empty()) { + continue; + } + + // Skip leading space. + const char *token = linebuf.c_str(); + token += strspn(token, " \t"); + + assert(token); + if (token[0] == '\0') continue; // empty line + + if (token[0] == '#') continue; // comment line + + // new mtl + if ((0 == strncmp(token, "newmtl", 6)) && IS_SPACE((token[6]))) { + // flush previous material. + if (!material.name.empty()) { + material_map->insert(std::pair( + material.name, static_cast(materials->size()))); + materials->push_back(material); + } + + // initial temporary material + InitMaterial(&material); + + has_d = false; + has_tr = false; + + // set new mtl name + token += 7; + { + std::stringstream sstr; + sstr << token; + material.name = sstr.str(); + } + continue; + } + + // ambient + if (token[0] == 'K' && token[1] == 'a' && IS_SPACE((token[2]))) { + token += 2; + real_t r, g, b; + parseReal3(&r, &g, &b, &token); + material.ambient[0] = r; + material.ambient[1] = g; + material.ambient[2] = b; + continue; + } + + // diffuse + if (token[0] == 'K' && token[1] == 'd' && IS_SPACE((token[2]))) { + token += 2; + real_t r, g, b; + parseReal3(&r, &g, &b, &token); + material.diffuse[0] = r; + material.diffuse[1] = g; + material.diffuse[2] = b; + continue; + } + + // specular + if (token[0] == 'K' && token[1] == 's' && IS_SPACE((token[2]))) { + token += 2; + real_t r, g, b; + parseReal3(&r, &g, &b, &token); + material.specular[0] = r; + material.specular[1] = g; + material.specular[2] = b; + continue; + } + + // transmittance + if ((token[0] == 'K' && token[1] == 't' && IS_SPACE((token[2]))) || + (token[0] == 'T' && token[1] == 'f' && IS_SPACE((token[2])))) { + token += 2; + real_t r, g, b; + parseReal3(&r, &g, &b, &token); + material.transmittance[0] = r; + material.transmittance[1] = g; + material.transmittance[2] = b; + continue; + } + + // ior(index of refraction) + if (token[0] == 'N' && token[1] == 'i' && IS_SPACE((token[2]))) { + token += 2; + material.ior = parseReal(&token); + continue; + } + + // emission + if (token[0] == 'K' && token[1] == 'e' && IS_SPACE(token[2])) { + token += 2; + real_t r, g, b; + parseReal3(&r, &g, &b, &token); + material.emission[0] = r; + material.emission[1] = g; + material.emission[2] = b; + continue; + } + + // shininess + if (token[0] == 'N' && token[1] == 's' && IS_SPACE(token[2])) { + token += 2; + material.shininess = parseReal(&token); + continue; + } + + // illum model + if (0 == strncmp(token, "illum", 5) && IS_SPACE(token[5])) { + token += 6; + material.illum = parseInt(&token); + continue; + } + + // dissolve + if ((token[0] == 'd' && IS_SPACE(token[1]))) { + token += 1; + material.dissolve = parseReal(&token); + + if (has_tr) { + ss << "WARN: Both `d` and `Tr` parameters defined for \"" + << material.name << "\". Use the value of `d` for dissolve." + << std::endl; + } + has_d = true; + continue; + } + if (token[0] == 'T' && token[1] == 'r' && IS_SPACE(token[2])) { + token += 2; + if (has_d) { + // `d` wins. Ignore `Tr` value. + ss << "WARN: Both `d` and `Tr` parameters defined for \"" + << material.name << "\". Use the value of `d` for dissolve." + << std::endl; + } else { + // We invert value of Tr(assume Tr is in range [0, 1]) + // NOTE: Interpretation of Tr is application(exporter) dependent. For + // some application(e.g. 3ds max obj exporter), Tr = d(Issue 43) + material.dissolve = 1.0f - parseReal(&token); + } + has_tr = true; + continue; + } + + // PBR: roughness + if (token[0] == 'P' && token[1] == 'r' && IS_SPACE(token[2])) { + token += 2; + material.roughness = parseReal(&token); + continue; + } + + // PBR: metallic + if (token[0] == 'P' && token[1] == 'm' && IS_SPACE(token[2])) { + token += 2; + material.metallic = parseReal(&token); + continue; + } + + // PBR: sheen + if (token[0] == 'P' && token[1] == 's' && IS_SPACE(token[2])) { + token += 2; + material.sheen = parseReal(&token); + continue; + } + + // PBR: clearcoat thickness + if (token[0] == 'P' && token[1] == 'c' && IS_SPACE(token[2])) { + token += 2; + material.clearcoat_thickness = parseReal(&token); + continue; + } + + // PBR: clearcoat roughness + if ((0 == strncmp(token, "Pcr", 3)) && IS_SPACE(token[3])) { + token += 4; + material.clearcoat_roughness = parseReal(&token); + continue; + } + + // PBR: anisotropy + if ((0 == strncmp(token, "aniso", 5)) && IS_SPACE(token[5])) { + token += 6; + material.anisotropy = parseReal(&token); + continue; + } + + // PBR: anisotropy rotation + if ((0 == strncmp(token, "anisor", 6)) && IS_SPACE(token[6])) { + token += 7; + material.anisotropy_rotation = parseReal(&token); + continue; + } + + // ambient texture + if ((0 == strncmp(token, "map_Ka", 6)) && IS_SPACE(token[6])) { + token += 7; + ParseTextureNameAndOption(&(material.ambient_texname), + &(material.ambient_texopt), token, + /* is_bump */ false); + continue; + } + + // diffuse texture + if ((0 == strncmp(token, "map_Kd", 6)) && IS_SPACE(token[6])) { + token += 7; + ParseTextureNameAndOption(&(material.diffuse_texname), + &(material.diffuse_texopt), token, + /* is_bump */ false); + continue; + } + + // specular texture + if ((0 == strncmp(token, "map_Ks", 6)) && IS_SPACE(token[6])) { + token += 7; + ParseTextureNameAndOption(&(material.specular_texname), + &(material.specular_texopt), token, + /* is_bump */ false); + continue; + } + + // specular highlight texture + if ((0 == strncmp(token, "map_Ns", 6)) && IS_SPACE(token[6])) { + token += 7; + ParseTextureNameAndOption(&(material.specular_highlight_texname), + &(material.specular_highlight_texopt), token, + /* is_bump */ false); + continue; + } + + // bump texture + if ((0 == strncmp(token, "map_bump", 8)) && IS_SPACE(token[8])) { + token += 9; + ParseTextureNameAndOption(&(material.bump_texname), + &(material.bump_texopt), token, + /* is_bump */ true); + continue; + } + + // bump texture + if ((0 == strncmp(token, "map_Bump", 8)) && IS_SPACE(token[8])) { + token += 9; + ParseTextureNameAndOption(&(material.bump_texname), + &(material.bump_texopt), token, + /* is_bump */ true); + continue; + } + + // bump texture + if ((0 == strncmp(token, "bump", 4)) && IS_SPACE(token[4])) { + token += 5; + ParseTextureNameAndOption(&(material.bump_texname), + &(material.bump_texopt), token, + /* is_bump */ true); + continue; + } + + // alpha texture + if ((0 == strncmp(token, "map_d", 5)) && IS_SPACE(token[5])) { + token += 6; + material.alpha_texname = token; + ParseTextureNameAndOption(&(material.alpha_texname), + &(material.alpha_texopt), token, + /* is_bump */ false); + continue; + } + + // displacement texture + if ((0 == strncmp(token, "disp", 4)) && IS_SPACE(token[4])) { + token += 5; + ParseTextureNameAndOption(&(material.displacement_texname), + &(material.displacement_texopt), token, + /* is_bump */ false); + continue; + } + + // reflection map + if ((0 == strncmp(token, "refl", 4)) && IS_SPACE(token[4])) { + token += 5; + ParseTextureNameAndOption(&(material.reflection_texname), + &(material.reflection_texopt), token, + /* is_bump */ false); + continue; + } + + // PBR: roughness texture + if ((0 == strncmp(token, "map_Pr", 6)) && IS_SPACE(token[6])) { + token += 7; + ParseTextureNameAndOption(&(material.roughness_texname), + &(material.roughness_texopt), token, + /* is_bump */ false); + continue; + } + + // PBR: metallic texture + if ((0 == strncmp(token, "map_Pm", 6)) && IS_SPACE(token[6])) { + token += 7; + ParseTextureNameAndOption(&(material.metallic_texname), + &(material.metallic_texopt), token, + /* is_bump */ false); + continue; + } + + // PBR: sheen texture + if ((0 == strncmp(token, "map_Ps", 6)) && IS_SPACE(token[6])) { + token += 7; + ParseTextureNameAndOption(&(material.sheen_texname), + &(material.sheen_texopt), token, + /* is_bump */ false); + continue; + } + + // PBR: emissive texture + if ((0 == strncmp(token, "map_Ke", 6)) && IS_SPACE(token[6])) { + token += 7; + ParseTextureNameAndOption(&(material.emissive_texname), + &(material.emissive_texopt), token, + /* is_bump */ false); + continue; + } + + // PBR: normal map texture + if ((0 == strncmp(token, "norm", 4)) && IS_SPACE(token[4])) { + token += 5; + ParseTextureNameAndOption( + &(material.normal_texname), &(material.normal_texopt), token, + /* is_bump */ false); // @fixme { is_bump will be true? } + continue; + } + + // unknown parameter + const char *_space = strchr(token, ' '); + if (!_space) { + _space = strchr(token, '\t'); + } + if (_space) { + std::ptrdiff_t len = _space - token; + std::string key(token, static_cast(len)); + std::string value = _space + 1; + material.unknown_parameter.insert( + std::pair(key, value)); + } + } + // flush last material. + material_map->insert(std::pair( + material.name, static_cast(materials->size()))); + materials->push_back(material); + + if (warning) { + (*warning) = ss.str(); + } +} + +bool MaterialFileReader::operator()(const std::string &matId, + std::vector *materials, + std::map *matMap, + std::string *err) { + std::string filepath; + + if (!m_mtlBaseDir.empty()) { + filepath = std::string(m_mtlBaseDir) + matId; + } else { + filepath = matId; + } + + std::ifstream matIStream(filepath.c_str()); + if (!matIStream) { + std::stringstream ss; + ss << "WARN: Material file [ " << filepath << " ] not found." << std::endl; + if (err) { + (*err) += ss.str(); + } + return false; + } + + std::string warning; + LoadMtl(matMap, materials, &matIStream, &warning); + + if (!warning.empty()) { + if (err) { + (*err) += warning; + } + } + + return true; +} + +bool MaterialStreamReader::operator()(const std::string &matId, + std::vector *materials, + std::map *matMap, + std::string *err) { + (void)matId; + if (!m_inStream) { + std::stringstream ss; + ss << "WARN: Material stream in error state. " << std::endl; + if (err) { + (*err) += ss.str(); + } + return false; + } + + std::string warning; + LoadMtl(matMap, materials, &m_inStream, &warning); + + if (!warning.empty()) { + if (err) { + (*err) += warning; + } + } + + return true; +} + +bool LoadObj(attrib_t *attrib, std::vector *shapes, + std::vector *materials, std::string *err, + const char *filename, const char *mtl_basedir, bool trianglulate) { + attrib->vertices.clear(); + attrib->normals.clear(); + attrib->texcoords.clear(); + shapes->clear(); + + std::stringstream errss; + + std::ifstream ifs(filename); + if (!ifs) { + errss << "Cannot open file [" << filename << "]" << std::endl; + if (err) { + (*err) = errss.str(); + } + return false; + } + + std::string baseDir; + if (mtl_basedir) { + baseDir = mtl_basedir; + } + MaterialFileReader matFileReader(baseDir); + + return LoadObj(attrib, shapes, materials, err, &ifs, &matFileReader, + trianglulate); +} + +bool LoadObj(attrib_t *attrib, std::vector *shapes, + std::vector *materials, std::string *err, + std::istream *inStream, MaterialReader *readMatFn /*= NULL*/, + bool triangulate) { + std::stringstream errss; + + std::vector v; + std::vector vn; + std::vector vt; + std::vector tags; + std::vector > faceGroup; + std::string name; + + // material + std::map material_map; + int material = -1; + + shape_t shape; + + std::string linebuf; + while (inStream->peek() != -1) { + safeGetline(*inStream, linebuf); + + // Trim newline '\r\n' or '\n' + if (linebuf.size() > 0) { + if (linebuf[linebuf.size() - 1] == '\n') + linebuf.erase(linebuf.size() - 1); + } + if (linebuf.size() > 0) { + if (linebuf[linebuf.size() - 1] == '\r') + linebuf.erase(linebuf.size() - 1); + } + + // Skip if empty line. + if (linebuf.empty()) { + continue; + } + + // Skip leading space. + const char *token = linebuf.c_str(); + token += strspn(token, " \t"); + + assert(token); + if (token[0] == '\0') continue; // empty line + + if (token[0] == '#') continue; // comment line + + // vertex + if (token[0] == 'v' && IS_SPACE((token[1]))) { + token += 2; + real_t x, y, z; + parseReal3(&x, &y, &z, &token); + v.push_back(x); + v.push_back(y); + v.push_back(z); + continue; + } + + // normal + if (token[0] == 'v' && token[1] == 'n' && IS_SPACE((token[2]))) { + token += 3; + real_t x, y, z; + parseReal3(&x, &y, &z, &token); + vn.push_back(x); + vn.push_back(y); + vn.push_back(z); + continue; + } + + // texcoord + if (token[0] == 'v' && token[1] == 't' && IS_SPACE((token[2]))) { + token += 3; + real_t x, y; + parseReal2(&x, &y, &token); + vt.push_back(x); + vt.push_back(y); + continue; + } + + // face + if (token[0] == 'f' && IS_SPACE((token[1]))) { + token += 2; + token += strspn(token, " \t"); + + std::vector face; + face.reserve(3); + + while (!IS_NEW_LINE(token[0])) { + vertex_index vi; + if (!parseTriple(&token, static_cast(v.size() / 3), + static_cast(vn.size() / 3), + static_cast(vt.size() / 2), &vi)) { + if (err) { + (*err) = "Failed parse `f' line(e.g. zero value for face index).\n"; + } + return false; + } + + face.push_back(vi); + size_t n = strspn(token, " \t\r"); + token += n; + } + + // replace with emplace_back + std::move on C++11 + faceGroup.push_back(std::vector()); + faceGroup[faceGroup.size() - 1].swap(face); + + continue; + } + + // use mtl + if ((0 == strncmp(token, "usemtl", 6)) && IS_SPACE((token[6]))) { + token += 7; + std::stringstream ss; + ss << token; + std::string namebuf = ss.str(); + + int newMaterialId = -1; + if (material_map.find(namebuf) != material_map.end()) { + newMaterialId = material_map[namebuf]; + } else { + // { error!! material not found } + } + + if (newMaterialId != material) { + // Create per-face material. Thus we don't add `shape` to `shapes` at + // this time. + // just clear `faceGroup` after `exportFaceGroupToShape()` call. + exportFaceGroupToShape(&shape, faceGroup, tags, material, name, + triangulate); + faceGroup.clear(); + material = newMaterialId; + } + + continue; + } + + // load mtl + if ((0 == strncmp(token, "mtllib", 6)) && IS_SPACE((token[6]))) { + if (readMatFn) { + token += 7; + + std::vector filenames; + SplitString(std::string(token), ' ', filenames); + + if (filenames.empty()) { + if (err) { + (*err) += + "WARN: Looks like empty filename for mtllib. Use default " + "material. \n"; + } + } else { + bool found = false; + for (size_t s = 0; s < filenames.size(); s++) { + std::string err_mtl; + bool ok = (*readMatFn)(filenames[s].c_str(), materials, + &material_map, &err_mtl); + if (err && (!err_mtl.empty())) { + (*err) += err_mtl; // This should be warn message. + } + + if (ok) { + found = true; + break; + } + } + + if (!found) { + if (err) { + (*err) += + "WARN: Failed to load material file(s). Use default " + "material.\n"; + } + } + } + } + + continue; + } + + // group name + if (token[0] == 'g' && IS_SPACE((token[1]))) { + // flush previous face group. + bool ret = exportFaceGroupToShape(&shape, faceGroup, tags, material, name, + triangulate); + (void)ret; // return value not used. + + if (shape.mesh.indices.size() > 0) { + shapes->push_back(shape); + } + + shape = shape_t(); + + // material = -1; + faceGroup.clear(); + + std::vector names; + names.reserve(2); + + while (!IS_NEW_LINE(token[0])) { + std::string str = parseString(&token); + names.push_back(str); + token += strspn(token, " \t\r"); // skip tag + } + + assert(names.size() > 0); + + // names[0] must be 'g', so skip the 0th element. + if (names.size() > 1) { + name = names[1]; + } else { + name = ""; + } + + continue; + } + + // object name + if (token[0] == 'o' && IS_SPACE((token[1]))) { + // flush previous face group. + bool ret = exportFaceGroupToShape(&shape, faceGroup, tags, material, name, + triangulate); + if (ret) { + shapes->push_back(shape); + } + + // material = -1; + faceGroup.clear(); + shape = shape_t(); + + // @todo { multiple object name? } + token += 2; + std::stringstream ss; + ss << token; + name = ss.str(); + + continue; + } + + if (token[0] == 't' && IS_SPACE(token[1])) { + tag_t tag; + + token += 2; + std::stringstream ss; + ss << token; + tag.name = ss.str(); + + token += tag.name.size() + 1; + + tag_sizes ts = parseTagTriple(&token); + + tag.intValues.resize(static_cast(ts.num_ints)); + + for (size_t i = 0; i < static_cast(ts.num_ints); ++i) { + tag.intValues[i] = atoi(token); + token += strcspn(token, "/ \t\r") + 1; + } + + tag.floatValues.resize(static_cast(ts.num_reals)); + for (size_t i = 0; i < static_cast(ts.num_reals); ++i) { + tag.floatValues[i] = parseReal(&token); + token += strcspn(token, "/ \t\r") + 1; + } + + tag.stringValues.resize(static_cast(ts.num_strings)); + for (size_t i = 0; i < static_cast(ts.num_strings); ++i) { + std::stringstream sstr; + sstr << token; + tag.stringValues[i] = sstr.str(); + token += tag.stringValues[i].size() + 1; + } + + tags.push_back(tag); + } + + // Ignore unknown command. + } + + bool ret = exportFaceGroupToShape(&shape, faceGroup, tags, material, name, + triangulate); + // exportFaceGroupToShape return false when `usemtl` is called in the last + // line. + // we also add `shape` to `shapes` when `shape.mesh` has already some + // faces(indices) + if (ret || shape.mesh.indices.size()) { + shapes->push_back(shape); + } + faceGroup.clear(); // for safety + + if (err) { + (*err) += errss.str(); + } + + attrib->vertices.swap(v); + attrib->normals.swap(vn); + attrib->texcoords.swap(vt); + + return true; +} + +bool LoadObjWithCallback(std::istream &inStream, const callback_t &callback, + void *user_data /*= NULL*/, + MaterialReader *readMatFn /*= NULL*/, + std::string *err /*= NULL*/) { + std::stringstream errss; + + // material + std::map material_map; + int material_id = -1; // -1 = invalid + + std::vector indices; + std::vector materials; + std::vector names; + names.reserve(2); + std::string name; + std::vector names_out; + + std::string linebuf; + while (inStream.peek() != -1) { + safeGetline(inStream, linebuf); + + // Trim newline '\r\n' or '\n' + if (linebuf.size() > 0) { + if (linebuf[linebuf.size() - 1] == '\n') + linebuf.erase(linebuf.size() - 1); + } + if (linebuf.size() > 0) { + if (linebuf[linebuf.size() - 1] == '\r') + linebuf.erase(linebuf.size() - 1); + } + + // Skip if empty line. + if (linebuf.empty()) { + continue; + } + + // Skip leading space. + const char *token = linebuf.c_str(); + token += strspn(token, " \t"); + + assert(token); + if (token[0] == '\0') continue; // empty line + + if (token[0] == '#') continue; // comment line + + // vertex + if (token[0] == 'v' && IS_SPACE((token[1]))) { + token += 2; + real_t x, y, z, w; // w is optional. default = 1.0 + parseV(&x, &y, &z, &w, &token); + if (callback.vertex_cb) { + callback.vertex_cb(user_data, x, y, z, w); + } + continue; + } + + // normal + if (token[0] == 'v' && token[1] == 'n' && IS_SPACE((token[2]))) { + token += 3; + real_t x, y, z; + parseReal3(&x, &y, &z, &token); + if (callback.normal_cb) { + callback.normal_cb(user_data, x, y, z); + } + continue; + } + + // texcoord + if (token[0] == 'v' && token[1] == 't' && IS_SPACE((token[2]))) { + token += 3; + real_t x, y, z; // y and z are optional. default = 0.0 + parseReal3(&x, &y, &z, &token); + if (callback.texcoord_cb) { + callback.texcoord_cb(user_data, x, y, z); + } + continue; + } + + // face + if (token[0] == 'f' && IS_SPACE((token[1]))) { + token += 2; + token += strspn(token, " \t"); + + indices.clear(); + while (!IS_NEW_LINE(token[0])) { + vertex_index vi = parseRawTriple(&token); + + index_t idx; + idx.vertex_index = vi.v_idx; + idx.normal_index = vi.vn_idx; + idx.texcoord_index = vi.vt_idx; + + indices.push_back(idx); + size_t n = strspn(token, " \t\r"); + token += n; + } + + if (callback.index_cb && indices.size() > 0) { + callback.index_cb(user_data, &indices.at(0), + static_cast(indices.size())); + } + + continue; + } + + // use mtl + if ((0 == strncmp(token, "usemtl", 6)) && IS_SPACE((token[6]))) { + token += 7; + std::stringstream ss; + ss << token; + std::string namebuf = ss.str(); + + int newMaterialId = -1; + if (material_map.find(namebuf) != material_map.end()) { + newMaterialId = material_map[namebuf]; + } else { + // { error!! material not found } + } + + if (newMaterialId != material_id) { + material_id = newMaterialId; + } + + if (callback.usemtl_cb) { + callback.usemtl_cb(user_data, namebuf.c_str(), material_id); + } + + continue; + } + + // load mtl + if ((0 == strncmp(token, "mtllib", 6)) && IS_SPACE((token[6]))) { + if (readMatFn) { + token += 7; + + std::vector filenames; + SplitString(std::string(token), ' ', filenames); + + if (filenames.empty()) { + if (err) { + (*err) += + "WARN: Looks like empty filename for mtllib. Use default " + "material. \n"; + } + } else { + bool found = false; + for (size_t s = 0; s < filenames.size(); s++) { + std::string err_mtl; + bool ok = (*readMatFn)(filenames[s].c_str(), &materials, + &material_map, &err_mtl); + if (err && (!err_mtl.empty())) { + (*err) += err_mtl; // This should be warn message. + } + + if (ok) { + found = true; + break; + } + } + + if (!found) { + if (err) { + (*err) += + "WARN: Failed to load material file(s). Use default " + "material.\n"; + } + } else { + if (callback.mtllib_cb) { + callback.mtllib_cb(user_data, &materials.at(0), + static_cast(materials.size())); + } + } + } + } + + continue; + } + + // group name + if (token[0] == 'g' && IS_SPACE((token[1]))) { + names.clear(); + + while (!IS_NEW_LINE(token[0])) { + std::string str = parseString(&token); + names.push_back(str); + token += strspn(token, " \t\r"); // skip tag + } + + assert(names.size() > 0); + + // names[0] must be 'g', so skip the 0th element. + if (names.size() > 1) { + name = names[1]; + } else { + name.clear(); + } + + if (callback.group_cb) { + if (names.size() > 1) { + // create const char* array. + names_out.resize(names.size() - 1); + for (size_t j = 0; j < names_out.size(); j++) { + names_out[j] = names[j + 1].c_str(); + } + callback.group_cb(user_data, &names_out.at(0), + static_cast(names_out.size())); + + } else { + callback.group_cb(user_data, NULL, 0); + } + } + + continue; + } + + // object name + if (token[0] == 'o' && IS_SPACE((token[1]))) { + // @todo { multiple object name? } + token += 2; + + std::stringstream ss; + ss << token; + std::string object_name = ss.str(); + + if (callback.object_cb) { + callback.object_cb(user_data, object_name.c_str()); + } + + continue; + } + +#if 0 // @todo + if (token[0] == 't' && IS_SPACE(token[1])) { + tag_t tag; + + token += 2; + std::stringstream ss; + ss << token; + tag.name = ss.str(); + + token += tag.name.size() + 1; + + tag_sizes ts = parseTagTriple(&token); + + tag.intValues.resize(static_cast(ts.num_ints)); + + for (size_t i = 0; i < static_cast(ts.num_ints); ++i) { + tag.intValues[i] = atoi(token); + token += strcspn(token, "/ \t\r") + 1; + } + + tag.floatValues.resize(static_cast(ts.num_reals)); + for (size_t i = 0; i < static_cast(ts.num_reals); ++i) { + tag.floatValues[i] = parseReal(&token); + token += strcspn(token, "/ \t\r") + 1; + } + + tag.stringValues.resize(static_cast(ts.num_strings)); + for (size_t i = 0; i < static_cast(ts.num_strings); ++i) { + std::stringstream ss; + ss << token; + tag.stringValues[i] = ss.str(); + token += tag.stringValues[i].size() + 1; + } + + tags.push_back(tag); + } +#endif + + // Ignore unknown command. + } + + if (err) { + (*err) += errss.str(); + } + + return true; +} +} // namespace tinyobj + +#endif diff --git a/results/010.gif b/results/010.gif new file mode 100644 index 0000000..daae473 Binary files /dev/null and b/results/010.gif differ diff --git a/results/Refraction_bunny_smoothed_bbox_cornell.txt b/results/Refraction_bunny_smoothed_bbox_cornell.txt new file mode 100644 index 0000000..bc73a5c --- /dev/null +++ b/results/Refraction_bunny_smoothed_bbox_cornell.txt @@ -0,0 +1,134 @@ +3976.585693 +3912.797119 +3918.107910 +3924.177490 +3924.577637 +3921.049561 +3922.551514 +3914.633789 +3923.435303 +3917.684570 +3920.967773 +3923.460449 +3926.824463 +3915.166016 +3918.992920 +3920.777344 +3919.606201 +3917.194336 +3917.381592 +3925.278809 +3924.702637 +3917.084717 +3914.118896 +3922.084473 +3918.544678 +3921.691650 +3920.128906 +3921.901123 +3924.286377 +3912.667480 +3920.502930 +3918.824463 +3919.931885 +3927.339355 +3915.789795 +3915.667725 +3914.093506 +3919.818604 +3924.102539 +3921.814453 +3924.270508 +3921.397705 +3914.004395 +3920.911133 +3913.965088 +3915.804688 +3915.218262 +3914.549805 +3911.420410 +3920.725586 +3912.371338 +3922.296631 +3907.398438 +3920.068604 +3916.839600 +3914.017578 +3919.437500 +3919.553223 +3912.827393 +3923.017090 +3919.732666 +3920.856934 +3916.665771 +3920.795654 +3912.104980 +3919.308838 +3912.475098 +3920.232666 +3919.554199 +3918.190430 +3919.968018 +3917.002441 +3913.561523 +3915.897217 +4708.132324 +3954.978516 +3919.682861 +3921.358154 +3924.479980 +3911.649414 +3923.902588 +3917.730469 +3914.130127 +3918.421631 +3919.288086 +3924.909668 +3916.566895 +3916.103760 +3915.941650 +3917.718750 +3919.283447 +3912.629639 +3912.287109 +3913.755615 +3921.755615 +3910.642822 +3920.664063 +3917.698486 +3915.132813 +3914.021973 +3918.822998 +3915.913330 +3917.460449 +3913.180664 +3926.718506 +3916.624023 +3926.360107 +3913.424316 +3916.386475 +3915.312012 +3915.799316 +3917.790771 +3920.721680 +3915.386475 +3918.795654 +3918.125977 +3913.275146 +3912.943848 +3910.628906 +3916.951660 +3913.520752 +3919.511719 +3916.692139 +3913.374512 +3920.418945 +3916.592529 +3914.071289 +3919.501953 +3918.413330 +3916.297607 +3920.766357 +3921.696289 +3913.007324 +3918.403809 diff --git a/results/Refraction_bunny_smoothed_without_bbox_cornell.png b/results/Refraction_bunny_smoothed_without_bbox_cornell.png new file mode 100644 index 0000000..102e995 Binary files /dev/null and b/results/Refraction_bunny_smoothed_without_bbox_cornell.png differ diff --git a/results/Refraction_bunny_smoothed_without_bbox_cornell.txt b/results/Refraction_bunny_smoothed_without_bbox_cornell.txt new file mode 100644 index 0000000..4461f1d --- /dev/null +++ b/results/Refraction_bunny_smoothed_without_bbox_cornell.txt @@ -0,0 +1,113 @@ +5859.234375 +4785.696777 +5787.355957 +5790.817383 +5792.310059 +5796.105957 +5800.704102 +5790.723633 +5788.008301 +4791.831543 +5791.459961 +5796.042480 +5798.360352 +5785.664063 +5790.910156 +5796.223145 +5787.013184 +4792.468750 +5789.725586 +5801.652832 +5794.796387 +5790.694824 +5788.911621 +5801.345703 +5797.170410 +5799.958496 +5796.866699 +5793.974609 +5794.103027 +5850.316406 +5801.764648 +5792.531250 +5792.556152 +5799.798828 +5800.020996 +5802.104492 +5799.549805 +5802.427246 +5803.891113 +5800.189941 +5806.252441 +5794.269043 +5789.887695 +5794.366211 +5788.144043 +5788.827637 +5791.484863 +5787.450195 +5787.672363 +5793.127930 +5790.019043 +4793.304688 +5786.687012 +5793.168945 +4792.261719 +5785.218750 +5795.547852 +5796.685059 +5792.595703 +5793.198242 +5798.429688 +5797.388184 +5791.604492 +5794.329590 +5790.036621 +5795.505371 +5788.531250 +5792.726074 +5795.072754 +5792.037109 +5799.254395 +5795.177246 +5795.386230 +5789.244141 +5800.237793 +5795.053223 +5795.422363 +5796.826172 +5793.700195 +5795.481445 +5801.317871 +5799.602051 +5797.437012 +5798.349609 +5804.438477 +5804.128906 +5796.643555 +5789.108398 +5804.247559 +5790.761719 +5797.682129 +5782.323730 +5786.493652 +5789.261230 +5799.687500 +5796.686523 +5799.263184 +5797.618652 +5794.815918 +5794.904297 +5800.783203 +5792.075684 +5798.398438 +5798.674805 +5802.579590 +5789.747559 +5792.280273 +5787.620605 +5792.882813 +5788.934570 +5792.825684 +5795.195313 +4794.953613 diff --git a/results/cis565_path_tracer.VC.VC.opendb b/results/cis565_path_tracer.VC.VC.opendb new file mode 100644 index 0000000..f9428ec Binary files /dev/null and b/results/cis565_path_tracer.VC.VC.opendb differ diff --git a/results/cornell.2017-09-24_05-21-10z.5000samp.png b/results/cornell.2017-09-24_05-21-10z.5000samp.png new file mode 100644 index 0000000..308220c Binary files /dev/null and b/results/cornell.2017-09-24_05-21-10z.5000samp.png differ diff --git a/results/cornell.2017-09-24_05-27-31z.5000samp.png b/results/cornell.2017-09-24_05-27-31z.5000samp.png new file mode 100644 index 0000000..7b75ad7 Binary files /dev/null and b/results/cornell.2017-09-24_05-27-31z.5000samp.png differ diff --git a/results/cornell.2017-09-24_06-05-34z.5000samp.png b/results/cornell.2017-09-24_06-05-34z.5000samp.png new file mode 100644 index 0000000..6af2c3f Binary files /dev/null and b/results/cornell.2017-09-24_06-05-34z.5000samp.png differ diff --git a/results/cornell.2017-09-24_06-22-48z.5000samp.png b/results/cornell.2017-09-24_06-22-48z.5000samp.png new file mode 100644 index 0000000..0751155 Binary files /dev/null and b/results/cornell.2017-09-24_06-22-48z.5000samp.png differ diff --git a/results/cornell.2017-09-24_15-39-02z.5000samp.png b/results/cornell.2017-09-24_15-39-02z.5000samp.png new file mode 100644 index 0000000..ea41aa2 Binary files /dev/null and b/results/cornell.2017-09-24_15-39-02z.5000samp.png differ diff --git a/results/cornell.2017-09-24_19-56-35z.5000samp.png b/results/cornell.2017-09-24_19-56-35z.5000samp.png new file mode 100644 index 0000000..e1ac274 Binary files /dev/null and b/results/cornell.2017-09-24_19-56-35z.5000samp.png differ diff --git a/results/cornell.2017-09-24_21-33-57z.5000samp_no_antialiasing.png b/results/cornell.2017-09-24_21-33-57z.5000samp_no_antialiasing.png new file mode 100644 index 0000000..9d2d1fa Binary files /dev/null and b/results/cornell.2017-09-24_21-33-57z.5000samp_no_antialiasing.png differ diff --git a/results/cornell.2017-09-25_21-30-06z.5000samp_with_antialiasing.png b/results/cornell.2017-09-25_21-30-06z.5000samp_with_antialiasing.png new file mode 100644 index 0000000..ce0102b Binary files /dev/null and b/results/cornell.2017-09-25_21-30-06z.5000samp_with_antialiasing.png differ diff --git a/results/cornell.2017-09-26_03-07-56z.5000samp.png b/results/cornell.2017-09-26_03-07-56z.5000samp.png new file mode 100644 index 0000000..7f2797b Binary files /dev/null and b/results/cornell.2017-09-26_03-07-56z.5000samp.png differ diff --git a/results/cornell.2017-09-26_03-23-13z.5000samp.png b/results/cornell.2017-09-26_03-23-13z.5000samp.png new file mode 100644 index 0000000..1779724 Binary files /dev/null and b/results/cornell.2017-09-26_03-23-13z.5000samp.png differ diff --git a/results/cornell.2017-09-26_03-33-04z.5000samp.png b/results/cornell.2017-09-26_03-33-04z.5000samp.png new file mode 100644 index 0000000..7f2797b Binary files /dev/null and b/results/cornell.2017-09-26_03-33-04z.5000samp.png differ diff --git a/results/cornell.2017-09-26_04-39-45z.5000samp.png b/results/cornell.2017-09-26_04-39-45z.5000samp.png new file mode 100644 index 0000000..18901e4 Binary files /dev/null and b/results/cornell.2017-09-26_04-39-45z.5000samp.png differ diff --git a/results/cornell.2017-09-27_19-52-54z.5000samp_without_reflection.png b/results/cornell.2017-09-27_19-52-54z.5000samp_without_reflection.png new file mode 100644 index 0000000..63da09e Binary files /dev/null and b/results/cornell.2017-09-27_19-52-54z.5000samp_without_reflection.png differ diff --git a/results/cornell.2017-09-27_20-31-09z.5000samp_with_reflection.png b/results/cornell.2017-09-27_20-31-09z.5000samp_with_reflection.png new file mode 100644 index 0000000..d7d172c Binary files /dev/null and b/results/cornell.2017-09-27_20-31-09z.5000samp_with_reflection.png differ diff --git a/results/cornell.2017-09-27_23-00-16z.5000samp.png b/results/cornell.2017-09-27_23-00-16z.5000samp.png new file mode 100644 index 0000000..f58b2c7 Binary files /dev/null and b/results/cornell.2017-09-27_23-00-16z.5000samp.png differ diff --git a/results/cornell.2017-09-27_23-22-31z.5000samp.png b/results/cornell.2017-09-27_23-22-31z.5000samp.png new file mode 100644 index 0000000..fcc5481 Binary files /dev/null and b/results/cornell.2017-09-27_23-22-31z.5000samp.png differ diff --git a/results/cornell.2017-09-27_23-34-47z.5000samp.png b/results/cornell.2017-09-27_23-34-47z.5000samp.png new file mode 100644 index 0000000..ecfa50f Binary files /dev/null and b/results/cornell.2017-09-27_23-34-47z.5000samp.png differ diff --git a/results/cornell.2017-09-28_00-04-06z.2648samp.png b/results/cornell.2017-09-28_00-04-06z.2648samp.png new file mode 100644 index 0000000..7f7c635 Binary files /dev/null and b/results/cornell.2017-09-28_00-04-06z.2648samp.png differ diff --git a/results/cornell.2017-09-28_00-12-02z.5000samp.png b/results/cornell.2017-09-28_00-12-02z.5000samp.png new file mode 100644 index 0000000..5d8d341 Binary files /dev/null and b/results/cornell.2017-09-28_00-12-02z.5000samp.png differ diff --git a/results/cornell.2017-09-30_18-54-18z.5000samp.png b/results/cornell.2017-09-30_18-54-18z.5000samp.png new file mode 100644 index 0000000..f1419d6 Binary files /dev/null and b/results/cornell.2017-09-30_18-54-18z.5000samp.png differ diff --git a/results/cornell.2017-09-30_21-10-33z.486samp.png b/results/cornell.2017-09-30_21-10-33z.486samp.png new file mode 100644 index 0000000..ae9853f Binary files /dev/null and b/results/cornell.2017-09-30_21-10-33z.486samp.png differ diff --git a/results/cornell.2017-09-30_21-28-18z.2846samp.png b/results/cornell.2017-09-30_21-28-18z.2846samp.png new file mode 100644 index 0000000..d031151 Binary files /dev/null and b/results/cornell.2017-09-30_21-28-18z.2846samp.png differ diff --git a/results/cornell.2017-09-30_22-42-30z.5000samp.png b/results/cornell.2017-09-30_22-42-30z.5000samp.png new file mode 100644 index 0000000..d4501a5 Binary files /dev/null and b/results/cornell.2017-09-30_22-42-30z.5000samp.png differ diff --git a/results/cornell.2017-10-01_05-45-27z.234samp.png b/results/cornell.2017-10-01_05-45-27z.234samp.png new file mode 100644 index 0000000..52a92a8 Binary files /dev/null and b/results/cornell.2017-10-01_05-45-27z.234samp.png differ diff --git a/results/cornell.2017-10-01_06-02-33z.133samp.png b/results/cornell.2017-10-01_06-02-33z.133samp.png new file mode 100644 index 0000000..044bdf0 Binary files /dev/null and b/results/cornell.2017-10-01_06-02-33z.133samp.png differ diff --git a/results/direct_light_test.png b/results/direct_light_test.png new file mode 100644 index 0000000..8f2ef31 Binary files /dev/null and b/results/direct_light_test.png differ diff --git a/results/form1.JPG b/results/form1.JPG new file mode 100644 index 0000000..100dafa Binary files /dev/null and b/results/form1.JPG differ diff --git a/results/form2.JPG b/results/form2.JPG new file mode 100644 index 0000000..7c95fde Binary files /dev/null and b/results/form2.JPG differ diff --git a/results/form3.JPG b/results/form3.JPG new file mode 100644 index 0000000..943d40a Binary files /dev/null and b/results/form3.JPG differ diff --git a/results/plot1.JPG b/results/plot1.JPG new file mode 100644 index 0000000..bc754d7 Binary files /dev/null and b/results/plot1.JPG differ diff --git a/results/plot3.JPG b/results/plot3.JPG new file mode 100644 index 0000000..b595724 Binary files /dev/null and b/results/plot3.JPG differ diff --git a/results/results.txt b/results/results.txt new file mode 100644 index 0000000..24423cf --- /dev/null +++ b/results/results.txt @@ -0,0 +1,365 @@ +188.450302 +108.747490 +105.584671 +109.242592 +104.293053 +105.414879 +105.183296 +180.712479 +105.711906 +104.892067 +108.673508 +105.718658 +107.542175 +107.691971 +105.868675 +109.882401 +112.431679 +110.255005 +108.191139 +110.801346 +106.501122 +105.851395 +106.911232 +106.044930 +110.310944 +107.011459 +106.545891 +107.096931 +108.772354 +105.163200 +107.232964 +116.389854 +104.722275 +105.457184 +104.135010 +106.831810 +105.782753 +110.550941 +105.009026 +108.242020 +108.056641 +109.701759 +107.734398 +108.474564 +109.654945 +109.129219 +108.365471 +110.120193 +106.223427 +109.054176 +109.798332 +106.202141 +107.200035 +106.361794 +104.427261 +109.014816 +106.306274 +106.999550 +107.743843 +113.902908 +163.915329 +107.284927 +107.443970 +106.814178 +106.718941 +108.177376 +104.590302 +105.151970 +105.131325 +105.595840 +105.275551 +105.025284 +103.933502 +105.041885 +104.520386 +104.259842 +105.953827 +105.135551 +105.336227 +106.634979 +107.718658 +106.667267 +106.256035 +105.048317 +107.758339 +106.748962 +105.334335 +103.919327 +103.285889 +105.177376 +106.085411 +107.857567 +105.872803 +104.971680 +105.347900 +103.821442 +107.112190 +106.288483 +106.353058 +106.395683 +106.696190 +107.957794 +108.149185 +103.732002 +111.837952 +103.533119 +108.208572 +103.013885 +104.879997 +105.659683 +106.003838 +105.147011 +106.888893 +105.674400 +106.001183 +106.423073 +106.284286 +108.121086 +105.082367 +103.853699 +107.333504 +105.651230 +106.616928 +111.902397 +109.281662 +105.911263 +105.714943 +107.154274 +107.534111 +110.309441 +105.846817 +107.015869 +104.514175 +103.112801 +103.412926 +109.000702 +102.868355 +103.224609 +102.875809 +107.942879 +105.180611 +104.737724 +105.367935 +110.005440 +106.192924 +107.022911 +107.181984 +103.537727 +104.551613 +103.644928 +103.239716 +102.413437 +106.768349 +102.203171 +106.126816 +106.968994 +109.157249 +105.610878 +107.361313 +108.882881 +106.647171 +114.311996 +106.954781 +103.784286 +110.073181 +105.991615 +108.443390 +113.157951 +109.130371 +110.985313 +107.713249 +108.402306 +106.980286 +108.855293 +111.062050 +191.156647 +102.941437 +106.396675 +104.788864 +105.965187 +104.618912 +106.936066 +103.382561 +105.565376 +105.088036 +108.987167 +107.642273 +105.801727 +104.655586 +108.060158 +106.046432 +104.417252 +104.111748 +106.889053 +102.293633 +109.017021 +103.214432 +104.838882 +104.057983 +105.689117 +109.692703 +110.299873 +111.798973 +112.802628 +111.958786 +115.309853 +113.912193 +114.566399 +116.707970 +116.107140 +113.919075 +115.231651 +115.945602 +115.102722 +118.212349 +115.201820 +114.821121 +112.438972 +115.823357 +113.559998 +110.033028 +110.359581 +110.276192 +116.713341 +112.463486 +114.446465 +112.234177 +114.554466 +112.282082 +112.560608 +114.227394 +112.049889 +111.775780 +116.733665 +112.661728 +115.426750 +110.362144 +114.059616 +111.871552 +113.761955 +114.923843 +111.816765 +114.027519 +115.195457 +110.434845 +115.732643 +115.409088 +118.378113 +115.735489 +112.734528 +112.966270 +114.314079 +122.626244 +185.322937 +118.199326 +117.687584 +114.665855 +114.842110 +114.105186 +116.690750 +110.682915 +107.834717 +112.860962 +111.591743 +108.887741 +109.137604 +110.299072 +108.856163 +109.138947 +110.048546 +109.347778 +110.988579 +110.554466 +110.527199 +109.787552 +110.176193 +109.668320 +109.591553 +109.625603 +110.776733 +110.389214 +111.997246 +111.852097 +110.142883 +110.332321 +113.002724 +112.824448 +106.803520 +110.793571 +113.839523 +112.939011 +114.570686 +117.942429 +115.326111 +116.506561 +115.117088 +115.379967 +116.971107 +113.980095 +112.912575 +113.942879 +118.876740 +118.506912 +114.487358 +112.690720 +112.752800 +113.963455 +115.599136 +115.688576 +115.651680 +115.635841 +112.763199 +113.584511 +109.644096 +114.310562 +114.287651 +118.007072 +113.740799 +112.766205 +116.771904 +113.990654 +114.293373 +112.912956 +112.310593 +113.051132 +114.824158 +112.615395 +115.000351 +114.930206 +115.342430 +112.878304 +115.006561 +112.155266 +115.340446 +112.993187 +113.762047 +111.512772 +112.944099 +111.537727 +110.461502 +110.819458 +113.113922 +115.023712 +113.786819 +114.215324 +114.446175 +111.106659 +113.868065 +114.244606 +113.748772 +113.643234 +112.965508 +114.288483 +116.815361 +115.099167 +112.425278 +113.204124 +110.715485 +116.497086 +115.305344 +114.911842 +113.073471 +112.208099 +112.807198 +113.810112 diff --git a/results/results_caching.txt b/results/results_caching.txt new file mode 100644 index 0000000..129ca16 --- /dev/null +++ b/results/results_caching.txt @@ -0,0 +1,319 @@ +134.253540 +63.011169 +65.233086 +64.641891 +64.954338 +62.750751 +66.058975 +67.653282 +58.821568 +62.518143 +60.422527 +61.600769 +61.205921 +64.028702 +63.015713 +62.443039 +62.260098 +60.078239 +58.779938 +59.491295 +60.098911 +60.176353 +59.665695 +113.426048 +66.198685 +65.666115 +62.502113 +64.471710 +64.693054 +63.954464 +65.334396 +67.581406 +63.770241 +64.211266 +66.345665 +68.902275 +64.240547 +65.848770 +64.927231 +64.297279 +65.468323 +65.712578 +65.311134 +67.454018 +63.814655 +65.230850 +64.855553 +65.520676 +65.471809 +64.191650 +62.802238 +62.328224 +67.738243 +65.191330 +64.823036 +65.757408 +66.723328 +63.103554 +64.863266 +64.339424 +66.301086 +63.880543 +65.002625 +63.731903 +63.074272 +64.215363 +63.482178 +63.659359 +66.649567 +64.532738 +63.151264 +66.606621 +66.998878 +65.103996 +64.402786 +63.683041 +63.112255 +65.159454 +63.671200 +62.443615 +65.198784 +63.179871 +63.314274 +66.314560 +66.586594 +66.208481 +65.484512 +65.217918 +65.036354 +63.308514 +68.978271 +63.747486 +114.932770 +61.938015 +64.048286 +66.563904 +62.091518 +65.659454 +66.355042 +64.392799 +63.240704 +62.668159 +62.704544 +64.649666 +61.340065 +64.762527 +63.960770 +62.468929 +62.869823 +62.945663 +61.420513 +65.637535 +62.902527 +61.821182 +64.903549 +62.935200 +67.416161 +65.851837 +62.822624 +63.270752 +67.098755 +65.639709 +64.347748 +64.086624 +62.808514 +61.953026 +62.875584 +61.905216 +61.549278 +64.231293 +63.313313 +64.773506 +61.237122 +62.262112 +62.238655 +62.411072 +63.207649 +61.799488 +65.040642 +62.969311 +62.629215 +64.662209 +68.630463 +69.147652 +67.128960 +66.174019 +63.055138 +65.008896 +63.947071 +62.345375 +65.430557 +64.489410 +65.275711 +63.782658 +63.012993 +66.450272 +67.553955 +65.139938 +64.908478 +64.612579 +65.803551 +63.910240 +64.687614 +63.624641 +61.002560 +63.674465 +63.074272 +65.552284 +65.703842 +64.780098 +63.332577 +65.086113 +64.154755 +64.059235 +64.459839 +63.520481 +63.861664 +64.935104 +64.507874 +64.607613 +64.662048 +65.369537 +62.250786 +61.967297 +64.375458 +63.588417 +61.623329 +66.367104 +62.435650 +64.630272 +64.355743 +64.267395 +63.178207 +65.768768 +62.117214 +62.034431 +65.179939 +62.972416 +63.573151 +62.806946 +64.813889 +63.668640 +68.673088 +65.013123 +62.511711 +68.889214 +63.542526 +63.088097 +64.193604 +62.096863 +61.512096 +66.893341 +62.581665 +65.587486 +62.983841 +63.473919 +64.544258 +65.841377 +64.064896 +63.230530 +63.624641 +64.619362 +61.871872 +61.270306 +63.171646 +63.888321 +62.606495 +66.607140 +62.834049 +63.467583 +65.852318 +62.780094 +62.925217 +62.745056 +62.829697 +62.858658 +63.943489 +63.742847 +65.322304 +63.850655 +64.643677 +61.865887 +62.562687 +62.482273 +65.604706 +61.958111 +62.837826 +64.935997 +62.100288 +63.873249 +67.569283 +62.716927 +65.725021 +60.936863 +60.610306 +65.096992 +62.785568 +62.035458 +66.933342 +64.721375 +65.161568 +65.143555 +63.606590 +66.626465 +67.298431 +62.504929 +61.587296 +63.564735 +62.064865 +63.248798 +63.410526 +63.274178 +63.760704 +64.210114 +64.234337 +61.886784 +62.150944 +64.717697 +63.112255 +61.982529 +62.715454 +62.456898 +61.802879 +63.207649 +61.623810 +62.556831 +66.507263 +62.610111 +61.251072 +67.256989 +63.439968 +63.174625 +64.698944 +64.166435 +63.990658 +61.485058 +64.668098 +62.114880 +64.418114 +63.555553 +61.773407 +61.909599 +62.639809 +62.643776 +65.070976 +65.404610 +61.871136 +62.476063 +63.843712 +62.934238 +62.458015 +64.645569 +61.900478 +63.776382 +63.473598 +61.854591 +63.404064 +62.533375 +66.618462 diff --git a/results/results_complicated_3507samples.txt b/results/results_complicated_3507samples.txt new file mode 100644 index 0000000..a85f2f1 --- /dev/null +++ b/results/results_complicated_3507samples.txt @@ -0,0 +1,3508 @@ +4556.139160 +4464.942383 +4484.811035 +4495.264648 +4479.148438 +4487.003906 +4486.702637 +4475.570801 +4474.416992 +4493.684570 +4549.401367 +4488.066406 +4561.755859 +4517.172363 +4610.132813 +4510.015137 +4516.733398 +4483.056152 +4479.226563 +4487.185547 +4485.473633 +4487.334961 +4471.564941 +4484.020020 +4491.236328 +4491.092285 +4475.458496 +4485.026855 +4479.496094 +4478.630859 +4485.252441 +4484.130859 +4472.646973 +4483.992676 +4484.363770 +4490.843750 +4479.358398 +4486.136230 +4475.773438 +4485.915527 +4484.602539 +4476.565430 +4475.427734 +4489.020508 +4475.772461 +4475.432129 +4485.397461 +4468.534668 +4485.966797 +4483.848145 +4479.070801 +4477.140137 +4479.942871 +4491.350586 +4483.563477 +4488.665527 +4483.709961 +4485.271973 +4486.582031 +4478.262207 +4472.081543 +4474.867676 +4475.408203 +4481.051270 +4480.033203 +4483.219238 +4476.440430 +4488.913086 +4481.180176 +4477.617676 +4482.501465 +4482.249512 +4488.676758 +4474.887695 +4487.580566 +4478.881836 +4483.300781 +4478.822266 +4488.518555 +4482.844727 +4494.221191 +4490.608887 +4482.200684 +4781.244629 +4478.863281 +4477.774414 +4473.711914 +4475.531250 +4482.164063 +4479.089844 +4486.497070 +4482.307617 +4477.702637 +4482.468750 +4473.866211 +4478.505371 +4491.765625 +4476.798828 +4487.000488 +4477.469238 +4488.197754 +4482.762695 +4473.821777 +4481.765137 +4482.761719 +4487.065918 +4492.721680 +4478.733887 +4469.335449 +4468.956543 +4477.513672 +4483.690918 +4482.609375 +4482.818848 +4484.326172 +4483.278320 +4486.549805 +4490.482422 +4483.356445 +4483.451660 +4481.702148 +4482.665527 +4483.177734 +4478.150391 +4486.085449 +4478.380371 +4489.349609 +4490.528320 +4491.225586 +4484.732910 +4487.503906 +4480.785645 +4486.261230 +4484.566895 +4498.565430 +4494.106934 +4479.526367 +4489.745117 +4471.805664 +4472.163086 +4478.008789 +4484.653809 +4480.977539 +4484.012207 +4482.869141 +4484.039063 +4481.278320 +4484.974121 +4491.186523 +4484.857910 +4470.310547 +4487.342285 +4484.289063 +4484.279785 +4481.487305 +4479.528809 +4482.425781 +4483.009277 +4485.622559 +4478.721191 +4475.735840 +4474.719727 +4491.149902 +4481.402344 +4486.520508 +4475.664063 +4485.746582 +4487.550293 +4487.209961 +4479.982910 +4478.047363 +4483.952637 +4480.443359 +4470.770020 +4477.520020 +4482.779297 +4482.249023 +4484.355469 +4474.007813 +4489.796875 +4482.236816 +4478.108398 +4473.783691 +4484.564941 +4480.708008 +4476.158203 +4473.292969 +4489.708496 +4488.795410 +4484.047363 +4479.060547 +4482.345215 +4477.263184 +4487.429199 +4482.772461 +4475.492676 +4481.241699 +4492.050293 +4478.127441 +4478.466309 +4488.892578 +4467.706543 +4482.130371 +4471.981445 +4475.474121 +4486.395996 +4483.000000 +4481.738281 +4487.331543 +4484.668945 +4478.632813 +4481.699707 +4480.016113 +4475.470703 +4479.989258 +4472.330078 +4483.819824 +4471.322266 +4492.599609 +4486.436035 +4483.305664 +4484.411621 +4488.523926 +4480.477051 +4476.339844 +4477.504395 +4472.352539 +4475.667969 +4481.955566 +4483.674316 +4486.752441 +4478.950684 +4491.184082 +4476.428223 +4487.445801 +4479.694336 +4483.442383 +4473.280762 +4479.222168 +4483.534180 +4479.700684 +4476.019531 +4471.624023 +4481.477051 +4483.270996 +4478.673828 +4483.853516 +4456.768066 +4478.871094 +4480.848145 +4486.228516 +4482.487793 +4484.383301 +4484.221191 +4482.247559 +4481.868164 +4476.368652 +4472.805176 +4480.963379 +4478.224121 +4490.338379 +4479.406738 +4485.323242 +4477.660156 +4476.224121 +4478.813965 +4487.990723 +4482.471680 +4481.827148 +4469.093750 +4483.588379 +4491.651367 +4476.230469 +4477.710938 +4479.530762 +4479.819336 +4487.945801 +4479.892578 +4484.191895 +4483.564453 +4485.502441 +4478.087891 +4479.240723 +4474.993164 +4801.824707 +4495.145020 +4474.284668 +4488.157227 +4479.591797 +4485.857422 +4481.389160 +4483.669434 +4480.853027 +4476.980469 +4495.992188 +4480.586426 +4474.833984 +4482.674805 +4477.262207 +4485.903320 +4483.962402 +4484.303711 +4472.167480 +4484.806641 +4478.397949 +4480.176270 +4474.894531 +4467.742188 +4483.437012 +4489.442383 +4491.653320 +4489.431152 +4481.766602 +4480.850586 +4479.963867 +4476.484375 +4484.001465 +4483.656738 +4482.637207 +4481.794922 +4488.665527 +4492.209961 +4480.414063 +4484.340820 +4483.974609 +4482.851074 +4481.110840 +4489.753906 +4482.792480 +4485.203125 +4478.236328 +4479.662598 +4486.102051 +4475.798340 +4482.623047 +4481.631836 +4480.912109 +4479.700684 +4481.747070 +4488.407715 +4482.167969 +4482.400391 +4482.511230 +4491.918945 +4489.271973 +4471.952148 +4483.126465 +4474.489258 +4490.591309 +4478.804688 +4482.287598 +4480.806641 +4483.451660 +4479.511719 +4481.440430 +4476.965332 +4484.360840 +4483.556152 +4485.064941 +4477.735840 +4468.828125 +4478.775391 +4481.702148 +4486.044434 +4474.755371 +4487.563965 +4481.721191 +4481.437988 +4480.471680 +4484.930176 +4474.406738 +4479.840332 +4475.978027 +4476.661621 +4488.074219 +4474.430176 +4490.769043 +4483.253418 +4484.244629 +4479.422852 +4478.885254 +4496.142578 +4479.995605 +4480.673828 +4481.628906 +4477.538086 +4481.857910 +4471.159180 +4484.267090 +4479.246094 +4488.494141 +4475.817871 +4485.351074 +4480.686523 +4484.503418 +4488.490723 +4474.662109 +4476.707520 +4470.814453 +4479.799316 +4477.694336 +4480.568848 +4490.832520 +4489.495117 +4484.735840 +4485.839355 +4477.781250 +4486.738281 +4490.740723 +4478.299805 +4492.292480 +4475.350586 +4482.971680 +4479.971680 +4477.970215 +4486.071289 +4481.352051 +4485.875977 +4490.981934 +4481.257813 +4478.229492 +4473.284668 +4488.371094 +4490.648438 +4492.486816 +4478.492676 +4483.239746 +4473.962402 +4482.299316 +4480.495605 +4491.078125 +4481.494629 +4476.235840 +4478.796387 +4477.749023 +4477.722656 +4479.944336 +4481.615234 +4479.007813 +4484.548828 +4477.485840 +4483.201660 +4477.755859 +4481.098145 +4484.714844 +4476.500000 +4476.032227 +4486.566895 +4478.758789 +4484.869629 +4491.240234 +4476.371094 +4479.263184 +4484.543457 +4486.063965 +4469.348145 +4480.448242 +4481.338379 +4481.563477 +4483.494629 +4473.993652 +4471.565918 +4477.661133 +4469.406738 +4487.559082 +4485.963379 +4490.893555 +4484.435547 +4477.058594 +4476.083008 +4483.351074 +4467.375488 +4483.134277 +4476.088379 +4486.655273 +4488.481934 +4483.528809 +4482.584473 +4486.612305 +4477.123047 +4473.013672 +4479.213867 +4479.407227 +4489.658203 +4475.304688 +5172.127930 +4492.046875 +4484.721191 +4479.976074 +4484.234863 +4485.808105 +4479.362793 +4474.660156 +4482.293457 +4483.743164 +4484.230469 +4477.919922 +4491.689453 +4487.079590 +4484.095215 +4483.269531 +4495.688477 +4490.351074 +4481.760742 +4479.197266 +4481.129395 +4474.240234 +4479.907715 +4484.803223 +4481.748535 +4489.754883 +4489.622559 +4482.363770 +4483.487305 +4477.671875 +4481.222656 +4490.027832 +4482.643555 +4479.286621 +4487.690918 +4482.169434 +4476.106445 +4476.312500 +4493.747070 +4478.062500 +4476.856934 +4479.830078 +4478.651855 +4482.278809 +4483.893066 +4473.633301 +4488.812012 +4481.021484 +4488.681152 +4476.921387 +4478.328125 +4487.419922 +4478.176758 +4469.763672 +4484.023438 +4483.915527 +4472.837891 +4479.677246 +4482.061035 +4487.405762 +4476.801758 +4478.273438 +4485.678711 +4474.672363 +4481.196777 +4495.839355 +4482.663086 +4483.896484 +4479.986816 +4471.584473 +4492.036621 +4472.104004 +4475.674805 +4473.248535 +4475.193848 +4475.791504 +4473.230957 +4486.074707 +4480.464844 +4480.875977 +4480.836914 +4477.642090 +4487.528809 +4474.174316 +4476.392090 +4476.124023 +4486.290527 +4483.751465 +4482.009766 +4488.004883 +4486.381348 +4482.502930 +4478.424805 +4483.253418 +4475.027832 +4483.373047 +4483.811035 +4470.590332 +4479.498047 +4481.057129 +4487.611816 +4476.647949 +4483.465332 +4481.373047 +4490.933594 +4485.244629 +4469.984863 +4494.871582 +4490.536621 +4474.514648 +4491.154297 +4481.363770 +4481.822754 +4486.628418 +4480.452637 +4482.112305 +4469.778809 +4491.868652 +4478.751465 +4482.341309 +4484.711426 +4477.770508 +4487.432617 +4477.797852 +4478.215820 +4484.515137 +4471.466797 +4485.196289 +4489.847168 +4478.849121 +4486.091309 +4476.749512 +4482.347168 +4479.112305 +4484.479980 +4482.749023 +4481.835938 +4476.332031 +4490.298828 +4474.976563 +4488.892578 +4475.904785 +4479.449707 +4481.473633 +4473.880859 +4470.364746 +4479.741211 +4485.084961 +4482.840820 +4489.276855 +4478.255371 +4481.232422 +4479.404297 +4486.555176 +4483.668457 +4479.242188 +4475.240234 +4477.756836 +4485.880859 +4483.913086 +4474.049805 +4485.213867 +4474.656738 +4489.760742 +4485.849121 +4478.494629 +4483.041992 +4481.822754 +4489.813477 +4479.782227 +4481.103027 +4472.776855 +4480.552246 +4485.222168 +4480.645508 +4481.207520 +4478.221191 +4477.875000 +4487.318359 +4476.371582 +4492.778809 +4473.621094 +4480.667480 +4469.893066 +4483.955078 +4484.902344 +4480.960449 +4489.791016 +4482.531250 +4489.027832 +4485.626953 +4488.373047 +4490.153809 +4491.823730 +4494.040039 +4488.828125 +4483.431641 +4482.831543 +4484.301270 +4481.235840 +4491.349121 +5530.036621 +4499.170898 +4479.352539 +4488.758789 +4484.286621 +4482.683594 +4486.358887 +4484.165039 +4475.802246 +4477.763184 +4473.175781 +4478.054199 +4481.698730 +4479.267578 +4481.536621 +4490.946289 +4480.294922 +4486.666992 +4491.044922 +4484.062500 +4479.961914 +4483.207520 +4482.577148 +4493.074707 +4479.706055 +4484.489258 +4478.550781 +4484.626953 +4477.682129 +4474.125000 +4479.554688 +4485.680176 +4488.474121 +4477.698730 +4484.653320 +4487.807617 +4481.587402 +4477.238281 +4474.206055 +4480.089844 +4480.333008 +4478.242676 +4484.879395 +4481.514160 +4483.604492 +4479.357422 +4477.700195 +4489.375000 +4484.111328 +4475.878906 +4479.497070 +4485.418945 +4475.910156 +4482.022949 +4479.492188 +4490.703125 +4492.127441 +4475.425293 +4478.416992 +4483.457031 +4487.754395 +4485.733398 +4481.206543 +4482.815918 +4485.239746 +4481.680664 +4475.727539 +4486.030762 +4478.789063 +4492.378418 +4482.035156 +4479.861328 +4478.699707 +4480.576172 +4474.430176 +4478.721191 +4481.625977 +4482.088867 +4481.348145 +4478.627930 +4486.524902 +4478.404297 +4473.093262 +4482.289063 +4480.066406 +4481.662598 +4474.800781 +4484.987793 +4485.790527 +4483.722656 +4477.952637 +4481.437012 +4472.958496 +4476.445313 +4487.542969 +4466.343750 +4477.238281 +4482.050781 +4481.274902 +4482.058594 +4493.047363 +4470.655762 +4473.789063 +4487.842285 +4474.196777 +4483.521484 +4474.026367 +4484.751953 +4474.802246 +4483.564453 +4482.917480 +4484.786621 +4479.294922 +4473.702637 +4477.388184 +4482.211426 +4481.365234 +4474.091797 +4478.232910 +4477.024414 +4486.042969 +4483.313477 +4485.057129 +4481.026855 +4476.049316 +4487.721680 +4475.709961 +4475.066895 +4473.645996 +4481.407227 +4471.196289 +4481.106934 +4476.328125 +4493.760254 +4483.258789 +4476.558105 +4475.034668 +4491.788574 +4482.742188 +4480.892090 +4473.124512 +4495.545410 +4477.255859 +4480.019043 +4488.789063 +4493.642090 +4485.639160 +4480.770508 +4471.961914 +4479.019531 +4483.105957 +4481.653320 +4471.736816 +4481.296875 +4478.858887 +4478.519043 +4484.851074 +4474.723145 +4484.704102 +4481.285156 +4483.901855 +4482.916504 +4480.096680 +4478.447266 +4474.881348 +4480.023926 +4491.510254 +4486.506348 +4482.501953 +4477.345703 +4485.680664 +4475.895996 +4475.727539 +4476.952148 +4479.573730 +4491.648438 +4482.588379 +4478.407715 +4475.859863 +4474.465332 +4479.391602 +4481.180176 +4476.148926 +4468.575195 +4479.885742 +4483.917969 +4484.504395 +4473.413574 +4485.089844 +4483.790527 +4485.766113 +4492.894531 +4471.777344 +4485.622559 +4490.819824 +4479.880371 +4480.325195 +4479.333008 +4481.846680 +4472.266113 +4485.205078 +5274.270020 +4540.924316 +4475.192383 +4485.097656 +4487.857910 +4487.800293 +4477.095703 +4481.091797 +4468.803223 +4480.087402 +4482.591309 +4481.145508 +4484.648926 +4493.514160 +4481.471680 +4476.225098 +4465.101563 +4474.166992 +4488.366699 +4478.227539 +4481.763672 +4488.848633 +4480.312012 +4472.523438 +4475.916016 +4475.021484 +4485.030762 +4471.015625 +4474.315918 +4464.813477 +4477.315430 +4473.114746 +4475.713867 +4471.322266 +4486.665527 +4473.931641 +4477.215820 +4488.894531 +4478.567871 +4478.274414 +4488.852051 +4486.156250 +4483.883789 +4484.163086 +4475.589355 +4487.614746 +4484.404297 +4483.319824 +4492.312988 +4475.234375 +4484.705566 +4496.960938 +4480.183594 +4480.761230 +4477.330078 +4485.723633 +4475.668945 +4480.450684 +4483.109375 +4474.703125 +4475.688477 +4487.165527 +4483.542480 +4488.231445 +4484.911621 +4477.487793 +4479.658691 +4475.808594 +4491.793945 +4477.796387 +4483.139160 +4474.954590 +4481.166992 +4486.122559 +4481.148926 +4465.362793 +4477.139160 +4485.126465 +4479.075195 +4491.756836 +4484.597656 +4474.282227 +4472.686523 +4482.037598 +4485.574707 +4491.500977 +4467.586426 +4479.965332 +4488.117676 +4484.129883 +4474.694336 +4484.161621 +4479.853516 +4486.738281 +4478.726563 +4471.195801 +4482.135742 +4488.952148 +4486.888184 +4485.597168 +4488.468750 +4478.808105 +4484.611328 +4483.922852 +4479.025391 +4487.953125 +4487.023438 +4485.395996 +4480.704590 +4477.548340 +4480.153809 +4477.701172 +4484.203125 +4495.520020 +4482.293457 +4481.877930 +4485.309082 +4490.734863 +4476.287109 +4472.083984 +4483.071777 +4482.692383 +4485.485840 +4474.858398 +4490.209961 +4486.592285 +4481.292969 +4481.246094 +4483.430176 +4492.234863 +4483.272461 +4481.473633 +4477.835449 +4481.671875 +4486.114258 +4478.881836 +4482.987305 +4482.501465 +4470.070801 +4478.293945 +4481.719727 +4482.497070 +4486.926758 +4488.582520 +4485.702148 +4465.853516 +4481.182617 +4480.197754 +4474.356934 +4481.210938 +4481.729492 +4493.649902 +4474.440918 +4476.765137 +4472.159180 +4482.088867 +4478.726563 +4488.068848 +4488.475586 +4478.956055 +4468.985352 +4490.494629 +4479.325684 +4476.645996 +4482.594238 +4479.051270 +4487.325684 +4477.171875 +4478.700684 +4483.512695 +4484.672852 +4493.121582 +4480.938965 +4477.567871 +4486.063965 +4487.577637 +4493.216797 +4479.706543 +4491.286133 +4496.058594 +4476.843750 +4483.132813 +4484.422852 +4485.979004 +4480.259277 +4489.341797 +4487.582520 +4476.963379 +4484.324219 +4491.126953 +4474.936035 +4488.647949 +4476.531250 +4480.406250 +4493.310547 +4489.303711 +4480.041016 +4490.740234 +4479.341309 +4474.095215 +4476.779297 +4482.615723 +4797.997559 +4481.679199 +4484.404297 +4483.300293 +4477.164063 +4485.692871 +4483.237793 +4490.222656 +4490.952637 +4483.241699 +4478.249512 +4481.941406 +4484.463379 +4486.563965 +4486.112793 +4484.097656 +4485.775879 +4471.403320 +4485.769531 +4484.417480 +4478.249512 +4489.524902 +4477.621582 +4484.400391 +4482.952148 +4480.565918 +4483.366211 +4475.866699 +4476.479980 +4485.353027 +4473.278809 +4481.561523 +4483.315430 +4473.921387 +4481.039551 +4482.793457 +4489.200684 +4481.000488 +4479.822754 +4483.987793 +4483.904785 +4485.361816 +4481.150879 +4476.709961 +4483.791992 +4473.282715 +4475.134766 +4484.651855 +4479.423340 +4473.212891 +4484.266602 +4483.567383 +4479.718262 +4480.817383 +4486.101563 +4483.136230 +4486.207031 +4480.446777 +4465.683105 +4471.242188 +4483.108398 +4476.451172 +4478.265625 +4489.230469 +4483.720215 +4489.883789 +4487.187012 +4472.812012 +4488.629395 +4477.943848 +4482.737793 +4475.762695 +4484.769043 +4487.538086 +4477.099121 +4486.572266 +4478.849609 +4478.412598 +4479.337891 +4481.474121 +4488.083008 +4487.755371 +4479.345215 +4484.572754 +4474.311523 +4486.986328 +4486.944824 +4476.756836 +4477.366211 +4486.685059 +4480.800781 +4484.321777 +4479.823730 +4477.256836 +4485.899414 +4464.644043 +4473.921875 +4480.619629 +4479.269531 +4473.508789 +4474.434082 +4485.971680 +4473.611328 +4485.401855 +4478.097656 +4482.908203 +4483.341309 +4486.355957 +4476.179688 +4491.665039 +4479.404785 +4488.780762 +4479.407715 +4480.295898 +4479.280762 +4482.398438 +4487.355957 +4481.833008 +4479.100098 +4475.886719 +4487.122559 +4489.333008 +4481.096680 +4470.900879 +4473.817383 +4488.621582 +4468.840820 +4475.440430 +4481.366699 +4488.788086 +4484.540527 +4488.317871 +4481.321289 +4479.370117 +4472.500977 +4478.896973 +4480.947266 +4477.097656 +4483.754395 +4486.878906 +4482.026855 +4481.215820 +4475.160645 +4475.933105 +4486.718750 +4480.934082 +4479.059570 +4475.107910 +4482.583008 +4489.636719 +4476.669922 +4491.204590 +4478.819336 +4477.209473 +4477.930176 +4483.411621 +4483.652832 +4479.375977 +4488.742676 +4478.176270 +4477.221191 +4471.133789 +4481.012695 +4485.219727 +4483.579590 +4477.380371 +4485.407227 +4480.714844 +4482.244141 +4475.467285 +4477.295410 +4485.134277 +4479.773926 +4476.719727 +4483.282227 +4477.791504 +4481.000488 +4477.346680 +4477.313965 +4472.498535 +4475.502930 +4483.201660 +4485.777344 +4483.424805 +4472.190430 +4476.750488 +4479.880859 +4480.991699 +4483.318359 +4480.417969 +4478.880371 +4484.595215 +4492.162109 +4486.544922 +4483.184570 +4492.568359 +4485.895996 +4491.224121 +4479.005859 +4482.319824 +4478.854980 +4800.699707 +4472.773438 +4478.327637 +4486.579590 +4476.304688 +4483.173828 +4485.691406 +4485.010254 +4487.214844 +4485.895020 +4479.979492 +4474.983398 +4478.452637 +4478.900391 +4494.987305 +4478.082031 +4485.491699 +4489.945313 +4481.123047 +4477.883301 +4482.432129 +4487.282227 +4478.991211 +4482.228516 +4483.289063 +4468.837402 +4478.585938 +4489.531250 +4482.894043 +4476.030762 +4473.372070 +4480.312988 +4481.776855 +4479.907715 +4477.510254 +4469.954102 +4474.786133 +4487.428711 +4482.124512 +4476.766602 +4475.154297 +4483.998535 +4498.301270 +4485.466797 +4487.988770 +4476.257813 +4481.665527 +4478.217285 +4482.533203 +4480.943359 +4477.427734 +4477.892090 +4482.609375 +4492.400391 +4476.871582 +4487.026367 +4488.696289 +4481.142578 +4474.444336 +4477.298828 +4474.276367 +4482.372559 +4489.579102 +4481.008301 +4472.480957 +4486.491211 +4488.724121 +4464.016113 +4482.150391 +4480.254395 +4477.818848 +4483.059570 +4481.360352 +4481.495117 +4480.881348 +4479.475098 +4488.233398 +4483.031250 +4478.728516 +4490.181152 +4479.810547 +4485.712402 +4483.244141 +4480.854004 +4488.502930 +4486.720215 +4470.357422 +4471.480957 +4486.296387 +4480.509766 +4476.699219 +4483.892090 +4474.722656 +4477.936523 +4477.427734 +4478.622070 +4479.796387 +4475.099121 +4482.187988 +4483.598633 +4477.482910 +4484.559570 +4475.433594 +4479.309570 +4482.923828 +4479.057617 +4487.246094 +4482.266113 +4485.901855 +4479.213379 +4483.811035 +4477.313965 +4478.383301 +4471.499512 +4478.476563 +4478.582520 +4482.362793 +4487.672363 +4474.360352 +4479.561035 +4482.905762 +4475.616211 +4484.549316 +4480.954102 +4475.341797 +4483.722656 +4473.711426 +4489.480469 +4470.714844 +4475.174316 +4479.916992 +4488.076172 +4478.254395 +4482.292969 +4477.623535 +4480.603027 +4491.920410 +4469.548828 +4480.518066 +4488.202637 +4474.588867 +4474.691895 +4476.936523 +4491.884277 +4477.579590 +4477.175293 +4473.068359 +4482.016113 +4484.000488 +4476.879883 +4486.567383 +4475.670898 +4486.867188 +4478.553711 +4481.056152 +4484.238770 +4492.165039 +4488.238770 +4486.224609 +4484.156250 +4491.608887 +4478.191895 +4488.487793 +4479.992676 +4484.403809 +4491.391113 +4482.061523 +4479.506348 +4485.635254 +4479.571777 +4488.050781 +4481.302246 +4481.074219 +4479.241699 +4496.994629 +4484.860840 +4477.597656 +4469.108398 +4480.128906 +4486.339844 +4476.555664 +4488.696777 +4484.313965 +4486.993164 +4471.170410 +4484.380371 +4483.779785 +4475.638672 +4477.113770 +4482.770508 +4490.817871 +4477.110352 +4481.867188 +4474.495117 +4483.296875 +4487.837891 +4474.341309 +4480.993652 +4482.195313 +4485.119629 +4490.154785 +4792.336426 +4492.865723 +4480.148926 +4481.090820 +4490.238281 +4485.371582 +4483.109863 +4491.546387 +4476.982910 +4476.293945 +4486.289551 +4463.496582 +4479.856445 +4488.801758 +4479.596680 +4473.649414 +4474.829102 +4471.827148 +4478.594238 +4481.488281 +4481.233887 +4467.075195 +4484.410156 +4476.943359 +4479.454590 +4478.758301 +4487.635742 +4484.856445 +4476.697266 +4483.963379 +4485.148438 +4477.754395 +4479.387695 +4489.907715 +4485.238770 +4485.559570 +4476.667480 +4483.167969 +4475.947266 +4479.083008 +4473.652344 +4483.116211 +4474.076660 +4470.444824 +4494.146973 +4474.698730 +4480.925293 +4481.235352 +4483.021484 +4482.455566 +4494.159668 +4475.193848 +4483.157227 +4486.908203 +4473.515137 +4481.644531 +4471.869629 +4483.021973 +4482.992188 +4480.222656 +4492.715820 +4479.554688 +4478.269531 +4484.306641 +4476.195313 +4489.746582 +4483.738281 +4486.723145 +4478.580078 +4474.624512 +4480.126953 +4478.053223 +4478.011230 +4476.404785 +4480.462402 +4475.667480 +4473.621582 +4478.629395 +4483.841797 +4485.163574 +4482.101563 +4479.783203 +4479.608398 +4478.271484 +4482.838379 +4477.236328 +4488.893555 +4473.232910 +4484.139648 +4480.603027 +4475.876953 +4469.400391 +4487.609375 +4477.752930 +4480.474121 +4478.180176 +4483.267578 +4475.548828 +4486.103027 +4481.249512 +4481.179199 +4481.486816 +4487.105469 +4477.042480 +4489.643555 +4481.990234 +4479.805176 +4484.425781 +4488.981934 +4476.983398 +4480.445313 +4476.249512 +4476.649414 +4474.895020 +4480.056152 +4486.828613 +4475.825195 +4465.433105 +4479.173828 +4479.221191 +4484.066895 +4480.151855 +4479.115234 +4488.216797 +4475.964355 +4485.769043 +4467.674805 +4481.956055 +4482.834961 +4474.053711 +4469.336426 +4480.130371 +4466.074219 +4474.995605 +4484.564453 +4478.888184 +4492.365723 +4485.969727 +4483.875488 +4478.879395 +4487.476563 +4476.944336 +4483.537109 +4476.571777 +4482.749512 +4481.083496 +4472.972656 +4483.756836 +4488.210449 +4486.219238 +4478.571289 +4478.232910 +4484.144531 +4473.024902 +4467.855469 +4481.715820 +4482.859863 +4476.244629 +4464.566406 +4480.355957 +4480.677734 +4475.676758 +4478.862305 +4479.397949 +4480.025879 +4483.897949 +4477.457520 +4474.058105 +4480.268555 +4555.262207 +4486.799316 +4545.933594 +4482.299805 +4531.898438 +4481.152344 +4474.634766 +4485.751465 +4489.123535 +4478.031250 +4493.001465 +4484.077637 +4465.770508 +4487.036621 +4479.116699 +4480.129395 +4475.231934 +4481.761230 +4495.741699 +4479.975098 +4490.895020 +4480.818359 +4480.558594 +4483.612305 +4477.239746 +4484.099609 +4472.713867 +4496.533691 +4486.680664 +4474.412109 +4481.397461 +4479.654785 +4712.742676 +4481.798828 +4475.825195 +4481.322754 +4484.791016 +4478.850586 +4475.466797 +4489.907227 +4480.167969 +4480.011230 +4470.210449 +4479.660645 +4483.843750 +4492.093750 +4487.693359 +4479.310547 +4488.073730 +4477.961426 +4481.578613 +4485.003906 +4480.755859 +4481.129883 +4485.028320 +4475.121582 +4474.694336 +4480.884766 +4489.867188 +4482.259277 +4476.693848 +4476.050293 +4482.957031 +4479.052734 +4470.948242 +4481.492188 +4477.018066 +4479.295410 +4476.465820 +4478.280273 +4482.389160 +4471.781738 +4488.024414 +4479.479980 +4489.829590 +4476.348145 +4480.538574 +4480.425293 +4474.041504 +4483.358398 +4472.734375 +4483.463379 +4491.534180 +4474.931152 +4494.829102 +4483.062500 +4469.029297 +4478.543457 +4483.733398 +4479.590820 +4472.955078 +4476.905762 +4491.616699 +4483.697754 +4482.309082 +4482.277344 +4484.280762 +4482.416992 +4479.791504 +4480.478516 +4475.286621 +4476.840332 +4480.121094 +4475.154297 +4478.361816 +4471.819824 +4490.429199 +4483.390625 +4478.112305 +4481.516602 +4476.160645 +4478.280273 +4481.544434 +4476.844238 +4473.710938 +4484.100586 +4488.037109 +4485.313477 +4486.412598 +4475.018555 +4481.671387 +4477.802734 +4486.077637 +4477.193848 +4481.226563 +4485.283203 +4480.268066 +4469.820801 +4489.881836 +4491.500488 +4478.484863 +4478.537598 +4475.437988 +4481.520508 +4478.084961 +4475.466797 +4480.793945 +4481.373535 +4477.915527 +4488.397949 +4479.388184 +4478.071777 +4481.885742 +4479.711914 +4483.502930 +4488.121582 +4484.651367 +4474.009766 +4490.791504 +4484.625977 +4476.255859 +4482.049805 +4477.687012 +4478.705566 +4487.105469 +4486.233887 +4472.852051 +4481.561035 +4475.700195 +4476.974121 +4478.813477 +4491.195801 +4475.829590 +4484.847656 +4475.102051 +4477.763184 +4478.252930 +4482.660156 +4480.729492 +4488.868164 +4486.092773 +4482.238770 +4484.604980 +4483.935059 +4487.618164 +4482.369141 +4480.757324 +4476.979004 +4474.562012 +4477.339355 +4485.113281 +4477.273926 +4480.360840 +4486.604004 +4485.860840 +4475.186523 +4484.585938 +4479.830566 +4481.316895 +4489.278320 +4485.473633 +4469.979980 +4479.036621 +4491.442871 +4483.499023 +4479.560059 +4499.430176 +4482.081055 +4484.002930 +4480.769531 +4476.354004 +4482.268066 +4477.467773 +4482.883789 +4481.112793 +4473.500000 +4480.025391 +4470.036133 +4477.176270 +4473.756348 +4483.176758 +4484.295410 +4485.443848 +4483.617676 +4475.789551 +4484.222656 +4481.349121 +4485.966309 +4484.802246 +4483.888184 +4484.118652 +4478.475586 +4471.963379 +4481.390137 +4483.087891 +4484.496582 +4487.907227 +4482.907227 +4482.916016 +4473.188477 +4481.790039 +4486.588867 +4480.983398 +5064.253906 +4492.072754 +4481.039063 +4479.987793 +4480.454590 +4479.343262 +4485.366211 +4488.462402 +4474.250977 +4465.910156 +4470.584473 +4474.514648 +4469.674316 +4488.570801 +4473.646973 +4473.990234 +4479.839844 +4478.613281 +4476.237793 +4479.289551 +4480.369629 +4479.698242 +4477.402344 +4484.210449 +4483.664063 +4488.895020 +4481.729492 +4474.085449 +4476.341309 +4483.284668 +4472.255371 +4481.823730 +4466.370605 +4478.716797 +4484.351074 +4486.953125 +4486.862793 +4471.009766 +4484.971680 +4484.568359 +4471.443359 +4472.452637 +4473.728516 +4478.720215 +4482.298340 +4486.432617 +4475.379395 +4487.580078 +4478.179199 +4465.106934 +4480.793457 +4478.668945 +4472.466797 +4489.059570 +4492.090820 +4479.374512 +4478.637695 +4474.225586 +4492.073730 +4486.164551 +4478.837891 +4481.274902 +4484.237305 +4486.650879 +4487.436523 +4480.785156 +4485.846680 +4483.437988 +4476.137695 +4483.751953 +4484.882813 +4486.518555 +4481.481445 +4466.453613 +4477.398926 +4472.750977 +4486.964355 +4478.632813 +4482.397949 +4484.562012 +4487.503906 +4482.193848 +4485.849121 +4485.979980 +4482.509766 +4484.667480 +4472.269531 +4476.097656 +4485.760742 +4480.529785 +4479.273438 +4488.282227 +4482.270996 +4478.784180 +4486.124023 +4476.034668 +4489.768066 +4482.983887 +4476.083008 +4487.152832 +4482.589844 +4482.955566 +4480.296387 +4478.528320 +4486.665039 +4481.860840 +4476.765137 +4475.148926 +4481.176758 +4488.885742 +4483.011230 +4468.479492 +4473.354980 +4487.771484 +4469.864258 +4487.711914 +4498.548828 +4486.042969 +4484.847656 +4475.957031 +4483.114258 +4480.329590 +4482.681641 +4487.502930 +4488.049316 +4485.063477 +4485.405273 +4492.879395 +4480.341797 +4481.853516 +4485.067383 +4477.365234 +4471.642090 +4488.321289 +4481.997559 +4475.542969 +4483.424316 +4482.097168 +4492.647949 +4472.232422 +4486.825195 +4481.271973 +4478.150391 +4470.527344 +4477.785645 +4481.459473 +4478.170410 +4478.188965 +4486.863770 +4483.933594 +4488.460938 +4476.737793 +4475.210449 +4478.183105 +4478.069336 +4481.188477 +4484.681641 +4474.725586 +4480.919922 +4474.085938 +4470.937012 +4479.543457 +4472.651367 +4485.868652 +4477.806641 +4476.653320 +4488.766602 +4473.573242 +4477.979004 +4490.902344 +4492.190430 +4480.670898 +4487.808594 +4475.680664 +4481.173828 +4485.771484 +4487.666016 +4475.633301 +4483.815918 +4491.567383 +4482.985840 +4487.033203 +4475.124512 +4479.395020 +4473.310059 +4483.131348 +4475.661133 +4479.189941 +4479.779785 +4482.918457 +4484.672363 +4475.692871 +4481.967285 +4474.416016 +4481.402832 +4471.160645 +4487.999512 +4482.755371 +4475.820801 +4472.926758 +4482.368652 +5142.206543 +4550.730957 +4483.004883 +4479.475586 +4469.753906 +4480.022949 +4490.809570 +4491.333008 +4496.021484 +4484.752930 +4478.882324 +4483.582031 +4485.601563 +4478.302246 +4479.883301 +4476.938477 +4467.834473 +4488.073242 +4489.284180 +4485.564941 +4480.287109 +4482.196777 +4480.812988 +4474.849609 +4476.475586 +4490.180176 +4483.207520 +4481.030273 +4482.268066 +4481.839355 +4475.607422 +4470.091309 +4488.732910 +4485.744629 +4476.056152 +4475.519043 +4486.004883 +4479.562988 +4484.522461 +4482.916992 +4483.941895 +4480.028320 +4477.170410 +4474.974609 +4485.740234 +4476.327637 +4473.541504 +4485.731445 +4476.443359 +4474.476074 +4482.659668 +4480.458496 +4472.363281 +4496.114258 +4478.688477 +4479.974121 +4490.948242 +4476.011230 +4479.616211 +4484.533203 +4473.443359 +4475.831055 +4474.308105 +4475.563477 +4477.561035 +4484.194336 +4476.046387 +4483.112793 +4475.666504 +4494.852051 +4471.625488 +4480.479980 +4482.600586 +4496.578613 +4478.483398 +4478.622070 +4488.127930 +4476.851563 +4477.562012 +4484.151367 +4493.848145 +4486.093262 +4484.322266 +4473.437012 +4480.330566 +4482.424805 +4473.186035 +4470.741211 +4485.233887 +4471.031250 +4476.643555 +4484.865723 +4486.469238 +4486.330078 +4472.039551 +4478.373047 +4481.537109 +4485.466797 +4478.705078 +4483.062988 +4482.488281 +4476.013184 +4489.748535 +4480.752930 +4476.440430 +4483.333008 +4475.138184 +4481.847656 +4486.286133 +4484.756348 +4486.806152 +4489.756348 +4485.457520 +4471.999512 +4475.862793 +4478.116699 +4482.980957 +4480.243652 +4482.216797 +4483.963867 +4487.652832 +4488.347168 +4470.994141 +4483.138672 +4477.713379 +4486.126465 +4486.987793 +4487.788574 +4500.087891 +4470.612305 +4491.711426 +4479.168457 +4479.056641 +4488.110352 +4484.987793 +4481.099121 +4478.967773 +4484.785645 +4482.163574 +4481.161621 +4475.242676 +4475.763672 +4473.870117 +4487.687500 +4476.965332 +4476.344727 +4486.591309 +4486.200684 +4487.743164 +4481.427246 +4478.782715 +4475.213379 +4483.419922 +4476.528320 +4482.216309 +4487.100098 +4488.001465 +4485.458496 +4474.005859 +4479.171387 +4482.897461 +4479.864746 +4478.476563 +4480.794434 +4486.298828 +4475.730957 +4478.533691 +4479.148438 +4476.667969 +4478.016113 +4471.130371 +4482.012695 +4480.533203 +4486.930176 +4477.091797 +4485.701172 +4479.261230 +4471.356934 +4477.944336 +4485.572754 +4483.081543 +4477.834473 +4483.083496 +4482.257813 +4483.990723 +4477.186035 +4472.889160 +4479.876953 +4477.201660 +4480.032227 +4482.400391 +4481.899414 +4495.686035 +4483.036621 +4479.900391 +4478.438477 +4482.870117 +4476.815430 +4476.246582 +4472.078613 +4481.532715 +4951.273926 +4709.208496 +4475.540039 +4486.267578 +4484.367676 +4473.321289 +4475.433594 +4489.723145 +4493.323730 +4490.879883 +4480.457520 +4480.909180 +4482.002930 +4483.589355 +4476.453613 +4478.533691 +4478.640137 +4482.846191 +4479.592285 +4481.378418 +4488.145020 +4471.524414 +4486.714844 +4476.320313 +4483.626953 +4477.766602 +4476.037598 +4492.244629 +4485.270996 +4485.810547 +4481.294922 +4485.944336 +4481.938477 +4483.938477 +4486.912598 +4492.851563 +4488.380371 +4475.743652 +4477.927246 +4477.056641 +4484.416504 +4479.468750 +4482.490723 +4485.892090 +4488.035645 +4477.327148 +4473.403809 +4474.498535 +4478.208984 +4493.557129 +4480.051758 +4476.861328 +4477.687012 +4482.541016 +4485.052246 +4476.346680 +4487.058105 +4482.150391 +4480.078125 +4473.784180 +4481.274414 +4483.536133 +4482.486816 +4482.921387 +4476.971191 +4480.234863 +4476.785645 +4474.757813 +4485.225586 +4475.731934 +4482.556152 +4487.290527 +4481.577148 +4479.430664 +4476.882813 +4487.962402 +4480.765137 +4494.089355 +4483.169922 +4483.269043 +4479.659668 +4490.960938 +4473.645508 +4486.004395 +4488.527344 +4477.457520 +4490.558594 +4477.636230 +4491.320313 +4476.236816 +4485.165039 +4481.042480 +4470.863281 +4482.614258 +4491.379883 +4485.487793 +4489.113770 +4469.557129 +4471.812012 +4488.962402 +4467.944824 +4486.245117 +4474.645020 +4477.255371 +4481.686035 +4475.455078 +4481.156250 +4481.063965 +4484.948730 +4489.590820 +4481.857422 +4479.962891 +4485.622070 +4482.663574 +4474.482910 +4486.346191 +4486.298828 +4486.492676 +4480.162109 +4484.588379 +4483.448730 +4482.187988 +4481.368652 +4491.241211 +4483.225098 +4476.213379 +4481.870605 +4475.447754 +4473.923340 +4472.869141 +4474.181641 +4481.273438 +4484.986328 +4485.126953 +4488.858398 +4471.760254 +4476.496582 +4487.442383 +4488.124512 +4487.304688 +4478.380859 +4483.266602 +4473.880371 +4474.819336 +4486.371582 +4480.527344 +4479.535156 +4477.149414 +4486.227539 +4487.414063 +4478.425293 +4478.004395 +4480.961426 +4488.537598 +4475.511230 +4479.724609 +4485.673340 +4483.295898 +4478.441895 +4470.645996 +4480.270508 +4481.748047 +4482.602051 +4485.208496 +4489.956543 +4481.524902 +4480.766602 +4484.348633 +4477.893066 +4480.262207 +4489.741211 +4480.832520 +4488.941406 +4480.187012 +4476.104004 +4473.064453 +4493.144043 +4481.084473 +4478.706543 +4477.592773 +4479.366699 +4489.189941 +4484.286621 +4483.243652 +4482.970703 +4483.416504 +4485.998047 +4474.902344 +4483.706543 +4482.836914 +4485.449707 +4481.735352 +4482.544434 +4482.540039 +4477.826660 +4481.352539 +4486.490723 +4480.653809 +4470.487305 +4482.917969 +4479.987305 +4500.435059 +4784.708496 +4470.881348 +4488.170898 +4480.509766 +4470.240234 +4484.456543 +4479.673340 +4478.632813 +4480.292969 +4478.302734 +4478.656250 +4482.569336 +4478.155762 +4467.560059 +4475.700195 +4478.656250 +4477.030762 +4489.720215 +4473.994141 +4470.979004 +4486.199219 +4486.080078 +4482.444336 +4492.197266 +4478.171875 +4465.893555 +4490.284668 +4486.558105 +4475.764160 +4475.449219 +4487.385742 +4486.144531 +4479.463867 +4474.989258 +4478.278809 +4488.704102 +4486.102051 +4487.846191 +4481.981934 +4469.395996 +4484.362305 +4480.370117 +4475.933594 +4482.291504 +4480.749512 +4480.887695 +4479.928223 +4485.131348 +4485.703125 +4478.758789 +4476.082520 +4490.957520 +4488.334961 +4478.161621 +4483.066895 +4480.619629 +4482.132813 +4495.786621 +4478.960449 +4473.008789 +4476.704590 +4487.657715 +4481.320313 +4479.163086 +4483.132324 +4485.979004 +4479.593750 +4484.563965 +4477.875000 +4491.000488 +4480.111816 +4485.177734 +4488.934082 +4491.513672 +4485.896484 +4489.184082 +4480.304688 +4479.125977 +4488.083008 +4477.215820 +4485.189453 +4480.184570 +4484.382813 +4475.713379 +4490.322266 +4482.516113 +4469.658691 +4479.318848 +4481.539551 +4487.504395 +4489.159180 +4478.844238 +4477.666016 +4487.342773 +4481.281738 +4487.584473 +4486.658203 +4482.790527 +4476.267090 +4479.467773 +4485.583496 +4487.282715 +4485.433594 +4479.576660 +4474.427734 +4476.744629 +4492.816406 +4476.604004 +4472.866699 +4476.085938 +4478.297363 +4480.887695 +4478.066406 +4487.123047 +4480.459961 +4482.871582 +4470.079102 +4483.199707 +4483.869629 +4488.009277 +4479.760254 +4481.425293 +4482.099121 +4476.909180 +4491.605469 +4481.130371 +4479.596680 +4475.650879 +4475.742676 +4486.418945 +4476.645508 +4475.203613 +4483.341309 +4478.902832 +4479.639648 +4472.792480 +4477.646484 +4476.766113 +4484.342773 +4475.619629 +4482.734375 +4482.789551 +4473.723633 +4486.589844 +4489.448242 +4474.020508 +4486.666016 +4482.611328 +4487.251465 +4475.646484 +4489.093750 +4483.898438 +4474.738770 +4488.040527 +4473.336426 +4472.712402 +4487.740723 +4475.100586 +4483.083984 +4484.873535 +4472.700195 +4478.675293 +4470.214355 +4474.946289 +4479.341309 +4486.997559 +4478.197266 +4481.842773 +4479.560547 +4486.109863 +4472.987305 +4485.158203 +4475.354492 +4474.687500 +4493.479980 +4485.554199 +4477.408203 +4479.242676 +4479.724609 +4487.128418 +4485.980957 +4488.275879 +4480.555176 +4482.824707 +4468.182129 +4483.737305 +4483.961914 +4477.840820 +4481.123047 +4469.941406 +4482.320313 +4474.481934 +4481.950195 +4470.168457 +4482.137695 +4484.887695 +4485.636230 +4482.949219 +4475.780273 +4474.589844 +4479.549316 +4809.639648 +4481.832031 +4473.864746 +4479.239258 +4492.428711 +4478.554688 +4476.839355 +4478.792969 +4492.688965 +4479.114258 +4485.153320 +4486.322266 +4473.899414 +4479.848633 +4475.932129 +4471.643066 +4478.865234 +4483.110840 +4479.742188 +4472.270020 +4478.023926 +4475.933105 +4470.659668 +4483.569336 +4482.366699 +4477.423828 +4472.821777 +4475.097168 +4481.360840 +4479.567383 +4481.557617 +4482.639648 +4482.912598 +4478.089844 +4485.935059 +4477.722656 +4479.766113 +4480.717773 +4489.998535 +4481.571289 +4488.474121 +4484.206055 +4471.771484 +4481.473145 +4479.748047 +4479.645996 +4487.804688 +4474.639160 +4475.422363 +4493.413086 +4484.405273 +4477.489258 +4488.828125 +4476.706055 +4474.387695 +4485.284668 +4483.673340 +4478.865234 +4478.553223 +4484.334961 +4476.149414 +4483.281738 +4471.836914 +4482.127441 +4486.124512 +4482.396484 +4474.357422 +4483.706543 +4480.294922 +4480.283691 +4490.576172 +4471.554199 +4486.774902 +4482.739258 +4487.603516 +4474.502441 +4486.083984 +4480.955078 +4472.494629 +4476.037109 +4480.819824 +4486.755371 +4479.383301 +4482.086426 +4479.135742 +4478.512207 +4489.297363 +4476.997559 +4489.125488 +4476.763184 +4478.291504 +4478.928711 +4484.266602 +4478.186523 +4490.493164 +4482.356445 +4478.616211 +4479.466309 +4493.161621 +4483.753418 +4478.436523 +4481.589355 +4482.949707 +4475.540527 +4478.065430 +4482.275391 +4478.960449 +4500.702637 +4472.435547 +4477.915039 +4486.984863 +4486.839844 +4488.916992 +4478.072754 +4483.896484 +4483.998047 +4476.321289 +4484.226563 +4479.175293 +4483.078613 +4486.012695 +4482.097656 +4474.320801 +4484.189453 +4483.846680 +4479.778320 +4481.847656 +4481.770996 +4478.964844 +4485.308594 +4483.566895 +4482.192871 +4469.897949 +4482.122070 +4497.237305 +4474.725586 +4476.805176 +4473.306641 +4480.929199 +4478.775391 +4486.823730 +4481.916504 +4489.106445 +4480.381348 +4480.087402 +4474.949219 +4487.860840 +4475.131836 +4483.204590 +4484.735352 +4479.602539 +4479.914551 +4497.394531 +4481.460938 +4483.837402 +4486.099609 +4485.479980 +4486.029297 +4480.854004 +4475.262695 +4477.126465 +4482.033203 +4480.981934 +4481.135742 +4484.165527 +4485.571289 +4477.971191 +4482.748535 +4482.702148 +4476.301270 +4476.646484 +4481.640137 +4478.061523 +4473.795898 +4485.706055 +4490.681152 +4480.458984 +4488.747070 +4477.651367 +4483.984863 +4473.560059 +4479.288086 +4481.482910 +4474.779297 +4486.881836 +4483.678223 +4475.112793 +4473.264648 +4483.791992 +4485.229980 +4483.251465 +4477.104980 +4479.308594 +4479.758789 +4477.731934 +4481.064453 +4481.374512 +4485.836426 +4474.652832 +4478.546875 +4477.237793 +4643.581055 +4472.765625 +4475.233887 +4482.639160 +4481.915039 +4495.490234 +4467.916992 +4485.878906 +4477.234863 +4486.875488 +4480.167969 +4492.505859 +4479.688477 +4482.883301 +4484.689453 +4478.340332 +4481.828125 +4493.012207 +4484.463379 +4488.108887 +4478.349121 +4472.635742 +4479.558594 +4483.939453 +4460.607910 +4474.449707 +4482.383789 +4475.706543 +4476.036621 +4475.373535 +4474.509277 +4481.874512 +4480.115723 +4487.672852 +4475.815918 +4477.738281 +4491.458008 +4484.250488 +4486.281250 +4478.538086 +4476.528809 +4486.138672 +4478.073242 +4482.553711 +4485.963867 +4480.321289 +4475.027344 +4476.930176 +4474.392578 +4480.313965 +4479.652344 +4477.955566 +4488.042480 +4483.129395 +4471.855957 +4487.707031 +4479.694824 +4479.893555 +4483.476563 +4481.806641 +4481.207031 +4483.888184 +4475.898926 +4480.669922 +4482.649902 +4475.340332 +4491.457031 +4483.558105 +4483.083008 +4478.968750 +4484.130371 +4481.429199 +4470.148438 +4478.691895 +4482.921387 +4482.921875 +4472.613770 +4475.493652 +4488.942871 +4478.984375 +4475.935059 +4476.163574 +4490.717773 +4478.477539 +4480.396973 +4478.413574 +4477.416016 +4479.631836 +4481.682129 +4480.188477 +4472.270996 +4485.734375 +4464.751465 +4480.273438 +4480.946289 +4478.574707 +4485.771484 +4478.080566 +4484.138672 +4483.475586 +4482.670410 +4483.607422 +4473.151855 +4475.234863 +4486.394043 +4491.043457 +4485.665039 +4481.364258 +4487.704590 +4488.658203 +4474.336914 +4481.927734 +4476.814941 +4479.305176 +4485.351563 +4477.603516 +4489.413574 +4481.566406 +4473.100586 +4487.509766 +4483.652344 +4487.387207 +4479.078125 +4487.229492 +4482.640625 +4473.789551 +4483.673828 +4477.933105 +4482.584961 +4485.113281 +4478.611816 +4487.657227 +4485.873047 +4480.414063 +4481.486328 +4484.960938 +4477.710449 +4482.629395 +4479.740723 +4483.190430 +4492.376953 +4479.754395 +4480.454102 +4477.911621 +4486.443848 +4480.147461 +4473.089355 +4485.783203 +4476.953613 +4488.452148 +4486.788086 +4481.447754 +4481.902832 +4478.811523 +4489.636719 +4477.205078 +4479.350586 +4483.080078 +4468.633789 +4478.822754 +4480.216309 +4474.003906 +4472.475586 +4484.333984 +4469.993164 +4483.821777 +4483.833984 +4487.171875 +4481.472656 +4481.302734 +4480.875488 +4479.045410 +4478.736816 +4486.458984 +4480.213379 +4485.378906 +4490.061523 +4464.256348 +4479.010742 +4489.394531 +4476.616211 +4479.287598 +4490.552246 +4485.812500 +4460.723633 +4476.130859 +4473.193359 +4486.681641 +4481.178711 +4481.588867 +4486.464355 +4485.946289 +4473.661621 +4483.189941 +4482.959473 +4477.964355 +4478.463867 +4489.681152 +4481.336914 +4480.355957 +4481.858887 +4797.584473 +4485.800293 +4473.955566 +4476.943359 +4480.667969 +4476.521973 +4481.066406 +4487.400879 +4487.668457 +4481.577148 +4484.431152 +4482.447754 +4480.581543 +4481.289551 +4475.610352 +4481.013672 +4474.721680 +4469.754395 +4481.078125 +4484.706055 +4476.420898 +4474.379883 +4477.051758 +4488.571777 +4474.484375 +4478.803711 +4488.127441 +4597.713867 +18338252.000000 +4529.673828 +4585.157715 +4581.594238 +4566.054688 +4590.888672 +4550.118652 +4588.277832 +4504.353516 +4513.572266 +4508.048340 +4468.707031 +4471.937988 +4484.764648 +4474.081055 +4478.678711 +4475.958008 +4485.164551 +4480.315918 +4481.217285 +4480.215332 +4484.135742 +4479.603027 +4477.787109 +4476.769531 +4473.154297 +4484.519531 +4482.660156 +4485.100586 +4487.486328 +4492.843750 +4485.686035 +4481.003906 +4485.558105 +4488.732422 +4492.636719 +4492.024414 +4483.537598 +4488.100098 +4485.894531 +4489.424316 +4485.439453 +4491.192871 +4483.606445 +4484.296387 +4479.236816 +4478.372070 +4465.504883 +4482.390625 +4479.307129 +4480.829102 +4473.294922 +4478.723145 +4479.078125 +4478.393066 +4475.686035 +4485.018555 +4486.197754 +4478.751465 +4488.969238 +4491.500488 +4487.446289 +4490.597656 +4485.122559 +4484.873535 +4484.634766 +4477.616211 +4482.337891 +4478.535645 +4482.952148 +4483.787109 +4470.736816 +4472.947754 +4480.200195 +4472.224609 +4477.785156 +4470.351563 +4479.481445 +4484.706055 +4484.270996 +4483.641602 +4486.261230 +4489.021484 +4491.036621 +4479.932617 +4481.306152 +4483.256348 +4490.552734 +4479.159668 +4482.421875 +4488.238770 +4486.314941 +4484.653809 +4480.497070 +4486.421875 +4484.976563 +4480.094727 +4479.384277 +4478.997559 +4474.232422 +4483.722168 +4479.608887 +4497.983398 +4480.782715 +4480.313965 +4484.489746 +4483.971191 +4487.161133 +4481.711914 +4476.873535 +4483.791016 +4496.495117 +4490.281738 +4486.159668 +4482.612793 +4477.827148 +4486.359863 +4483.991699 +4480.292969 +4485.693848 +4490.389160 +4482.838379 +4482.810547 +4485.370117 +4489.215820 +4482.428711 +4492.980469 +4486.268555 +4475.562500 +4491.130859 +4491.043457 +4477.115723 +4483.212402 +4485.001953 +4485.169922 +4488.766113 +4478.000977 +4483.147461 +4478.599609 +4474.192871 +4476.743164 +4476.542480 +4488.919434 +4483.441895 +4479.437988 +4486.209961 +4476.244629 +4484.709473 +4483.883789 +4474.209961 +4484.395996 +4474.547363 +4469.136719 +4476.458984 +4481.925293 +4486.504883 +4476.847656 +4483.260254 +4480.229980 +4492.742676 +4489.567871 +4476.928711 +4477.682129 +4478.416992 +4490.917969 +4485.027832 +4485.746094 +4491.620117 +4482.306641 +4482.322754 +4974.006348 +4480.302246 +4482.839844 +4489.131348 +4493.363770 +4485.476074 +4482.115723 +4482.863770 +4478.434082 +4474.266113 +4485.039551 +4481.038086 +4484.401367 +4477.865723 +4479.491211 +4489.228516 +4469.658203 +4473.876465 +4479.804688 +4470.841309 +4471.058594 +4476.721680 +4477.003906 +4476.860840 +4470.940430 +4475.329102 +4473.792480 +4472.100586 +4477.540039 +4477.190918 +4488.899902 +4476.725586 +4483.317383 +4471.021973 +4473.928223 +4478.479004 +4468.259766 +4488.469727 +4483.795410 +4492.867188 +4478.512695 +4471.332031 +4473.717773 +4480.841309 +4473.432617 +4474.069336 +4469.229980 +4476.824219 +4492.596191 +4488.716309 +4479.699707 +4488.027832 +4476.676758 +4474.601563 +4480.934082 +4475.525391 +4469.693359 +4479.550293 +4488.476563 +4486.166016 +4474.745605 +4477.595703 +4482.138184 +4478.812988 +4479.635742 +4482.416504 +4480.561035 +4500.718750 +4488.889160 +4477.215332 +4482.369141 +4481.397461 +4483.426758 +4484.042969 +4475.031250 +4484.572754 +4483.546875 +4488.940918 +4466.259766 +4491.566895 +4480.679199 +4480.731934 +4481.087402 +4482.456055 +4487.269531 +4482.856445 +4486.749023 +4482.309570 +4487.028809 +4483.876953 +4484.630859 +4486.026855 +4477.756836 +4486.540039 +4494.114258 +4488.866699 +4479.399414 +4483.545410 +4477.567383 +4482.779297 +4480.763184 +4484.686523 +4484.846680 +4476.557617 +4488.940918 +4478.268555 +4481.171387 +4479.374512 +4485.605469 +4483.005859 +4478.398438 +4481.810547 +4488.738281 +4484.530273 +4488.973145 +4485.276367 +4476.370605 +4483.436035 +4480.794434 +4482.729492 +4484.419922 +4484.590332 +4475.645996 +4491.878906 +4479.926270 +4485.211914 +4488.017578 +4481.469727 +4477.270996 +4488.160645 +4473.171387 +4483.404297 +4482.152344 +4486.213379 +4480.663086 +4480.399414 +4483.082031 +4486.997070 +4490.712891 +4480.543945 +4472.948242 +4490.868164 +4472.812500 +4496.265625 +4487.074219 +4482.129395 +4480.779785 +4492.442871 +4478.997559 +4476.627441 +4491.698730 +4483.998535 +4481.432617 +4470.806152 +4485.196777 +4481.346680 +4484.666504 +4484.011230 +4493.715332 +4484.553223 +4476.491699 +4488.324707 +4489.880859 +4484.355957 +4492.671875 +4503.270996 +4492.022949 +4487.231934 +4487.619141 +4484.359863 +4483.575684 +4478.183594 +4480.160645 +4478.251465 +4483.030273 +4490.820801 +4491.466309 +4482.516602 +4481.443359 +4488.802246 +4475.262695 +4476.456055 +4484.240723 +4473.590820 +4481.604492 +4491.363281 +4482.964844 +4481.331543 +4483.008789 +4482.012207 +4488.049805 +4477.177246 +4487.731934 +4483.067383 +4486.372070 +4475.738770 +4481.489258 +4492.264648 +4473.475098 +4470.876953 +4487.502441 +4484.566406 +4483.641602 +4483.974121 +4469.937012 +4478.262695 +4499.625977 +4481.982910 +4482.833008 +4492.728027 diff --git a/results/results_without_caching.txt b/results/results_without_caching.txt new file mode 100644 index 0000000..ec364ca --- /dev/null +++ b/results/results_without_caching.txt @@ -0,0 +1,350 @@ +132.738205 +70.571747 +69.745949 +70.972420 +67.914787 +71.219299 +70.621727 +74.021309 +64.987488 +67.346848 +65.028221 +68.617439 +66.172195 +65.997757 +67.028992 +66.804733 +64.861664 +67.031906 +66.715073 +67.934082 +65.657661 +68.433121 +65.351456 +127.922112 +71.551903 +68.607361 +72.466972 +71.360703 +71.665085 +70.134560 +70.358559 +74.344193 +71.905342 +69.145378 +71.511902 +71.510017 +69.246750 +73.026016 +69.324448 +73.313728 +73.873596 +73.267357 +70.446976 +69.609695 +71.615967 +70.416573 +72.687805 +68.354851 +73.878883 +73.804802 +68.987389 +71.893791 +70.291779 +69.483932 +73.092995 +70.840355 +71.432289 +69.464638 +68.473763 +71.284706 +70.222816 +70.536575 +69.377182 +72.054276 +69.461823 +70.034142 +70.303391 +69.883453 +71.036385 +70.217567 +70.931267 +74.738625 +69.439713 +69.191772 +73.211426 +70.653023 +70.187103 +71.931808 +68.853760 +72.194077 +71.718849 +69.960159 +71.948448 +71.157120 +70.622627 +72.718178 +68.785347 +72.588318 +118.652481 +69.248253 +71.944412 +71.160896 +67.512962 +72.604065 +69.231712 +71.838814 +69.948318 +67.486206 +68.675743 +69.584450 +69.790436 +69.811684 +68.313988 +71.340195 +67.208893 +69.861984 +68.054848 +70.890274 +69.266434 +70.433060 +69.614014 +70.320610 +72.960480 +69.745316 +68.489662 +70.101471 +69.889854 +69.042114 +68.767105 +70.470627 +71.480003 +69.954620 +68.756126 +67.755966 +71.295006 +68.886208 +71.931519 +68.811966 +71.926941 +67.733887 +70.024704 +70.434364 +68.543678 +71.445694 +69.653793 +68.672287 +70.205406 +70.551262 +70.251076 +73.279266 +67.162338 +68.920418 +70.974846 +67.494972 +72.047005 +70.230270 +68.815613 +69.447197 +70.395203 +68.278915 +68.853920 +70.502304 +68.960579 +70.300705 +68.165504 +68.888672 +71.276192 +68.140671 +68.848450 +71.797340 +68.563423 +69.090561 +71.970848 +69.831619 +68.847870 +70.185471 +69.500481 +67.052284 +73.004578 +69.484642 +71.833122 +69.425667 +67.937538 +69.431999 +69.813828 +67.498116 +70.290947 +72.473152 +70.178398 +71.067360 +67.923203 +68.647873 +69.917633 +68.304222 +70.298782 +70.335518 +66.908829 +70.510590 +69.833374 +69.340225 +68.979362 +71.372223 +70.216835 +69.062592 +70.470047 +69.791649 +76.842690 +69.775330 +71.518684 +73.874496 +72.533981 +70.487518 +73.335487 +68.485374 +70.550880 +71.410782 +70.567551 +73.272575 +69.970078 +69.857758 +68.849152 +69.832001 +71.090721 +68.265953 +67.354492 +67.684639 +70.329597 +71.256927 +69.166496 +68.420189 +71.607170 +69.418556 +69.941277 +70.833153 +70.612930 +70.566628 +68.957664 +73.596191 +68.887970 +66.742210 +71.571777 +69.711327 +70.408577 +71.400452 +69.459358 +69.302338 +72.166046 +67.705116 +68.804413 +71.544670 +68.408257 +67.886948 +70.060066 +67.251549 +70.259842 +72.292290 +68.437759 +68.880287 +69.630112 +68.138977 +73.203583 +69.452896 +70.527107 +69.233727 +68.740417 +69.523453 +68.579903 +69.397156 +70.846466 +70.966049 +70.014786 +69.112099 +71.603554 +70.540192 +67.552925 +72.151901 +69.929825 +67.592545 +71.200768 +68.036636 +69.779457 +69.853027 +69.231392 +67.892387 +70.751328 +73.616066 +69.921471 +71.671165 +68.764771 +68.726753 +68.938271 +69.327103 +69.434013 +69.293533 +67.072510 +69.302177 +70.436707 +69.746590 +69.503006 +69.821732 +68.513634 +72.725822 +72.704193 +68.609184 +69.546051 +69.032608 +69.261505 +70.269569 +69.982529 +67.919586 +70.465187 +70.240959 +71.924995 +69.987968 +67.759583 +68.504387 +68.486877 +69.324158 +67.761375 +69.556450 +67.947037 +72.707901 +71.025917 +68.271774 +72.356865 +68.993568 +72.342178 +78.688995 +69.329948 +69.423134 +70.908386 +71.164093 +73.607071 +68.194946 +70.695328 +69.749664 +69.289566 +68.373856 +69.744865 +73.749214 +69.285088 +67.856483 +71.672707 +69.397156 +68.631294 +70.643936 +67.696129 +69.536224 +71.095100 +68.591232 +71.007172 +69.194206 +68.204193 +72.525826 +68.759491 +69.643677 +70.349121 +69.936417 +66.434143 +72.180222 diff --git a/results/test1.2017-09-28_00-41-30z.5000samp.png b/results/test1.2017-09-28_00-41-30z.5000samp.png new file mode 100644 index 0000000..f6b86fb Binary files /dev/null and b/results/test1.2017-09-28_00-41-30z.5000samp.png differ diff --git a/results/test1.2017-09-28_00-50-21z.5000samp.png b/results/test1.2017-09-28_00-50-21z.5000samp.png new file mode 100644 index 0000000..be5b2c7 Binary files /dev/null and b/results/test1.2017-09-28_00-50-21z.5000samp.png differ diff --git a/results/test1.2017-09-29_22-02-26z.5000samp.png b/results/test1.2017-09-29_22-02-26z.5000samp.png new file mode 100644 index 0000000..fef28dc Binary files /dev/null and b/results/test1.2017-09-29_22-02-26z.5000samp.png differ diff --git a/results/test1.2017-09-29_22-39-27z.5000samp.png b/results/test1.2017-09-29_22-39-27z.5000samp.png new file mode 100644 index 0000000..f46de27 Binary files /dev/null and b/results/test1.2017-09-29_22-39-27z.5000samp.png differ diff --git a/results/test1.2017-10-01_06-21-18z.3507samp.png b/results/test1.2017-10-01_06-21-18z.3507samp.png new file mode 100644 index 0000000..e96a7f8 Binary files /dev/null and b/results/test1.2017-10-01_06-21-18z.3507samp.png differ diff --git a/results/title.jpg b/results/title.jpg new file mode 100644 index 0000000..8ee0404 Binary files /dev/null and b/results/title.jpg differ diff --git a/results/with_anti.JPG b/results/with_anti.JPG new file mode 100644 index 0000000..48402a3 Binary files /dev/null and b/results/with_anti.JPG differ diff --git a/results/without_anti.JPG b/results/without_anti.JPG new file mode 100644 index 0000000..c024b4f Binary files /dev/null and b/results/without_anti.JPG differ diff --git a/scenes/cornell.txt b/scenes/cornell.txt index 83ff820..f8277d6 100644 --- a/scenes/cornell.txt +++ b/scenes/cornell.txt @@ -43,7 +43,7 @@ MATERIAL 4 RGB .98 .98 .98 SPECEX 0 SPECRGB .98 .98 .98 -REFL 1 +REFL 0 REFR 0 REFRIOR 0 EMITTANCE 0 @@ -58,7 +58,8 @@ FILE cornell EYE 0.0 5 10.5 LOOKAT 0 5 0 UP 0 1 0 - +FOCALLEN 9.0 +LENSRAD 1.0 // Ceiling light OBJECT 0 @@ -67,6 +68,7 @@ material 0 TRANS 0 10 0 ROTAT 0 0 0 SCALE 3 .3 3 +TRANS_END 0 10 0 // Floor OBJECT 1 @@ -75,6 +77,7 @@ material 1 TRANS 0 0 0 ROTAT 0 0 0 SCALE 10 .01 10 +TRANS_END 0 0 0 // Ceiling OBJECT 2 @@ -83,6 +86,7 @@ material 1 TRANS 0 10 0 ROTAT 0 0 90 SCALE .01 10 10 +TRANS_END 0 10 0 // Back wall OBJECT 3 @@ -91,6 +95,7 @@ material 1 TRANS 0 5 -5 ROTAT 0 90 0 SCALE .01 10 10 +TRANS_END 0 5 -5 // Left wall OBJECT 4 @@ -99,6 +104,7 @@ material 2 TRANS -5 5 0 ROTAT 0 0 0 SCALE .01 10 10 +TRANS_END -5 5 0 // Right wall OBJECT 5 @@ -107,6 +113,7 @@ material 3 TRANS 5 5 0 ROTAT 0 0 0 SCALE .01 10 10 +TRANS_END 5 5 0 // Sphere OBJECT 6 @@ -115,3 +122,4 @@ material 4 TRANS -1 4 -1 ROTAT 0 0 0 SCALE 3 3 3 +TRANS_END 0 3 -1 diff --git a/scenes/cornell_closed.txt b/scenes/cornell_closed.txt new file mode 100644 index 0000000..11a9aea --- /dev/null +++ b/scenes/cornell_closed.txt @@ -0,0 +1,134 @@ +// Emissive material (light) +MATERIAL 0 +RGB 1 1 1 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 5 + +// Diffuse white +MATERIAL 1 +RGB .98 .98 .98 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Diffuse red +MATERIAL 2 +RGB .85 .35 .35 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Diffuse green +MATERIAL 3 +RGB .35 .85 .35 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Specular white +MATERIAL 4 +RGB .98 .98 .98 +SPECEX 0 +SPECRGB .98 .98 .98 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Camera +CAMERA +RES 800 800 +FOVY 45 +ITERATIONS 5000 +DEPTH 8 +FILE cornell +EYE 0.0 5 4.9 +LOOKAT 0 5 0 +UP 0 1 0 +FOCALLEN 9.0 +LENSRAD 1.0 + +// Ceiling light +OBJECT 0 +cube +material 0 +TRANS 0 10 0 +ROTAT 0 0 0 +SCALE 3 .3 3 +TRANS_END 0 10 0 + +// Floor +OBJECT 1 +cube +material 1 +TRANS 0 0 0 +ROTAT 0 0 0 +SCALE 10 .01 10 +TRANS_END 0 0 0 + +// Ceiling +OBJECT 2 +cube +material 1 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .01 10 10 +TRANS_END 0 10 0 + +// Back wall +OBJECT 3 +cube +material 1 +TRANS 0 5 -5 +ROTAT 0 90 0 +SCALE .01 10 10 +TRANS_END 0 5 -5 + +// Left wall +OBJECT 4 +cube +material 2 +TRANS -5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +TRANS_END -5 5 0 + +// Right wall +OBJECT 5 +cube +material 3 +TRANS 5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +TRANS_END 5 5 0 + +// Sphere +OBJECT 6 +sphere +material 4 +TRANS -1 4 -2 +ROTAT 0 0 0 +SCALE 3 3 3 +TRANS_END 0 3 -1 + +// Front wall +OBJECT 7 +cube +material 1 +TRANS 0 5 5 +ROTAT 0 90 0 +SCALE .01 10 10 +TRANS_END 0 5 -5 diff --git a/scenes/mesh_load_refraction.txt b/scenes/mesh_load_refraction.txt new file mode 100644 index 0000000..6b1b977 --- /dev/null +++ b/scenes/mesh_load_refraction.txt @@ -0,0 +1,136 @@ +// Emissive material (light) +MATERIAL 0 +RGB 1 1 1 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 6 + +// Diffuse white +MATERIAL 1 +RGB .98 .98 .98 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Diffuse red +MATERIAL 2 +RGB .85 .35 .35 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Diffuse green +MATERIAL 3 +RGB .35 .85 .35 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Specular white +MATERIAL 4 +RGB .98 .98 .98 +SPECEX 0 +SPECRGB .98 .98 .98 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Refraction +MATERIAL 5 +RGB .50 .75 .98 +SPECEX 0 +SPECRGB .98 .98 .98 +REFL 0 +REFR 1 +REFRIOR 1.5 +EMITTANCE 0 + +// Camera +CAMERA +RES 800 800 +FOVY 45 +ITERATIONS 5000 +DEPTH 8 +FILE cornell +EYE 0.0 5 10.5 +LOOKAT 0 5 0 +UP 0 1 0 +FOCALLEN 9.0 +LENSRAD 1.0 + +// Ceiling light +OBJECT 0 +cube +material 0 +TRANS 0 10 0 +ROTAT 0 0 0 +SCALE 3 .3 3 +TRANS_END 0 10 0 + +// Floor +OBJECT 1 +cube +material 1 +TRANS 0 0 0 +ROTAT 0 0 0 +SCALE 10 .01 10 +TRANS_END 0 0 0 + +// Ceiling +OBJECT 2 +cube +material 1 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .01 10 10 +TRANS_END 0 10 0 + +// Back wall +OBJECT 3 +cube +material 1 +TRANS 0 5 -5 +ROTAT 0 90 0 +SCALE .01 10 10 +TRANS_END 0 5 -5 + +// Left wall +OBJECT 4 +cube +material 2 +TRANS -5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +TRANS_END -5 5 0 + +// Right wall +OBJECT 5 +cube +material 3 +TRANS 5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +TRANS_END 5 5 0 + +// Mesh +OBJECT 6 +mesh +material 5 +TRANS 0 1.5 0 +ROTAT 0 0 0 +SCALE 2 2 2 +TRANS_END 0 3 -1 +OBJ_PATH bunny_smoothed.obj \ No newline at end of file diff --git a/scenes/sphere.txt b/scenes/sphere.txt index a74b545..9d93d28 100644 --- a/scenes/sphere.txt +++ b/scenes/sphere.txt @@ -18,6 +18,8 @@ FILE sphere EYE 0.0 5 10.5 LOOKAT 0 5 0 UP 0 1 0 +FOCALLEN 9.0 +LENSRAD 1.0 // Sphere OBJECT 0 diff --git a/scenes/test1.txt b/scenes/test1.txt new file mode 100644 index 0000000..390fb8a --- /dev/null +++ b/scenes/test1.txt @@ -0,0 +1,188 @@ +// Emissive material (light) +MATERIAL 0 +RGB 1 1 1 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 5 + +// Diffuse white +MATERIAL 1 +RGB .98 .98 .98 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Diffuse red +MATERIAL 2 +RGB .85 .35 .35 +SPECEX 0 +SPECRGB .85 .35 .35 +REFL 1 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Diffuse green +MATERIAL 3 +RGB .35 .85 .35 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Specular white +MATERIAL 4 +RGB .98 .98 .20 +SPECEX 0 +SPECRGB .98 .98 .98 +REFL 0 +REFR 1 +REFRIOR 1.4 +EMITTANCE 0 + +// Camera +CAMERA +RES 800 800 +FOVY 45 +ITERATIONS 5000 +DEPTH 8 +FILE test1 +EYE 0.0 5 10.5 +LOOKAT 0 5 0 +UP 0 1 0 +FOCALLEN 20 +LENSRAD 0.5 + +// Ceiling light +OBJECT 0 +cube +material 0 +TRANS 0 10 0 +ROTAT 0 0 0 +SCALE 3 .3 3 +TRANS_END 0 10 0 + +// Floor +OBJECT 1 +cube +material 1 +TRANS 0 0 0 +ROTAT 0 0 0 +SCALE 10 .01 10 +TRANS_END 0 0 0 + +// Ceiling +OBJECT 2 +cube +material 1 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .01 10 10 +TRANS_END 0 10 0 + +// Back wall +OBJECT 3 +cube +material 1 +TRANS 0 5 -15 +ROTAT 0 90 0 +SCALE .01 10 10 +TRANS_END 0 5 -15 + +// Left wall +OBJECT 4 +cube +material 2 +TRANS -5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +TRANS_END -5 5 0 + +// Right wall +OBJECT 5 +cube +material 3 +TRANS 5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +TRANS_END 5 5 0 + +// Sphere +OBJECT 6 +sphere +material 4 +TRANS -1 4 -1 +ROTAT 0 0 0 +SCALE 3 3 3 +TRANS_END -1.5 2 -1 + +// Ceiling light +OBJECT 7 +cube +material 0 +TRANS 0 10 -5 +ROTAT 0 0 0 +SCALE 3 .3 3 +TRANS_END 0 10 -5 + +// Floor +OBJECT 8 +cube +material 1 +TRANS 0 0 -10 +ROTAT 0 0 0 +SCALE 10 .01 10 +TRANS_END 0 0 -10 + +// Ceiling +OBJECT 9 +cube +material 1 +TRANS 0 10 -10 +ROTAT 0 0 90 +SCALE .01 10 10 +TRANS_END 0 10 -10 + +// Left wall +OBJECT 10 +cube +material 2 +TRANS -5 5 -10 +ROTAT 0 0 0 +SCALE .01 10 10 +TRANS_END -5 5 -10 + +// Right wall +OBJECT 11 +cube +material 3 +TRANS 5 5 -10 +ROTAT 0 0 0 +SCALE .01 10 10 +TRANS_END 5 5 -10 + +// Cube +OBJECT 12 +cube +material 1 +TRANS 2 4 -10 +ROTAT 0 45 45 +SCALE 3 3 3 +TRANS_END 2 4 -10 + +// Ceiling light +OBJECT 13 +cube +material 0 +TRANS 0 10 -10 +ROTAT 0 0 0 +SCALE 3 .3 3 +TRANS_END 0 10 -10 diff --git a/scenes/test_complicated.txt b/scenes/test_complicated.txt new file mode 100644 index 0000000..f3ad8c8 --- /dev/null +++ b/scenes/test_complicated.txt @@ -0,0 +1,218 @@ +// Emissive material (light) +MATERIAL 0 +RGB 1 1 1 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 6 + +// Diffuse white +MATERIAL 1 +RGB .98 .98 .98 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Diffuse red +MATERIAL 2 +RGB .85 .35 .35 +SPECEX 0 +SPECRGB .85 .35 .35 +REFL 1 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Diffuse green +MATERIAL 3 +RGB .35 .85 .35 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Refraction Yellow +MATERIAL 4 +RGB .98 .98 .20 +SPECEX 0 +SPECRGB .98 .98 .98 +REFL 0 +REFR 1 +REFRIOR 1.4 +EMITTANCE 0 + +// Specullar White +MATERIAL 5 +RGB .98 .98 .98 +SPECEX 0 +SPECRGB .98 .98 .98 +REFL 1 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Diffuse Blue +MATERIAL 6 +RGB .50 .75 .98 +SPECEX 0 +SPECRGB .98 .98 .98 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Camera +CAMERA +RES 800 800 +FOVY 45 +ITERATIONS 5000 +DEPTH 8 +FILE test1 +EYE 0.0 5 10.5 +LOOKAT 0 5 0 +UP 0 1 0 +FOCALLEN 20 +LENSRAD 0.5 + +// Ceiling light +OBJECT 0 +cube +material 0 +TRANS 0 10 0 +ROTAT 0 0 0 +SCALE 3 .3 3 +TRANS_END 0 10 0 + +// Floor +OBJECT 1 +cube +material 1 +TRANS 0 0 0 +ROTAT 0 0 0 +SCALE 10 .01 10 +TRANS_END 0 0 0 + +// Ceiling +OBJECT 2 +cube +material 1 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .01 10 10 +TRANS_END 0 10 0 + +// Back wall +OBJECT 3 +cube +material 1 +TRANS 0 5 -15 +ROTAT 0 90 0 +SCALE .01 10 10 +TRANS_END 0 5 -15 + +// Left wall +OBJECT 4 +cube +material 2 +TRANS -5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +TRANS_END -5 5 0 + +// Right wall +OBJECT 5 +cube +material 3 +TRANS 5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +TRANS_END 5 5 0 + +// Bunny +OBJECT 6 +mesh +material 4 +TRANS -1 1.0 0 +ROTAT 0 0 0 +SCALE 2 2 2 +TRANS_END 0 3 -1 +OBJ_PATH bunny_smoothed.obj + +// Ceiling light +OBJECT 7 +cube +material 0 +TRANS 0 10 -5 +ROTAT 0 0 0 +SCALE 3 .3 3 +TRANS_END 0 10 -5 + +// Floor +OBJECT 8 +cube +material 1 +TRANS 0 0 -10 +ROTAT 0 0 0 +SCALE 10 .01 10 +TRANS_END 0 0 -10 + +// Ceiling +OBJECT 9 +cube +material 1 +TRANS 0 10 -10 +ROTAT 0 0 90 +SCALE .01 10 10 +TRANS_END 0 10 -10 + +// Left wall +OBJECT 10 +cube +material 2 +TRANS -5 5 -10 +ROTAT 0 0 0 +SCALE .01 10 10 +TRANS_END -5 5 -10 + +// Right wall +OBJECT 11 +cube +material 3 +TRANS 5 5 -10 +ROTAT 0 0 0 +SCALE .01 10 10 +TRANS_END 5 5 -10 + +// Cube +OBJECT 12 +cube +material 5 +TRANS 2 4 -10 +ROTAT 0 45 45 +SCALE 3 3 3 +TRANS_END 2 4 -10 + +// Ceiling light +OBJECT 13 +cube +material 0 +TRANS 0 10 -10 +ROTAT 0 0 0 +SCALE 3 .3 3 +TRANS_END 0 10 -10 + +// Sphere +OBJECT 14 +sphere +material 6 +TRANS 2 1 0 +ROTAT 0 0 0 +SCALE 2 2 2 +TRANS_END 2 4 -10 diff --git a/scenes/test_dof.txt b/scenes/test_dof.txt new file mode 100644 index 0000000..bb1547d --- /dev/null +++ b/scenes/test_dof.txt @@ -0,0 +1,237 @@ +// Emissive material (light) +MATERIAL 0 +RGB 1 1 1 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 6 + +// Diffuse white +MATERIAL 1 +RGB .98 .98 .98 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Diffuse red +MATERIAL 2 +RGB .85 .35 .35 +SPECEX 0 +SPECRGB .85 .35 .35 +REFL 1 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Diffuse green +MATERIAL 3 +RGB .35 .85 .35 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Specular white +MATERIAL 4 +RGB .98 .98 .98 +SPECEX 0 +SPECRGB .98 .98 .98 +REFL 0 +REFR 1 +REFRIOR 1.4 +EMITTANCE 0 + +// Camera +CAMERA +RES 800 800 +FOVY 45 +ITERATIONS 5000 +DEPTH 8 +FILE cornell +EYE 0.0 5 10.5 +LOOKAT 0 5 0 +UP 0 1 0 +FOCALLEN 10 +LENSRAD 0.5 + +// Ceiling light +OBJECT 0 +cube +material 0 +TRANS 0 10 0 +ROTAT 0 0 0 +SCALE 3 .3 3 +TRANS_END 0 10 0 + +// Floor +OBJECT 1 +cube +material 1 +TRANS 0 0 0 +ROTAT 0 0 0 +SCALE 10 .01 10 +TRANS_END 0 0 0 + +// Ceiling +OBJECT 2 +cube +material 1 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .01 10 10 +TRANS_END 0 10 0 + +// Back wall +OBJECT 3 +cube +material 1 +TRANS 0 5 -15 +ROTAT 0 90 0 +SCALE .01 10 10 +TRANS_END 0 5 -15 + +// Left wall +OBJECT 4 +cube +material 2 +TRANS -5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +TRANS_END -5 5 0 + +// Right wall +OBJECT 5 +cube +material 3 +TRANS 5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +TRANS_END 5 5 0 + +// Sphere +OBJECT 6 +sphere +material 1 +TRANS -1 4 0 +ROTAT 0 0 0 +SCALE 1 1 1 +TRANS_END -1.5 2 -1 + +// Ceiling light +OBJECT 7 +cube +material 0 +TRANS 0 10 -5 +ROTAT 0 0 0 +SCALE 3 .3 3 +TRANS_END 0 10 -5 + +// Floor +OBJECT 8 +cube +material 1 +TRANS 0 0 -10 +ROTAT 0 0 0 +SCALE 10 .01 10 +TRANS_END 0 0 -10 + +// Ceiling +OBJECT 9 +cube +material 1 +TRANS 0 10 -10 +ROTAT 0 0 90 +SCALE .01 10 10 +TRANS_END 0 10 -10 + +// Left wall +OBJECT 10 +cube +material 2 +TRANS -5 5 -10 +ROTAT 0 0 0 +SCALE .01 10 10 +TRANS_END -5 5 -10 + +// Right wall +OBJECT 11 +cube +material 3 +TRANS 5 5 -10 +ROTAT 0 0 0 +SCALE .01 10 10 +TRANS_END 5 5 -10 + +// Sphere +OBJECT 12 +sphere +material 1 +TRANS -1 4 2 +ROTAT 0 45 45 +SCALE 1 1 1 +TRANS_END 2 4 -10 + +// Ceiling light +OBJECT 13 +cube +material 0 +TRANS 0 10 -10 +ROTAT 0 0 0 +SCALE 3 .3 3 +TRANS_END 0 10 -10 + + +// Sphere +OBJECT 14 +sphere +material 1 +TRANS -1 4 4 +ROTAT 0 45 45 +SCALE 1 1 1 +TRANS_END 2 4 -10 + + +// Sphere +OBJECT 15 +sphere +material 1 +TRANS -1 4 6 +ROTAT 0 45 45 +SCALE 1 1 1 +TRANS_END 2 4 -10 + + +// Sphere +OBJECT 16 +sphere +material 1 +TRANS -1 4 -2 +ROTAT 0 45 45 +SCALE 1 1 1 +TRANS_END 2 4 -10 + +// Sphere +OBJECT 17 +sphere +material 1 +TRANS -1 4 -4 +ROTAT 0 45 45 +SCALE 1 1 1 +TRANS_END 2 4 -10 + +// Sphere +OBJECT 18 +sphere +material 1 +TRANS -1 4 -6 +ROTAT 0 45 45 +SCALE 1 1 1 +TRANS_END 2 4 -10 + diff --git a/scenes/test_mesh_load.txt b/scenes/test_mesh_load.txt new file mode 100644 index 0000000..60fdd04 --- /dev/null +++ b/scenes/test_mesh_load.txt @@ -0,0 +1,126 @@ +// Emissive material (light) +MATERIAL 0 +RGB 1 1 1 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 5 + +// Diffuse white +MATERIAL 1 +RGB .98 .98 .98 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Diffuse red +MATERIAL 2 +RGB .85 .35 .35 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Diffuse green +MATERIAL 3 +RGB .35 .85 .35 +SPECEX 0 +SPECRGB 0 0 0 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Specular white +MATERIAL 4 +RGB .98 .98 .98 +SPECEX 0 +SPECRGB .98 .98 .98 +REFL 0 +REFR 0 +REFRIOR 0 +EMITTANCE 0 + +// Camera +CAMERA +RES 800 800 +FOVY 45 +ITERATIONS 5000 +DEPTH 8 +FILE test_bunny_load +EYE 0.0 5 10.5 +LOOKAT 0 5 0 +UP 0 1 0 +FOCALLEN 9.0 +LENSRAD 1.0 + +// Ceiling light +OBJECT 0 +cube +material 0 +TRANS 0 10 0 +ROTAT 0 0 0 +SCALE 3 .3 3 +TRANS_END 0 10 0 + +// Floor +OBJECT 1 +cube +material 1 +TRANS 0 0 0 +ROTAT 0 0 0 +SCALE 10 .01 10 +TRANS_END 0 0 0 + +// Ceiling +OBJECT 2 +cube +material 1 +TRANS 0 10 0 +ROTAT 0 0 90 +SCALE .01 10 10 +TRANS_END 0 10 0 + +// Back wall +OBJECT 3 +cube +material 1 +TRANS 0 5 -5 +ROTAT 0 90 0 +SCALE .01 10 10 +TRANS_END 0 5 -5 + +// Left wall +OBJECT 4 +cube +material 2 +TRANS -5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +TRANS_END -5 5 0 + +// Right wall +OBJECT 5 +cube +material 3 +TRANS 5 5 0 +ROTAT 0 0 0 +SCALE .01 10 10 +TRANS_END 5 5 0 + +// Mesh +OBJECT 6 +mesh +material 1 +TRANS 0 2 3 +ROTAT 0 0 0 +SCALE 20 20 20 +TRANS_END 0 3 -1 +OBJ_PATH bunny.obj \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a1cb3fb..d1a8649 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,6 +15,18 @@ set(SOURCE_FILES "preview.cpp" "utilities.cpp" "utilities.h" + "common.h" + "common.cu" + "cpu.h" + "cpu.cu" + "naive.h" + "naive.cu" + "efficient.h" + "efficient.cu" + "thrust.h" + "thrust.cu" + "radix.cu" + "radix.h" ) cuda_add_library(src diff --git a/src/Setting_defines.h b/src/Setting_defines.h new file mode 100644 index 0000000..672eede --- /dev/null +++ b/src/Setting_defines.h @@ -0,0 +1,10 @@ +#pragma once +#define Caching_Toggle 1 +#define Sorting_Toggle 0 +#define AntiAliasing_Toggle 1 +#define MotionBlur_Toggle 0 +#define Depth_Of_Field_Toggle 0 +#define Bounding_Box_Toggle 1 +#define AABB_Test_Toggle 1 +#define Smooth_Shading_Toggle 1 +#define Direct_Light_Toggle 0 \ No newline at end of file diff --git a/src/common.cu b/src/common.cu new file mode 100644 index 0000000..355d86b --- /dev/null +++ b/src/common.cu @@ -0,0 +1,51 @@ +#include "common.h" + +//void checkCUDAErrorFn(const char *msg, const char *file, int line) { +// cudaError_t err = cudaGetLastError(); +// if (cudaSuccess == err) { +// return; +// } +// +// fprintf(stderr, "CUDA error"); +// if (file) { +// fprintf(stderr, " (%s:%d)", file, line); +// } +// fprintf(stderr, ": %s: %s\n", msg, cudaGetErrorString(err)); +// exit(EXIT_FAILURE); +//} + + +namespace StreamCompaction { + namespace Common { + + /** + * Maps an array to an array of 0s and 1s for stream compaction. Elements + * which map to 0 will be removed, and elements which map to 1 will be kept. + */ + __global__ void kernMapToBoolean(int n, int *bools, const int *idata) { + // TODO + int index = threadIdx.x + (blockIdx.x * blockDim.x); + if (index >= n) + return; + + if (idata[index]) + bools[index] = true; + } + + /** + * Performs scatter on an array. That is, for each element in idata, + * if bools[idx] == 1, it copies idata[idx] to odata[indices[idx]]. + */ + __global__ void kernScatter(int n, int *odata, + const int *idata, const int *bools, const int *indices) { + // TODO + int index = threadIdx.x + (blockIdx.x * blockDim.x); + if (index >= n) + return; + + if (bools[index]) + odata[indices[index]] = idata[index]; + } + + } +} diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..30d7c28 --- /dev/null +++ b/src/common.h @@ -0,0 +1,132 @@ +#pragma once + +#include +#include + +#include +#include +#include +#include +#include +#include + +#define FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) +#define checkCUDAError(msg) checkCUDAErrorFn(msg, FILENAME, __LINE__) + +/** + * Check for CUDA errors; print and exit if there was a problem. + */ +void checkCUDAErrorFn(const char *msg, const char *file = NULL, int line = -1); + +inline int ilog2(int x) { + int lg = 0; + while (x >>= 1) { + ++lg; + } + return lg; +} + +inline int ilog2ceil(int x) { + return ilog2(x - 1) + 1; +} + +namespace StreamCompaction { + namespace Common { + __global__ void kernMapToBoolean(int n, int *bools, const int *idata); + + __global__ void kernScatter(int n, int *odata, + const int *idata, const int *bools, const int *indices); + + /** + * This class is used for timing the performance + * Uncopyable and unmovable + * + * Adapted from WindyDarian(https://github.com/WindyDarian) + */ + class PerformanceTimer + { + public: + PerformanceTimer() + { + cudaEventCreate(&event_start); + cudaEventCreate(&event_end); + } + + ~PerformanceTimer() + { + cudaEventDestroy(event_start); + cudaEventDestroy(event_end); + } + + void startCpuTimer() + { + if (cpu_timer_started) { throw std::runtime_error("CPU timer already started"); } + cpu_timer_started = true; + + time_start_cpu = std::chrono::high_resolution_clock::now(); + } + + void endCpuTimer() + { + time_end_cpu = std::chrono::high_resolution_clock::now(); + + if (!cpu_timer_started) { throw std::runtime_error("CPU timer not started"); } + + std::chrono::duration duro = time_end_cpu - time_start_cpu; + prev_elapsed_time_cpu_milliseconds = + static_cast(duro.count()); + + cpu_timer_started = false; + } + + void startGpuTimer() + { + if (gpu_timer_started) { throw std::runtime_error("GPU timer already started"); } + gpu_timer_started = true; + + cudaEventRecord(event_start); + } + + void endGpuTimer() + { + cudaEventRecord(event_end); + cudaEventSynchronize(event_end); + + if (!gpu_timer_started) { throw std::runtime_error("GPU timer not started"); } + + cudaEventElapsedTime(&prev_elapsed_time_gpu_milliseconds, event_start, event_end); + gpu_timer_started = false; + } + + float getCpuElapsedTimeForPreviousOperation() //noexcept //(damn I need VS 2015 + { + return prev_elapsed_time_cpu_milliseconds; + } + + float getGpuElapsedTimeForPreviousOperation() //noexcept + { + return prev_elapsed_time_gpu_milliseconds; + } + + // remove copy and move functions + PerformanceTimer(const PerformanceTimer&) = delete; + PerformanceTimer(PerformanceTimer&&) = delete; + PerformanceTimer& operator=(const PerformanceTimer&) = delete; + PerformanceTimer& operator=(PerformanceTimer&&) = delete; + + private: + cudaEvent_t event_start = nullptr; + cudaEvent_t event_end = nullptr; + + using time_point_t = std::chrono::high_resolution_clock::time_point; + time_point_t time_start_cpu; + time_point_t time_end_cpu; + + bool cpu_timer_started = false; + bool gpu_timer_started = false; + + float prev_elapsed_time_cpu_milliseconds = 0.f; + float prev_elapsed_time_gpu_milliseconds = 0.f; + }; + } +} diff --git a/src/cpu.cu b/src/cpu.cu new file mode 100644 index 0000000..41af197 --- /dev/null +++ b/src/cpu.cu @@ -0,0 +1,87 @@ +#include +#include "cpu.h" + +#include "common.h" + +namespace StreamCompaction { + namespace CPU { + using StreamCompaction::Common::PerformanceTimer; + PerformanceTimer& timer() + { + static PerformanceTimer timer; + return timer; + } + + /** + * CPU scan (prefix sum). + * For performance analysis, this is supposed to be a simple for loop. + * (Optional) For better understanding before starting moving to GPU, you can simulate your GPU scan in this function first. + */ + void scan(int n, int *odata, const int *idata, bool timer_on) { + if(timer_on) + timer().startCpuTimer(); + // TODO + /*int test[8] = { 3,1,7,0,4,1,6,3 }; + int test_results[8] = {}; + + test_results[0] = 0; + for (int k = 1; k < 8; k++) { + test_results[k] = test_results[k - 1] + test[k - 1]; + } + */ + if (n <= 0) + return; + odata[0] = 0; + for (int k = 1; k < n; k++) { + odata[k] = odata[k - 1] + idata[k - 1]; + } + if(timer_on) + timer().endCpuTimer(); + } + + /** + * CPU stream compaction without using the scan function. + * + * @returns the number of elements remaining after compaction. + */ + int compactWithoutScan(int n, int *odata, const int *idata) { + timer().startCpuTimer(); + // TODO + if (n <= 0) + return 0; + int count = 0; + for (int k = 0; k < n; k++) { + if (idata[k]) + odata[count++] = idata[k]; + } + timer().endCpuTimer(); + return count; + } + + /** + * CPU stream compaction using scan and scatter, like the parallel version. + * + * @returns the number of elements remaining after compaction. + */ + int compactWithScan(int n, int *odata, const int *idata) { + timer().startCpuTimer(); + // TODO + int *check_array = new int[n]; + for (int k = 0; k < n; k++) { + if (idata[k]) + check_array[k] = 1; + else + check_array[k] = 0; + } + scan(n, odata, check_array, false); + delete check_array; + int count = odata[n - 1] + idata[n - 1]; + for (int k = 0; k < n; k++) { + if (idata[k]) + odata[odata[k]] = idata[k]; + } + timer().endCpuTimer(); + return count; + } + } +} diff --git a/src/cpu.h b/src/cpu.h new file mode 100644 index 0000000..c0fa2f1 --- /dev/null +++ b/src/cpu.h @@ -0,0 +1,15 @@ +#pragma once + +#include "common.h" + +namespace StreamCompaction { + namespace CPU { + StreamCompaction::Common::PerformanceTimer& timer(); + + void scan(int n, int *odata, const int *idata, bool timer_on); + + int compactWithoutScan(int n, int *odata, const int *idata); + + int compactWithScan(int n, int *odata, const int *idata); + } +} diff --git a/src/efficient.cu b/src/efficient.cu new file mode 100644 index 0000000..2be5338 --- /dev/null +++ b/src/efficient.cu @@ -0,0 +1,242 @@ +#include +#include +#include "common.h" +#include "efficient.h" +#include "sceneStructs.h" + +static int blockSize = 1024; +static dim3 blockNum; + +namespace StreamCompaction { + namespace Efficient { + using StreamCompaction::Common::PerformanceTimer; + PerformanceTimer& timer() + { + static PerformanceTimer timer; + return timer; + } + + /** + * Performs prefix-sum (aka scan) on idata, storing the result into odata. + */ +//Non-optimized Scan: + __global__ void non_opt_cudaSweepUp(int n, int d, int *data) { + int index = threadIdx.x + (blockIdx.x * blockDim.x); + int interval_length = 1 << (d + 1); + if (index >= n) + return; + if (index % interval_length == 0) { + data[index + (1 << (d + 1)) - 1] += data[index + (1 << d) - 1]; + } + } + + __global__ void non_opt_cudaSweepDown(int n, int d, int *data) { + int index = threadIdx.x + (blockIdx.x * blockDim.x); + int interval_length = 1 << (d + 1); + // k from 0 to n-1 + if (index >= n) + return; + if (index % interval_length == 0) { + int temp = data[index + (1 << d) - 1]; + data[index + (1 << d) - 1] = data[index + (1 << (d + 1)) - 1]; + data[index + (1 << (d + 1)) - 1] += temp; + } + } + + void non_opt_scan(int n, int *odata, const int *idata) { + // TODO + if (n <= 0) + return; + int celllog = ilog2ceil(n); + + int pow2len = 1 << celllog; + + int *dev_data; + cudaMalloc((void**)&dev_data, pow2len * sizeof(int)); + checkCUDAError("cudaMalloc dev_data failed!"); + + cudaMemcpy(dev_data, idata, pow2len * sizeof(int), cudaMemcpyHostToDevice); + checkCUDAError("cudaMemcpy failed!"); + + timer().startGpuTimer(); + + //Up-Sweep + for (int d = 0; d <= celllog - 1; d++) { + blockNum = (pow2len + blockSize) / blockSize; + non_opt_cudaSweepUp << > >(pow2len, d, dev_data); + } + + //cudaMemcpy(odata, dev_data, n * sizeof(int), cudaMemcpyDeviceToHost); + + //Down-Sweep + cudaMemset(dev_data + pow2len - 1, 0, sizeof(int)); + checkCUDAError("cudaMemset failed!"); + + for (int d = celllog - 1; d >= 0; d--) { + blockNum = (pow2len + blockSize) / blockSize; + non_opt_cudaSweepDown << > >(pow2len, d, dev_data); + } + timer().endGpuTimer(); + + cudaMemcpy(odata, dev_data, n * sizeof(int), cudaMemcpyDeviceToHost); + + checkCUDAError("cudaMalloc dev_data to odata failed!"); + + cudaFree(dev_data); + checkCUDAError("cudaFree dev_data failed!"); + + } + +//Optimized Scan + __global__ void cudaSweepUp(int n, int d, int *data) { + int index = threadIdx.x + (blockIdx.x * blockDim.x); + int interval_length = 1 << (d + 1); + if (index >= n) + return; + //int idx1 = index * interval_length + (1 << (d + 1)) - 1; + //int idx2 = index * interval_length + (1 << d) - 1; + data[index * interval_length + (1 << (d + 1)) - 1] += data[index * interval_length + (1 << d) - 1]; + } + + __global__ void cudaSweepDown(int n, int d, int *data) { + int index = threadIdx.x + (blockIdx.x * blockDim.x); + int interval_length = 1 << (d + 1); + // k from 0 to n-1 + if (index >= n) + return; + + int temp = data[index * interval_length + (1 << d) - 1]; + data[index * interval_length + (1 << d) - 1] = data[index * interval_length + (1 << (d + 1)) - 1]; + data[index * interval_length + (1 << (d + 1)) - 1] += temp; + } + + void scan(int n, int *odata, const int *idata) { + // TODO + if (n <= 0) + return; + int celllog = ilog2ceil(n); + + int pow2len = 1 << celllog; + + int *dev_data; + + cudaMalloc((void**)&dev_data, pow2len * sizeof(int)); + checkCUDAError("cudaMalloc dev_data failed!"); + + cudaMemcpy(dev_data, idata, pow2len * sizeof(int), cudaMemcpyHostToDevice); + checkCUDAError("cudaMemcpy failed!"); + + timer().startGpuTimer(); + + //Up-Sweep + for (int d = 0; d <= celllog - 1; d++) { + int interval_length = (1 << (d + 1)); + blockNum = (pow2len / interval_length + blockSize) / blockSize; + cudaSweepUp<<>>(pow2len / interval_length, d, dev_data); + } + + //cudaMemcpy(odata, dev_data, n * sizeof(int), cudaMemcpyDeviceToHost); + + //Down-Sweep + cudaMemset(dev_data + pow2len - 1, 0, sizeof(int)); + checkCUDAError("cudaMemset failed!"); + + for (int d = celllog - 1; d >= 0; d--) { + int num_operations = (1 << (d + 1)); + blockNum = (pow2len / num_operations + blockSize) / blockSize; + cudaSweepDown<<>>(pow2len / num_operations, d, dev_data); + } + timer().endGpuTimer(); + + cudaMemcpy(odata, dev_data, n * sizeof(int), cudaMemcpyDeviceToHost); + + checkCUDAError("cudaMmcpy dev_data to odata failed!"); + + cudaFree(dev_data); + checkCUDAError("cudaFree dev_data failed!"); + + } + + /** + * Performs stream compaction on idata, storing the result into odata. + * All zeroes are discarded. + * + * @param n The number of elements in idata. + * @param odata The array into which to store elements. + * @param idata The array of elements to compact. + * @returns The number of elements remaining after compaction. + */ + int compact(int n, int *odata, const int *idata) { + // TODO + if (n <= 0) + return -1; + int celllog = ilog2ceil(n); + int pow2len = 1 << celllog; + + int *dev_idata, *dev_odata, *dev_bool_data, *dev_indices; + cudaMalloc((void**)&dev_idata, pow2len * sizeof(int)); + checkCUDAError("cudaMalloc dev_idata failed!"); + cudaMalloc((void**)&dev_odata, pow2len * sizeof(int)); + checkCUDAError("cudaMalloc dev_odata failed!"); + cudaMalloc((void**)&dev_bool_data, pow2len * sizeof(int)); + checkCUDAError("cudaMalloc dev_bool_data failed!"); + cudaMalloc((void**)&dev_indices, pow2len * sizeof(int)); + checkCUDAError("cudaMalloc dev_indices failed!"); + + //bool Mapping + cudaMemcpy(dev_idata, idata, n * sizeof(int), cudaMemcpyHostToDevice); + timer().startGpuTimer(); + blockNum = (n + blockSize) / blockSize; + Common::kernMapToBoolean<<>>(n, dev_bool_data, dev_idata); + // Scan + cudaMemcpy(dev_indices, dev_bool_data, pow2len * sizeof(int), cudaMemcpyDeviceToDevice); + checkCUDAError("cudaMemcpy failed!"); + dev_bool_data; + + //Up-Sweep + for (int d = 0; d <= celllog - 1; d++) { + int interval_length = (1 << (d + 1)); + blockNum = (pow2len / interval_length + blockSize) / blockSize; + cudaSweepUp << > >(pow2len / interval_length, d, dev_indices); + } + + + //Down-Sweep + cudaMemset(dev_indices + pow2len - 1, 0, sizeof(int)); + checkCUDAError("cudaMemset failed!"); + + for (int d = celllog - 1; d >= 0; d--) { + int num_operations = (1 << (d + 1)); + blockNum = (pow2len / num_operations + blockSize) / blockSize; + cudaSweepDown << > >(pow2len / num_operations, d, dev_indices); + } + + + //Scattered + blockNum = (n + blockSize) / blockSize; + Common::kernScatter<<>>(n, dev_odata, dev_idata, dev_bool_data, dev_indices); + + timer().endGpuTimer(); + //compute count + int a, b; + cudaMemcpy(&a, dev_bool_data + (n - 1), sizeof(int), cudaMemcpyDeviceToHost); + cudaMemcpy(&b, dev_indices + (n - 1), sizeof(int), cudaMemcpyDeviceToHost); + int count = a + b; + cudaMemcpy(odata, dev_odata, count * sizeof(int), cudaMemcpyDeviceToHost); + checkCUDAError("cudaMemcpy dev_odata to odata failed!"); + + //Free data + cudaFree(dev_idata); + checkCUDAError("cudaFree dev_idata failed!"); + cudaFree(dev_odata); + checkCUDAError("cudaFree dev_idata failed!"); + cudaFree(dev_bool_data); + checkCUDAError("cudaFree dev_idata failed!"); + cudaFree(dev_indices); + checkCUDAError("cudaFree dev_idata failed!"); + + + return count; + } + } +} diff --git a/src/efficient.h b/src/efficient.h new file mode 100644 index 0000000..749bbef --- /dev/null +++ b/src/efficient.h @@ -0,0 +1,19 @@ +#pragma once + +#include "common.h" + +namespace StreamCompaction { + namespace Efficient { + StreamCompaction::Common::PerformanceTimer& timer(); + + void non_opt_scan(int n, int *odata, const int *idata); + + __global__ void cudaSweepUp(int n, int d, int *data); + + __global__ void cudaSweepDown(int n, int d, int *data); + + void scan(int n, int *odata, const int *idata); + + int compact(int n, int *odata, const int *idata); + } +} diff --git a/src/interactions.h b/src/interactions.h index 5ce3628..c453590 100644 --- a/src/interactions.h +++ b/src/interactions.h @@ -66,14 +66,71 @@ glm::vec3 calculateRandomDirectionInHemisphere( * * You may need to change the parameter list for your purposes! */ +#define Shift_Bias 0.02f + __host__ __device__ void scatterRay( PathSegment & pathSegment, glm::vec3 intersect, glm::vec3 normal, const Material &m, - thrust::default_random_engine &rng) { + thrust::default_random_engine &rng, + bool outside) { // TODO: implement this. // A basic implementation of pure-diffuse shading will just call the // calculateRandomDirectionInHemisphere defined above. + if (glm::dot(pathSegment.ray.direction, normal) > 0.0f && m.hasRefractive <= 0.001f) + { + pathSegment.color = glm::vec3(0.0f); + pathSegment.remainingBounces = 0; + return; + } + if (m.emittance > 0.0f) { + // emittance + pathSegment.is_terminated = true; + pathSegment.remainingBounces = 0; + pathSegment.color *= (m.color * m.emittance); + return; + } + else if (m.hasReflective > 0.0f) { + // Reflective + pathSegment.remainingBounces--; + pathSegment.ray.direction = glm::normalize(glm::reflect(pathSegment.ray.direction, normal)); + pathSegment.ray.origin = intersect + Shift_Bias * pathSegment.ray.direction; + pathSegment.color *= m.specular.color; + pathSegment.color *= glm::abs(glm::dot(pathSegment.ray.direction, normal)) * m.color; + } + else if (m.hasRefractive > 0.0f) { + // Refractive + pathSegment.remainingBounces--; + float eta = outside ? 1.0f / m.indexOfRefraction : m.indexOfRefraction; + + thrust::uniform_real_distribution u01(0, 1); + float random_flag = u01(rng); + + float cos_theta = abs(glm::dot(pathSegment.ray.direction, normal)); + float R0 = pow((1 - eta) / (1 + eta), 2); + float fresel = R0 + (1 - R0)*pow(1 - cos_theta, 5); + if (fresel > random_flag) { + pathSegment.ray.direction = glm::normalize(glm::reflect(pathSegment.ray.direction, normal)); + pathSegment.ray.origin = intersect + Shift_Bias * pathSegment.ray.direction; + pathSegment.color *= m.specular.color; + pathSegment.color *= glm::abs(glm::dot(pathSegment.ray.direction, normal)) * m.color; + } + else { + pathSegment.ray.direction = glm::normalize(glm::refract(pathSegment.ray.direction, normal, eta)); + pathSegment.ray.origin = intersect + Shift_Bias * pathSegment.ray.direction; + pathSegment.color *= m.color; + } + } + else{ + // Diffuse + pathSegment.remainingBounces--; + + pathSegment.ray.direction = glm::normalize(calculateRandomDirectionInHemisphere(normal, rng)); + pathSegment.ray.origin = intersect + Shift_Bias * pathSegment.ray.direction; + //pathSegment.ray.origin = intersect + Shift_Bias * normal; + //pathSegment.color *= glm::abs(glm::clamp(glm::dot(pathSegment.ray.direction, normal), 0.90f, 1.0f)) * m.color; + pathSegment.color *= m.color; + } } diff --git a/src/intersections.h b/src/intersections.h index 6f23872..a7a887a 100644 --- a/src/intersections.h +++ b/src/intersections.h @@ -6,6 +6,9 @@ #include "sceneStructs.h" #include "utilities.h" +//Toggles Defines +#include "Setting_defines.h" + /** * Handy-dandy hash function that provides seeds for random number generation. */ @@ -142,3 +145,127 @@ __host__ __device__ float sphereIntersectionTest(Geom sphere, Ray r, return glm::length(r.origin - intersectionPoint); } + +__host__ __device__ bool aabbBoxIntersect(const Ray& r, glm::vec3 min, glm::vec3 max) +{ + float tnear = FLT_MIN; + float tfar = FLT_MAX; + + for (int i = 0; i<3; i++) + { + float t0, t1; + + if (fabs(r.direction[i]) < EPSILON) + { + if (r.origin[i] < min[i] || r.origin[i] > max[i]) + return false; + else + { + t0 = FLT_MIN; + t1 = FLT_MAX; + } + } + else + { + t0 = (min[i] - r.origin[i]) / r.direction[i]; + t1 = (max[i] - r.origin[i]) / r.direction[i]; + } + + tnear = glm::max(tnear, glm::min(t0, t1)); + tfar = glm::min(tfar, glm::max(t0, t1)); + } + + if (tfar < tnear) return false; // no intersection + + if (tfar < 0) return false; // behind origin of ray + + return true; + +} + +__host__ __device__ float meshIntersectionTest(Geom mesh, Ray r, + glm::vec3 &intersectionPoint, glm::vec3 &normal, bool &outside, Vertex *vertices) { + + //world to local + Ray rt; + rt.origin = multiplyMV(mesh.inverseTransform, glm::vec4(r.origin, 1.0f)); + rt.direction = glm::normalize(multiplyMV(mesh.inverseTransform, glm::vec4(r.direction, 0.0f))); + +#if AABB_Test_Toggle + if (!aabbBoxIntersect(rt, mesh.bbox_min, mesh.bbox_max)) + return -1; +#endif + int start_index = mesh.start_Index; + int num_vertices = mesh.vertices_Num; + + float t = FLT_MAX; + + float u = 0, v = 0; + + for (int i = 0; i < num_vertices; i += 3) { + glm::vec3 baryPosition; + glm::vec3 v0, v1, v2; + v0 = vertices[start_index + i].position; + v1 = vertices[start_index + i + 1].position; + v2 = vertices[start_index + i + 2].position; + + // Front Face Intersection Checking + bool res = glm::intersectRayTriangle(rt.origin, rt.direction, v0, v1, v2, baryPosition); + float ti = FLT_MAX; + glm::vec3 intersectPoint = rt.origin + rt.direction * baryPosition.z; + u = baryPosition.x; + v = baryPosition.y; + + if (res) + ti = baryPosition.z; + if (ti < t) { + t = ti; +#if Smooth_Shading_Toggle + normal = (vertices[start_index + i].normal * (1 - u - v) + vertices[start_index + i + 1].normal * u + vertices[start_index + i + 2].normal * v); +#else + normal = (vertices[start_index + i].normal + vertices[start_index + i + 1].normal + vertices[start_index + i + 2].normal) / 3.0f; +#endif + intersectionPoint = intersectPoint; + } + // Back Face Intersection Checking + res = glm::intersectRayTriangle(rt.origin, rt.direction, v2, v1, v0, baryPosition); + ti = FLT_MAX; + intersectPoint = rt.origin + rt.direction * baryPosition.z; + u = baryPosition.x; + v = baryPosition.y; + + if (res) + ti = baryPosition.z; + if (ti < t) { + t = ti; +#if Smooth_Shading_Toggle + normal = (vertices[start_index + i + 2].normal * (1 - u - v) + vertices[start_index + i + 1].normal * u + vertices[start_index + i].normal * v); +#else + normal = (vertices[start_index + i].normal + vertices[start_index + i + 1].normal + vertices[start_index + i + 2].normal) / 3.0f; +#endif + intersectionPoint = intersectPoint; + } + } + + // no intersection + if (t == FLT_MAX) { + return -1; + } + + + if (glm::dot(rt.direction, normal) >= 0) { + outside = false; + normal = -normal; + } + else { + outside = true; + } + + //local to world + intersectionPoint = glm::vec3(multiplyMV(mesh.transform, glm::vec4(intersectionPoint, 1.0f))); + normal = glm::normalize(multiplyMV(mesh.invTranspose, glm::vec4(normal, 0.0f))); + //printf ("Hit Triangle: %f %f %f \n", intersectionPoint.x, intersectionPoint.y, intersectionPoint.z); + + + return glm::length(r.origin - intersectionPoint); +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index fe8e85e..e776102 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ #include "main.h" #include "preview.h" #include +#include static std::string startTimeString; @@ -19,6 +20,8 @@ float zoom, theta, phi; glm::vec3 cameraPosition; glm::vec3 ogLookAt; // for recentering the camera +FILE *fp; + Scene *scene; RenderState *renderState; int iteration; @@ -31,7 +34,10 @@ int height; //------------------------------- int main(int argc, char** argv) { - startTimeString = currentTimeString(); + + fp = fopen("results.txt", "w"); + + startTimeString = currentTimeString(); if (argc < 2) { printf("Usage: %s SCENEFILE.txt\n", argv[0]); diff --git a/src/naive.cu b/src/naive.cu new file mode 100644 index 0000000..1df1088 --- /dev/null +++ b/src/naive.cu @@ -0,0 +1,73 @@ +#include +#include +#include "common.h" +#include "naive.h" + +static int blockSize = 1024; +static dim3 blockNum; + +namespace StreamCompaction { + namespace Naive { + using StreamCompaction::Common::PerformanceTimer; + PerformanceTimer& timer() + { + static PerformanceTimer timer; + return timer; + } + // TODO: __global__ + __global__ void Parallel_Add(int n, int d, int *odata, const int *idata) { + int index = threadIdx.x + (blockIdx.x * blockDim.x); + + if (index >= n) + return; + + int flag = 1 << (d - 1); + if (index >= flag) { + odata[index] = idata[index - flag] + idata[index]; + } + else { + odata[index] = idata[index]; + } + + } + /** + * Performs prefix-sum (aka scan) on idata, storing the result into odata. + */ + void scan(int n, int *odata, const int *idata) { + // TODO + if (n <= 0) + return; + int celllog = ilog2ceil(n); + odata[0] = 0; + + int *dev_data[2]; + + cudaMalloc((void**)&dev_data[0], n * sizeof(int)); + checkCUDAError("cudaMalloc dev_data[0] failed!"); + + cudaMalloc((void**)&dev_data[1], n * sizeof(int)); + checkCUDAError("cudaMalloc dev_data[1] failed!"); + + cudaMemcpy(dev_data[0], idata, n * sizeof(int), cudaMemcpyHostToDevice); + checkCUDAError("cudaMemcpy failed!"); + + timer().startGpuTimer(); + int out_index = 0; + + blockNum = (n + blockSize - 1) / blockSize; + for (int d = 1; d <= celllog; d++) { + out_index ^= 1; + Parallel_Add << > > (n, d, dev_data[out_index], dev_data[out_index ^ 1]); + } + timer().endGpuTimer(); + + cudaMemcpy(odata + 1, dev_data[out_index], (n-1) * sizeof(int), cudaMemcpyDeviceToHost); + checkCUDAError("cudaMalloc dev_data[1] failed!"); + + cudaFree(dev_data[0]); + cudaFree(dev_data[1]); + checkCUDAError("cudaMalloc dev_data[1] failed!"); + + } + } +} diff --git a/src/naive.h b/src/naive.h new file mode 100644 index 0000000..37dcb06 --- /dev/null +++ b/src/naive.h @@ -0,0 +1,11 @@ +#pragma once + +#include "common.h" + +namespace StreamCompaction { + namespace Naive { + StreamCompaction::Common::PerformanceTimer& timer(); + + void scan(int n, int *odata, const int *idata); + } +} diff --git a/src/pathtrace.cu b/src/pathtrace.cu index c1ec122..09a6326 100644 --- a/src/pathtrace.cu +++ b/src/pathtrace.cu @@ -9,15 +9,32 @@ #include "scene.h" #include "glm/glm.hpp" #include "glm/gtx/norm.hpp" +#include +#include #include "utilities.h" #include "pathtrace.h" #include "intersections.h" #include "interactions.h" +#include "efficient.h" +#include +#include +#include +#include "radix.h" +#include + +//Toggles Defines +#include "Setting_defines.h" + +//Results file +extern FILE *fp; #define ERRORCHECK 1 #define FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) + #define checkCUDAError(msg) checkCUDAErrorFn(msg, FILENAME, __LINE__) + + void checkCUDAErrorFn(const char *msg, const char *file, int line) { #if ERRORCHECK cudaDeviceSynchronize(); @@ -74,6 +91,13 @@ static Material * dev_materials = NULL; static PathSegment * dev_paths = NULL; static ShadeableIntersection * dev_intersections = NULL; // TODO: static variables for device memory, any extra info you need, etc +static PathSegment * dev_cache_paths = NULL; +static ShadeableIntersection * dev_cache_intersections = NULL; +static int * dev_flag_array = NULL; + +static Vertex * dev_vertices = NULL; +static int * dev_lights_indices = NULL; + // ... void pathtraceInit(Scene *scene) { @@ -96,7 +120,22 @@ void pathtraceInit(Scene *scene) { cudaMemset(dev_intersections, 0, pixelcount * sizeof(ShadeableIntersection)); // TODO: initialize any extra device memeory you need + //Cache + cudaMalloc(&dev_cache_paths, pixelcount * sizeof(PathSegment)); + + cudaMalloc(&dev_cache_intersections, pixelcount * sizeof(ShadeableIntersection)); + cudaMemset(dev_intersections, 0, pixelcount * sizeof(ShadeableIntersection)); + cudaMalloc(&dev_flag_array, pixelcount * sizeof(int)); + + //Smooth Normals: + //hst_scene->Smooth_Normals(); + + cudaMalloc(&dev_vertices, hst_scene->vertices.size() * sizeof(Vertex)); + cudaMemcpy(dev_vertices, hst_scene->vertices.data(), hst_scene->vertices.size() * sizeof(Vertex), cudaMemcpyHostToDevice); + + cudaMalloc(&dev_lights_indices, hst_scene->lights_indices.size() * sizeof(int)); + cudaMemcpy(dev_lights_indices, hst_scene->lights_indices.data(), hst_scene->lights_indices.size() * sizeof(int), cudaMemcpyHostToDevice); checkCUDAError("pathtraceInit"); } @@ -107,10 +146,56 @@ void pathtraceFree() { cudaFree(dev_materials); cudaFree(dev_intersections); // TODO: clean up any extra device memory you created - + cudaFree(dev_cache_paths); + cudaFree(dev_cache_intersections); + cudaFree(dev_flag_array); + cudaFree(dev_lights_indices); checkCUDAError("pathtraceFree"); } +//Reference: PBRT source code https://www.dartdocs.org/documentation/dartray/0.0.1/core/ConcentricSampleDisk.html +//ConcentricSampleDisk +__device__ glm::vec2 ConcentricSampleDisk(float u1, float u2) { + float r, theta; + float a, b; + // Map uniform random numbers to $[-1,1]^2$ + float sx = 2 * u1 - 1; + float sy = 2 * u2 - 1; + if (sx == 0.0 && sy == 0.0) { + return glm::vec2(0.f); + } + if (sx >= -sy) { + if (sx > sy) { + // Handle first region of disk + r = sx; + if (sy > 0.0) theta = sy / r; + else theta = 8.0f + sy / r; + } + else { + // Handle second region of disk + r = sy; + theta = 2.0f - sx / r; + } + } + else { + if (sx <= sy) { + // Handle third region of disk + r = -sx; + theta = 4.0f - sy / r; + } + else { + // Handle fourth region of disk + r = -sy; + theta = 6.0f + sx / r; + } + } + theta *= PI / 4.f; + a = r * cosf(theta); + b = r * sinf(theta); + glm::vec2 returnValue(a, b); + return returnValue; +} + /** * Generate PathSegments with rays from the camera through the screen into the * scene, which is the first bounce of rays. @@ -129,19 +214,51 @@ __global__ void generateRayFromCamera(Camera cam, int iter, int traceDepth, Path PathSegment & segment = pathSegments[index]; segment.ray.origin = cam.position; - segment.color = glm::vec3(1.0f, 1.0f, 1.0f); - - // TODO: implement antialiasing by jittering the ray + segment.color = glm::vec3(1.0f, 1.0f, 1.0f); + segment.is_terminated = false; + thrust::default_random_engine rng = makeSeededRandomEngine(iter, x + y, 0); + thrust::uniform_real_distribution u01(0, 1); + +// TODO: implement antialiasing by jittering the ray +//Stochastic Sampling +#if AntiAliasing_Toggle + segment.ray.direction = glm::normalize(cam.view + - cam.right * cam.pixelLength.x * ((float)(x + u01(rng)) - (float)cam.resolution.x * 0.5f) + - cam.up * cam.pixelLength.y * ((float)(y + u01(rng)) - (float)cam.resolution.y * 0.5f) + ); +#else segment.ray.direction = glm::normalize(cam.view - cam.right * cam.pixelLength.x * ((float)x - (float)cam.resolution.x * 0.5f) - cam.up * cam.pixelLength.y * ((float)y - (float)cam.resolution.y * 0.5f) - ); + ); +#endif +//Depth of Field +#if Depth_Of_Field_Toggle + float u1 = u01(rng), u2 = u01(rng); + glm::vec2 pLens = cam.lensRadius * ConcentricSampleDisk(u1, u2); + glm::vec3 pFocus = segment.ray.origin + glm::abs(cam.focalLength / segment.ray.direction.z) * segment.ray.direction; + + segment.ray.origin += pLens.x * cam.right + pLens.y * cam.up; + segment.ray.direction = glm::normalize(pFocus - segment.ray.origin); +#endif + + + segment.rand_time = u01(rng); segment.pixelIndex = index; segment.remainingBounces = traceDepth; } } +__host__ __device__ glm::mat4 buildTransformationMatrix(glm::vec3 translation, glm::vec3 rotation, glm::vec3 scale) { + glm::mat4 translationMat = glm::translate(glm::mat4(), translation); + glm::mat4 rotationMat = glm::rotate(glm::mat4(), rotation.x * (float)PI / 180, glm::vec3(1, 0, 0)); + rotationMat = rotationMat * glm::rotate(glm::mat4(), rotation.y * (float)PI / 180, glm::vec3(0, 1, 0)); + rotationMat = rotationMat * glm::rotate(glm::mat4(), rotation.z * (float)PI / 180, glm::vec3(0, 0, 1)); + glm::mat4 scaleMat = glm::scale(glm::mat4(), scale); + return translationMat * rotationMat * scaleMat; +} + // TODO: // computeIntersections handles generating ray intersections ONLY. // Generating new rays is handled in your shader(s). @@ -153,6 +270,7 @@ __global__ void computeIntersections( , Geom * geoms , int geoms_size , ShadeableIntersection * intersections + , Vertex *vertices ) { int path_index = blockIdx.x * blockDim.x + threadIdx.x; @@ -166,17 +284,22 @@ __global__ void computeIntersections( glm::vec3 normal; float t_min = FLT_MAX; int hit_geom_index = -1; - bool outside = true; glm::vec3 tmp_intersect; glm::vec3 tmp_normal; + bool outside = true; // naive parse through global geoms for (int i = 0; i < geoms_size; i++) { Geom & geom = geoms[i]; - +#if MotionBlur_Toggle + glm::vec3 blur_pos = glm::clamp((1 - pathSegment.rand_time) * geom.translation + pathSegment.rand_time * geom.translation_end, geom.translation, geom.translation_end); + geom.transform = buildTransformationMatrix(blur_pos, geom.rotation, geom.scale); + geom.inverseTransform = glm::inverse(geom.transform); + geom.invTranspose = glm::inverseTranspose(geom.transform); +#endif if (geom.type == CUBE) { t = boxIntersectionTest(geom, pathSegment.ray, tmp_intersect, tmp_normal, outside); @@ -185,6 +308,9 @@ __global__ void computeIntersections( { t = sphereIntersectionTest(geom, pathSegment.ray, tmp_intersect, tmp_normal, outside); } + else if (geom.type == MESH) { + t = meshIntersectionTest(geom, pathSegment.ray, tmp_intersect, tmp_normal, outside, vertices); + } // TODO: add more intersection tests here... triangle? metaball? CSG? // Compute the minimum t from the intersection tests to determine what @@ -208,6 +334,7 @@ __global__ void computeIntersections( intersections[path_index].t = t_min; intersections[path_index].materialId = geoms[hit_geom_index].materialid; intersections[path_index].surfaceNormal = normal; + intersections[path_index].outside = outside; } } } @@ -265,6 +392,163 @@ __global__ void shadeFakeMaterial ( } } +__global__ void shadeRealMaterial( + int iter + , int num_paths + , ShadeableIntersection * shadeableIntersections + , PathSegment * pathSegments + , Material * materials + , glm::vec3 * image + , int *flag_array +) +{ + int idx = blockIdx.x * blockDim.x + threadIdx.x; + if (idx < num_paths) + { + ShadeableIntersection intersection = shadeableIntersections[idx]; + PathSegment &this_Path = pathSegments[idx]; + + if (intersection.t > 0.0f) { // if the intersection exists... + // Set up the RNG + // LOOK: this is how you use thrust's RNG! Please look at + // makeSeededRandomEngine as well. + thrust::default_random_engine rng = makeSeededRandomEngine(iter, idx, 0); + thrust::uniform_real_distribution u01(0, 1); + + Material material = materials[intersection.materialId]; + glm::vec3 materialColor = material.color; + + if (this_Path.remainingBounces) { + flag_array[idx] = 1; + scatterRay(this_Path, intersection.t * this_Path.ray.direction + this_Path.ray.origin, intersection.surfaceNormal, material, rng, intersection.outside); + } + else { + flag_array[idx] = 0; + if(this_Path.is_terminated) + image[this_Path.pixelIndex] += this_Path.color; + } + } + else { + flag_array[idx] = 0; + } + } +} + +__global__ void shadeRealMaterial_Direct( + int iter + , int num_paths + , ShadeableIntersection * shadeableIntersections + , PathSegment * pathSegments + , Material * materials + , glm::vec3 * image + , int *flag_array + , int *lights_indices + , int num_lights + , Geom * geoms + , int geoms_size + , Vertex *vertices +) +{ + int idx = blockIdx.x * blockDim.x + threadIdx.x; + if (idx < num_paths) + { + ShadeableIntersection intersection = shadeableIntersections[idx]; + PathSegment &this_Path = pathSegments[idx]; + thrust::default_random_engine rng = makeSeededRandomEngine(iter, idx, 0); + thrust::uniform_real_distribution u01(0, 1); + + //Direct Light + if (this_Path.remainingBounces == 1) { + int lights_hits = 0; + glm::vec3 color; + for (int i = 0; i < num_lights; i++) { + int light_id = lights_indices[i]; + + Geom &geom_light = geoms[light_id]; + this_Path.ray.direction = glm::normalize(geom_light.translation - this_Path.ray.origin); + + float t; + glm::vec3 intersect_point; + glm::vec3 normal; + float t_min = FLT_MAX; + int hit_geom_index = -1; + + glm::vec3 tmp_intersect; + glm::vec3 tmp_normal; + bool outside = true; + + + //compute intersection and t + for (int j = 0; j < geoms_size; j++) { + Geom & geom = geoms[j]; +#if MotionBlur_Toggle + glm::vec3 blur_pos = glm::clamp((1 - pathSegment.rand_time) * geom.translation + pathSegment.rand_time * geom.translation_end, geom.translation, geom.translation_end); + geom.transform = buildTransformationMatrix(blur_pos, geom.rotation, geom.scale); + geom.inverseTransform = glm::inverse(geom.transform); + geom.invTranspose = glm::inverseTranspose(geom.transform); +#endif + if (geom.type == CUBE) + { + t = boxIntersectionTest(geom, this_Path.ray, tmp_intersect, tmp_normal, outside); + } + else if (geom.type == SPHERE) + { + t = sphereIntersectionTest(geom, this_Path.ray, tmp_intersect, tmp_normal, outside); + } + else if (geom.type == MESH) { + t = meshIntersectionTest(geom, this_Path.ray, tmp_intersect, tmp_normal, outside, vertices); + } + + // scene geometry object was hit first. + if (t > 0.0f && t_min > t) + { + t_min = t; + hit_geom_index = j; + intersect_point = tmp_intersect; + normal = tmp_normal; + } + } + + if (hit_geom_index == lights_indices[i]) { + lights_hits++; + Material m = materials[geoms[hit_geom_index].materialid]; + color += this_Path.color * (m.color * m.emittance); + } + + } + if (lights_hits) { + color = color / float(lights_hits); + image[this_Path.pixelIndex] += color; + } + flag_array[idx] = 0; + this_Path.remainingBounces--; + } + + if (intersection.t > 0.0f) { // if the intersection exists... + // Set up the RNG + // LOOK: this is how you use thrust's RNG! Please look at + // makeSeededRandomEngine as well. + + + Material material = materials[intersection.materialId]; + glm::vec3 materialColor = material.color; + + if (this_Path.remainingBounces) { + flag_array[idx] = 1; + scatterRay(this_Path, intersection.t * this_Path.ray.direction + this_Path.ray.origin, intersection.surfaceNormal, material, rng, intersection.outside); + } + else { + flag_array[idx] = 0; + if (this_Path.is_terminated) + image[this_Path.pixelIndex] += this_Path.color; + } + } + else { + flag_array[idx] = 0; + } + } +} + // Add the current iteration's output to the overall image __global__ void finalGather(int nPaths, glm::vec3 * image, PathSegment * iterationPaths) { @@ -277,6 +561,105 @@ __global__ void finalGather(int nPaths, glm::vec3 * image, PathSegment * iterati } } +__global__ void kernScatterPaths(int n, PathSegment *odata, + const PathSegment *idata, const int *bools, const int *indices) { + int index = threadIdx.x + (blockIdx.x * blockDim.x); + if (index >= n) + return; + + if (bools[index]) + odata[indices[index]] = idata[index]; +} + +int compact_Paths(int n) { + // TODO + if (n <= 0) + return -1; + int celllog = ilog2ceil(n); + int pow2len = 1 << celllog; + + int *dev_indices; + cudaMalloc((void**)&dev_indices, pow2len * sizeof(int)); + checkCUDAError("cudaMalloc dev_indices failed!"); + PathSegment *dev_temp_paths; + cudaMalloc((void**)&dev_temp_paths, pow2len * sizeof(PathSegment)); + cudaMemcpy(dev_temp_paths, dev_paths, n * sizeof(PathSegment), cudaMemcpyDeviceToDevice); + + // Scan + cudaMemcpy(dev_indices, dev_flag_array, n * sizeof(int), cudaMemcpyDeviceToDevice); + checkCUDAError("cudaMemcpy failed!"); + + int blockSize = 128; + int blockNum; + + //Up-Sweep + for (int d = 0; d <= celllog - 1; d++) { + int interval_length = (1 << (d + 1)); + blockNum = (pow2len / interval_length + blockSize) / blockSize; + StreamCompaction::Efficient::cudaSweepUp << > >(pow2len / interval_length, d, dev_indices); + } + //Down-Sweep + cudaMemset(dev_indices + pow2len - 1, 0, sizeof(int)); + checkCUDAError("cudaMemset failed!"); + + for (int d = celllog - 1; d >= 0; d--) { + int interval_length = (1 << (d + 1)); + blockNum = (pow2len / interval_length + blockSize) / blockSize; + StreamCompaction::Efficient::cudaSweepDown << > >(pow2len / interval_length, d, dev_indices); + } + + + //Scattered + blockNum = (n + blockSize) / blockSize; + kernScatterPaths << > >(n, dev_paths, dev_temp_paths, dev_flag_array, dev_indices); + + //compute count + int a, b; + cudaMemcpy(&a, dev_flag_array + (n - 1), sizeof(int), cudaMemcpyDeviceToHost); + cudaMemcpy(&b, dev_indices + (n - 1), sizeof(int), cudaMemcpyDeviceToHost); + int count = a + b; + + //Free data + cudaFree(dev_indices); + checkCUDAError("cudaFree dev_idata failed!"); + cudaFree(dev_temp_paths); + checkCUDAError("cudaFree dev_temp_paths failed!"); + + return count; +} + +void compressedPathandIntersection(int& num_paths, PathSegment *paths, int *flag) +{ + thrust::device_ptr dev_ptrFlag(flag); + thrust::device_ptr dev_ptrPaths(paths); + thrust::remove_if(dev_ptrPaths, dev_ptrPaths + num_paths, dev_ptrFlag, thrust::logical_not()); + num_paths = thrust::count_if(dev_ptrFlag, dev_ptrFlag + num_paths, thrust::identity()); +} + +// Sort by materialId +typedef thrust::tuple Tuple; +class cmp +{ +public: + __host__ __device__ bool operator()(const Tuple &a, const Tuple &b) + { + return a.get<1>().materialId < b.get<1>().materialId; + } +}; + +void sortByMaterialId(int num_paths, PathSegment *dev_paths, ShadeableIntersection *dev_intersections) +{ + thrust::device_ptr ptrPath(dev_paths); + thrust::device_ptr ptrIntersection(dev_intersections); + + typedef thrust::tuple, thrust::device_ptr> IteratorTuple; + typedef thrust::zip_iterator ZipIterator; + ZipIterator zip_begin = thrust::make_zip_iterator(thrust::make_tuple(ptrPath, ptrIntersection)); + ZipIterator zip_end = zip_begin + num_paths; + thrust::sort(zip_begin, zip_end, cmp()); +} + + /** * Wrapper for the __global__ call that sets up the kernel calls and does a ton * of memory management @@ -325,69 +708,160 @@ void pathtrace(uchar4 *pbo, int frame, int iter) { // for you. // TODO: perform one iteration of path tracing - - generateRayFromCamera <<>>(cam, iter, traceDepth, dev_paths); - checkCUDAError("generate camera ray"); - +// -------------- Caching -------------- int depth = 0; PathSegment* dev_path_end = dev_paths + pixelcount; int num_paths = dev_path_end - dev_paths; - - // --- PathSegment Tracing Stage --- + bool outside = true; + StreamCompaction::Efficient::timer().startGpuTimer(); + + +#if Caching_Toggle && !AntiAliasing_Toggle && !MotionBlur_Toggle && !Depth_Of_Field_Toggle + if (iter == 1) { + generateRayFromCamera << > >(cam, iter, traceDepth, dev_paths); + checkCUDAError("generate camera ray"); + cudaMemcpy(dev_cache_paths, dev_paths, num_paths * sizeof(PathSegment), cudaMemcpyDeviceToDevice); + checkCUDAError("Memcpy dev_paths to dev_cache_paths"); + // clean shading chunks + cudaMemset(dev_intersections, 0, pixelcount * sizeof(ShadeableIntersection)); + + // tracing + dim3 numblocksPathSegmentTracing = (num_paths + blockSize1d - 1) / blockSize1d; + computeIntersections << > > ( + depth + , num_paths + , dev_paths + , dev_geoms + , hst_scene->geoms.size() + , dev_intersections + , dev_vertices + ); + checkCUDAError("trace one bounce"); + cudaMemcpy(dev_cache_intersections, dev_intersections, num_paths * sizeof(ShadeableIntersection), cudaMemcpyDeviceToDevice); + checkCUDAError("Memcpy dev_intersections to dev_cache_intersections"); + } +#endif + + +// --------------- PathSegment Tracing Stage ----------------- // Shoot ray into scene, bounce between objects, push shading chunks - bool iterationComplete = false; - while (!iterationComplete) { - - // clean shading chunks - cudaMemset(dev_intersections, 0, pixelcount * sizeof(ShadeableIntersection)); + bool iterationComplete = false; + bool firstStage = true; - // tracing - dim3 numblocksPathSegmentTracing = (num_paths + blockSize1d - 1) / blockSize1d; - computeIntersections <<>> ( - depth - , num_paths - , dev_paths - , dev_geoms - , hst_scene->geoms.size() - , dev_intersections - ); - checkCUDAError("trace one bounce"); - cudaDeviceSynchronize(); - depth++; + while (!iterationComplete) { + dim3 numblocksPathSegmentTracing = (num_paths + blockSize1d - 1) / blockSize1d; + // clean shading chunks + cudaMemset(dev_intersections, 0, pixelcount * sizeof(ShadeableIntersection)); + + if (firstStage) { + firstStage = false; +#if Caching_Toggle && !AntiAliasing_Toggle && !MotionBlur_Toggle && !Depth_Of_Field_Toggle + cudaMemcpy(dev_paths, dev_cache_paths, num_paths * sizeof(PathSegment), cudaMemcpyDeviceToDevice); + cudaMemcpy(dev_intersections, dev_cache_intersections, num_paths * sizeof(ShadeableIntersection), cudaMemcpyDeviceToDevice); +#else + generateRayFromCamera << > >(cam, iter, traceDepth, dev_paths); + checkCUDAError("generate camera ray"); + // clean shading chunks + cudaMemset(dev_intersections, 0, pixelcount * sizeof(ShadeableIntersection)); + + // tracing + dim3 numblocksPathSegmentTracing = (num_paths + blockSize1d - 1) / blockSize1d; + computeIntersections << > > ( + depth + , num_paths + , dev_paths + , dev_geoms + , hst_scene->geoms.size() + , dev_intersections + , dev_vertices + ); + checkCUDAError("trace one bounce"); +#endif + } + else { + computeIntersections << > > ( + depth + , num_paths + , dev_paths + , dev_geoms + , hst_scene->geoms.size() + , dev_intersections + , dev_vertices + ); + checkCUDAError("trace one bounce"); + cudaDeviceSynchronize(); + } + depth++; // TODO: - // --- Shading Stage --- +// ---------------- Shading Stage ------------------ // Shade path segments based on intersections and generate new rays by // evaluating the BSDF. // Start off with just a big kernel that handles all the different // materials you have in the scenefile. // TODO: compare between directly shading the path segments and shading // path segments that have been reshuffled to be contiguous in memory. + + + //The last + //int num_materials = 5; + //StreamCompaction::Radix::RadixSort_Path_Interactions(num_paths, dev_paths, dev_intersections, num_materials); +#if Sorting_Toggle + sortByMaterialId(num_paths, dev_paths, dev_intersections); +#endif - shadeFakeMaterial<<>> ( - iter, - num_paths, - dev_intersections, - dev_paths, - dev_materials - ); - iterationComplete = true; // TODO: should be based off stream compaction results. +#if Direct_Light_Toggle + shadeRealMaterial_Direct << > >( + iter, + num_paths, + dev_intersections, + dev_paths, + dev_materials, + dev_image, + dev_flag_array, + dev_lights_indices, + hst_scene->lights_indices.size(), + dev_geoms, + hst_scene->geoms.size(), + dev_vertices + ); +#else + shadeRealMaterial << > >( + iter, + num_paths, + dev_intersections, + dev_paths, + dev_materials, + dev_image, + dev_flag_array + ); +#endif + //get new paths and new flag_array +// ----------------- Stream Compaction ---------------- + num_paths = compact_Paths(num_paths); + //compressedPathandIntersection(num_paths, dev_paths, dev_flag_array); + //get new path pool and num_paths + if(num_paths <= 0) + iterationComplete = true; // TODO: should be based off stream compaction results. } - // Assemble this iteration and apply it to the image - dim3 numBlocksPixels = (pixelcount + blockSize1d - 1) / blockSize1d; - finalGather<<>>(num_paths, dev_image, dev_paths); + // Assemble this iteration and apply it to the image + /*dim3 numBlocksPixels = (pixelcount + blockSize1d - 1) / blockSize1d; + finalGather << > >(num_paths, dev_image, dev_paths);*/ +/////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////// + StreamCompaction::Efficient::timer().endGpuTimer(); + //std::cout << " elapsed time: " << StreamCompaction::Efficient::timer().getGpuElapsedTimeForPreviousOperation() << " ms\n"; + fprintf(fp, "%lf\n", StreamCompaction::Efficient::timer().getGpuElapsedTimeForPreviousOperation()); - // Send results to OpenGL buffer for rendering - sendImageToPBO<<>>(pbo, cam.resolution, iter, dev_image); + // Send results to OpenGL buffer for rendering + sendImageToPBO << > >(pbo, cam.resolution, iter, dev_image); - // Retrieve image from GPU - cudaMemcpy(hst_scene->state.image.data(), dev_image, - pixelcount * sizeof(glm::vec3), cudaMemcpyDeviceToHost); + // Retrieve image from GPU + cudaMemcpy(hst_scene->state.image.data(), dev_image, + pixelcount * sizeof(glm::vec3), cudaMemcpyDeviceToHost); - checkCUDAError("pathtrace"); + checkCUDAError("pathtrace"); } diff --git a/src/preview.cpp b/src/preview.cpp index 4eb0bc1..4ec54c5 100644 --- a/src/preview.cpp +++ b/src/preview.cpp @@ -2,6 +2,7 @@ #include #include "main.h" #include "preview.h" +#include "efficient.h" GLuint positionLocation = 0; GLuint texcoordsLocation = 1; @@ -169,7 +170,8 @@ bool init() { } void mainLoop() { - while (!glfwWindowShouldClose(window)) { + + while (!glfwWindowShouldClose(window)) { glfwPollEvents(); runCuda(); @@ -185,6 +187,9 @@ void mainLoop() { glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); glfwSwapBuffers(window); } + + + glfwDestroyWindow(window); glfwTerminate(); } diff --git a/src/radix.cu b/src/radix.cu new file mode 100644 index 0000000..5ad3aad --- /dev/null +++ b/src/radix.cu @@ -0,0 +1,261 @@ +#include +#include +#include "common.h" +#include "naive.h" +#include "radix.h" + +namespace StreamCompaction { + namespace Radix { + using StreamCompaction::Common::PerformanceTimer; + PerformanceTimer& timer() { + static PerformanceTimer timer; + return timer; + } + + int *dev_Data[2]; + int *dev_bArray; + int *dev_eArray; + int *dev_fArray; + int *dev_tArray; + int *dev_dArray; + int *dev_materialIds; + PathSegment *dev_temp_paths[2]; + ShadeableIntersection *dev_temp_intersections[2]; + + __global__ void cudaSweepUp(int n, int d, int *data) { + int index = threadIdx.x + (blockIdx.x * blockDim.x); + int interval_length = 1 << (d + 1); + if (index >= n) + return; + //int idx1 = index * interval_length + (1 << (d + 1)) - 1; + //int idx2 = index * interval_length + (1 << d) - 1; + data[index * interval_length + (1 << (d + 1)) - 1] += data[index * interval_length + (1 << d) - 1]; + } + + __global__ void cudaSweepDown(int n, int d, int *data) { + int index = threadIdx.x + (blockIdx.x * blockDim.x); + int interval_length = 1 << (d + 1); + // k from 0 to n-1 + if (index >= n) + return; + + int temp = data[index * interval_length + (1 << d) - 1]; + data[index * interval_length + (1 << d) - 1] = data[index * interval_length + (1 << (d + 1)) - 1]; + data[index * interval_length + (1 << (d + 1)) - 1] += temp; + } + + __global__ void cudaGetBEArray(int pass, int *idata, int *odata1, int *odata2, int n) { + int index = (blockIdx.x * blockDim.x) + threadIdx.x; + if (index >= n) + return; + odata1[index] = (idata[index] >> pass) & 1; + odata2[index] = odata1[index] ^ 1; + } + + __global__ void cudaGetTArray(int *idata, int *e, int *odata, int n) { + int index = (blockIdx.x * blockDim.x) + threadIdx.x; + int totalFalses = idata[n - 1] + e[n - 1]; + if (index >= n) + return; + odata[index] = index - idata[index] + totalFalses; + } + + __global__ void cudaGetDArray(int *idata1, int *idata2, int *idata3, int *odata, int n) { + int index = (blockIdx.x * blockDim.x) + threadIdx.x; + if (index >= n) + return; + odata[index] = idata1[index] ? idata2[index] : idata3[index]; + } + + __global__ void cudaGetResult(int *idata, int *odata, int *data, int n) { + int index = (blockIdx.x * blockDim.x) + threadIdx.x; + if (index >= n) + return; + odata[idata[index]] = data[index]; + } + + void RadixSort(int n, int *odata, int *idata) { + + int blockSize = 512; + int blockNum; + int celllog = ilog2ceil(n); + int pow2len = 1 << celllog; + int pout = 1; + cudaMalloc((void**)&dev_Data[0], n * sizeof(int)); + cudaMalloc((void**)&dev_Data[1], n * sizeof(int)); + cudaMalloc((void**)&dev_bArray, n * sizeof(int)); + cudaMalloc((void**)&dev_eArray, pow2len * sizeof(int)); + cudaMalloc((void**)&dev_fArray, pow2len * sizeof(int)); + cudaMalloc((void**)&dev_tArray, n * sizeof(int)); + cudaMalloc((void**)&dev_dArray, n * sizeof(int)); + cudaMemset(dev_eArray, 0, pow2len * sizeof(int)); + cudaMemcpy(dev_Data[0], idata, sizeof(int) * n, cudaMemcpyHostToDevice); + checkCUDAError("cudaMemcpy to device failed!"); + checkCUDAError("cudaMalloc failed!"); + + int max_num = 0; + for (int i = 0; i < n; i++) + if (idata[i] > max_num) + max_num = idata[i]; + + timer().startGpuTimer(); + int pass = 0; + while (true) { + int pin = pout ^ 1; + if ((max_num >> pass) == 0) + break; + blockNum = n / blockSize + 1; + cudaGetBEArray << > > (pass, dev_Data[pin], dev_bArray, dev_eArray, n); + cudaMemcpy(dev_fArray, dev_eArray, pow2len * sizeof(int), cudaMemcpyDeviceToDevice); + checkCUDAError("cudaMemcpy device to device failed!"); + + for (int d = 0; d <= celllog - 1; d++) { + int interval_length = (1 << (d + 1)); + blockNum = (pow2len / interval_length + blockSize) / blockSize; + cudaSweepUp << > > (pow2len / interval_length, d, dev_fArray); + } + + cudaMemset(dev_fArray + pow2len - 1, 0, sizeof(int)); + checkCUDAError("cudaMemset failed!"); + for (int d = celllog - 1; d >= 0; d--) { + int interval_length = (1 << (d + 1)); + blockNum = (pow2len / interval_length + blockSize) / blockSize; + cudaSweepDown << > > (pow2len / interval_length, d, dev_fArray); + } + + blockNum = n / blockSize + 1; + cudaGetTArray << > > (dev_fArray, dev_eArray, dev_tArray, n); + cudaGetDArray << > > (dev_bArray, dev_tArray, dev_fArray, dev_dArray, n); + cudaGetResult << > > (dev_dArray, dev_Data[pout], dev_Data[pin], n); + + pass++; + pout ^= 1; + } + timer().endGpuTimer(); + + cudaMemcpy(odata, dev_Data[pout ^ 1], sizeof(int) * n, cudaMemcpyDeviceToHost); + checkCUDAError("cudaMemcpy to host failed!"); + + + cudaFree(dev_Data[0]); + cudaFree(dev_Data[1]); + cudaFree(dev_bArray); + cudaFree(dev_eArray); + cudaFree(dev_fArray); + cudaFree(dev_tArray); + cudaFree(dev_dArray); + } + + __global__ void kernStoreMaterialId(int n, int * dev_materialIds, ShadeableIntersection *dev_interactions) { + int index = threadIdx.x + (blockIdx.x * blockDim.x); + if (index >= n) + return; + dev_materialIds[index] = dev_interactions[index].materialId; + } + + __global__ void cudaGetResult_Path_Interactions(int *idata, int *odata, int *data, int n, + PathSegment *odev_paths, ShadeableIntersection *odev_interactions, + PathSegment *dev_paths, ShadeableIntersection *dev_interactions) { + int index = (blockIdx.x * blockDim.x) + threadIdx.x; + if (index >= n) + return; + odata[idata[index]] = data[index]; + odev_paths[idata[index]] = dev_paths[index]; + odev_interactions[idata[index]] = dev_interactions[index]; + + } + __host__ __device__ int GetMax(int *idata, int n) { + int max_num = 0; + for (int i = 0; i < n; i++) + if (idata[i] > max_num) + max_num = idata[i]; + return max_num; + + } + void RadixSort_Path_Interactions(int n, PathSegment *dev_paths, ShadeableIntersection *dev_interactions, int m_num) { + + int blockSize = 512; + int blockNum; + int celllog = ilog2ceil(n); + int pow2len = 1 << celllog; + int pout = 1; + cudaMalloc((void**)&dev_temp_paths[0], n * sizeof(PathSegment)); + cudaMalloc((void**)&dev_temp_paths[1], n * sizeof(PathSegment)); + cudaMalloc((void**)&dev_temp_intersections[0], n * sizeof(ShadeableIntersection)); + cudaMalloc((void**)&dev_temp_intersections[1], n * sizeof(ShadeableIntersection)); + cudaMalloc((void**)&dev_Data[0], n * sizeof(int)); + cudaMalloc((void**)&dev_Data[1], n * sizeof(int)); + cudaMalloc((void**)&dev_bArray, n * sizeof(int)); + cudaMalloc((void**)&dev_eArray, pow2len * sizeof(int)); + cudaMalloc((void**)&dev_fArray, pow2len * sizeof(int)); + cudaMalloc((void**)&dev_tArray, n * sizeof(int)); + cudaMalloc((void**)&dev_dArray, n * sizeof(int)); + cudaMemset(dev_eArray, 0, pow2len * sizeof(int)); + checkCUDAError("cudaMemcpy to device failed!"); + checkCUDAError("cudaMalloc failed!"); + + blockNum = (n + blockSize) / blockSize; + kernStoreMaterialId<<>>(n, dev_Data[0], dev_interactions); + cudaMemcpy(dev_temp_paths[0], dev_paths, n * sizeof(PathSegment), cudaMemcpyDeviceToDevice); + cudaMemcpy(dev_temp_intersections[0], dev_interactions, n * sizeof(ShadeableIntersection), cudaMemcpyDeviceToDevice); + + int max_num = m_num - 1; + + timer().startGpuTimer(); + int pass = 0; + while (true) { + int pin = pout ^ 1; + if ((max_num >> pass) == 0) + break; + blockNum = n / blockSize + 1; + cudaGetBEArray << > >(pass, dev_Data[pin], dev_bArray, dev_eArray, n); + cudaMemcpy(dev_fArray, dev_eArray, pow2len * sizeof(int), cudaMemcpyDeviceToDevice); + checkCUDAError("cudaMemcpy device to device failed!"); + + for (int d = 0; d <= celllog - 1; d++) { + int interval_length = (1 << (d + 1)); + blockNum = (pow2len / interval_length + blockSize) / blockSize; + cudaSweepUp << > >(pow2len / interval_length, d, dev_fArray); + } + + cudaMemset(dev_fArray + pow2len - 1, 0, sizeof(int)); + checkCUDAError("cudaMemset failed!"); + for (int d = celllog - 1; d >= 0; d--) { + int interval_length = (1 << (d + 1)); + blockNum = (pow2len / interval_length + blockSize) / blockSize; + cudaSweepDown << > >(pow2len / interval_length, d, dev_fArray); + } + + blockNum = n / blockSize + 1; + cudaGetTArray << > > (dev_fArray, dev_eArray, dev_tArray, n); + cudaGetDArray << > >(dev_bArray, dev_tArray, dev_fArray, dev_dArray, n); + cudaGetResult_Path_Interactions << > >(dev_dArray, dev_Data[pout], dev_Data[pin], n, + dev_temp_paths[pout], dev_temp_intersections[pout], + dev_temp_paths[pin], dev_temp_intersections[pin]); + + + pass++; + pout ^= 1; + } + timer().endGpuTimer(); + + cudaMemcpy(dev_paths, dev_temp_paths[pout ^ 1], sizeof(PathSegment) * n, cudaMemcpyDeviceToDevice); + cudaMemcpy(dev_interactions, dev_temp_intersections[pout ^ 1], sizeof(ShadeableIntersection) * n, cudaMemcpyDeviceToDevice); + checkCUDAError("cudaMemcpy to host failed!"); + + cudaFree(dev_temp_paths[0]); + cudaFree(dev_temp_paths[1]); + cudaFree(dev_temp_intersections[0]); + cudaFree(dev_temp_intersections[1]); + cudaFree(dev_Data[0]); + cudaFree(dev_Data[1]); + cudaFree(dev_bArray); + cudaFree(dev_eArray); + cudaFree(dev_fArray); + cudaFree(dev_tArray); + cudaFree(dev_dArray); + } + + + } +} \ No newline at end of file diff --git a/src/radix.h b/src/radix.h new file mode 100644 index 0000000..8bf4ead --- /dev/null +++ b/src/radix.h @@ -0,0 +1,9 @@ +#pragma once +#include "sceneStructs.h" + +namespace StreamCompaction { + namespace Radix { + void RadixSort(int n, int *odata, int *idata); + void RadixSort_Path_Interactions(int n, PathSegment *dev_paths, ShadeableIntersection *dev_interactions, int m_num); + } +} \ No newline at end of file diff --git a/src/scene.cpp b/src/scene.cpp index cbae043..33a76e6 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -3,6 +3,8 @@ #include #include #include +#include + Scene::Scene(string filename) { cout << "Reading scene from " << filename << " ..." << endl; @@ -13,6 +15,7 @@ Scene::Scene(string filename) { cout << "Error reading from file - aborting!" << endl; throw; } + dir_path = filename; while (fp_in.good()) { string line; utilityCore::safeGetline(fp_in, line); @@ -41,6 +44,7 @@ int Scene::loadGeom(string objectid) { cout << "Loading Geom " << id << "..." << endl; Geom newGeom; string line; + bool isMesh = false; //load object type utilityCore::safeGetline(fp_in, line); @@ -51,7 +55,12 @@ int Scene::loadGeom(string objectid) { } else if (strcmp(line.c_str(), "cube") == 0) { cout << "Creating new cube..." << endl; newGeom.type = CUBE; - } + } + else if (strcmp(line.c_str(), "mesh") == 0) { + cout << "Creating new mesh..." << endl; + newGeom.type = MESH; + isMesh = true; + } } //link material @@ -75,6 +84,15 @@ int Scene::loadGeom(string objectid) { } else if (strcmp(tokens[0].c_str(), "SCALE") == 0) { newGeom.scale = glm::vec3(atof(tokens[1].c_str()), atof(tokens[2].c_str()), atof(tokens[3].c_str())); } + else if (strcmp(tokens[0].c_str(), "TRANS_END") == 0) { + newGeom.translation_end = glm::vec3(atof(tokens[1].c_str()), atof(tokens[2].c_str()), atof(tokens[3].c_str())); + } + else if (strcmp(tokens[0].c_str(), "OBJ_PATH") == 0) { + std::string folderfile = dir_path.substr(0, dir_path.find_last_of("/\\")); + std::string OBJfile = tokens[1]; + OBJfile = folderfile + '/' + OBJfile; + loadMesh(OBJfile, newGeom); + } utilityCore::safeGetline(fp_in, line); } @@ -84,6 +102,9 @@ int Scene::loadGeom(string objectid) { newGeom.inverseTransform = glm::inverse(newGeom.transform); newGeom.invTranspose = glm::inverseTranspose(newGeom.transform); + if (materials[newGeom.materialid].emittance > 0.0f) { + lights_indices.push_back(geoms.size()); + } geoms.push_back(newGeom); return 1; } @@ -125,6 +146,12 @@ int Scene::loadCamera() { } else if (strcmp(tokens[0].c_str(), "UP") == 0) { camera.up = glm::vec3(atof(tokens[1].c_str()), atof(tokens[2].c_str()), atof(tokens[3].c_str())); } + else if (strcmp(tokens[0].c_str(), "FOCALLEN") == 0) { + camera.focalLength = atof(tokens[1].c_str()); + } + else if (strcmp(tokens[0].c_str(), "LENSRAD") == 0) { + camera.lensRadius = atof(tokens[1].c_str()); + } utilityCore::safeGetline(fp_in, line); } @@ -186,3 +213,77 @@ int Scene::loadMaterial(string materialid) { return 1; } } + +int Scene::loadMesh(std::string Path, Geom &geom) { + tinyobj::attrib_t attrib; + std::vector shapes; + std::vector materials; + std::string err; + + bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, Path.c_str()); + + if (!err.empty()) { // `err` may contain warning message. + std::cerr << err << std::endl; + } + + if (!ret) { + exit(1); + } + float max_x, max_y, max_z, min_x, min_y, min_z; + max_x = max_y = max_z = -10000; + min_x = min_y = min_z = 10000; + geom.start_Index = vertices.size(); + // Loop over shapes + for (size_t s = 0; s < shapes.size(); s++) { + // Loop over faces(polygon) + size_t index_offset = 0; + for (size_t f = 0; f < shapes[s].mesh.num_face_vertices.size(); f++) { + int fv = shapes[s].mesh.num_face_vertices[f]; + + // Loop over vertices in the face. + for (size_t v = 0; v < fv; v++) { + // access to vertex + tinyobj::index_t idx = shapes[s].mesh.indices[index_offset + v]; + float vx = attrib.vertices[3 * idx.vertex_index + 0]; + float vy = attrib.vertices[3 * idx.vertex_index + 1]; + float vz = attrib.vertices[3 * idx.vertex_index + 2]; + float nx = attrib.normals[3 * idx.normal_index + 0]; + float ny = attrib.normals[3 * idx.normal_index + 1]; + float nz = attrib.normals[3 * idx.normal_index + 2]; + vertices.push_back(Vertex(glm::vec3(vx, vy, vz), glm::vec3(nx, ny, nz))); + max_x = max_x > vx ? max_x : vx; + max_y = max_y > vy ? max_y : vy; + max_z = max_z > vz ? max_z : vz; + min_x = min_x < vx ? min_x : vx; + min_y = min_y < vy ? min_y : vy; + min_z = min_z < vz ? min_z : vz; + } + index_offset += fv; + + // per-face material + //shapes[s].mesh.material_ids[f]; + } + } + geom.bbox_max = glm::vec3(max_x, max_y, max_z); + geom.bbox_min = glm::vec3(min_x, min_y, min_z); + geom.vertices_Num = vertices.size() - geom.start_Index; + return 1; +} + +int Scene::Smooth_Normals() { + for (int i = 0; i < vertices.size(); i++) { + std::vector nor_i_indices; + nor_i_indices.push_back(i); + glm::vec3 sum; + for (int j = 0; j < vertices.size(); j++) { + if (vertices[j].position == vertices[i].position) { + sum += vertices[j].normal; + nor_i_indices.push_back(j); + } + } + sum /= (nor_i_indices.size()); + for (int j = 0; j < nor_i_indices.size(); j++) { + vertices[j].normal = sum; + } + } +} diff --git a/src/scene.h b/src/scene.h index f29a917..6106774 100644 --- a/src/scene.h +++ b/src/scene.h @@ -16,11 +16,17 @@ class Scene { int loadMaterial(string materialid); int loadGeom(string objectid); int loadCamera(); + int loadMesh(std::string Path, Geom &geom); + std::string dir_path; public: Scene(string filename); ~Scene(); + std::vector lights_indices; std::vector geoms; + std::vector vertices; std::vector materials; RenderState state; + + int Smooth_Normals(); }; diff --git a/src/sceneStructs.h b/src/sceneStructs.h index b38b820..9e5d3f9 100644 --- a/src/sceneStructs.h +++ b/src/sceneStructs.h @@ -10,6 +10,7 @@ enum GeomType { SPHERE, CUBE, + MESH, }; struct Ray { @@ -21,11 +22,17 @@ struct Geom { enum GeomType type; int materialid; glm::vec3 translation; + glm::vec3 translation_end; glm::vec3 rotation; glm::vec3 scale; glm::mat4 transform; glm::mat4 inverseTransform; glm::mat4 invTranspose; + + int start_Index; + int vertices_Num; + glm::vec3 bbox_max; + glm::vec3 bbox_min; }; struct Material { @@ -49,6 +56,8 @@ struct Camera { glm::vec3 right; glm::vec2 fov; glm::vec2 pixelLength; + float focalLength; + float lensRadius; }; struct RenderState { @@ -64,6 +73,8 @@ struct PathSegment { glm::vec3 color; int pixelIndex; int remainingBounces; + float rand_time; + bool is_terminated = false; }; // Use with a corresponding PathSegment to do: @@ -73,4 +84,13 @@ struct ShadeableIntersection { float t; glm::vec3 surfaceNormal; int materialId; + bool outside; }; + + +struct Vertex { + glm::vec3 position; + glm::vec3 normal; + Vertex(glm::vec3 pos, glm::vec3 nor) :position(pos), normal(nor) {} + //Vertex(glm::vec3 pos) :position(pos) {} +}; \ No newline at end of file diff --git a/src/thrust.cu b/src/thrust.cu new file mode 100644 index 0000000..1bbd85f --- /dev/null +++ b/src/thrust.cu @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#include +#include "common.h" +#include "thrust.h" + +namespace StreamCompaction { + namespace Thrust { + using StreamCompaction::Common::PerformanceTimer; + PerformanceTimer& timer() + { + static PerformanceTimer timer; + return timer; + } + /** + * Performs prefix-sum (aka scan) on idata, storing the result into odata. + */ + void scan(int n, int *odata, const int *idata) { + thrust::device_vector dev_idata(idata, idata + n); + thrust::device_vector dev_odata(odata, odata + n); + timer().startGpuTimer(); + thrust::exclusive_scan(dev_idata.begin(), dev_idata.end(), dev_odata.begin()); + // TODO use `thrust::exclusive_scan` + // example: for device_vectors dv_in and dv_out: + // thrust::exclusive_scan(dv_in.begin(), dv_in.end(), dv_out.begin()); + timer().endGpuTimer(); + thrust::copy(dev_odata.begin(), dev_odata.end(), odata); + } + } +} diff --git a/src/thrust.h b/src/thrust.h new file mode 100644 index 0000000..fe98206 --- /dev/null +++ b/src/thrust.h @@ -0,0 +1,11 @@ +#pragma once + +#include "common.h" + +namespace StreamCompaction { + namespace Thrust { + StreamCompaction::Common::PerformanceTimer& timer(); + + void scan(int n, int *odata, const int *idata); + } +} diff --git a/src/tiny_obj_loader.cpp b/src/tiny_obj_loader.cpp new file mode 100644 index 0000000..05ce41e --- /dev/null +++ b/src/tiny_obj_loader.cpp @@ -0,0 +1,2 @@ +#define TINYOBJLOADER_IMPLEMENTATION +#include "tiny_obj_loader.h" \ No newline at end of file diff --git a/stream_compaction/CMakeLists.txt b/stream_compaction/CMakeLists.txt index ac358c9..3d71227 100644 --- a/stream_compaction/CMakeLists.txt +++ b/stream_compaction/CMakeLists.txt @@ -1,4 +1,16 @@ set(SOURCE_FILES + "common.h" + "common.cu" + "cpu.h" + "cpu.cu" + "naive.h" + "naive.cu" + "efficient.h" + "efficient.cu" + "thrust.h" + "thrust.cu" + "radix.cu" + "radix.h" ) cuda_add_library(stream_compaction diff --git a/stream_compaction/common.cu b/stream_compaction/common.cu new file mode 100644 index 0000000..92aea9c --- /dev/null +++ b/stream_compaction/common.cu @@ -0,0 +1,51 @@ +#include "common.h" + +void checkCUDAErrorFn(const char *msg, const char *file, int line) { + cudaError_t err = cudaGetLastError(); + if (cudaSuccess == err) { + return; + } + + fprintf(stderr, "CUDA error"); + if (file) { + fprintf(stderr, " (%s:%d)", file, line); + } + fprintf(stderr, ": %s: %s\n", msg, cudaGetErrorString(err)); + exit(EXIT_FAILURE); +} + + +namespace StreamCompaction { + namespace Common { + + /** + * Maps an array to an array of 0s and 1s for stream compaction. Elements + * which map to 0 will be removed, and elements which map to 1 will be kept. + */ + __global__ void kernMapToBoolean(int n, int *bools, const int *idata) { + // TODO + int index = threadIdx.x + (blockIdx.x * blockDim.x); + if (index >= n) + return; + + if (idata[index]) + bools[index] = true; + } + + /** + * Performs scatter on an array. That is, for each element in idata, + * if bools[idx] == 1, it copies idata[idx] to odata[indices[idx]]. + */ + __global__ void kernScatter(int n, int *odata, + const int *idata, const int *bools, const int *indices) { + // TODO + int index = threadIdx.x + (blockIdx.x * blockDim.x); + if (index >= n) + return; + + if (bools[index]) + odata[indices[index]] = idata[index]; + } + + } +} diff --git a/stream_compaction/common.h b/stream_compaction/common.h new file mode 100644 index 0000000..30d7c28 --- /dev/null +++ b/stream_compaction/common.h @@ -0,0 +1,132 @@ +#pragma once + +#include +#include + +#include +#include +#include +#include +#include +#include + +#define FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) +#define checkCUDAError(msg) checkCUDAErrorFn(msg, FILENAME, __LINE__) + +/** + * Check for CUDA errors; print and exit if there was a problem. + */ +void checkCUDAErrorFn(const char *msg, const char *file = NULL, int line = -1); + +inline int ilog2(int x) { + int lg = 0; + while (x >>= 1) { + ++lg; + } + return lg; +} + +inline int ilog2ceil(int x) { + return ilog2(x - 1) + 1; +} + +namespace StreamCompaction { + namespace Common { + __global__ void kernMapToBoolean(int n, int *bools, const int *idata); + + __global__ void kernScatter(int n, int *odata, + const int *idata, const int *bools, const int *indices); + + /** + * This class is used for timing the performance + * Uncopyable and unmovable + * + * Adapted from WindyDarian(https://github.com/WindyDarian) + */ + class PerformanceTimer + { + public: + PerformanceTimer() + { + cudaEventCreate(&event_start); + cudaEventCreate(&event_end); + } + + ~PerformanceTimer() + { + cudaEventDestroy(event_start); + cudaEventDestroy(event_end); + } + + void startCpuTimer() + { + if (cpu_timer_started) { throw std::runtime_error("CPU timer already started"); } + cpu_timer_started = true; + + time_start_cpu = std::chrono::high_resolution_clock::now(); + } + + void endCpuTimer() + { + time_end_cpu = std::chrono::high_resolution_clock::now(); + + if (!cpu_timer_started) { throw std::runtime_error("CPU timer not started"); } + + std::chrono::duration duro = time_end_cpu - time_start_cpu; + prev_elapsed_time_cpu_milliseconds = + static_cast(duro.count()); + + cpu_timer_started = false; + } + + void startGpuTimer() + { + if (gpu_timer_started) { throw std::runtime_error("GPU timer already started"); } + gpu_timer_started = true; + + cudaEventRecord(event_start); + } + + void endGpuTimer() + { + cudaEventRecord(event_end); + cudaEventSynchronize(event_end); + + if (!gpu_timer_started) { throw std::runtime_error("GPU timer not started"); } + + cudaEventElapsedTime(&prev_elapsed_time_gpu_milliseconds, event_start, event_end); + gpu_timer_started = false; + } + + float getCpuElapsedTimeForPreviousOperation() //noexcept //(damn I need VS 2015 + { + return prev_elapsed_time_cpu_milliseconds; + } + + float getGpuElapsedTimeForPreviousOperation() //noexcept + { + return prev_elapsed_time_gpu_milliseconds; + } + + // remove copy and move functions + PerformanceTimer(const PerformanceTimer&) = delete; + PerformanceTimer(PerformanceTimer&&) = delete; + PerformanceTimer& operator=(const PerformanceTimer&) = delete; + PerformanceTimer& operator=(PerformanceTimer&&) = delete; + + private: + cudaEvent_t event_start = nullptr; + cudaEvent_t event_end = nullptr; + + using time_point_t = std::chrono::high_resolution_clock::time_point; + time_point_t time_start_cpu; + time_point_t time_end_cpu; + + bool cpu_timer_started = false; + bool gpu_timer_started = false; + + float prev_elapsed_time_cpu_milliseconds = 0.f; + float prev_elapsed_time_gpu_milliseconds = 0.f; + }; + } +} diff --git a/stream_compaction/cpu.cu b/stream_compaction/cpu.cu new file mode 100644 index 0000000..41af197 --- /dev/null +++ b/stream_compaction/cpu.cu @@ -0,0 +1,87 @@ +#include +#include "cpu.h" + +#include "common.h" + +namespace StreamCompaction { + namespace CPU { + using StreamCompaction::Common::PerformanceTimer; + PerformanceTimer& timer() + { + static PerformanceTimer timer; + return timer; + } + + /** + * CPU scan (prefix sum). + * For performance analysis, this is supposed to be a simple for loop. + * (Optional) For better understanding before starting moving to GPU, you can simulate your GPU scan in this function first. + */ + void scan(int n, int *odata, const int *idata, bool timer_on) { + if(timer_on) + timer().startCpuTimer(); + // TODO + /*int test[8] = { 3,1,7,0,4,1,6,3 }; + int test_results[8] = {}; + + test_results[0] = 0; + for (int k = 1; k < 8; k++) { + test_results[k] = test_results[k - 1] + test[k - 1]; + } + */ + if (n <= 0) + return; + odata[0] = 0; + for (int k = 1; k < n; k++) { + odata[k] = odata[k - 1] + idata[k - 1]; + } + if(timer_on) + timer().endCpuTimer(); + } + + /** + * CPU stream compaction without using the scan function. + * + * @returns the number of elements remaining after compaction. + */ + int compactWithoutScan(int n, int *odata, const int *idata) { + timer().startCpuTimer(); + // TODO + if (n <= 0) + return 0; + int count = 0; + for (int k = 0; k < n; k++) { + if (idata[k]) + odata[count++] = idata[k]; + } + timer().endCpuTimer(); + return count; + } + + /** + * CPU stream compaction using scan and scatter, like the parallel version. + * + * @returns the number of elements remaining after compaction. + */ + int compactWithScan(int n, int *odata, const int *idata) { + timer().startCpuTimer(); + // TODO + int *check_array = new int[n]; + for (int k = 0; k < n; k++) { + if (idata[k]) + check_array[k] = 1; + else + check_array[k] = 0; + } + scan(n, odata, check_array, false); + delete check_array; + int count = odata[n - 1] + idata[n - 1]; + for (int k = 0; k < n; k++) { + if (idata[k]) + odata[odata[k]] = idata[k]; + } + timer().endCpuTimer(); + return count; + } + } +} diff --git a/stream_compaction/cpu.h b/stream_compaction/cpu.h new file mode 100644 index 0000000..c0fa2f1 --- /dev/null +++ b/stream_compaction/cpu.h @@ -0,0 +1,15 @@ +#pragma once + +#include "common.h" + +namespace StreamCompaction { + namespace CPU { + StreamCompaction::Common::PerformanceTimer& timer(); + + void scan(int n, int *odata, const int *idata, bool timer_on); + + int compactWithoutScan(int n, int *odata, const int *idata); + + int compactWithScan(int n, int *odata, const int *idata); + } +} diff --git a/stream_compaction/efficient.cu b/stream_compaction/efficient.cu new file mode 100644 index 0000000..898b597 --- /dev/null +++ b/stream_compaction/efficient.cu @@ -0,0 +1,241 @@ +#include +#include +#include "common.h" +#include "efficient.h" + +static int blockSize = 1024; +static dim3 blockNum; + +namespace StreamCompaction { + namespace Efficient { + using StreamCompaction::Common::PerformanceTimer; + PerformanceTimer& timer() + { + static PerformanceTimer timer; + return timer; + } + + /** + * Performs prefix-sum (aka scan) on idata, storing the result into odata. + */ +//Non-optimized Scan: + __global__ void non_opt_cudaSweepUp(int n, int d, int *data) { + int index = threadIdx.x + (blockIdx.x * blockDim.x); + int interval_length = 1 << (d + 1); + if (index >= n) + return; + if (index % interval_length == 0) { + data[index + (1 << (d + 1)) - 1] += data[index + (1 << d) - 1]; + } + } + + __global__ void non_opt_cudaSweepDown(int n, int d, int *data) { + int index = threadIdx.x + (blockIdx.x * blockDim.x); + int interval_length = 1 << (d + 1); + // k from 0 to n-1 + if (index >= n) + return; + if (index % interval_length == 0) { + int temp = data[index + (1 << d) - 1]; + data[index + (1 << d) - 1] = data[index + (1 << (d + 1)) - 1]; + data[index + (1 << (d + 1)) - 1] += temp; + } + } + + void non_opt_scan(int n, int *odata, const int *idata) { + // TODO + if (n <= 0) + return; + int celllog = ilog2ceil(n); + + int pow2len = 1 << celllog; + + int *dev_data; + cudaMalloc((void**)&dev_data, pow2len * sizeof(int)); + checkCUDAError("cudaMalloc dev_data failed!"); + + cudaMemcpy(dev_data, idata, pow2len * sizeof(int), cudaMemcpyHostToDevice); + checkCUDAError("cudaMemcpy failed!"); + + timer().startGpuTimer(); + + //Up-Sweep + for (int d = 0; d <= celllog - 1; d++) { + blockNum = (pow2len + blockSize) / blockSize; + non_opt_cudaSweepUp << > >(pow2len, d, dev_data); + } + + //cudaMemcpy(odata, dev_data, n * sizeof(int), cudaMemcpyDeviceToHost); + + //Down-Sweep + cudaMemset(dev_data + pow2len - 1, 0, sizeof(int)); + checkCUDAError("cudaMemset failed!"); + + for (int d = celllog - 1; d >= 0; d--) { + blockNum = (pow2len + blockSize) / blockSize; + non_opt_cudaSweepDown << > >(pow2len, d, dev_data); + } + timer().endGpuTimer(); + + cudaMemcpy(odata, dev_data, n * sizeof(int), cudaMemcpyDeviceToHost); + + checkCUDAError("cudaMalloc dev_data to odata failed!"); + + cudaFree(dev_data); + checkCUDAError("cudaFree dev_data failed!"); + + } + +//Optimized Scan + __global__ void cudaSweepUp(int n, int d, int *data) { + int index = threadIdx.x + (blockIdx.x * blockDim.x); + int interval_length = 1 << (d + 1); + if (index >= n) + return; + //int idx1 = index * interval_length + (1 << (d + 1)) - 1; + //int idx2 = index * interval_length + (1 << d) - 1; + data[index * interval_length + (1 << (d + 1)) - 1] += data[index * interval_length + (1 << d) - 1]; + } + + __global__ void cudaSweepDown(int n, int d, int *data) { + int index = threadIdx.x + (blockIdx.x * blockDim.x); + int interval_length = 1 << (d + 1); + // k from 0 to n-1 + if (index >= n) + return; + + int temp = data[index * interval_length + (1 << d) - 1]; + data[index * interval_length + (1 << d) - 1] = data[index * interval_length + (1 << (d + 1)) - 1]; + data[index * interval_length + (1 << (d + 1)) - 1] += temp; + } + + void scan(int n, int *odata, const int *idata) { + // TODO + if (n <= 0) + return; + int celllog = ilog2ceil(n); + + int pow2len = 1 << celllog; + + int *dev_data; + + cudaMalloc((void**)&dev_data, pow2len * sizeof(int)); + checkCUDAError("cudaMalloc dev_data failed!"); + + cudaMemcpy(dev_data, idata, pow2len * sizeof(int), cudaMemcpyHostToDevice); + checkCUDAError("cudaMemcpy failed!"); + + timer().startGpuTimer(); + + //Up-Sweep + for (int d = 0; d <= celllog - 1; d++) { + int interval_length = (1 << (d + 1)); + blockNum = (pow2len / interval_length + blockSize) / blockSize; + cudaSweepUp<<>>(pow2len / interval_length, d, dev_data); + } + + //cudaMemcpy(odata, dev_data, n * sizeof(int), cudaMemcpyDeviceToHost); + + //Down-Sweep + cudaMemset(dev_data + pow2len - 1, 0, sizeof(int)); + checkCUDAError("cudaMemset failed!"); + + for (int d = celllog - 1; d >= 0; d--) { + int num_operations = (1 << (d + 1)); + blockNum = (pow2len / num_operations + blockSize) / blockSize; + cudaSweepDown<<>>(pow2len / num_operations, d, dev_data); + } + timer().endGpuTimer(); + + cudaMemcpy(odata, dev_data, n * sizeof(int), cudaMemcpyDeviceToHost); + + checkCUDAError("cudaMmcpy dev_data to odata failed!"); + + cudaFree(dev_data); + checkCUDAError("cudaFree dev_data failed!"); + + } + + /** + * Performs stream compaction on idata, storing the result into odata. + * All zeroes are discarded. + * + * @param n The number of elements in idata. + * @param odata The array into which to store elements. + * @param idata The array of elements to compact. + * @returns The number of elements remaining after compaction. + */ + int compact(int n, int *odata, const int *idata) { + // TODO + if (n <= 0) + return -1; + int celllog = ilog2ceil(n); + int pow2len = 1 << celllog; + + int *dev_idata, *dev_odata, *dev_bool_data, *dev_indices; + cudaMalloc((void**)&dev_idata, pow2len * sizeof(int)); + checkCUDAError("cudaMalloc dev_idata failed!"); + cudaMalloc((void**)&dev_odata, pow2len * sizeof(int)); + checkCUDAError("cudaMalloc dev_odata failed!"); + cudaMalloc((void**)&dev_bool_data, pow2len * sizeof(int)); + checkCUDAError("cudaMalloc dev_bool_data failed!"); + cudaMalloc((void**)&dev_indices, pow2len * sizeof(int)); + checkCUDAError("cudaMalloc dev_indices failed!"); + + //bool Mapping + cudaMemcpy(dev_idata, idata, n * sizeof(int), cudaMemcpyHostToDevice); + timer().startGpuTimer(); + blockNum = (n + blockSize) / blockSize; + Common::kernMapToBoolean<<>>(n, dev_bool_data, dev_idata); + // Scan + cudaMemcpy(dev_indices, dev_bool_data, pow2len * sizeof(int), cudaMemcpyDeviceToDevice); + checkCUDAError("cudaMemcpy failed!"); + dev_bool_data; + + //Up-Sweep + for (int d = 0; d <= celllog - 1; d++) { + int interval_length = (1 << (d + 1)); + blockNum = (pow2len / interval_length + blockSize) / blockSize; + cudaSweepUp << > >(pow2len / interval_length, d, dev_indices); + } + + + //Down-Sweep + cudaMemset(dev_indices + pow2len - 1, 0, sizeof(int)); + checkCUDAError("cudaMemset failed!"); + + for (int d = celllog - 1; d >= 0; d--) { + int num_operations = (1 << (d + 1)); + blockNum = (pow2len / num_operations + blockSize) / blockSize; + cudaSweepDown << > >(pow2len / num_operations, d, dev_indices); + } + + + //Scattered + blockNum = (n + blockSize) / blockSize; + Common::kernScatter<<>>(n, dev_odata, dev_idata, dev_bool_data, dev_indices); + + timer().endGpuTimer(); + //compute count + int a, b; + cudaMemcpy(&a, dev_bool_data + (n - 1), sizeof(int), cudaMemcpyDeviceToHost); + cudaMemcpy(&b, dev_indices + (n - 1), sizeof(int), cudaMemcpyDeviceToHost); + int count = a + b; + cudaMemcpy(odata, dev_odata, count * sizeof(int), cudaMemcpyDeviceToHost); + checkCUDAError("cudaMemcpy dev_odata to odata failed!"); + + //Free data + cudaFree(dev_idata); + checkCUDAError("cudaFree dev_idata failed!"); + cudaFree(dev_odata); + checkCUDAError("cudaFree dev_idata failed!"); + cudaFree(dev_bool_data); + checkCUDAError("cudaFree dev_idata failed!"); + cudaFree(dev_indices); + checkCUDAError("cudaFree dev_idata failed!"); + + + return count; + } + } +} diff --git a/stream_compaction/efficient.h b/stream_compaction/efficient.h new file mode 100644 index 0000000..4e3d15e --- /dev/null +++ b/stream_compaction/efficient.h @@ -0,0 +1,15 @@ +#pragma once + +#include "common.h" + +namespace StreamCompaction { + namespace Efficient { + StreamCompaction::Common::PerformanceTimer& timer(); + + void non_opt_scan(int n, int *odata, const int *idata); + + void scan(int n, int *odata, const int *idata); + + int compact(int n, int *odata, const int *idata); + } +} diff --git a/stream_compaction/naive.cu b/stream_compaction/naive.cu new file mode 100644 index 0000000..1df1088 --- /dev/null +++ b/stream_compaction/naive.cu @@ -0,0 +1,73 @@ +#include +#include +#include "common.h" +#include "naive.h" + +static int blockSize = 1024; +static dim3 blockNum; + +namespace StreamCompaction { + namespace Naive { + using StreamCompaction::Common::PerformanceTimer; + PerformanceTimer& timer() + { + static PerformanceTimer timer; + return timer; + } + // TODO: __global__ + __global__ void Parallel_Add(int n, int d, int *odata, const int *idata) { + int index = threadIdx.x + (blockIdx.x * blockDim.x); + + if (index >= n) + return; + + int flag = 1 << (d - 1); + if (index >= flag) { + odata[index] = idata[index - flag] + idata[index]; + } + else { + odata[index] = idata[index]; + } + + } + /** + * Performs prefix-sum (aka scan) on idata, storing the result into odata. + */ + void scan(int n, int *odata, const int *idata) { + // TODO + if (n <= 0) + return; + int celllog = ilog2ceil(n); + odata[0] = 0; + + int *dev_data[2]; + + cudaMalloc((void**)&dev_data[0], n * sizeof(int)); + checkCUDAError("cudaMalloc dev_data[0] failed!"); + + cudaMalloc((void**)&dev_data[1], n * sizeof(int)); + checkCUDAError("cudaMalloc dev_data[1] failed!"); + + cudaMemcpy(dev_data[0], idata, n * sizeof(int), cudaMemcpyHostToDevice); + checkCUDAError("cudaMemcpy failed!"); + + timer().startGpuTimer(); + int out_index = 0; + + blockNum = (n + blockSize - 1) / blockSize; + for (int d = 1; d <= celllog; d++) { + out_index ^= 1; + Parallel_Add << > > (n, d, dev_data[out_index], dev_data[out_index ^ 1]); + } + timer().endGpuTimer(); + + cudaMemcpy(odata + 1, dev_data[out_index], (n-1) * sizeof(int), cudaMemcpyDeviceToHost); + checkCUDAError("cudaMalloc dev_data[1] failed!"); + + cudaFree(dev_data[0]); + cudaFree(dev_data[1]); + checkCUDAError("cudaMalloc dev_data[1] failed!"); + + } + } +} diff --git a/stream_compaction/naive.h b/stream_compaction/naive.h new file mode 100644 index 0000000..37dcb06 --- /dev/null +++ b/stream_compaction/naive.h @@ -0,0 +1,11 @@ +#pragma once + +#include "common.h" + +namespace StreamCompaction { + namespace Naive { + StreamCompaction::Common::PerformanceTimer& timer(); + + void scan(int n, int *odata, const int *idata); + } +} diff --git a/stream_compaction/radix.cu b/stream_compaction/radix.cu new file mode 100644 index 0000000..378b958 --- /dev/null +++ b/stream_compaction/radix.cu @@ -0,0 +1,146 @@ +#include +#include +#include "common.h" +#include "naive.h" + +namespace StreamCompaction { + namespace Radix { + using StreamCompaction::Common::PerformanceTimer; + PerformanceTimer& timer(){ + static PerformanceTimer timer; + return timer; + } + + int *dev_Data[2]; + int *dev_bArray; + int *dev_eArray; + int *dev_fArray; + int *dev_tArray; + int *dev_dArray; + + __global__ void cudaSweepUp(int n, int d, int *data) { + int index = threadIdx.x + (blockIdx.x * blockDim.x); + int interval_length = 1 << (d + 1); + if (index >= n) + return; + //int idx1 = index * interval_length + (1 << (d + 1)) - 1; + //int idx2 = index * interval_length + (1 << d) - 1; + data[index * interval_length + (1 << (d + 1)) - 1] += data[index * interval_length + (1 << d) - 1]; + } + + __global__ void cudaSweepDown(int n, int d, int *data) { + int index = threadIdx.x + (blockIdx.x * blockDim.x); + int interval_length = 1 << (d + 1); + // k from 0 to n-1 + if (index >= n) + return; + + int temp = data[index * interval_length + (1 << d) - 1]; + data[index * interval_length + (1 << d) - 1] = data[index * interval_length + (1 << (d + 1)) - 1]; + data[index * interval_length + (1 << (d + 1)) - 1] += temp; + } + + __global__ void cudaGetBEArray(int pass, int *idata, int *odata1, int *odata2, int n){ + int index = (blockIdx.x * blockDim.x) + threadIdx.x; + if (index >= n) + return; + odata1[index] = (idata[index] >> pass) & 1; + odata2[index] = odata1[index] ^ 1; + } + + __global__ void cudaGetTArray(int *idata, int *e, int *odata, int n){ + int index = (blockIdx.x * blockDim.x) + threadIdx.x; + int totalFalses = idata[n - 1] + e[n - 1]; + if (index >= n) + return; + odata[index] = index - idata[index] + totalFalses; + } + + __global__ void cudaGetDArray(int *idata1, int *idata2, int *idata3, int *odata, int n){ + int index = (blockIdx.x * blockDim.x) + threadIdx.x; + if (index >= n) + return; + odata[index] = idata1[index] ? idata2[index] : idata3[index]; + } + + __global__ void cudaGetResult(int *idata, int *odata, int *data, int n){ + int index = (blockIdx.x * blockDim.x) + threadIdx.x; + if (index >= n) + return; + odata[idata[index]] = data[index]; + } + + void RadixSort(int n, int *odata, int *idata){ + + int blockSize = 512; + int blockNum; + int celllog = ilog2ceil(n); + int pow2len = 1 << celllog; + int pout = 1; + cudaMalloc((void**)&dev_Data[0], n * sizeof(int)); + cudaMalloc((void**)&dev_Data[1], n * sizeof(int)); + cudaMalloc((void**)&dev_bArray, n * sizeof(int)); + cudaMalloc((void**)&dev_eArray, pow2len * sizeof(int)); + cudaMalloc((void**)&dev_fArray, pow2len * sizeof(int)); + cudaMalloc((void**)&dev_tArray, n * sizeof(int)); + cudaMalloc((void**)&dev_dArray, n * sizeof(int)); + cudaMemset(dev_eArray, 0, pow2len * sizeof(int)); + cudaMemcpy(dev_Data[0], idata, sizeof(int) * n, cudaMemcpyHostToDevice); + checkCUDAError("cudaMemcpy to device failed!"); + checkCUDAError("cudaMalloc failed!"); + + int max_num = 0; + for (int i = 0; i < n; i++) + if (idata[i] > max_num) + max_num = idata[i]; + + timer().startGpuTimer(); + int pass = 0; + while (true){ + int pin = pout ^ 1; + if ((max_num >> pass) == 0) + break; + blockNum = n / blockSize + 1; + cudaGetBEArray << > >(pass, dev_Data[pin], dev_bArray, dev_eArray, n); + cudaMemcpy(dev_fArray, dev_eArray, pow2len * sizeof(int), cudaMemcpyDeviceToDevice); + checkCUDAError("cudaMemcpy device to device failed!"); + + for (int d = 0; d <= celllog - 1; d++){ + int interval_length = (1 << (d + 1)); + blockNum = (pow2len / interval_length + blockSize) / blockSize; + cudaSweepUp << > >(pow2len / interval_length, d, dev_fArray); + } + + cudaMemset(dev_fArray + pow2len - 1, 0, sizeof(int)); + checkCUDAError("cudaMemset failed!"); + for (int d = celllog - 1; d >= 0; d--) { + int interval_length = (1 << (d + 1)); + blockNum = (pow2len / interval_length + blockSize) / blockSize; + cudaSweepDown << > >(pow2len / interval_length, d, dev_fArray); + } + + blockNum = n / blockSize + 1; + cudaGetTArray << > > (dev_fArray, dev_eArray, dev_tArray, n); + cudaGetDArray << > >(dev_bArray, dev_tArray, dev_fArray, dev_dArray, n); + cudaGetResult << > >(dev_dArray, dev_Data[pout], dev_Data[pin], n); + + pass++; + pout ^= 1; + } + timer().endGpuTimer(); + + cudaMemcpy(odata, dev_Data[pout ^ 1], sizeof(int) * n, cudaMemcpyDeviceToHost); + checkCUDAError("cudaMemcpy to host failed!"); + + + cudaFree(dev_Data[0]); + cudaFree(dev_Data[1]); + cudaFree(dev_bArray); + cudaFree(dev_eArray); + cudaFree(dev_fArray); + cudaFree(dev_tArray); + cudaFree(dev_dArray); + } + + } +} \ No newline at end of file diff --git a/stream_compaction/radix.h b/stream_compaction/radix.h new file mode 100644 index 0000000..6cc72a5 --- /dev/null +++ b/stream_compaction/radix.h @@ -0,0 +1,7 @@ +#pragma once + +namespace StreamCompaction { + namespace Radix { + void RadixSort(int n, int *odata, int *idata); + } +} \ No newline at end of file diff --git a/stream_compaction/thrust.cu b/stream_compaction/thrust.cu new file mode 100644 index 0000000..1bbd85f --- /dev/null +++ b/stream_compaction/thrust.cu @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#include +#include "common.h" +#include "thrust.h" + +namespace StreamCompaction { + namespace Thrust { + using StreamCompaction::Common::PerformanceTimer; + PerformanceTimer& timer() + { + static PerformanceTimer timer; + return timer; + } + /** + * Performs prefix-sum (aka scan) on idata, storing the result into odata. + */ + void scan(int n, int *odata, const int *idata) { + thrust::device_vector dev_idata(idata, idata + n); + thrust::device_vector dev_odata(odata, odata + n); + timer().startGpuTimer(); + thrust::exclusive_scan(dev_idata.begin(), dev_idata.end(), dev_odata.begin()); + // TODO use `thrust::exclusive_scan` + // example: for device_vectors dv_in and dv_out: + // thrust::exclusive_scan(dv_in.begin(), dv_in.end(), dv_out.begin()); + timer().endGpuTimer(); + thrust::copy(dev_odata.begin(), dev_odata.end(), odata); + } + } +} diff --git a/stream_compaction/thrust.h b/stream_compaction/thrust.h new file mode 100644 index 0000000..fe98206 --- /dev/null +++ b/stream_compaction/thrust.h @@ -0,0 +1,11 @@ +#pragma once + +#include "common.h" + +namespace StreamCompaction { + namespace Thrust { + StreamCompaction::Common::PerformanceTimer& timer(); + + void scan(int n, int *odata, const int *idata); + } +}