# Do Ray Tracing

## Generate Ray

Generate a ray that goes from the camera’s origin through the pixel location (pixelPosX, pixelPosY) of the camera. Note that pixelPosX and pixelPosY can be non-integer. The image origin is at the bottom-leftmost corner, that means:

• The bottom-leftmost corner of the image is (0, 0).
• The top-rightmost corner of the image is (imageWidth, imageHeight).
• The center of the bottom-leftmost pixel is (0.5, 0.5).
• The center of the top-rightmost pixel is (imageWidth-0.5, imageHeight-0.5).

## Nearest Surface

Find whether and where the ray hits some surface. Take the nearest hit point.

## Shadow

Add to result the phong lightin contributed by each point light source. Compute shadow if hasShadow is true.

## Reflection

Add to result the reflection of the scene.

## Hammersley Sampling

We know that binary numbers are used to represent data in the computer. The corresponding relations between decimal and binary systems are shown in the following table.

Decimal Binary
1 1
2 10
3 11
4 100

And Hammersley Sampling is to generate uniformly distributed 2D random sampliong points by using this characteristics.

It constructs a value by implementing a Radical Inverse method for a binary number. Its process is as follows

Decimal Binary Radical Inverse Value
1 1 .1 = 1 * 1/2 0.5
2 10 .01 = 0 1/2 + 1 1/4 0.25
3 11 .11 = 1 1/2 + 1 1/4 0.75
4 100 .001 = 0 1/2 + 0 1/4 + 1 * 1/8 0.125

Constructing a set of 2D random sampling points for Hammersley Sampling

## Anti-Aliasing

In ray tracing world, Anti-Aliasing method is simply, it only just increase the amount of sampling.

Learn OpenGL

Share