92
Jump to first page POVRAY Tutorial 204481 Foundation of Computer graphics Pradondet Nilagupta

POVRAY Tutorial

  • Upload
    ivo

  • View
    47

  • Download
    0

Embed Size (px)

DESCRIPTION

POVRAY Tutorial. 204481 Foundation of Computer graphics Pradondet Nilagupta. What is POV-Ray?. POVRAY = Persistence of Vision Ray-Tracer POV-Ray is a high-quality, freely available ray-tracing software package that is available for PC, Macintosh and UNIX platforms. POV-Ray is no toy. - PowerPoint PPT Presentation

Citation preview

Page 1: POVRAY Tutorial

Jump to first page

POVRAY Tutorial

204481 Foundation of Computer graphicsPradondet Nilagupta

Page 2: POVRAY Tutorial

Jump to first page

-What is POV Ray?

POVRAY = Persistence of Vision R-ay Tracer

- - POV Ray is a high quality, freely a - vailable ray tracing software pack

age that is available for PC, Macin tosh and UNIX platforms.

- POV Ray is no toy. - POV Ray is what is known as a "re

ndering engine".

Page 3: POVRAY Tutorial

Jump to first page

- Written POV Ray lan guage

- Describing scenes to POV Ray is f airly simple

- Give POV Ray a file containing a d escription of every object in the s

- cene. POV Ray takes this file and generates a picture, which you ca

n then view.

Page 4: POVRAY Tutorial

Jump to first page

Object description ofPOVRAY What type of object you want (on

- e of POV Ray's simple objects or o ne you've created yourself.

Various attributes of the object (it s color, how it reflects light, etc).

Page 5: POVRAY Tutorial

Jump to first page

-What is ray tracing? - Ray tracing is a method of creatin

g visual art in which a description of an object or scene is mathemat

ically converted into a picture. - ray tracing is the process of math

-ematically generating near photo realistic images from a given des cription of a scene via geometrica

l modeling of light rays.

Page 6: POVRAY Tutorial

Jump to first page

- POV Ray's Coordin ate System

-The coordinate system that POV -Ray uses, then, is called a three d

imensional (or 3D) Cartesian coor dinate system.

The axis we have drawn is not fix - -- ed in POV Ray the way the axis l

ooks (in terms of which axes are which) really depends on where y

ou place your camera -in POV Ray.

Page 7: POVRAY Tutorial

Jump to first page

-Vectors in POV Ray The term vector refers to any gro

up of numbers describing a certai -- n thing there are color vectors a

nd normal vectors. vectors are surrounded by angle

brackets (that's < and >). For example, to specify the origin

- in terms that POV Ray understan ds, we would say <0,0,0>

Page 8: POVRAY Tutorial

Jump to first page

How to describe colo r: RGB and RGBF Vec

tors In describing a color, each element of th

e vector corresponds to the amount of a -- primary color red, green and blue. Suc

h a vector is called a RGB vector (for red green blue vector).

In a RGB vector, the numbers should be between 0.0 and 1.0.

For example, the color black, is describe d by the color vector <0 ,0 ,0 >. And

col or whi t e, is specified by the color vector<1,1,1>.

Page 9: POVRAY Tutorial

Jump to first page

Normal Vectors

normal vectors are used to specif y an orientation , not a distance.

Page 10: POVRAY Tutorial

Jump to first page

Normal Vector (cont.) - POV Ray is kind enough to automaticall

y define three normal vectors for you x (corresponding to <1,0,0>), the norm

al vector for a plane lying along the y an d z axes

y (corresponding to <0, 1, 0>), the nor mal vector for a plane lying along the x and z axes,

z (corresponding to <0, 0, 1>), the nor mal vector for a plane lying along the x and y axes.

Page 11: POVRAY Tutorial

Jump to first page

- POV Ray Source Code

There are three things you need t - o know about POV Ray source co

de - POV Ray source code is case sens

itive - POV Ray ignores whitespace Ordering is unimportant

Page 12: POVRAY Tutorial

Jump to first page

Source Code (cont.)

camera { -location <0, 2.25, 35> direction <0, 0, 10> up <0, 1, 0> right <1, 0, 0> look_at <0, 0, 90>}

- camera { location <0, 2.25, 35> di rection <0, 0, 10> up <0, 1, 0> ri

ght <1, 0, 0> look_at <0, 0, 90>}

Page 13: POVRAY Tutorial

Jump to first page

-Comments in POV Ra y Source Code

Comments can be enclosed in /* - *and /, or, for single line commen

ts, can be prefixed with a //. Example - // this is a single line comment /* this is another comment. it can be as l

ong as you want it to be */

Page 14: POVRAY Tutorial

Jump to first page

Including files

IIIIIIIII IIIII II I IIIIIII II I II - y languages that makes re using

code easier Adding the string #include "file

name" to the beginning of your file.

Example #include "colors.inc"

Page 15: POVRAY Tutorial

Jump to first page

Creating simple objects

- The building blocks of all POV RayIIIIIII III IIIIII III IIIIII primitive s. Primitives are objects tha - t POV Ray already knows about, a

nd all you have to do is describe a - few attributes. POV Ray primitive

s are usually simple geometric sh apes such as spheres, cubes, and

cones.

Page 16: POVRAY Tutorial

Jump to first page

Describing primitives

Object_Name { Object_Parameters Some_Simple_Attribute Some_Ot

her_Simple_Attribute Some_Com plex_Attribute { Some_Attribute

Some_Other_Attribute }

Page 17: POVRAY Tutorial

Jump to first page

Example

sphere { <0 , 0 , 0 >, 5 pigment { color rgb <1, 0, 0> }}

Page 18: POVRAY Tutorial

Jump to first page

The Camera

This example defines a camera lo - cated at <2,5, 10> and pointing

at the origin.

camera { -location <2,5, 10> look_at <0,0,0>}

Page 19: POVRAY Tutorial

Jump to first page

Light sources

There are a few different types of ligh - t sources in POV Ray. We will concent

rate here on the most simple (and us eful): the point light source . A point li

ght source can be thought of as an inf initely small object that emits light.

light_source {

- 010 10 11< , , > color rgb < , , I 1

Page 20: POVRAY Tutorial

Jump to first page

First POVRAY

// Persistence of Vision R ayTracer version 2 Scen

e descr i pt i on fi l e // File: Lesson_1.pov // Description: Chr ome Spher e on che

cker s // Date: January 5, 2000 // Author: Pr adondet Ni l agupt a //

#include "shapes.inc" IIIIIIIIIIII#

#include "textures.inc"

camera { -022535location < , . , > < 0 , 0 , 1 0 > < 0 , 1 , 0 > right <1, 0, 0> _ < 0 , 0 , 9 0 >}

//Key Light -light_source {<50, 100, 8

0> color White}

//Back Light light_source {<100, 50, 8

0> color Blue}

Page 21: POVRAY Tutorial

Jump to first page

First POVRAY

First we'll place our plane into the picture. At the end of your source

file, type: object {

plane {y, 0} 1 1 1pigment {color rgb < , ,

>}}

Page 22: POVRAY Tutorial

Jump to first page

First POVRAY

Now let's add the sphere. Type: object {

sphere {<0, 1.5, 1> 1.5} 1 1 1pigment {color rgb < , ,

>}}

Page 23: POVRAY Tutorial

Jump to first page

Camera Again The camera defines what you exactly

you see when you render an image. camera {

location <loc> sky <sky vector> up <up vector> right <right vector> direction <direction vector> look_at <target>

*/ translations , rotations , and scales */

}

Page 24: POVRAY Tutorial

Jump to first page

Camera Again

Whendeclaringacamera, component s t hat appear shoul d do so in this order. This is because some la ter components modify previous ones, a nd putting them in the wrong order may

result in your camera not doing exactly what you expect.

- Locationisprettyselfevident; ittellsPOV Ray wher e i n space t o l ocat e the camera. It takes an <x, y, z> vector

of the location.

Page 25: POVRAY Tutorial

Jump to first page

Camera Again

Sky is used to tell the camera which way is up. Modifying this value can be used t o roll the camera around its central axis.

Up, right, and direction are used to modi fy the field of view and aspect ratio of th

e image. Direction and look_at are used to point t

he camera at a specific point in the scen e. Direction is more typically used with u

p and right to define field of view then to position the camera, though.

Page 26: POVRAY Tutorial

Jump to first page

Location

-The location keyword tells POV R ay where to position the camera.

This parameter must always be s pecified.

It takes an <x, y, z> vector which tells the location of the camera.

Page 27: POVRAY Tutorial

Jump to first page

Up Vector The up vector is used to define th

e height of the viewing pyramid The default value of the up vector

is "up <0, 1, 0>". This, together with the value "rig

ht <4/3, 0, 0>" (also default) defi nes the aspect ratio of the render

ed image to be (4/3) / (1) = 4/3.

Page 28: POVRAY Tutorial

Jump to first page

Right Vector

The right vector controls the widt h of the view.

The angular width of the viewing pyramid can be found with the fol

lowing equation.

width = 2 * atan(|right| / |direction|)

Page 29: POVRAY Tutorial

Jump to first page

Direction

The direction vector is primarily used in conjunction with up and right to define t

hefi el d of vi ew. Increasing the magnitude of the directio

n vector "stretches " thevi ewi ng pyr ami d a nd creates a telephoto sort of effect.

Decreasing the magnitude of the directi on vector "compresses " the viewing pyr

-amid and gives the effect of a wide angl e camera.

Page 30: POVRAY Tutorial

Jump to first page

Direction

direction <0 , 0 , 0 .5 > direction <0 , 0 , 1 >

direction <0 , 0 , 2 > direction <0 , 0 , 4 >

Page 31: POVRAY Tutorial

Jump to first page

Look At The look_at parameter controls th

e orientation of the camera. It is b y far the easiest way to get the ca

mera to point at the thing you wa nt it to point at.

One thing to keep in mind when u sing look_at is that the location I

nd look_at points should never be set so that the camera is looking

-directly down (parallel to the y ax is).

Page 32: POVRAY Tutorial

Jump to first page

Sky

The vector tells the camera which w ay is up.

This is not to be confused with the up vector which defines the aspect ra

tio. The default sky vector is <0, 1, 0>.

By modifiying this value, you can rol l the camera around its central axis.

The sky vector, if specified, must ap pear before the look_at point is spec ified.

Page 33: POVRAY Tutorial

Jump to first page

Sky

The first image below is rendered with "sky <2, 1, 0>", and the sec - ond with "sky <0, 1, 0>".

Page 34: POVRAY Tutorial

Jump to first page

Common Object Types

plane , sphere , torus , box , cylinder , cone , lathe , prism (extruded shape) , blob , and text.

Page 35: POVRAY Tutorial

Jump to first page

The Plane

The plane consists of only two val ues; which of the 3 major axis it c

rosses, and it's position on that a xis. The plane will be perpendicul

ar to the axis declared object{ - plane {y, 1 .5 } //{axis, loc

ation} pigment {color rgb <.5 ,.5 ,.5 >}}

Page 36: POVRAY Tutorial

Jump to first page

Sphere The sphere also consists of only two

values; the location, and the radius. The location defines the center of th

e sphere. object {

sphere {<0, .5, 0> 1} //{<location>IIIIIII

111pigment {color rgb < , , >} //scale <2 ,1 ,1 > //scale to mak

e an el i pseI

Page 37: POVRAY Tutorial

Jump to first page

Torus The torus definition consists of two

radius statements. The first, or major radius extends from the center

- of the torus to the mid line of the ri m. The second, or minor radius de

fines the radius of the cross section of the rim.

object{ torus {1.75, .5} //{outer radius, rad.

of cross section} pigment {color rgb <1 ,1 ,1 >} translate <0,.5,0> //must use trans

late to move } //its location.

Page 38: POVRAY Tutorial

Jump to first page

Box

POV defines boxes as two points. The points form opposite corners

of the box such as lower back righ t and upper front left.

object{ - - - box {< 1, 1, 1> // first corner positi

on < 1 , 1 , 1 >} // second corner p

osition pigment {color rgb <1 ,1 ,1 >}}

Page 39: POVRAY Tutorial

Jump to first page

Cylinder

A cylinder consists of 4 values. Th e first three, first point , second

point , and radius are mandatory . The fourth, open , is optional.

object{ - cylinder {<0, 1,0>, <0,1,0>, 1 //{<1s

t point>, <2nd point>, radius //open //uncomment to m

ake it a tube } pigment {color rgb <1 ,1 ,1 >}}

Page 40: POVRAY Tutorial

Jump to first page

Cone A cone is very similar to a cylinder; the diffe

rence being that you can define the radius o f both ends. The first point defines one end

of the cone. The first radius defines the radi us of the cone at this point. The second poin

t and its radius define the center of the othe r end of the cone

object{ - cone {<0, 1,0>, 1.0, //{<1st point>, 1st radius <0,1,0>, 0.0 //{<2nd point>, 2nd radius //open //uncomment to make it open en

III } 1 1 1pigment{colorrgb< , , >}}

Page 41: POVRAY Tutorial

Jump to first page

Color and Texture

object { sphere {<0, 1.5, 1> 1.5} pigment {color rgb <1, 1, 1>} }

0151 15object { sphere {< , . , > . } texture {PinkAlabaster} }

Page 42: POVRAY Tutorial

Jump to first page

Pigment

object { 0plane {y, } 001pigment {checker color rgb < , , > color rg

b <0,1,0>} 2scale} The pigment is defined as checker, and

is given two colors. You could also use t extures instead of colors to make, say,

a black marble and white marble tile flo or.

The statement scale 2 scales the size of the squares.

Page 43: POVRAY Tutorial

Jump to first page

Finish

the term "finish" refers to the quality of the surface (shiny, dull, reflective, - etc.). Ther e ar e some pr e defi ned fi ni

shes in the colors.inc file. object{ sphere {<0 , 1 .5 , 1 > 1 .5 } pigment {color rgb <1 , 1 , 1 >} finish { ambient .2 }}

ambient has to doI IIII II II IIII II I

ight on the "shaddo w" side of the objec

t. Is it completely d ark (black) or slightl

y lit? .2 is pretty dar k, but not black.

Page 44: POVRAY Tutorial

Jump to first page

Diffuse and Specular diffuse refers to the way the light chan

ges from sark to light. A high number m eans the light changes from light to sha ddow very gradually; conversely, a low

number (like 0.1) would have a very abr upt change from light to shaddow.

specular is the small round highlight o n the surface. A small number will creat e a tiny "dot" of "pure" light; a large nu

mber will create a larger highlight.

Page 45: POVRAY Tutorial

Jump to first page

Diffuse and Specular

object { sphere {<0 , 1 .5 , 1 > 1 .5 }

pigment {color rgb <1 , 1 , 1 >} finish {

ambient .2 diffuse .5 }

}

object { sphere {<0 , 1 .5 , 1 > 1 .5 }

pigment {color rgb <1 , 1 , 1 >} finish {

ambient .2 diffuse .5 } specular .2 5

}

Page 46: POVRAY Tutorial

Jump to first page

Reflection

object { sphere {<0 , 1 .5 , 1 > 1 .5 }

pigment {color rgb <1 , 1 , 1 >} finish {

ambient .2 diffuse .5 } specular .2 5 reflection 1

}reflection is just that: refle ction. 1

means the objects is 100% reflect ive (liek a mirror); 0 means there i

s no reflection.

Page 47: POVRAY Tutorial

Jump to first page

Transparency

object{ sphere {<0 , 1 .5 , 1 > 1 .5 } pigment {color rgbf <1 ,1 ,1 ,.7 5 >} finish { ambient .1 diffuse .5 specular .5 }}

Page 48: POVRAY Tutorial

Jump to first page

Finish Reference finish {

ambient ambient lighting brilliance brilliance crand crand amount diffuse diffuse lighting ior index of refraction metallic phong phong highlighting phong_size phong size reflection reflected light refraction refract toggle roughness roughness specular specular highlighting}

Page 49: POVRAY Tutorial

Jump to first page

Finish

The sum of the values of ambient, diffus e, and reflection should be about 1 .0 .

Muchhigher, andyourcol or s wi l l sat ur at e and l ook fl a t. Much lower, and your colors will appe ar dark.

Objects with reflection and refraction (a ctually, any object with a nonzero filter)

will increase your rendering time. Refle ction requires an extra ray to be traced

to determine the reflected color, while with transparent objects, an extra ray m

ust be traced to determine the color tha t is being filtered.

Page 50: POVRAY Tutorial

Jump to first page

Finish

You usually don't need both phon g and specular highlights.

The argument to refraction shoul d be 1 or 0 only.

Page 51: POVRAY Tutorial

Jump to first page

Ambient

Themambi ent fi ni sh cont r ol s howmuch of t he color of a surface comes from ambien

t lighting. Its parameter is a float value in the rang

e 0 .0 to 1 .0 (typically). The default value is 0.1 Lowval ues mean t hat obj ect s whi ch ar e no

t directly lit will retain some of their color.

Hi gher val ues can make an obj ect appe ar t o gl ow

Page 52: POVRAY Tutorial

Jump to first page

Brilliance

Br i l l i ance modi fi es t he behavi or ofdiffuse lighting.

Brilliance takes a float parameter which modifies how diffuse light bounces off a

n object. The default value is 1.0. The flatter this angle is, the less the surf

ace is illuminated. Higher brilliance valu es make the light illuminate less at flat

angles The first image was rendered with the d

efault, the second with brillance 5, and t he third with brilliance 0.2.

Page 53: POVRAY Tutorial

Jump to first page

Crand

Crand can be used to simulate ver y rough surfaces like concrete and

sand which have grainy surfaces. Crand takes a float parameter fro

m 0.0 to 1.0. The default is 0.0 You should not use crand in animat

ions. the first image is again the default,

while the second has crand 0.1 thrII I II

Page 54: POVRAY Tutorial

Jump to first page

Diffuse

Diffuse light is basically light that c omes from a light source and diffu

ses in all directions. The value can range from 0.0 (no li

ght from light sources) to 1.0 (very 06well lit). The default value is . .

IIIII II III IIIIIIII III IIIIII , has diffuse 0.3, and the third has d

iffuse 0.9.

Page 55: POVRAY Tutorial

Jump to first page

Ior

This value controls the index of re fraction for transparent objects w

hich refract.

Page 56: POVRAY Tutorial

Jump to first page

Metallic

The metallic keyword is a modifie r for the phong III specular highl

ights. Metallic takes no parameter; eith

er it's there or it's not. The first was rendered with phon

g highlighting without metallic, a nd the second is with metallic

Page 57: POVRAY Tutorial

Jump to first page

Phong

The phong keyword creates a highlight on an object that is the color of the light

source . Phong takes a float parameter which ex

presses how bright the highlight shouldbe.

The size of the highlight can be controll ed wi t h t he phong_size parameter.

First image: no highlights, second imag e: phong0.9

Page 58: POVRAY Tutorial

Jump to first page

Phong Size

The phong_size parameter is a modifier f or t he IIIII finish. It takes a float par

ameter (greater than zero) which define s how large the phong highlight will be.

Typical values range from 1 (pretty dul l) to 250 (very shiny).

The default is 40. The images were rendered with "phong

III _ 40 " (), "_ 4 " , "phong_size 180", respectively.

Page 59: POVRAY Tutorial

Jump to first page

Reflection

The reflection finish gives an obje ct a mirrored or partially mirrored

surface. This object will then refle ct other objects in the scene.

A value of 0 turns off reflection for the object, a value of 1 gives the

object a perfectly mirrored surfac e (almost).

The first scene has no reflection, t he second has reflection 0.3.

Page 60: POVRAY Tutorial

Jump to first page

Refraction

Refraction only has meaning on objects that have at least a little bit of transpar

IIIIIIIIII II III IIIIIII II IIIII I. ays as they pass into a more dense or le

ss dense medium Youcanchangetheiorofarefractingobjectwiththe"ior" keyword. Someexamplesofindicesofrefractionare"ior1.000292" (air) "ior1.33" (water), and"ior1.5" (glass)

. The first image has no refraction, the se

cond has "ior 1.5", and the third has "ior2.0".

Page 61: POVRAY Tutorial

Jump to first page

Roughness

The roughness parameter controls the s ize of the highlight produced by the spe

cular keyword. Typical values range fro m 1.0 (sand paper) to 0.0005 (polished

glass). The default roughness is 0.05. IIIIII IIII IIII I IIII IIIII IIII I,

arge highlight. Small values give a very small, tight highlight. 0 is a very bad nu

mber for roughness. III IIIII IIII III " 0 . 9 " .

default roughness, the second uses "ro ughness 0.75", the third "roughness 0.0

01".

Page 62: POVRAY Tutorial

Jump to first page

Specular

The specular finish is similar to phong , b ut this one is more accurate as far as ph

ysical laws are concerned. It produces a highlight on the object where the reflect

ion of the light source would be if the ob ject were reflective

The size of the highlight can be controll ed (to some extent) with the roughness

parameter. Here's what specular (0 .9 ) looks like.

Page 63: POVRAY Tutorial

Jump to first page

Normal Reference Here's the general syntax for a bump m

ap. normal {

bump_map { type "filename" [_ size] [interpolate mode] [use_color] [use_index] [once] [map_type map mode] }}

Page 64: POVRAY Tutorial

Jump to first page

Normal

The normal component of a texture allo ws you to create effects on the surface

of an object Normalshavethreeparts, t he t ype, t he modi fi er s, and t hen t

ransformations. A normal can only have one type, and t

hat is one of bumps , dents , ripples , waves , or wrinkles . They each take a depth parameter between 0 .0 (Flat) and

10. (Violent).

Page 65: POVRAY Tutorial

Jump to first page

Normal

here's a standard ripples normal and another with "turbulence 0.7

I III III IIIIIII IIII IIII IIII" . slated to put their center on the t

op of the sphere.

Page 66: POVRAY Tutorial

Jump to first page

Bumps

The bumps normal creates a rand om bumpy pattern on the object.

The bumps normal takes a float p arameter from 0.0 (Flat) to 1.0 (M

ountainous) that describes the de pth of the bumps.

Page 67: POVRAY Tutorial

Jump to first page

Dents

The surface appears to have dent s (naturally enough) beaten into i t. Dents takes a float parameter fr

om 0.0 (Brand New) to 1.0

Page 68: POVRAY Tutorial

Jump to first page

Ripples The ripples normal creates evenl

y space, smooth ripples which ori ginate from 10 random locations i

nside the box with corners <0, 0, 0 1 1 1>, < , , >. All the waves have the same frequency, so the ripple effect is smooth at a signifi

cant distance from the center.

Page 69: POVRAY Tutorial

Jump to first page

Waves Waves are similar to ripples , exce

pt instead of creating smooth, ev en ripples, it creates more rough

and tumble waves. Theoretically t hese look more like deep ocean w aves. The waves normal takes th

e standard 0.0 (Becalmed) to 1.0 (Tsunami) parameter.

Page 70: POVRAY Tutorial

Jump to first page

Wrinkles

This normal specifier basically ma kes the object look like it had bee

n wadded up and then stretched back out again.

Page 71: POVRAY Tutorial

Jump to first page

Declarations (variables)

Variables are a way to store and r ecall frequently used items. In PO

V variables (declarations) can sto re a number, a word, an entire obj

ect, or even an ent ire scene. Example

#declare sizeOfSphere = 1.5

object{ sphere {<0 , 1 .5 , 1 > sizeOfSphere} pigment {color rgb <1 , 1 , 1 >}}

Page 72: POVRAY Tutorial

Jump to first page

Declarations

IIIIIII # 111declare MyPrettyWhite = rgb < , ,

> object{ sphere {<0 , 1 .5 , 1 > 1 .5 } pigment {MyPrettyWhite}}

Page 73: POVRAY Tutorial

Jump to first page

Declarations

# 0declare XPosition = # 1declare ZPosition = # 111declare MyPrettyWhite = rgb < , ,

> # 5declare MyRadius = .

object{

5sphere {< XPosition, . , ZPosition > MyRadi us} pigment {MyPrettyWhite}

}

Page 74: POVRAY Tutorial

Jump to first page

Declarations

#declare WhiteBall = sphere { < XPosition, MyRadius, ZPosition

> MyRadius pigment {MyPrettyWhite}}

Now replace the code for each of th e objects so that it looks like this:

object {WhiteBall}

Page 75: POVRAY Tutorial

Jump to first page

Declarations #declare MyPrettyWhite = rgb

111< , , > # 5declare MyRadius = .

# 0declare XPosition = # 1declare ZPosition =

IIIIIIIIIIII #

#declare WhiteBall = sphere { < XPosition, MyRadius, ZPositi on > MyRadius

{} } - camera { location <0, 2.25, 35>

0010 01direction < , , > up < , , 0 12500> right < . , , > look_at < 0 , 0 , 90> }

IIIII // - 5010080light_source{< , , >colorMyPr et t yWhi t e}

//Back Light light_source {<100, 50, 80> color rgb <0,

0,1>} 0object { plane {y, } pigment {MyPrettyW

hite} scale 2 } #declare BallCount = 1

# 21while (BallCount < )IIIIII IIIIIIIIIII

# 1declare MyRadius = MyRadius + . # 1declare XPosition = XPosition + .

# 4declareZPosition=ZPosi t i on +

#declare WhiteBall = sphere { < XPosi tion, MyRadius, ZPosition > MyRadius pi

gment {MyPrettyWhite}} # 1declare BallCount = BallCount +

#end

Page 76: POVRAY Tutorial

Jump to first page

Declarations

Page 77: POVRAY Tutorial

Jump to first page

Transformations

- Transformations, in ray tracing te rms, are attributes that change th

e position, size or orientation of o bjects (and of the various attribut

es of the objects). The most common types of transf

ormations, and the ones that POV- Ray supports, are translations , rotations III scalings.

Page 78: POVRAY Tutorial

Jump to first page

Translation

I translation is a transformation that m oves an object relative to its current pos

ition. - 142A translation of < , , > results in the c

ube being moved left one unit, up four, and back two.

Page 79: POVRAY Tutorial

Jump to first page

Rotation

A rotation is a transformation that changes the orientation of an obj

ect (the way that it's facing). A rotation of <0,0,45> rotates th

e cube 45 degrees around the z Ixis,

Page 80: POVRAY Tutorial

Jump to first page

Rotation

if we translated the cube first, and th en rotated it

if we rotated the cube first, and then translated it

Page 81: POVRAY Tutorial

Jump to first page

Scaling

Scaling changes the size of the ob ject with respect to its current siz

e. If we scaled the object with the st

ring scale <1,4,1>, we would get a result like this

Page 82: POVRAY Tutorial

Jump to first page

Example

torus { 3 11, pigment { color Yellow } scale <1.5,1,1> -rotate < 45,0,0> translate <0,2,0>} This code makes a yellow torus, sli

ghtly widened around the x axis, r - otated 4 5 degrees around the x

axis and with its center at <0 ,2 ,0>.

Page 83: POVRAY Tutorial

Jump to first page

Constructive Solid Geometry

The five types of CSG are: I IIII Merge Intersection Difference Inverse

Page 84: POVRAY Tutorial

Jump to first page

Union

Union is a way of joining objects together.

union{ object{greenBox} object{redTorus} - rotate <20, 65, 0>}

Page 85: POVRAY Tutorial

Jump to first page

Merge #declaregreenBox=

box{ - - - 212 212< , , >, < , , > pigment{color rgbf <0 , 1 , 0 , .

5 > }}

#declare redTorus =torus{ 125 000. , // MAJOR radius ( , , to mi

- d line of ring 05. // MINOR radius (radius of c

ross section of ring pigment{color rgbf <1 , 0 , 0 , .5>}

translate 1*y}

merge{ object{greenBox} object{redTorus} - rotate <2 0 , 6 5 , 0 >}

Render the image a nd you'll see that th

e torus now does no t extend inside the

box.

Page 86: POVRAY Tutorial

Jump to first page

Union and Merge

Union Merge

Page 87: POVRAY Tutorial

Jump to first page

Intersection

Intersection renders only the are as where the objects in the CSG i

ntersect, or overlap.

intersection{ object{greenBox} object{redTorus} - rotate <20, 65, 0>}

Page 88: POVRAY Tutorial

Jump to first page

Difference

POV will render the first object minus any following objects.

difference{ object{greenBox} object{redTorus} - rotate <20, 65, 0>}

Page 89: POVRAY Tutorial

Jump to first page

Troubleshooting

CSG has one major flaw that you should be aware of. When surface

s of CSG objects are identical, str ange artifacts can appear.

difference{ object{greenBox} box{ - - - I I11 1 1 1 1

pigment{color rgb <1, 0, 0>} } - rotate <20, 65, 0>}

Page 90: POVRAY Tutorial

Jump to first page

Troubleshooting

That is because as rays from the light so urce(s) reach the two objects, sometim

es they hit the red box first, and other ti mes they hit the green box first.

The problem is eliminated by ensuring t he objects in a CSG have "clearance" fro

m each other. Stretching the y values of the red box beyond those of the green b

ox alleviates the problem.

Page 91: POVRAY Tutorial

Jump to first page

Troubleshooting

difference{ object{greenBox} box{ - - - 115 11 151< , . , >,< , . , > pigment{color rgb <1 , 0 , 0 >} } - < 20 , 65 , 0>} IIIIIIII I IIIIII III IIIIIIIIII I

o show the overlap or "clearance."

Page 92: POVRAY Tutorial

Jump to first page

END