BudgiePanic / PushingP

A Whitted ray tracing implementation written in Java
Apache License 2.0
1 stars 0 forks source link

PushingP

PushingP is an offline Whitted ray tracing renderer written in Java.

PushingP was created out of an enthusiasm for computer graphics and a desire to learn about ray tracing algorithms and data structures.

Project Name

PushingP is short for PushingP(ixels), a refence to the application's job of filling the pixels of the screen with color.

Background

PushingP was developed by following Jamis Buck's book The Ray Tracer Challenge

Usage

Building PusingP

To build PushingP from source, the project requires Java 21 and Maven 3 to be installed on the host device.

To build a jar file that contains PushingP and demonstration scenes run:

The generated jar file will be in the /target folder.

Using PushingP

In the directory that contains the jar file:

PushingP can also be run using: java -cp PushingP-version.jar com.BudgiePanic.rendering.App -argument

You can render an image of your own scene using:

The following class generates an image of a sphere infront of a flat surface.
MyFile.java

import com.BudgiePanic.rendering.util.*;
import com.BudgiePanic.rendering.scene.*;
import com.BudgiePanic.rendering.util.light.*;
import com.BudgiePanic.rendering.util.pattern.*;
import com.BudgiePanic.rendering.util.shape.*;
import com.BudgiePanic.rendering.util.transform.Transforms;
import com.BudgiePanic.rendering.util.transform.View;
import com.BudgiePanic.rendering.toy.BaseDemo;

public class MyFile extends BaseDemo {
    public static void main(String[] args) {
        new MyFile().run();
    }

    @Override
    public String getName() {
        return "my_image.ppm";
    }

    @Override
    public Camera getCamera() {
        return new SuperSamplingCamera(
            new PinHoleCamera(640, 480, AngleHelp.toRadians(90), 
            View.makeViewMatrix(Tuple.makePoint(0,1,-5), Tuple.makePoint(0,0,1), Directions.up)), 
            SuperSamplingCamera.defaultMode
        );
    }

    @Override
    public World createWorld() {
        World world = new World();

        Light light = new AreaLight(Colors.white, Tuple.makePoint(5,5,-7), Directions.forward, Directions.up, 3, 3, AreaLight.randomSamples);
        world.addLight(light);

        var sphere = new Sphere(Transforms.identity().assemble());
        world.addShape(sphere);

        var background = new Cube(Transforms.identity().scale(15,15,0.1).translate(0,0,5).assemble());
        world.addShape(background);

        return world;
    }

}

Examples

The toy package contains code examples of how to use PushingP.

Viewing images

PushingP currently exports images in the ppm format.
ppm images can be viewed using an image viewing program, such as GNU's GIMP application.

Features

PushingP has the following features:

License

PushingP is released under the Apache 2.0 open source license