Git Product home page Git Product logo

rt's Introduction

rt

A backward ray tracer that takes in JSON scene files and outputs images.

Motivation

Ever since I took a ray tracing course in college, I wanted to build one outside of the constraints of the class. I enjoy the images that ray tracers produce almost as much as I enjoy the way they're produced (as opposed to more traditional graphics engines). This project is largely a learning exercise in architecture, unit testing, and class design. I've chosen C# since it's the language I'm currently most familiar with, but I could see this slowly converting over to C++ libraries as I develop more of the project.

Thanks for stopping by!

How To Run

Requirements

I used Microsoft Visual Studio Community 2019 to create this project, though if you're code-savvy you might be able to compile it with whatever tools you prefer.

Steps

  1. Clone the project
  2. Open up rt.sln
  3. Press F5
  • Optional
    • Tweak dev_config.json to change how detailed you want the image, and to specify which scene you want to render.
    • Keep reading if you want to understand the specifics.

Data Files

Paths

rt is nearly completely data-driven, it reads in files from the following locations in the given priority order.

  1. The same directory as the exe
  2. The root of the development directory, called <src_root>
  3. The <src_root>\scenes directory
  4. The <src_root>\scenes\unit_tests directory
  5. The <src_root>\scenes\unconverted directory

Two types of files are supported, one for the config that rt takes as a command line argument, and within that file there's the specified scenes.

Config

Config files contain information on how to generate the image. In this file you specify:

  • See <src_root>\dev_config.json as an example.

  • width - The number of pixels for the width of the image. The height is calculated from the aspect ratio of the projection plane in the scene file.

  • renderDepth - The max number of bounces each ray can make, the higher this number the more light detail is calculated for each pixel at the cost of render speed.

  • output - What you want the generated file to be called, unused currently.

  • sceneFile - A list of scenes that you want to render, all of which use the same width and renderDepth values.

Scene

Scene files contain information about how the scene is constructed, specifically:

  • See any file in <src_root>\scenes\ as an example.

  • camera - Represents the viewpoint through which we observe the scene.

    • eyeDirection - Direction vector specifying the camera's eye position relative to the projection plane's center.
    • projectionPlane - The surface through which we view the scene, used in conjunction with the camera's eye position to generate the initial rays that we cast.
      • center - Center of the projection plane, used for per-pixel location calculations.
      • uAxis - Horizontal axis of the projection plane, length is half the width of the projection plane.
      • vAxis - Vertical axis of the projection plane, length is half the height of the projection plane.
  • shapes

    • material - All shapes contain this set of properties that describe how they appear, basic explainations are given but correct terms are used if you want to search online for more info.
      • transmissionAttenuation - The type of color produced by light that goes through the object, RGB values in the range of [0, 1]
      • diffuse - The surface color of the object, RGB values in the range of [0, 1]
      • specularCoefficient - How shiny the object appears, values in the range of [0, 1]
      • specularExponent - How big the shiny dot appears, values usually >1
      • electricPermittivity - Used to calculate the air's index of refraction.
      • magneticPermeability - Used to calculate the air's index of refraction and reflection coefficients.
    • spheres - Point and radius
    • boxes - Corner point and 3 scaled direction vectors. Vectors don't need to be orthogonal, which will result in parallelpipeds.
    • polygons - List of vertices specified in a fan format (first point is the anchor, every consecutive set of 2 points after the first are used to create individual triangles with the first).
    • ellipsoids - Point and 3 scaled direction vectors. Vectors are assumed to be orthogonal.
  • lights

    • points
      • transform\position - Outdated format of specifying position of the light, will be center soon.
      • color - Color emitted by the light, RGB values in the range of [0, 1]
      • radius - Size of the light, will be used in future shadow test feature.
  • ambient - Ambient light diffuse color, represented by 3 floating point values in the RBG format.

  • air - The medium that light travels that isn't a shape.

    • attenuation - The "color" of the air, energy is lost as light travels through a medium and air is no different.
    • electricPermittivity - Used to calculate the air's index of refraction.
    • magneticPermeability - Used to calculate the air's index of refraction and reflection coefficients.

rt's People

Contributors

bstrukus avatar

Stargazers

Kiki Saintonge avatar

rt's Issues

Basic Scene Loading

Develop & consume a JSON scene file format that can support

  • Camera
  • Spheres
  • Boxes
  • Lights
  • Image output settings

I am nub. Add how to use to README

Can you expand the README section to include steps on how to setup and pass in the scenes to render when running from the command prompts?

I get this error:
image

Because I am not passing in any args to run the program, but I'm not sure which ones I should be passing or what the cmd line is for that. Documentation would be greatly appreciated.

Soft Shadows

Where basic shadows do a single raycast from the point in question to the lights in the scene, soft shadows cast multiple points to each light to take into consideration the volume component of the lights. The lights in my scenes already have a radius component, but the code doesn't make use of that.

  • Cast multiple rays from point in scene to all lights
  • Randomly pick rays to cast using some RNG implementation
  • Use resultant factor to scale the shadow component instead of doing a boolean test

Find & bookmark CS400 notes

Since the goal of this project is to practice developing a program from my own research and ideas, I'm only using my CS400 notes. Finding & bookmarking the sections that pertain towards v1.0 would help a lot.

Scene Editor

I'd like to write an exporter for Blender to take generated scenes and output files that rt can read. I'd like to use Python for this.

  • Get rid of Unity folder since I won't be using that program anymore.

Rework scene conversion code

I have scene conversion code that'll read in old CS500 scene files and convert them to the format I use for rt, but I'd like to take an opportunity to redo this logic in Python since that'll be what I plan to use for my Blender output scripts.

More Shapes

More shapes! Here's what I was thinking...

  • Torus
  • Cylinder
  • Capsule

Random Number Generator

I've never written one of these before and a few of the features (that I know about) will require random ray generation to look good. All I know is the keywords "Monte Carlo" so I'll probably start there.

Anti-Aliasing

v1.0 stopped just short of implementing anti-aliasing, so I'd like to get that going when I pick this project back up.

  • Uniform anti-aliasing
  • Intelligent supersampling
  • Monte Carlo selection

Basic Parallelization

Currently I'm only making use of one thread, but I want to leverage the .NET framework to create a job system. I've done this in C++ years ago, so this will be a good crash course in multi-threading my application in C#

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.