Git Product home page Git Product logo

ray-tracer's Introduction

Ray-Tracer

A simple ray tracing program for rendering 3D scene written in C++.

Final Image

Features:

  • Camera (Projection, Perspective)
  • Shading (Ambient, Diffuse, Specular)
  • Shadows
  • Reflections
  • Plane, sphere and custom geometry
  • Simple scene graph
  • Simple animations

Installation:

Clone/fork repository (make sure to use the recursive flat to fetch submodules too, e.g git clone http://repo.link --recursive)

mkdir build and cd build

run cmake ../ -DCMAKE_BUILD_TYPE=Release

run make

run ./Raytracer

Usage:

The ray tracer uses a simple scene graph structure which makes it easier to add/remove objects from the rendered scene. For example this is how you could create a scene with a sphere:

    //Instance a scene
    Scene scene;
  
    //Create a perspective camera (1st parameter is position)
    Camera::PerspectiveCamera camera(Vector3d(0, 0, -2));
  
    //Create a diffused material
    Material diffusedMat(0.2, //Ambient intensity
                         Vector3d(1, 1, 1.5), // Ambient coefficiencies
                         0.4, // Diffuse intensity
                         Vector3d(1, 1, 1.5), // Diffuse coefficiencies
                         0,//Specular intensity
                         Vector3d(1, 1, 1), //Specular coefficiencies
                         1000); // Phong exponent

    
    //Instance a sphere
    Sphere sphere(Vector3d(-1, .5, 3), 0.5);
    sphere.setMaterial(specularMat);
    scene.add(sphere);

To add a light to the same scene we would do this

  // Instance a light (vec3 position, float intensity)
  Light light(Vector3d(-3, .5, -1.8), 1);
  scene.add(light);

And finally to load an .off model we would do this

  //First argument is a position vector
  Model model(Vector3d(-4, 10, 50));
  model.loadOFF("bumpy_cube.off");
  model.setMaterial(specularMat);

Dependencies:

Tested on macOS (10.13.2) using CMake (3.10.0)

ray-tracer's People

Contributors

juniorxsound 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.