Git Product home page Git Product logo

ray_tracer's Introduction

Javascript Simple Ray Tracer

This is a ray tracing implemented in javascript.

Screenshot

How to play with it

Open the link in your browser and wait for the image to be rendered. This can take from a few seconds to a minute depending on your machine.

Use the checkboxes to modify the scene and hit render button to render again.

Controls

Graphics features

  • Object intersection of planes and spheres
  • Point light
  • Reflection
  • Shadow
  • Material
    • color
    • specular component
    • reflectiveness

Algorithms Used

Primary Ray

Each pixel shoots one primary ray, which originates from the camera postion. The ray travels in the direction of the center of the pixel - camera position.

Object Intersection

Each primary ray intersects zero or more objects. If the ray hits an object, the intersection with the lowest t value larger than epsilon is returned, along with the object properties useful for shading (such as color, normal, etc.). Each type of object has its own hit() method for calculating intersection with a ray. If a ray does not intersection any object, background color is returned.

Shading

This ray tracer uses a simple Phong light model. All objects have ambient light by default. The contribution of each light, including diffuse light and specular light, on the a intersection point is calculated and accumulated.

Shadow

A shadow ray is casted from an intersection to each light. If the shadow ray hits an object, then the intersection point is in the shadow of that object and a shadow color is returned.

Reflection

A reflection ray is casted from each intersection point and the returned color is added to the color of the intersection point after being multiplied by the relfectiveness of the object surface. This procedure is recursive so a limit is set on the recursion depth.

Third-part Library

gl-matrix.js was used for all the vector calculations, including add, subtract, dot product and scaling, etc. gl-matrix.js vector calculation functions look like this: vec3.function(). Some of the most used functions in this project are:

  • vec3.create()
  • vec3.fromValues()
  • vec3.add()
  • vec3.sub()
  • vec3.dot()
  • vec3.scale()
  • vec3.scaleAndAdd()

Acknowledgement

Special thanks to Professor Peter Yoon for his book on ray tracing.

Thanks to Brandon Jones and Colin MacKenzie for their gl-matrix.js math library.

ray_tracer's People

Contributors

minghui-liu avatar gilmaicor avatar

Watchers

James Cloos avatar  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.