Thursday, April 18, 2013

HW9 - Sphere Ray Tracer 1



I made a class called Canvas_RT to do all of my ray tracing for me. Shadows are implemented. To shade an object I keep a tbuffer rather than a zbuffer, which stores the time it took for the ray to hit the object, and I use Phong's reflectance algorithm. I determine if a shaded point P is in shadow with respect to light L by ray tracing from P outwards in the direction of L and checking if the ray hits any other spheres.

I added couple of basic helper methods to my Light and Material classes.

Applet

  • [ UP / DOWN ] - change rotation angle of white sphere
  • [ LEFT / RIGHT ] - select the next sphere (white)
  • [ space ] - reset all rotation angles to random
  • [ q w e a s d ] - change direction of light
  • [ - = ] - zoom out / in

Applet - Ray Tracer


EDIT: added subsampling for massive speedup and added anti-aliasing
  • [ 1 ] - show ray traced pixels (subsampling)
  • [ 2 ] - show anti-aliased pixels
  • [ 3 ] - toggle anti-aliasing
NEW Applet

___________________________________________________________________________________
HW9_Package.zip
HW9_szymczak.java
Canvas_RT.java

Wednesday, April 10, 2013

HW8 - Materials and Phong's Reflectance



I got tired of copying-and-pasting my drawing code from one HW to the next so I created a Canvas class that does all of it for me. The pipeline is the same as for HW7.
  • renderShape(Geometry shape)splits each face into triangles and performs transform on vertices and normals.
  • renderTriangle() calculates area of the triangle, and renders accordingly by calling methods below
  • vertexData() calculates pixels, depth, and colors at A, B, C, and D. Vertex A is oriented on top; D-B in the middle; C on the bottom.
  • fillTriangle(int[] vertex, double[] color, double depth) : parameters give data for the apex of the triangle (either A or C).
  • interpolate(double fraction, double[] a, double[] b) : linearly interpolate fraction along the way between a and b.
  • phong(double[] color) : Phong's color reflectance algorithm
  • gamma(double[] color) : Gamma correction

I added a bunch of helper methods to my Matrix class -- operations on arrays. In the .java file they are grouped together.
  • add, subtract, cmult, dot, normalize, copy, copyCol

I also added a Light class that simply stores data for a light and a Material class that stores the relevant values to mimic a material. Each Geometry object has a Material object as a class variable.


Applet

    • [ arrow keys ] - rotation
    • [ . / ] - zoom out and in
    • [ space ] - pause rotation

Click for Applet
It's kind of boring but I didn't have time to create a fun game this week.

___________________________________________________________________________________
HW8_package.zip
HW8_szymczak.java
Canvas.java
Material.java
Light.java
Matrix.java
Geometry.java