Skip to the content.

It is developed for the course Numerical techniques for photorealistic image generation held by professor Maurizio Tomasi (University of Milan, AY2020-2021).

๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป The main contributors to this repository are Elisa Legnani and Adele Zaini.

Table of Contents

Brief description

The main functionality of the library is rendering photorealistic images from user instructions on an external input text file. The code features four different backwards raytracing algorithms (onoff, flat, pathtracer, pointlight tracer) and โ€“at the momentโ€“ the scene elements are basic geometric shapes (spheres, planes, boxes). Setting material properties of the objects determines the interaction with light rays, while the observer point of view is represented by a camera with two different projections available (orthogonal and perspective). This library has another useful functionality that is converting HDR images to LDR ones. The format supported are respectively PFM and PNG/JPG.

Here you can find a detailed explanation of the program usage for better understanding how to generate photorealistic images and to convert images together with the parameters you can set.

๐ŸŒˆ โ€œReality leaves a lot to the imagination.โ€ โ€“ J. Lennon. Here is the mean, now itโ€™s your turnโ€ฆ unleash all your imagination!

Installation

๐Ÿ”— Information on how to install and compile the code are on our GitHub repository.

Usage

You can run the program through the script raytracer, located in the build directory.

The code implements two features, that you can call with commands:

The basic usage is the following:

./raytracer [COMMAND] [INPUT_FILENAME] {OPTIONS}

The [INPUT_FILENAME] represents the input filename with the path where to find it, it is a required argument to pass. There are some examples in the examples directory if you want to give it a try or play with the code!

To have more information about available {OPTIONS}, a commmand-line help shows more details about program features and parameters:

./raytracer --help

The command line interface is built using the argument parsing library Taywee/args.

For further details, see below.

Create your own photorealistic image

In order to create your photorealistic images, you need to give instructions to the code on the scene you want to render. You can write them in a TXT file and run in the build directory:

  ./raytracer render [SCENE_FILENAME] {OPTIONS}

Scene file

First argument to pass is:

At the moment (any contribution is welcome!!), the implemented elements you can add at the scene are:

whose you can set material and geometric properties.

๐Ÿ”— You can find detailed instructions on how to write the scene file at the page Scene description.

In the examples/render directory, some scene file examples are provided to start playing with the code. Expecially, look at demo.txt to explore all the potentialities of the code! Our suggestion is to try passing the same scene file with different rendering algorithms while changing the parameters setting, this will surely tickle your creativity! โœจ

Parameters

Some parameters are available for users to set properties of the rendered image. You can set them directly in the command line, as explained in {OPTIONS} of the help interface (running ./raytracer render).

๐Ÿ”— For further explanation on the fuctionality of each parameter, see the full documentation.

Here is an example of usage:

  ./raytracer render ../examples/render/demo.txt -w 640 -h 480 -r pathtracer --output ../my_first_image.png -v angle=30

๐Ÿ’ก Warning on pointlight tracer: the pointlight tracer is not able to render reflective surfaces.

โณ Note: the more parameters values increase, the more the rendering process takes a long time to produce an image.

Generate image

You may easily try the code running in the examples/render directory:

  ./generate-image.sh ANGLE <a-factor>

which automatically runs the following code:

  ../../build/./raytracer render image.txt --declare_var ang=ANGLE --output img/imageANGLE.png --a_r a-factor

You just need to set the ANGLE (deg) from which you look at the scene and optionally also the luminosity <a-factor> (default 1).

The scene description is in image.txt file (support file).

Note: if you change image.txt content, remember to:

1) adapt the files path properly, you are now in examples/render directory; 2) keep rotation_z(ang) in the camera transformation.

Generate animation

In the examples/render directory, you may generate an animation of a simple scene described in image.txt, rotating 360ยฐ around the objects.

In order to run the code, you need to:

This is needed to run in parallel the code and speed up the execution, otherwise it would take a very long time.

  ./generate-animation.sh NUM_OF_CORES <a-factor> <output_filename>

You can also set the luminosity <a-factor> (default 1) and the <output_filename> (default video.mp4).

Here is a suggestive animation of the solar system:

โณ Pay attention when passing a scene description that takes long to render: even if we are using a parallel execution there are lots of images to render and can take a while.

Parallelize image execution

In the examples/render directory, another script called ./parallelize-image.sh has the functionality to parallelize the program execution when rendering the instructions in image.txt. The purpose is to speed up the execution particullarly when running the pathtracer algorithm. Here is the usage:

./parallelize-image.sh NUM_OF_CORES <angle> <width> <height> <output_filename> <a-factor> <samples> <n_rays> <depth>

You just need to set the NUM_OF_CORES, while the other parameters are optional.

Default values: angle 0 width 640 height 480 output_filename image.png ` a-factor 1 samples 0 n_rays 10 depth` 2

Convert HDR image into LDR

In the build directory run:

  ./raytracer hdr2ldr [HDR_IMAGE] {OPTIONS}

The HDR image format supported is PFM, while LDR ones are PNG and JPG.

You can also set some parameters according to your preferences in the output image visualisation. You can set them directly in the command line, as explained in {OPTIONS} of the help interface (running ./raytracer hdr2ldr).

  ./raytracer hdr2ldr [HDR_IMAGE] -a 0.3 -g 1.0 --out <output_file.jpg>

๐Ÿ”— For further explanation on the specific meaning of the two parameters, see the full documentation.

Example

In the examples/hdr2ldr directory, there is a PFM input file called memorial.pfm. You can play with the code and parameters simply running (in the build directory):

  ./raytracer hdr2ldr ../examples/hdr2ldr/memorial.pfm -a 0.3 -g 1.0 

PFM

Documentation

๐Ÿ““ The complete documentation of the library is available here. It was generated with Doxygen. This is the first version of the documentation, any suggestions are very appreciated!

Potentialities and examples

๐Ÿคน๐Ÿปโ€โ™€๏ธ There is a nice overview of the library potentialities with lots of examples, hoping this can tickle your creativity!

Contributing

๐Ÿšง Please open pull requests or use the issue tracker to suggest any code implementations or report bugs. Any contributions are welcome!

License

๐Ÿ“‹ The code is released under the terms of the GNU General Public License v3.0. See the file LICENSE.md.