Giter Club home page Giter Club logo

monte_carlo_ray_tracing's Introduction

Environments

The implementation code can be found here

System: WIN10

Compiler: Visual Studio 2019

Dependencies: glm, opencv, sol

  • The sol has been properly set up, but you need to configure glm and opencv in order to run it.
  • Use vcpkg for configuration. After downloading, click on the .bat file inside the folder, add the folder to system path, and enter the commands vcpkg install glm and vcpkg install opencv:x64-windows to install glm and opencv.
  • Save the image using svpng.
  • The loading of .obj files is facilitated using tiny_obj_loader.

Content

Programming implementation of the Monte Carlo Path Tracing algorithm. The detail requirements of this task are given here.

Input: Model files in obj format and material files in mtl format, with lua as the configuration file, setting the radiance of light sources and various attributes of the camera, etc.

Output: The current rendering information would be displayed in the console, and the results would be saved in the result folder in .png format when the rendering is finished.

High specular reflection, diffuse reflection, and refraction effects have been implemented.

Run

Open MonteCarloPathTracing.vcxproj, run main.cpp in release and x64 mode, adjust the SPP parameter through scene.cpp, and save the results in the result folder.

Explanation of project structures

  • BoundingBox is a bounding box used for accelerating calculations.
  • BVH is a structure tree of bounding boxes.
  • Camera represents a camera, including projection type, camera position, viewing direction, upward direction, and fovy information. These information can be read from a .lua file.
  • DataFrame is a data structure for storing images.
  • IntersectResult is the result of an intersection calculation, which stores necessary data required for certain computations.
  • Light is a class representing light sources, which stores relevant information about the light source. However, the radiance of the light source is still stored in the Triangle class.
  • LuaConfigParser is used for reading .lua information.
  • main.h file contains some #define, such as PI, EPSILON, and the probability in the Russian roulette.
  • Material is used for storing textures and contains a built-in isTextureFlag, which is set to true when the texture needs to be mapped to an external file. The file name of this external file is stored in the corresponding string.
  • Obj is used for loading .obj files.
  • Ray represents a ray, which includes the starting point and direction of the ray, as well as functions for reflection and refraction.
  • Sample represents a sampling.
  • Scene represents a scene, which contains necessary information such as models, cameras, and light sources.
  • Shape represents geometry and contains the Point class and Triangle class.
  • Texture represents texture mapping.

Acceleration instructions

  • Direct lighting is used, which means before sampling, the light sources in the scene are traversed to calculate the direct illumination at intersection points. In this way, a relatively bright rendering result can be achieved with a small number of samples. Then, ray tracing is performed based on this result, which allows the rendering result to quickly converge to the realistic scene effect.
  • The BVH data structure is used for acceleration. The entire scene's models are organized into a hierarchical tree structure consisting of bounding boxes. By performing simple intersection tests between rays and bounding boxes, it can be determined whether further intersection tests with the scene are necessary. This avoids performing intersection calculations for rays that do not intersect with the scene, thereby improving the efficiency of the intersection calculations that are frequently performed in path tracing algorithms. As a result, the algorithm's efficiency is significantly improved.
  • Utilize OpenMP for loop acceleration in the path tracing algorithm. In the path tracing algorithm, the ray tracing between different pixels is independent, and there are no dependencies between them, allowing for parallel computation. OpenMP provides excellent support for compiling programs into multi-core parallel code, thereby effectively utilizing the hardware resources of multi-core CPUs and achieving acceleration of the path tracing algorithm.

Result

staircase-128SPP

cornell-box-16SPP

veach-mis-1024SPP

monte_carlo_ray_tracing's People

Contributors

haominguo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

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

  • Vue.js photo Vue.js

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

  • Typescript photo Typescript

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

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

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

  • web

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

  • server

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

  • Machine learning

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

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

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

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.