Giter Site home page Giter Site logo

ray-tracing's Introduction

Ray-tracing

A set of C++ codes to render a scene using stochastic ray tracing.

Overview

This repository contains codes that can be used to :

  • define a scene with objects having their own optical properties
  • and render this scene (as an image) with stochastic ray casting

Each object can be a sphere, a triangular face, or a more complex object defined by a triangular mesh (i.e. an ensemble of triangular faces).

Ray casting works by tracing a path from an imaginary eye through each pixel in a virtual screen, and calculating the color of the object visible through it. In our case, we use the recursive version of that algorithm where each cast ray generates refracted or reflected rays which will be taken into account to compute tje color of the pixel.

Features

Here a brief and visual summary of the different features available in this code.

Direct and indirect lighting (Monte-Carlo)

Each object can be illuminated in two ways :

  • through direct lighting, i.e. with light coming from the light source
  • through indirect lighting, i.e. with light reflected by intermediary objects
The indirect component is computed by Monte-Carlo integration of stochastic rays, i.e. rays cast in random directions.
Direct lighting only Direct & Indirect lighting

Also note the importance of the number of stochastic rays (N) in the monte-carlo integration and the influence it has on the quality of the rendered image.

4 rays 2000 rays

Expanded light source

Having a spatially extended light source (instead of a punctual one) causes shadows to be softer. In our case, we modeled that by considering that the light source was a sphere oy radius R_lum.

Expanded source, R_lum=2 Expanded light source, R_lum=6

Anti-aliasing

There are several methods to implement anti-aliasing. We opted for one that consists in casting N rays from random positions inside each pixel instead of having all of them cast from pixel centers.

Without anti-aliasing With anti-aliasing

Phong's smoothing

Phong's smoothing is a technique that renders smoother meshes. It consists in interpolating, for each pixel, surface normals of triangular elements.

Without Phong's smoothing With Phong's smoothing

Depth of field

To simulate blur in our images, we chose to model a pinhole camera, which are made of a lens and a shutter.

Default camera Pinhole camera

How to use it

To use this code, first make sure that you have a C++ compiler. Then, we advise you to use Visual Code Studio. You can open the project from Visual Studio Code using the Lancer de Rayon\Lancer de Rayon.sln file.Finally, generate the solution and run the code to render the image that was defined in the Lancer de Rayon\Lancer de Rayon\Source.cpp script.

ray-tracing's People

Contributors

mehdi-elion 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.