Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing Different Objects #2

Open
Tloru opened this issue May 14, 2020 · 3 comments
Open

Implementing Different Objects #2

Tloru opened this issue May 14, 2020 · 3 comments
Labels
easy Good for newcomers, help wanted enhancement New feature or request

Comments

@Tloru
Copy link
Contributor

Tloru commented May 14, 2020

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.

@Tloru Tloru added easy Good for newcomers, help wanted enhancement New feature or request labels May 14, 2020
@mustafapc19
Copy link

I am intrested in contributing. But I dont know much about rendering engine in general. So cant gurantee. And cargo build is failing.

@Tloru
Copy link
Contributor Author

Tloru commented Jun 2, 2020

Hey @mustafapc19, thanks for the interest. In light of your failed cargo build, I recently cloned and rebuilt the project myself. It turns out that my most recent changes hadn't saved before commiting, so I've saved them and pushed to master - the project should be buildable now.

Computer graphics is a fun subject, and there are lots of resources to get started.

The way keikan currently works is simple: A scene is a list of objects with a camera. At render time, the camera asks each object to provide information about it. This information is used to calculate light bounces, which renders the final scene.

Currently, keikan supports two rendering techniques, ray-tracing and ray-marching. Ray-marching uses the distance to objects to calculate collisions, whereas ray-tracing uses direct intersections to calculate collisions. Currently, all objects are in the /objects subfolder. Each object is a structure that implements at either of the Trace or March trait, or both.

The March trait requires you implement a function that returns the distance to the nearest point on that object given a point in 3D space. For example, the distance to the nearest point on a sphere is given by the equation:

length(point - sphere_position) - sphere_radius

So to implement that for Keikan you just need to translate that to Rust and wrap it into a neat little function:

impl March for Sphere {
    // ... snip

    fn march(&self, point: Vec3) -> f64 {
        (point - self.position).length() - self.radius
    }
}

There are a lot of cool fractals you can make this way. If you want to see the distance functions for some more shapes, check out Inigo Quilez's website: https://iquilezles.org/www/articles/distfunctions/distfunctions.htm

Ray-tracing is a bit more involved. Given a ray, a ray tracer must determine:

  1. Whether the object was hit (i.e. intersects the ray)
  2. How far away the collision was
  3. And the normal of the collision (which way the face of the object was facing)

There are a lot of well-documented ray-intersection tests online, just google one for the specific shape you're trying to implement. If you need any help getting started, feel free to reach out. Thanks again for the interest.

@mustafapc19
Copy link

Thanx. I will look into it. But this a new thing for me and I dont know if I have time to actually contribute. But If I can I surely will.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy Good for newcomers, help wanted enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants