Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
(EOD).Software topics.pdf
Скачиваний:
18
Добавлен:
23.08.2013
Размер:
1.55 Mб
Скачать

page 147

When we are rendering images we quite often will try to add a texture or pattern to the surface. This can be done by having a separate splines model of the object. While rendering the parametric model is interrogated as each surface point is being rendered.

A simple example is the mapping of a checkerboard pattern on a plane using a function.

.

This function was simplified by aligning the checkerboard along the x-z plane. This avoided the problem of having to transform the point on the plane (thus speeding calculations). The only problem to be considered was how to map alternating squares onto the floor. This involved a calculation of a remainder value when dividing the x-z location by the grid spacing.

x

division width

z

The remainder function will find the offset from an integer number of divisions. This value will be up to plus/minus half a division. Thus

if((remainder(x, division) * remainder(y, division)) > 0.0) then assign color 1

else

assign color 2 endif

A Surface with a CheckerBoard Pattern

12.8.2 Ray Tracer Algorithms

• This ray tracer will backtrack rays, and follow their paths through space. This involves a basic

page 148

set of functions. First the general algorithm description is given for ray tracing, in general,

Load geometry and view information from file

Precalculate constant values and transforms

Pick pixel (or surrounding pixels for anti-aliasing)

Find a Ray for pixel in space

Follow Ray for a prespecified number of intersections

Backtrack light on tree

Resolve a set of pixels if anti-aliasing

When done save to file

Basic Order of Higher Level Ray Tracer Features

This structure involves performing as many calculations as possible before execution begins. Although not all calculations are done before, some tricks will be described below which greatly improve the speed of ray tracing.

The process of filling up the image has multiple approaches. If a simple image is needed, then a simple scan of all the pixels can be made. An anti-aliasing technique requires oversampling of the pixels. When a pixel is chosen, the pixel must be mapped to a ray in space. This ray may be considered on a purely geometrical basis.

When backtracking rays in space, they will either hit an object, or take on the background color. If an object has been hit by a light ray, it can either reflect or refract, and it will take on the optical properties of the surface. This leads to a tree data structure for the collisions.

page 149

Depth = 0

Build Tree

 

Depth = 1

 

Depth = 2

Depth = 3

This symbol is used to represent a collision which includes light emitted from the surface, a ray of reflection, and a ray for refraction.

The Basic Concept of Back Tracing Rays

• As seen in Figure above, the light rays may be followed, but the only colors (color explanation follows later) attached to any nodes in this tree are the diffuse lighting from ambient and point sources, and also the specular reflection. After the tree has been fully expanded, the light may be traced forward to the eye. The figure shows the light being propagated back up the tree to the eye (screen pixel).

page 150

Depth = 0

Propagate light

 

Depth = 1

 

back through tree

 

 

Depth = 2

Depth = 3

The Basic Concept of Back Tracing Light Values in a Ray Tree

This structure gives rise to a tree based on a linked list. Each node in the linked list has:

Forward and back pointers,

Surface normals, and optical properties for refraction (used for backtracking),

The lighting from diffuse and specular sources,

Vectors for before and after reflection and refraction,

Positions for ray origins and collision points,

The depth in the search tree,

The identification of which object the ray has come from and has hit.

All of these properties are used in a dynamic fashion, and the list may be grown until all branches have been terminate (i.e. hit background) or are at the maximum search depth.

This Ray tree structure is constructed with the data stored in a second structure. The second structure for scene data contains geometric information:

Objects for each ball including centers, radii, and ordered lists of the closest ball,

An object for the floor, eye, and light, including positions, orientations, and a list of balls, ordered from closest to farthest,

Transformation matrices,

•The same perspective parameters used in the user interface, •A list of picture areas only filled with background light,

Соседние файлы в предмете Электротехника