46
Unit -6 Ray Tracing Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for rendering scenes. The ray is here now or the ray reaches the point first We shall remarkable the property of ray tracing: it automatically solves the “hidden surface removal problem”, since the first surface hit by the ray is the closest object of the eye. More remote surfaces are ignored. The resulting color is then displayed at the pixel. The path of ray is traced through the scene; interesting visual effects such as shadowing, reflection, refraction are easy to in-corporate, producing images of dazzling/shinning realism that are difficult to create by any other method. SDL (scene description language) is very useful for describing the objects in a scene.

studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

Unit -6 Ray Tracing

Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for rendering scenes.

The ray is here now or the ray reaches the point first

We shall remarkable the property of ray tracing: it automatically solves the “hidden surface removal problem”, since the first surface hit by the ray is the closest object of the eye.

More remote surfaces are ignored. The resulting color is then displayed at the pixel.

The path of ray is traced through the scene; interesting visual effects such as shadowing, reflection, refraction are easy to in-corporate, producing images of dazzling/shinning realism that are difficult to create by any other method.

SDL (scene description language) is very useful for describing the objects in a scene.

Page 2: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

1. Overview of the ray tracing process The scene to be ray traced is inhabited/occupied by various geometric

objects and light sources.

The scene contains spheres, cones, boxes, cylinders and the like, each having a specified shape, size and position.

Pseudo code Skelton for ray tracer

These objects are described in some fashion and stored in an object list.

The camera as described earlier is also created.

Then for each pixel in turn we construct a ray that starts at the eye and passes through the lower left corner of the pixel.

Evaluating the direction dirrc for the rcth ray.

First find the rcth ray intersects each object in the list, and so we note the “hit time”- the value of “t” at which the ray “r(t)” coincides with object surface.

The location of the hit point on the object is then found, along with the normal vector to this object surface at the hit point.

The color of the light that reflects of this object, in the direction of the eye, is then computed and stored in the pixel.

Page 3: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

Example:

Description s of all objects are stored in an object list, suggested in the figure by the linked list of descriptive records

P hit= eye+ dirr, c t hit {hit spot}

It is clear that the fundamental operation in ray tracing is the calculation of intersection b/n a ray and a given object

2. Intersecting rays with other primitives We need to develop the hit ( ) method for other shape classes.

All hit methods are similar: the ray is 1st transformed into the generic co-ordinates of the object in question, and various interactions with the generic object are computed and its answer.

We need only work out the specific details of intersection for each generic shape.

1. Intersecting with a square2. Intersecting with a tapered cylinder3. Intersecting cube or any convex polyhedron a. The intersection algorithm for the generic cube b. the intersection algorithm for any convex polyhedron c. The intersection algorithm for a mesh object4. Adding more primitives

Page 4: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

1. Intersecting with a square• A square is a useful generic/basic/standard shape.

• The generic square lies in the z=0 plane and extends from -1 to +1 in both x and y.

• F (P) = Pz for mod Px <=1 and mod Py <=1.

• It can be transformed into any parallelogram positioned space, and so it often used in scenes to provide thin flat surfaces such as walls and windows.

• Hit( ) first finds where the ray hits the generic plane

F(P)=mod P2-1

and then tests whether this hit spot also lies within the square , as suggested in figure 12.1

2. Intersecting with a tapered cylinder• The generic tapered cylinders is shown in fig.12.18, along with several

ways.

• The side of the cylinder is part of an infinitely long wall, here after called the wall, with a radius of 1 at z=0 and a small radius of s at z=1.

• If s=1, shape becomes the generic cylinder.

• If s=0, its becomes the generic cone.

• Hit ( ) method for tapered cylinder, which provides as well a hit( ) method for the cylinder and cone.

• Several rays as shown in figure, variety of rays in which the ray can hit or miss this object.

Ray A hits the wall, twice on the actual cylinder(tapered cylinder)

Page 5: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

Same as Ray B, C, D, E.

With is many possibilities we need to organize the approach that avoids an un-widely number of if( )..else tests.

The solution is to identify hits in whatever order is convenient and put them in the inter.hit[ ] list regardless of order.

At the end, if inter.hit[ ] holds two hits out of order, the two items are swapped.

Its practical that we already have a list available to put these hits in.

The individual tests are straight forward.

The ray strikes the wall, substitute S + ct into the implicit form for the tapered cylinder to obtain the quadratic equation At2+2Bt+C=0

Where d=(s-1)cz

F=1+(s-1)Sz

Page 6: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

What do these parameters become for the cylinder and the cone?• We use the coefficients in same manner as sphere.

• If the disicriminent B2-AC is –ve, the ray pass tapered cylinder wall

• It is not –ve the ray doesn't strike the wall, and the hit times can found by solving the quadratic equations.

• Each hit is on the actual cylinder wall, find z-component of the hit spot.

• If ray hits the z component lies in 0 and 1.

• The intersection in base, The plane z=0, suppose it hits (x,y,0), the hit spot lies in the cap if x2+y2<1.

• The intersection in cap, The plane z=1, suppose it hits (x,y,1), the hit spot lies in the cap if x2+y2<s2

• A cylinder has one or more surfaces.

• We want to paste a different texture on the wall than on the cap.

1. The wall is surface 0

2. The base is surface 1

3. The cap is surface 2

• The approx values is placed in the surface field of each hit record.

• It is not difficult but lengthy, to bring these ideas together and to create code for intersecting a ray with a tapered cylinder.

• The normal vector found its two hit points

• The normal to the cylinder wall at point ( x, y, z ) is simply

( x , y, -(s-1)(1+(s-1)z)

• The normal's to the cap and base are (0, 0, 1) and (0, 0, -1), respectively.

• The hitNormal fields are filled with the appropriate values by hit( )

Page 7: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

3. Intersecting cube or any convex polyhedron• Bounding planes are easy to develop an intersection routine for a ray with

any convex polyhedron.

• One particular convex polyhedron, the generic cube, deserves special attention. (+-1,+-1,+-1) lies in corner and center at (0,0,0)

• It has 6 faces.

• The generic cube has two important reasons.

1. A large variety of intersecting boxes can be modeled and placed in a scene by applying an affine transformation to a generic cube. When tracing ray, each ray can be inverse transformed into the generic cubes coordinate system use a Ray with generic cube, which made very efficient.

2. Generic cube can be used an Extent is for other generic primitives in the sense of a bounding box. If a ray misses the extent , it must miss the object. It is a strong efficient algorithm to intersect a ray with the generic cube

a. The intersection algorithm for the generic cube• The cube inside half-space and outside half-space.

• A point on a ray lies inside the cube if and only if lies on the inside of every half space of the cube.

• So, intersecting a ray with a cube is a matter of finding the interval of time in which the ray lies in side all planes of the cube

Page 8: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

• Call the cube P.

• Test the ray against each plane of P ,in some chosen order and also compute the time at which ray either enters or exits the inside half-space for that plane.

• Keep track of candidate interval.

• CI=[tin, tout]

• Values of t is not inside the CI definitely not inside this half space.

• t< tin (plane outside)

• t< tout (plane inside)

• As each plane P is tested, we chop/cut/split away at this interval, either increasing tin or reducing tout

• At any point CI empty, the ray must be miss the object.

• If, after testing all the planes of P, the remaining CI is not-empty, the ray enters the object at tin, exits at tout.

Initially CI=(-α,α)

Outside of CI=(-α, 2.9) same as all CI’s

Finally CI= (1.8, 2.7)

Page 9: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

• Let the ray be S+ct and suppose the plane in question has outward pointing normal m and contains the point B

• The implicit for this plane is F(P)=m.(P-B),so the ray hits it when m.(S+ct-B)=0 or at the it time.

• T=numer/denom

• Where numer=m.(B-S)

and denom=m.c

• If denom>0(outside half-space ray passing)

• If denom <0(inside half-space ray passing)

• If denom=0(//el to the plane)

• Values of numer whether it is wholly inside/outside

Page 10: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

The generic cube the qunatities numer and denom can be computed very quickly

b. The intersection algorithm for any convex polyhedron

• The extension of hit( ) for any convex polyhedron is very straight-forward.

• Suppose there are N bounding planes, and the ith plane contains Bi and has outward normal vector mi see the fig(a) in cube is used for the calculation of numer and denom.

• Now two expensive dot products must be performed, and for loop become:

c. The intersection algorithm for a mesh object

• Develop a hit ( ) method for meshes.

• The mesh objects are described by a list of faces, and each face is a list of vertices along with a normal vector at each vertex.

• We shall take each face of the mesh in turn and treat it as bounding plane

• Call the plane associated with each face its face plane

Page 11: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

1. In the part a is convex, so its face planes are same as its bounding plane.

2.The part b shows the non-convex object.3. The portion that is inside all of its face

planes is shown shaded.

4. To build hit( ) for a mesh, we form numer and denom for each face in turn.

Pt[face[f].vert[0]vertindex] for a point

vertex.norm[face[f].vert[0].normIndex] for a norm

4. Adding more primitives• Different types of shapes other than generic primitives with the implicit form

of F(P) of the shape• So, in-order to determine the location of ray s+ct intersect surface and

replaces s+ct for Q in implicit form of F(P) with the time interval “t” such that

• D(t)=F(S+ct) • Function operations: 1. The function stays +ve only at the value of “t” at which point lying and the

ray stays outside the object.2. The function becomes -ve the rays stays inside the surface/object.3. For intersection different values of “t” are substituted to make d(t)=04. Thus the ray intersection is more or less equal to solving the given equation.• This is implied to sphere and other quadratic surface is

Page 12: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

• F(P)=(sqrt (p2x+p2

y)-d)2+p2z -1

• Thus the resulting eq. d(t)=0;is difficult to solve.• For instance, a general shape of d(t) where t increases, when the ray is

positioned towards the object, its initial point lies outside the object the below given shape is obtained

1. The value of d(0) is +ve, the ray starts outside the object.2. The d(t) decreases, reaching 0 if the ray intersects the surface at t1 is shown

in fig.

3. The d(t)<0 the ray inside the surface.4. Re-enters the ray to the object, here the ray is misses the object and d(t) is decreases, after its don’t reaches the d(0).5. The quadric such as sphere, d(t) has a parabolic shape, and for the torus(donut object draw that dig in exam) a quadratic shape. 6. For other surfaces d(t) may be so complicated, that we have to search numerically to locate t’s for which d(.) equals 0.

3. Compound objects: Boolean operations on objects

• We can trace only a limited variety of shapes: transformed spheres, planes, cones, and so on.

• But if a way can be found to combine these simple shapes into more complex ones, and to develop a ray tracing method for them, much richer and more interesting scenes can be ray traced., Is shown in fig

Page 13: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

• The method known as CSG(constructive soild geometry)• Arbitrary/random complex shapes are defined by set operations, also called

Boolean operations, on similar shapes.• Objects such as lens and hollow, fish bowls, and objects with holes, are

easily formed by combining the generic shapes treated so far.• Such objects variously called compound, boolean or CSG objects. • The ray tracing method extends in a very organized way to compound

objects: it is one of the great strengths of ray tracing that it fits so naturally with CSG models.

• For ex: union, intersection, difference.

1. Intersection(L=S1 intersection(symbol) S2); L= lens2. Union(L=S1 U S2)3. Difference is analogous to removing material, to cutting or carving the bowl is specified by equation B=(S1-S2)-C

Page 14: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

Types of compound objects: Boolean operations on objects

1. Ray tracing CSG objects2. Data structures for Boolean objects3. Intersecting rays with Boolean objects4. Building and using extents for CSG objects.

1. Ray tracing CSG objects• The intersection of a ray with a 3D CSG object is reduced to the intersection

of an ordered list of one dimensional numbers with one dimensional parts of a CSG parts.

• Consider the example with spheres of S1 and S2 spheres at the time indicated.

• Write the brief explanation of in below diag.

list of t- values for a ray with two objects 1. Call the set of t values for which the ray inside the object throughout each object its inside set.

Page 15: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

2. In general , if we denote by T(A) and T(B) the inside set of the two objects is, A and B as shown in eq is T(A op B)=T(A) op T(B)

2. Data structures for Boolean objects

Fig 1 shows the tree corresponding to the object

(((B1 ∩ B2) U C2)U((S1-S2)-B3))-C1)

• Each internal node (shown as circle) represents an operator, and each leaf(shown as sphere)is a primitive shape.

• A tree is made up by combining subtrees, which are turn primitive objects or subtrees

• When a node contains difference operator, it is understood that the node produces the (left subtree)-(right subtree), as opposed to(right subtree )-(left subtree).

• Currently all the object types like sphere and cube are derived from the shape class which is turn derived from the basic GemonObj class.

• Booleans are very expensive to ray trace, and anything that speeds this up is a blessing.

• To improve the matters to derive separate classes for the three kinds of booleans: UnionBool, IntersectionBool and DifferenceBool.

Page 16: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

• Notice that Booleans do not have their own affine transformations: only shapes do.

• This causes a Boolean tree to have transformations only at its leaves. • The way to specify the Boolean in an SDL(Scene Description Language)

file is to use one of the keywords union intersection, difference is placed on left and right one for specifications(shapes)

SDL code

3. Intersecting ray with Boolean objects• Hit() method is developed to operate with all types of Boolean objects.• It creates the inside set ray with right subtrees and subsequently join these

sets.• A skeleton of hit() is shown below which performs intersection operation.

Page 17: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

• The code is similar to the union and difference.Combining hits : The process of combining t-lists are logical and complicated.

• To illustrate this, consider two hit lists L and R,for simply L[],R[] in place of leftInter.thehit[] and rightInter.thehit[].

Expalin about the fig. Going through the subtrees, the state of the ray is traced with variables as shown in below

• These are the states of the ray between hits-that is just before the next hit to be considered.

Page 18: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

• lftInside is initialized according to whether the ray enters or exists the left object at the first hit-that is according to L[0].

• lftInside is false if the first hit is entering (because before the hit ray must be outside) and it is true the 1st hit is exiting.

• Same as right side.• Finally, the combine is initialized both left side and right side is true. • If the operator is union, combInside is true if lftInside or rtinside or both are

true, Using the logically operators are: • combInside=lftInside|| rtInside.• Same as intersection are:• combInside=lftInside && rtInside.• Same as difference are:• combInside=lftInside &&! rtInside.• Both the lists are traversed gradually and the hit times are updated. • If one of the list reaches final list the unused list item are ignored different

operators handle these items differently.• When intersection is used , they are ignored.• When union is used they are transverd incrementally.• When the difference is used, the right item list are ignored and left item lists

are traversed incrementally3. Building and using extents for CSG objects. During the processing step the tree for the CSG object is scanned, and

extents are built for each node and stored within the node itself. The hit() method of the object class is used to test the extent of each node by

ray tracing. If it is clear the ray cannot hot the object. Thus saving the cost of list integration. Otherwise the ray hits the left and right subtrees, the process of creation of

projection, sphere, box extents are as follows.1. To make box extents: • The box extent of CSG tree is used for enclosing the object.• Suppose the objects P and Q represents the node of a tree, consider the

representation of object P op Q using a node where P,Q are object shapes and op be the Boolean operator.

• If the ray misses the hit on box extent, then it is confirmed that the ray also misses hit on the object.

• Determining the tightest aligned box without systematic/order/regular processing is difficult because of the complex shapes of the object.

• So a simplex approach is used for creation of box extents for L op R

Page 19: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

• The box extent for L op R can be defined using the following operators:• Union: E(L) and E(R) at the same time. This is represented as E(E(L) U

E(R)), it also involves uncertainty such as:• It is efficient to test E(L) and E(R) separately.• If both the extents are missed, it misses L U R too.• Is E(L U R) remains one.• Intersection: E(L) ∩ E(R). The resultant generated is, most likely to the

aligned box. • Its left, right, front, back, top, bottom can be easily computed.• The resultant extent will be tight the L, R extents are tight.• The uncertainties are involved here is if the ray misses the extent it is

necessary that it will miss L ∩ R • Difference: E(L) - E(R) being smaller than E(L) - E(R) is not utilized. So

the box extent will be E(L) itself., however deep and clear analysis of this type of extent will be expensive.

2. To make sphere extents:

• The projection extent pertaining to the node is the combination of the left and right objects projection extents.

• It is created for all the nodes of CSG objects tree.• Every class adopts its own method to create projection extent i.e,

makeprojectionExtent( ).• Let P(object) be the projection extent of an object by using this it has some

rules are:

Page 20: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

2. To make sphere extents:

• The projection extent pertaining to the node is the combination of the left and right objects projection extents.

• It is created for all the nodes of CSG objects tree.• Every class adopts its own method to create projection extent i.e,

makeprojectionExtent( ).• Let P(object) be the projection extent of an object by using this it has some

rules are:

3. To make sphere Extent:

• Sphere extent is formed by determining the cloud of points for the object in world co-ordinates and building a box around it and is constructed non- recursively.

• The sphere extent of Boolean objects for union operator is the finding of cloud points in the world co-ordinates and design them to form a sphere shape, for intersection operator.

• It is difficult to compare the true sphere extent.• For difference operator, use the sphere extent of both the left and right

objects

4. Adding surface textureFor each face F a pair of texture coordinates was attached to each vertex of F, and OpenGl painted each pixel inside the face by using the color of the corresponding point within a texture images.

Page 21: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

Two principal kind of texture are used.

1. Image texture2. Solid texture1. Image texture : A 2d image is pasted on onto each surface of the object2. Solid texture: the object is included which are carved/fixed out of block of

some material. The material itself has texturing and ray tracer gives the color to the texture on every surface of the object.

Solid texture:

• Solid texture sometimes called 3d texture.• It is a simplest texture.• It was 1st suggested by perlin and peachy.• It passes an object curved out of textured material is wood and marble• It is done by the function (x,y,z).• This function is used to impart colors (r,g,b) on the surface at every

single point in the space.• For an instance, consider a texture with colors or inkers which is

dependent on position• This implies if the position is changes, the color is also changes.• So, when viewed at different points (x,y,z) different colors achieved

(r,g,b)• If the object with certain shape is defined in the space and it all its outer

material is taken off.• Then the surface of the object such that the point (x,y,z) present on the

surface gets exposed/open to the elements with a surface texture.I. Ray tracing objects compose of solid texture

• The basic element for ray tracing a solid texture is a function called texture( )

• It adopts different methods to make changes in the light focused upon the surface. They are:1. The light can be set equal to texture ( ) itself, as if the object were

glowing/illuminating with that color.

Page 22: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

2. The texture can modulate the ambient and diffuse reflection coefficients, such thatI= texture(x,y,z)(Iaρa+ Isρd lambert) + Isρs phong

The above equation, evaluating of texture (x,y,z) is done at the hit point (x,y,z) with respect to the ray.

Aesthetically, the surface appearance is based upon the changes in the texture ( ), such that its original colors are lighter or darker on various points.

Subsequently, the textured object becomes shiny just like plastic this is because the specular highlight acquires the same color, which is not spoiled the texture.

The hit point (x,y,z) can either be in generic co-ordinates or in world co-ordinates.

Mostly the hit points is generic co-ordinates, where the object keeps on holding the texture where ever it is rotated or moved to last position in the space such scenario can be seen in animation in which the object moving from one frame to another frame is tightly attached to the texture or vice versa.

Here the texture is fixed in the space and if the object is rotated or displaced from its position, the texture then sweeps over the object.

As a result, the object comes out as though it is carved out from the new material at new position. Thus, giving a new visual effect.

II. Wood grain texture The wood grain texture is a rich and varied solid texture. It is easy to create and also easy model the original materials The presence of grains in the log of wood is because of the occurrence of

concentric cylinders.

Page 23: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

These cylinders acquires different colors in accordance to the rings which are visible when the log is cut into two pieces.

The distance between the points from certain axis chages, in essence the function jumps from on value o another value back and front.

This can be computed using the modulo function

Rings(rg) = ((int)rg%2)

While the ring in z-axis with radius r=sqrt(x2+y2) The value of rings %2 jumps between 0 to1, as r increases from0. The texture is can be made to jump between two preset/fixed values, say D

and D+A, using:

Simple_wood(x,y,z)=D+A*rings(r/M)%2;

Where again r= sqrt(x2+y2) developes the rings with M thickness about z-axis.

A part from this inorder to rotate, skew/twist, swing or shake the rings a component is used which changes according to azimuth θ about z axis

Rings(r/M + k sin (θ/N ))

Even through the radius is kept constant the rings changes because the θ value keeps on changing.

Thus, making the rings swing N and OUT “N” number of times around the axis.

Notice that, we are nesting functions to add more effects: the argument of rings ( ) is not just r but is the sum of r/M and a sinusoid.

This is noting but the quotient of a specific angle and N, thus making it a powerful functional composition for developing visual effects.

Further, advancements can be made to the swing wood grain by using.

Rings(r/M + ksin(θ/N + Bz))

This causes the change in the sinusoid phase about z- axis, thus giving a effect of swing as height varies/changes.

But, if the grain is to be tilted so as to make it concentric about a certain/other axis.(but not z-axis) apply a rotation before equating r and θ.

Page 24: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

Suppose r=sqrt(x2 + y2) Where (x',y',z')= T(x, y, z) for rotation T( )

III. 3D Noise Texture:

The texture of the marble contains irregularity with light and dark color patterns.

The material has grains, which causes mess/disorder in the texture. In simple terms the stone texture has turbulent/disorderly streams of the dark

material with whirls/rotate and blotches/marks/spots present at random positions across the stone.

As if the stone was formed of some violently stirred molten material. This turbulence can be generated a noise function which make random

values at every single point (x, y, z) in the space.

Page 25: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

Consider the random value (x, y, z)=( i, j, k)for every combination of integers i, j, k ,such an arrangement is called “integer lattice”

The large amount of array is needed to store the collection of noise values such that float N[1000] [1000] demand large memory.

On other hand it is easy to generate single noise value t a time. This can be achieved by using the function called float lattice Noise (int i,

int j, int k) which returns a random value with integers i, j, k defining appositions in lattice.

It is important to note that the function is iterative and efficient so as to produce a uniform value of noise for given( i, j, k)

i. Generating repeatable random values:ii. Developing he noise classiii. Turbulence

i. Generating repeatable random values: Set up a fixed array, say noise table []. Array of length 256 have been quite adequate, so we must use the length. Now the main function, latticeNoise (i, j, k), simply index into noiseTable[]

in a repeatable way. To insure that there is little or no pattern in the noise value, the indexing

function scramble/mix up or hash/search the ( i, j, k) combination into a value between 0 to 255.

Page 26: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

This easy to accomplish usin a second array, index [],that combines the values 0and through 255 randomly permutated.

Peachy suggests developing two macros#define PERM(x) index[(x) & 255]#dfine INDEX(ix, iy, iz ) PERM( (ix)+ PERM(iy) + PERM(iz)))

The latticeNoise( )function isFloat latticeNoise(int i,int j,int k){ returnnoiseTable[INDEX( i, j, k)];}

ii. Developing the noise class: Class Noise ( ) that we will use to generate marble and other noise like

textures. Marble ( ) class, which returns a position dependent value of brightness

between 0 and 1 that mimics/copies the rivulets/streams of dark and light stone in marble.

The method marble( ) uses noise( ) and turbulence( ), helper function is latticeNoise( )

The class constructor creates and fills the arrays noiseTable[] and index[] and rand( ) function is used to put into random values in an noiseTable[], scaling the values is lies between 0.1 to1.0.

iii. Turbulence: The idea is to mix together several noise components, one that

fluctuates/chanes/alter (in the directions of) slowly as we move slightly though space, the fluctuates repeats 4 times randomly .

Turb( s, x, y,z) = ½ noise(s, x, y, z) + ¼ noise(2s, x, y, z)+ 1/8 noise(4s , x, y, z)Here s is scale distances.

Page 27: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

IV. Marble texture: The texture of the marble contains veins/layers which are of the light and

dark material. These veins exhibit regularities as well as disorder regularities. Interestingly, the veins can be transformed in order to produce smooth

pattern in z-direction which is then disordered using the function turb ( ). This gives the veins a marble like 3d texture. Consider a texture which is uniform in both x and y plane and slowly

shows the variations in z- plane, given below is the function marble.a. Marble(x,y,z)=undulate(sin(z))

Where,I. undulate( ): it is a spline shaped function, it varies between dark

and light values, and variations in arguments from -1 to +1II. sin(z): it gives an effect of periodic ripple/wave/flow in z –

plane, this swings back and forth across the spline curve.

b. Marble(x, y, z)=undulate(sin(2+ k turb (s, x, y, z)))I. sin( ) gives a realistic pattern of veins/layers.

II. Here s and k are parameters.c. The figure illustrates the marble texture on the surface of the cube.

Page 28: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

g= spline (sin(2Πz + k turb (5, x, y, k)))I. Where z shifts from 0 in right and 1 in left side

II. y-plane points in upward directionIII. k is amplitude and have value = 1 to create minute/little

turbulence.In 2nd and 3rd figure k is kept 3 and 6 to produce an effect of high turbulence/unpredictable movements.

2. To paste images on to surfaces:

The process of pasting images on arbitrary curved surfaces is a simple method

It is efficient but consumes a lot of execution time when implemented with openGL

Here individual computation of every pixel is done and scan-line coherence is not over used

Suppose 2d texture of the function (i , j) differing from 0 to 1. At every point (i, j) an intensive color is generated. We observe that the texture (i, j) is a procedural texture is similar to

checkerboard or Mandelbrot set. A part from this, it could also be an image texture present in pixmap. The pixmap is done as N by M array of pixel values which is referred to as

t=t×r[][]. i, j occurring the values 0 and 1,the pixel of t × r, by using the following

t×tr[(int) (i/N) ][(int)(j/M) ]

4. Reflections and transparency:

Page 29: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

In general, the light travels through many different objects before hitting a surface.

During this period several reflections and refractions can occurs resulting in the reflection from shiny surface before coming in contact with eye

In case of light travelling through the mirror like or transparent surfaces, the light which reaches the eye holds the 5 components.I = Iamb + Idir +Ispec +Iref + Itrans

amb=ambient, dir=direction, sepc=specular, ref=reflection, trans= transparency

The diffuse and specular (properties of mirror) derived from the light sources, which are seen at ph .

The reflected light Irefl obtaining from the light source IR is incident upon ph

along with the direction dir. This direction has impact on angle of incidence making it equal.

r = dir- 2(dir. m) m The transmitted light Itrans is originated from light sources IR is then

propagates through transparent material to ph in the direction –t. Subsequently the small part of this light gets bent when it travels over the

surface. Later the light proceeds through the dir and the refraction direction t rely

over multiple factors.

I is a combination of several light contributions. From the figure, IR is light which can be found at Ph from a ray P' to Ph. Ir is generating the second ray from Ph

towards the direction r.

Page 30: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

In the figure 2 represents the addition of reflected component R1, transmitted component T1, local component L1 where T1 is obtained from refraction.

These local components are nothing but the addition of ambient, specular, diffuse, reflections near Ph, also it rely upon the natural light sources, are not calculated through secondary rays. Basically the term is used to estimate the effect of diffuse and specular reflections of the remaining surfaces.

Here, R1 = R3 + T3 + L3

Where, T3 = R4 + T4+ L4,

Here each variable is a addition of three variables, through this method the light intensity is calculated.

Fig 2(b) represents the light components in the form of tree of light contributions.

4.1 The refraction of light:

The refraction of light is defined as a ray of light travelling through an object and hitting the transparent surface in so doing a small part of ray penetrates the object is shown in fig.

Page 31: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

Consequently, the speed of light changes in every medium which is turn varies the direction of the ray from “dir to t”.

along the same lines the vector “t” exit in same plane corresponding to “dir”, normal plane m

when the angle of incidence of the ray is ϴ1 then snells law gives the angle of reflection ϴ2 in the equation issin (ϴ2 )/C2 =sin(ϴ1 )/C1

Here speed of light in medium 1 is defined as C1 and speed of light is defined C2.

The “index of fraction” of medium 2 relative to medium1 is given as the fraction of C1/C2.

If ϴ1 = 0 and ϴ2 =0, in other words light striking an interface with respect to right angles is always in a straight line without any bend.

Critical angle:

the angle of incidence beyond which rays of light passing through a denser medium to the surface of a less dense medium are no longer refracted but totally reflected. Or

A light ray is in the more denser medium and approaching the less dense medium. The angle of incidence for the light ray is greater than the so called critical angle.

Page 32: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

Fig a: represents the light travelling from faster to slower medium Fig b: represents the travelling of light from slower to faster medium. Fig c and d: represents same produce showing. The angle formed at 90̊ is larger angle and the small angle is close to critical

angle. The small angle is present in the slower medium hold become large and

enforces the angle from 90̊.this is highly impossible because light cannot pass through the second medium. This effect is known as “total internal reflection”.

Here sin (ϴ1 ) =(C1/C2) sin(ϴ2 ).

Finding the direction of transmission, t:

For ray tracing purposes we must find the direction t, the surface normal m, and the ray direction dir.

t= C2/C1 dir + (C2/C1(m.dir) – cos(ϴ2 ))m

Where cos(ϴ2 )= sqrt(1-(C1-C2)2(1- (m.dir)2)

Cos(ϴ2 ) becomes –ve, the t becomes irrelavent, this is happens at critical angle.

IV.2 Dealing with refractions in shade: Ray tracing scenes involves transparent objects, it is important that the

programmer must monitor the medium through which ray travels. The value C2/C1 at the cross section occurring in a situation like or exiting

can be determined present object or entering the next object.

Page 33: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

Shade( ) function handle the ray present in the object.1. Design policy 1: No two transparent objects may interpenetrate:

The modeler promises never to let two transparent objects interpenetrate. There can be no glass marble placed inside another, no cube of water inside a glass box. Then each ray is either in air alone or inside a single object.

I. Suppose, the current ray in shade ( ) present outside the object, it then strikes a transparent object A. finds the transparent A.t= C2/C1 dir + (C2/C1 (m.dir) – cos(ϴ2 ))m

The direction “t” corresponding transmitted ray is calculated. Using C1 = 1, for air obtaining C2 from the properties of A. The new ray is too built, with its recurseLevel dully incremented

and containing a pointer A. Shade is then called recursively and ultimately returns a color.

II. Suppose on the other hand, that the current ray is inside some object A and hits it’s another surface. Since it must be a surface of A, the ray is exiting into air.

If the ray is present inside the object, the sign of the striking point should be changed. i.e, the sign should be reversed.

If the ray inside the object, it understood the ray not exposed the light

Thus freeing the programmer from the burden of calculating the ambient, diffuse and specular intensities.

On other hand, the reflected ray is transparent, so the value C1 is obtained from properties of A.

C2 is assigned from 1 from air.2. Design policy 2: transparent objects may interpenetrate:

When the modeler is allowed to accept the transparent objects, into the scene the situation becomes complicated because it leads to interpenetration.

As shown in figure(a) the glass cube has many objects present in it such as quart spherical marble, a cylinder in air hole, a cube of water, half imbedded glass cone with individual speed of light.

The figure(b)shows the cross sectional no. of objects in a complex scenes.

Page 34: studenzmaterial.files.wordpress.com  · Web viewUnit -6 Ray Tracing. Ray-tracing is a technique for computing the visibility between the points. It is most powerful approach for

Therefore the complex sequences of adding and deleting through the list.

For example: in case of interpenetration of green marble with blue marble then the joint region gives blue color.