Back To Home Page  
 
CURRENTLY VIEWING

RENDERING
& TEXTURING

Some rendering and texturing algorithms which I have implemented in OpenGL

Rendering & Texturing
      + Depth-Of-Field (Raytraced)
      + Solid Textures
      + Raytracing

Depth-Of-Field Using Raytracing

This is a program written in openGL to simulate depth-of-field (DOF) effect using raytracing. User will define 3 parameters to specify the DOF look, namely the aperture size (which determines how blur the objects out of focus are), the focal length (which determines the z-distance in the view space which objects will be in focus) and the number of rays (which determines the quality of the blur).

DOF render with: Focal Length = 2, Aperture Size = 64, Rays = 16
DOF render with: Focal Length = 2, Aperture Size = 64, Rays = 16

DOF render with: Focal Length = 5, Aperture Size = 128, Rays = 16
DOF render with: Focal Length = 5, Aperture Size = 128, Rays = 16

An imaginary focal plane F is first defined behind the image plane. A ray is then cast from the eye through the current pixel to be rendered. The intersection point between this ray and F is the focal point P.

Focal point P is found by intersecting the current ray with focal plane F
Focal point P is found by intersecting the current ray with focal plane F

A square grid of length m (determined by the aperture size set by user) is placed on top of the current pixel and n rays are shot out from this grid to P, using stratified sampling. These DOF rays originate from the sampled grid point in image space and not from the eye. The results collected from these rays are blended to get the final color of the pixel to be rendered.

n rays are shot out from the newly placed grid, through the focal point P
n rays are shot out from the newly placed grid, through the focal point P

I used similar triangles to find out where P is at for the current ray. We first find:

  • d: The perpendicular distance from eye to image plane
  • d’: The distance from the eye to the pixel in question

The intersection point of the current ray (due to the current pixel to be rendered) with the focal plane is calculated as

equation

where e is the eye’s world position, v is the unit vector from eye to current pixel and f is the focal length as specified by the user.

Initially I did not jitter the sampling points on the grid and the result obtain had visible bands due to uniform sampling. It is the visual justification that we should use random sampling instead.

Undesired banded appearance due to uniform sampling
Undesired banded appearance due to uniform sampling

Note: As this is part of a group project, this DOF effect is created by modifying a distributed raytracer done by my groupmate Neo Jiet Shern.

Back To Top Back To Top


Solid Textures

The wood texture that I have created is simply an offset to a cosine noise function. For any 3D point P(x,y,z), the wood texture is obtained by using cos(P.x + turbulence(P))/2+0.5. The last two numbers are used to clamp the result to [0, 1]. The final color produced by this wood function is modulated with a brown RGB color value.

The turbulence() function above is created by adding up the values of noise with different octaves. Each successive noise added should have twice the previous frequency (thus an octave) and half the amplitude. For noise i, the frequency is 2i and the amplitude is pi, where p is the persistence of the noise. Each successive addition of an octave will include noisier details to the result.

Turbulence render with: Octaves = 3, Persistence = 4
Turbulence render with: Octaves = 3, Persistence = 4

Turbulence render with: Octaves = 1, Persistence = 1
Turbulence render with: Octaves = 1, Persistence = 1

Turbulence render with: Octaves = 5, Persistence = 2
Turbulence render with: Octaves = 5, Persistence = 2
(Doesn't look like wood anymore but I just wanted to show various settings)

Since wood textures normally stretch in a certain direction, I stretched the wood texture by multiplying a texture vector T(tx, ty, tz) where each element is the texture repeat factor for that axis e.g. T(2, 0.5, 1) will repeat texture in X-axis twice, stretch texture in Y-axis by 2 times, and no change texture in Z-axis. We obtain the result R by multiplying this vector T with the point P(x,y,z) as such: R = (tx*x, ty*y, tz*z).

So then how do we obtain the noise function? I used the gradient noise method to generate the pseudo-random noise values, similar to what Ken Perlin has suggested in his 1985 paper. A 3D grid with vertices at integer values is defined. Each vertex on the grid has a value of 0 and has an associated pseudo-random gradient vector. To obtain a value of any point within the grid, a trilinear interpolation (total of 7 linear interpolations) is applied on the 8 grid vertices surrounding the given point. Basically, given any point in the 3D space of the grid, I am now able to return the noise value associated with the point. An important characteristic of this noise function is that it must be pseudo-random and not really random i.e. it must return the same “random” noise value when the same (x,y,z) values are supplied.

Note: As this is part of a group project, this 3D wood texture is created by modifying a distributed raytracer done by my groupmate Neo Jiet Shern.

Back To Top Back To Top


Raytracing

Raytracing is a powerful framework which allows for rendering of surface properties which are hard to achieve with the normal renderer. It is based on modeling the paths taken by light rays so that shadows, reflection, refraction and hidden surface removal can all be elegantly produced in a single framework.

Raytrace render of 3 spheres: opaque, reflective and translucent
Raytrace render of 3 spheres in OpenGL: opaque, reflective and translucent

The image above is rendered using a raytracing program which I have written in OpenGL. It shows a completely opaque sphere, a reflective sphere and a translucent sphere to illustrate the effect which a raytracer can achieve. The checkerboard pattern is generated procedurally.

Note: Program template provided by Dr Anthony Fang.

Back To Top Back To Top

 
CG:SKEELOGY
ABOUT ME (view full)

[ SKEEL LEE ]
- Character TD
- Game Physics Programmer

(+65) 96162157
skeel@skeelogy.com
Resume is now available! Drop me a mail to request.
I am interested in character rigging, deformation and Physics simulations.
I also do R&D on the
above topics to find practical solutions to challenging problems.
MY OTHER SITES
    + Skeelogy
       (Design Portfolio)
    + CG:S's Blog
    + CG:S's YouTube
NEWS FEED
Site best viewed with
IE 6.0+ and 1024x768+.