Class RayTracer
- All Implemented Interfaces:
Runnable
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
- The camera's view frustum corners are obtained via
RaytracingCamera.getCameraView(). - For each pixel, a primary ray is constructed from the camera center through the interpolated position on the view plane.
- The ray is traced through the octree using
OctreeVolume.traceCell(int, int, int, int, int, Ray). - 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.
- The final pixel color is the cell's base color modulated by the accumulated light.
- 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 Summary
ConstructorsConstructorDescriptionRayTracer(Texture texture, OctreeVolume octreeVolume, Vector<LightSource> lights, RaytracingCamera raytracingCamera, ViewPanel viewPanel) Creates a new ray tracer for the given scene configuration. -
Method Summary
-
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 resolutionoctreeVolume- the octree volume containing the scene geometrylights- the light sources to use for illuminationraytracingCamera- the raytracing camera defining the viewpointviewPanel- 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.
-