This project is a 3D renderer built from scratch in Java. It renders a procedural "planet" using ray marching with Signed Distance Functions (SDFs). The planet's complex and natural-looking terrain is generated using multiple layers of Fractional Brownian Motion (fBm) noise.
The planet's terrain is built by layering multiple octaves of noise onto a base sphere, which is the technique of Fractional Brownian Motion.
The process is as follows:
- Start with a simple "host sphere" SDF.
- Generate a 3D grid of spheres, which acts as one layer of noise.
- Clip this noise layer using a "smooth max" function against an inflated version of the host sphere.
- "Glue" this clipped noise onto the host sphere using a "smooth min" (polynomial smooth union) function.
- Rotate the noise grid to prevent axis-aligned visual artifacts.
- Repeat steps 2-5 with a scaled-down version of the noise grid to add finer details.
For each pixel in the screen, the renderer follows a pipeline built on ray marching:
- Cast Ray: A ray is generated from the camera origin through the pixel.
- Ray March: The ray "marches" through the scene. In each step, it advances by the distance to the closest object in the scene. This distance is calculated using a Signed Distance Function (SDF), which defines the entire scene's geometry.
- Hit & Material: Once the ray hits an object (or gets close enough), its material properties are retrieved.
- Lighting & Normals: The surface normal at the hit point is calculated using finite difference. This normal is used to compute diffuse and specular lighting.
- Shadows: A shadow ray is cast from the hit point toward the light source to check for occlusion. This project implements Soft Shadows, where rays passing close to an object transmit less light, creating a more realistic penumbra.
- Effects: Post-processing effects like fog are applied to add depth.
- Draw Pixel: The final calculated color is drawn to the screen.
This project depends on StdDraw (included in the project) and javax.vecmath.
To install javax.vecmath on Debian/Ubuntu based systems, run apt install libvecmath-java. It might also be necessary to set the CLASSPATH environment variable by executing export CLASSPATH=$CLASSPATH:/usr/share/java/*.
javac *.java
java RayMarcher
- Yuxiang Lin
- Xiangnan Hu
- Sardor Akhmedjonov
- Tuguldur Davaanyam
The core procedural generation technique was heavily inspired by Inigo Quilez's article on generating terrain using SDF-based Fractional Brownian Motion:
- Main Reference: SDF-based Fractional Brownian Motion
Other foundational articles by Inigo Quilez were also used:
- Polynomial Smooth Min (smin)
- Raymarching Signed Distance Functions
- Distance Functions
- Volumetric Fog
This project's raytracing fundamentals were informed by the following tutorials:





