Skip to content

theta-lin/cs_201_bk_2

Repository files navigation

COMPSCI 201 BirdKan Project 2: Ray Marching of a Procedural "Planet"

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.

Presentation Slides

Final Render

Procedural Generation with Fractional Brownian Motion (fBm)

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:

  1. Start with a simple "host sphere" SDF.

  2. Generate a 3D grid of spheres, which acts as one layer of noise.

  3. Clip this noise layer using a "smooth max" function against an inflated version of the host sphere.

  4. "Glue" this clipped noise onto the host sphere using a "smooth min" (polynomial smooth union) function.
  5. Rotate the noise grid to prevent axis-aligned visual artifacts.

  6. Repeat steps 2-5 with a scaled-down version of the noise grid to add finer details.

Core Rendering Pipeline

For each pixel in the screen, the renderer follows a pipeline built on ray marching:

  1. Cast Ray: A ray is generated from the camera origin through the pixel.
  2. 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.
  3. Hit & Material: Once the ray hits an object (or gets close enough), its material properties are retrieved.
  4. Lighting & Normals: The surface normal at the hit point is calculated using finite difference. This normal is used to compute diffuse and specular lighting.
  5. 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.
  6. Effects: Post-processing effects like fog are applied to add depth.
  7. Draw Pixel: The final calculated color is drawn to the screen.

Dependency

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/*.

Build

javac *.java

Run

java RayMarcher

Team Members

  • Yuxiang Lin
  • Xiangnan Hu
  • Sardor Akhmedjonov
  • Tuguldur Davaanyam

References

The core procedural generation technique was heavily inspired by Inigo Quilez's article on generating terrain using SDF-based Fractional Brownian Motion:

Other foundational articles by Inigo Quilez were also used:

This project's raytracing fundamentals were informed by the following tutorials:

About

Procedural "planet" using ray marching on SDF and Fractal Brownian Motion

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages