Giter Site home page Giter Site logo

keikan's Introduction

Keikan (警官)

An elegant (imo) rendering engine written in Rust.

Keikan is a multithreaded photorealistic rendering engine that supports path-tracing, ray-marching, Photo Based Rendering (through a principled implementation), and more.

I've tried my hand a few toy path-tracers and ray-marchers in the past, and I wanted to write something more than just a toy. Having just stumbled upon Rust, I decided to try my hand at it by implementing a rendering engine from scratch.

This project was originally inspired by Ray Tracing in One Weekend, but after I knocked out the core engine, I've pulled from a number of different sources and my own experience to develop it further.

Results

Here's a recent render of a ray-marched Mandelbulb (a type of fractal):

A Mandelbulb fractal

Rendered in a little over 2 minutes on a potato.

There are some images bundles in this repository under the keikan/renders/ folder, ordered chronologically. Go check them out!

Design Goals

Keikan is able to render a large variety of objects, including fractals to near-infinite precision, due to its support of both path-tracing and ray-marching.

Ray-marching is rendering through the use of a signed distance field. I personally got interested in computer graphics through writing ray-marching renderer, so I decided that if I wrote another rendering engine, I'd have include ray-marching as a technique.

Getting Started

To render a small demo, clone this repository and run Keikan:

git clone https://github.com/slightknack/keikan.git
cd keikan
cargo run --release -- ~/Desktop/demo.png  # where to save the image

You should see some output right away. Keikan will spawn as many threads as detected CPU cores, so it should be pretty relatively fast (for non-GPU-based rendering code, haha).

I'd like to use GPU features, as I've made some ray marchers in GLSL, but it seems like Rust doesn't have standardized GPU support. If you know how to run Rust on the GPU, open an issue so we can discuss it further!

Why (the Name) Keikan?

It's Japanese for policeman.

keikan's People

Contributors

manugildev avatar slightknack avatar tloru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

keikan's Issues

File support

This is a hard one, but different 3d files should be importable. Given a file object, a file parser should read, parse, and output a scene using that file. This will probably require a Parser trait or the like.

Update Rendering Code to be PBR Compliant.

In the rendering code, this rather ugly line of code determines the color of the ray:

// combine the samples in a PBR manner
return (
    (
        ( // for dielectric materials. TODO: fresnel blending
            (
                (transmission *        material.transmission)  // mix transparent
              + (diffuse      * (1.0 - material.transmission)) // and diffuse
            )
          + (specular * material.specular) // with a specular layer on top
          // TODO: specular seems off, violating cons. of energy. review.
        )
      * (1.0 - material.metallic) // lerp with metal

      + ( // for metallic materials
            specular * material.color
        )
      * material.metallic
    )
  * (1.0 - material.emission).max(0.0) // modified lerp with emissive

  + ( // for emissive materials
      material.color * material.emission
    )
);

I'll simplify it a bit:

// combine the samples in a PBR manner
// mix transparent and diffuse
let base = (transmission * material.transmission) + (diffuse * (1.0 - material.transmission));

// TODO: specular seems off, violating cons. of energy. review.
let dielectric = base + (specular * material.specular); // with a specular layer on top
let electric = specular * material.color; // for metallic materials

// lerp electric and dielectric
let non_emmisive = (electric * material.metallic) + (dielectric * (1.0 - material.metallic));
let combined = (material.color * material.emission) + (non_emmisive * (1.0 - material.emmision).max(0.0));

// final color.
return combined;

This color combination technique is naive, at best. This should be fixed to work in a PBR compliant manner. Any help is appreciated.

Texturing Objects

Right now, objects can only take on solid colors. This is not a limitation in the render itself, it's perfectly capable of building textured objects.

To implement this feature, two things need to be done. First, traits.rs should be refactored to include a textured trait, and the material function should be moved out of March and Trace. All objects should be required to implement the material trait.

Additionally, the material function should be refactored to take a 3d point, so the texture can be determined.

Implementing Different Objects

Right now, keikan supports:

  • Planes
  • Spheres
  • and Mandelulbs (a fractal).

This is quite a small number of objects. At the least, the following primitives should be implemented:

  • Triangles
  • Rectangular Prisms
  • Cones

To implement a new object, go to objects/ and make a new file with a data structure that implements the March and/or the Trace traits.

Librarification of keikan

Right now, keikan is not a library. A lib.rs should be added, makescene should be moved to be a test, and the rendering code (render.rs) should be moved to more appropriate places (Like an impl on camera and scene, for instance).

Parallel Rendering

Right now, keikan is single threaded. This is bad, because rendering is the ultimate parallelizable operation. Using tokio, reimplement render.rs so that is is parallelized.

Lens blur and depth of field

Right now, keikan doesn't support depth of field. This is a fairly easy thing to do, it just requires the ray generation code to be modified in render.rs.

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.