java.lang.Object
eu.svjatoslav.sixth.e3d.renderer.octree.raytracer.RayTracer
All Implemented Interfaces:
Runnable

public class RayTracer extends Object implements Runnable
Ray tracing engine for rendering OctreeVolume scenes onto a Texture.

RayTracer implements Runnable and is designed to execute as a background task. It casts one ray per pixel through the camera's view frustum, tracing each ray into the octree volume to find intersections with solid cells. When a hit is found, the ray tracer computes per-pixel lighting by casting shadow rays from the hit point toward each LightSource along multiple surface-normal-offset directions (6 directions: +X, -X, +Y, -Y, +Z, -Z) to approximate diffuse illumination with soft shadows.

Rendering pipeline

  1. The camera's view frustum corners are obtained via RaytracingCamera.getCameraView().
  2. For each pixel, a primary ray is constructed from the camera center through the interpolated position on the view plane.
  3. The ray is traced through the octree using OctreeVolume.traceCell(int, int, int, int, int, Ray).
  4. If a solid cell is hit, up to 6 shadow rays are cast toward each light source. If no shadow ray is occluded, the light's contribution is accumulated.
  5. The final pixel color is the cell's base color modulated by the accumulated light.
  6. Computed lighting is cached in the octree cell data (cell3) for reuse.

Progress is reported periodically by invalidating the texture's mipmap cache and requesting a repaint on the ViewPanel, allowing partial results to be displayed while rendering continues.

See Also:
  • Constructor Details

    • RayTracer

      public RayTracer(Texture texture, OctreeVolume octreeVolume, Vector<LightSource> lights, RaytracingCamera raytracingCamera, ViewPanel viewPanel)
      Creates a new ray tracer for the given scene configuration.
      Parameters:
      texture - the texture to render into; its primary bitmap dimensions determine the output resolution
      octreeVolume - the octree volume containing the scene geometry
      lights - the light sources to use for illumination
      raytracingCamera - the raytracing camera defining the viewpoint
      viewPanel - the view panel for triggering progress repaints
  • Method Details

    • run

      public void run()
      Executes the ray tracing render pass.

      Iterates over every pixel of the target texture, constructs a primary ray from the camera center through the view plane, traces it into the octree volume, and writes the resulting color. The texture is periodically refreshed to show progressive results.

      Specified by:
      run in interface Runnable