Ray Tracing RayTracing, basic principles, judging the intersection of objects and rays

Three assumptions about light:

  1. light travels in straight lines
  2. rays do not collide
  3. The light will enter the camera through a series of refraction and reflection.
    The light can be emitted from the camera, and a reversible light
    insert image description here
    path In the figure, the transparent ball is at the line directly connected to the camera, and the results of the refraction and reflection coloring points need to be added. If there is a light source directly , it is necessary to add the coloring result of the light source at this point. The
    insert image description here
    first ray directly emitted by the camera is the primary Ray, and the subsequent processing is called secondaryRay, and the connection with the light source is called shadowRay
  • Definition of rays
    insert image description here
    For the surface of the sphere,
    insert image description here
    the value of t is obtained after finding the intersection point of rays:
    insert image description here
    insert image description here
    t: first, it is a positive number.
    It can be discussed in many cases, separated, intersected, and tangent
  • The overall process can be summarized as:
    insert image description here
  • About the intersection of light and object
    If the light source is inside the object, the number of intersections with the object must be an odd number, otherwise it must be an even number
  • intersection of light and object
  • Intersecting with a triangle
    You can first convert this problem into intersecting a ray and a plane, and then determine whether the intersection point is within the triangle
  • How to define a plane?
    Record a point p on the plane and the normal of the plane to define a plane. In
    insert image description here
    the figure above, N is the normal, p' is a point on the plane, and any point p in the plane can satisfy the subband of the
    formula The value of t can be obtained from the formula of the incident ray, so that the focus of the ray and the plane can be obtained.
    insert image description here
    Finally, whether the point is in the triangle can be obtained according to the knowledge of the center of gravity coordinates.
  • Another method, Moller Trumbore algorithm,
    solves this formula mainly through matrix form
    insert image description here
  • AABB bounding box (enclosing volume)
    Axis-Aligned Bounding Box Axis-Aligned Bounding Box
    If you judge whether each triangle on the object will be illuminated by light, the consumption will be very large, so the AABB bounding box mechanism is introduced. The process of judging the light irradiation is accelerated. If the light does not touch the bounding box, it is impossible to touch any triangle on the object.
    insert image description here
  • The ray intersects the bounding box
    insert image description here
    in the above figure, find the time when the ray passes through the x0, x1 plane, find the time when the ray passes through y0, y1, and obtain tmin and tmax through the nature of the intersection. If the final result is tmax > tmin, then it means the ray After passing through the bounding box
    , then find tmin and tmax for the 3D bounding box:
    insert image description here
    if the light entering time is negative and the leaving time is positive, it means that the light source is inside the bounding box, then
    there are:
    insert image description here

Guess you like

Origin blog.csdn.net/KamikazePilot/article/details/131033120