Voxelers/mcthings

Explore the Cyrille Rossant Python Ray Tracer

acs opened this issue · 4 comments

acs commented

Continue from #127:

https://gist.github.com/rossant/6046463

and improved by James Bowman as described in https://excamera.com/sphinx/article-ray.html in the GitHub repository:

https://github.com/jamesbowman/raytrace

acs commented

Ok, let's describe how the ray trace works. The ray tracer renderer has:

  • A 3D Scene is defined with 4 elements: 3 spheres and a plane.
  • The Scene has also lights (ambient and diffuse) and a camera pointing to the center of the Scene
  • A 2D image where the 3D scene is rendered using ray tracing

The logic is:

  • For each pixel in the 2D image fill the color based on ray tracing.
  • Cast a ray with origin (O) the camera that goes through each pixel (this defines the direction)
  • Find if the ray hits any object in the Scene.
    • If no hits, drop the ray (no effects in the pixel color)
    • If the ray hits an object, find the hit point (M)
      • If the hit point is shadowed drop the ray (no effects in the pixel color)
      • Find the hit point color contribution to the pixel based on:
        • Ambient light
        • Diffuse light using Lambert shading
        • Specular light using Blinn-Phong shading
    • Create max_depth reflection rays and repeat the above process
acs commented

One of the hardest problems with ray tracing is the intersection point and howto find the direction of the ray from the light to the hit point. In this simple case, we have a plane and a sphere. In these cases, it is pretty simple.

https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection

acs commented

All done for this first iteration.