Presentation is loading. Please wait.

Presentation is loading. Please wait.

Components of illumination that from diffuse illumination (incident rays come from all over, not just one direction) - E d that from a point source which.

Similar presentations


Presentation on theme: "Components of illumination that from diffuse illumination (incident rays come from all over, not just one direction) - E d that from a point source which."— Presentation transcript:

1 Components of illumination that from diffuse illumination (incident rays come from all over, not just one direction) - E d that from a point source which is scattered diffusely from the surface - E sd that from a point source which is specularly reflected. - E ss E = E d + E sd + E ss E

2 Combining the illumination Combining all three components (diffuse illumination, diffuse reflection from a point source and specular reflection from a point source) gives us the following expression: E = E d + E sd + E ss

3 Diffuse illumination A proportion of light reaching surface is reflected back to the observer. This proportion is derived from the angle of incident light and properties of the surface Not dependent on the location of the viewer.

4 Diffuse illumination I d - incident illumination E d - observed intensity E d = R.I d where: –R is the reflection coefficient of the surface (0 <= R <=1) R is the proportion of the light that is reflected back out

5 Diffuse scattering from a point source When a light ray strikes a surface it is scattered diffusely (i.e. in all directions) Doesn’t change with the angle the observer is looking from

6 Diffuse scattering from a point source The intensity of the reflected rays is: E sd = R.cos(i).I s i - angle of incidence – the angle between the surface normal and the ray of light - 0 <= i <= 90 E sd - intensity of the scattered diffuse rays I s - intensity of the incident light ray. R - reflection coefficient of the surface (0 <= R <=1)

7 Specular reflection relationship between a ray from point source to the reflected ray is given by Lambert’s Law: i = r i - angle of incidence r - angle of reflection

8 Specular reflection For a perfect reflector, all the incident light would be reflected back out in the direction of S. In fact, when the light strikes a surface it is scattered diffusely (i.e. in all directions): For an observer viewing as an angle (s) to the reflection direction S, some fraction of the reflected light is still visible (due to the fact that the surface isn’t a perfect reflector - some degree of diffusion takes place). How much?

9 Specular reflection The proportion of light visible is a function of – the angle s (in fact it is proportional to cos(s) – the quality of the surface – angle of incidence i. We can define a coefficient w(i) the specular reflection coefficient - which is a function of the material of which the surface is made and of i. Each surface will have its own w(i).

10 Specular reflection coefficient

11 Specular reflection E ss = w(i).cos n (s).I s

12 Specular reflection E ss is the intensity of the light ray in the direction of O n is a fudge factor: n=1 rough surface (paper) n=10 smooth surface (glass) w(i) is usually never calculated - simply choose a constant (0.5?). It is actually derived from the physical properties of the material from which the surface is made.

13 Specular reflection cos n (s) - This is in fact a fudge which has no basis in physics, (stochastic model) but works to produce reasonable results. By raising cos(s) to the power n, what we do is control how much the reflected ray spreads out as it leaves the surface.

14 Combining the illumination Combining all three components (diffuse illumination, diffuse reflection from a point source and specular reflection from a point source) gives us the following expression: E = E d + E sd + E ss

15 Combining the illumination E = R.I d + (R.cos(i) + w(i) + cos n (s)).I s E is the total intensity of light seen reflected from the surface by the observer.

16 Calculating E E – We’re trying to calculate E, so obviously that is unknown. R - is defined for each surface, so we need to add it as a variable to our surface class and define it when creating the surface, so its known. I d - The incident diffuse light - we can define this to be anything we like; 0 = darkness, for an 8-bit greyscale 255 = white. – Known cos(i) - we can work this out from L.N w(i) - we can define this to be anything between 0 and 1 - trial and error called for! - Known

17 Calculating E n - is defined for each surface, so we need to add it as a variable to our surface class and define it when creating the surface, so, basically its known. I s - the intensity of the incident point light source - again we can define this to be anything we like; 0 = darkness, for an 8-bit greyscale 255 = white. See below for a discussion of adding lights to our data model. - Known. cos(s) ? Ah!

18 Calculating cos s cos s = S.O We know O Need S

19 Calculating cos s –Thanks to Lambert’s law we know that S is the mirror of the incident ray about the surface normal. It can be found from some vector maths: S = 2 Q - L

20 Lambert Shading Finally, we know all of the terms in the combined illumination equation and for any surface in our model we can calculate the appropriate shade. E = R id + (R.cos(i) + w(i) + cos n (s)).I s A program which implements this model of shading is said to implement Lambert Shading

21 Extending to colour Each surface has a colour which means it reflects different colours by different amounts, i.e. it has a different value of R for red, blue and green E red = E dred + E sdred + E ssred E green = E dgreen + E sdgreen + E ssgreen E blue = E dblue + E sdblue + E ssblue

22 Gouraud Shading and Phong Shading Adopted from U Strathclyde’s graphics course

23 Problems with Lambert –Using a different colour for each polygon means that the polygons show up very clearly (the appearance of the model is said to be facetted.

24 Mach bands

25 –This is a physiological effect whereby the contrast between two areas of a different shade is enhanced as the border between the shades

26 Smooth Shading What is required is some means of smoothing the sudden transition in colour. Various algorithms exist for this; amongst the best known are: –Gouraud shading and –Phong shading both named after their inventors.

27 Gouraud Shading –The facetted appearance of a Lambert shaded model is due to each polygon having only a single colour. –To avoid this effect, it is necessary to vary the colour across a polygon:

28 Gouraud Shading Colour must be calculated for each pixel of the polygon. The method we use to calculate the colour results in the neighbouring pixels across the border between two polygons ending up with approximately the same colours. This blends the shades of the two polygons and avoids the sudden discontinuity at the border.

29 Gouraud shading –based upon calculating a vertex normal –an artificial construct (a true normal cannot exist for a point such as a vertexl). –can be thought of as the average of the normals of all the polygons that share that vertex

30 Gouraud shading

31 –Having found the vertex normals for each vertex of the polygon we want to shade, we can calculate the colour at each vertex using the same formula that we did for Lambert Shading

32 Calculating the colour of each pixel Interpolating “scan- line algorithm” Light intensity at P given by:

33

34 Phong Shading –Phong shading is based on interpolating the surface normal vector – The arrows (and thus the interpolated vectors) give an indication of the curvature of the smooth surface which the flat polygon is approximating to.

35 Phong Shading The interpolation is (like Gouraud shading) based upon calculating the vertex normals (red arrows)…. …using these as the basis for interpolatation along the polygon edges (blue arrows) …. …..and then using these as the basis for interpolating along a scan line to produce the internal normals (green vectors) a colour value calculated for each pixel based on the interpolated value of the normal vector.

36 Gouraud vs Phong Phong shading is requires more calculations, but produces better results for specular reflection than Goraud shading in the form of more realistic highlights.

37 Why? Consider the specular reflection term Cos n s If n is large (the surface is a good smooth reflector) and one vertex has a very small value of s (it is reflecting the light ray in the direction of the observer) whilst the rest of the vertices have large values of s - a highlight occurs somewhere on our polygon.

38 Why? With Gouraud shading, nowhere on the polygon can have a brighter colour (i.e higher value) than a vertex unless the highlight occurs on or near a vertex, it will be missed out altogether. When it is near a vertex, its effect is spread over the whole polygon. With Phong shading however, an internal point may indeed have a higher value than a vertex. and the highlight will occur tightly focused in the (approximately) correct position

39 Summary Lambert shading leads to a facetted appearance To get round this, use a smooth shading algorithm Gouraud and Phong shading produce good effects but at the cost of more calculations. Gouraud interpolates the calculated vertex colours Phong interpolates the calculated vertex normals Phong – slower but better highlights

40 Finer Details Adding fine details –Why we don’t use the brute force approach –Faking it with pictures

41 Fine details We could explicitly model this block of wood with lots of small, different coloured surfaces. Immense amount of work.

42 Fine details In fact, we don’t. “Stick” a picture (.bmp,.gif, etc.) onto a surface. This is “texture mapping” Picture is called a “texture map”

43 Texture Mapping Need to shade image on a pixel by pixel basis

44 Texture Mapping From shading model we know: E = R id + (R.cos(i) + w(i) + cos n (s)).I s With texture mapping, we have a different R for each pixel The texture map “modulates” R

45 Texture Mapping Sticking the picture on. Map projection coords to image coords

46 Texture mapping – scan line Need to lookup colour value (R) at point P But where is P? Consider ratios: AS 1 : AC = as 1 : ac BS 2 : BC = bs 2 : bc S 1 P:S 1 S 2 = s 1 p:s 1 s 2

47 Texture mapping – scan line S 1 x = (C x - A x ). (s 1x - a x /c x - a x ) S 1 y = (C y - A y ). (s 1y - a y /c y - a y ) and S 2 x = (C x - B x ). (s 2x - b x /c x - b x ) S 2 y = (C y - B y ). (s 2y - b y /c y - b y ) Thus: P x = (S 2x - S 1x ). (s 2x - p x /s 2x - s 1x ) P y = (S 2y - S 1y ). (s 2y - p y /s 2y - s 1y )

48 Other maps and modulations There are other parameters in our shading equation which we can modulate:

49 Bump Mapping Surface normal vector Simulate ‘bumps’ or other small texture irregularities By artificially altering the surface normal vector, we alter the direction of the S vector and hence the amount of light reaching the observer.

50 Bump Mapping

51 Diffusion Mapping

52 The end of the line

53 Summary the need to model fine details to achieve realism that explicitly modelling fine details is difficult and time consuming. fine detail can be simulated using texture mapping and bump mapping texture mapping works by modulating the surface colour term in the shading equation bump mapping works by modulating the surface normal vector in the shading equation.

54 Hidden Line Removal Adopted from U Strathclyde’s course page

55 Introduction Depth cueing Surfaces Vectors/normals Hidden face culling Convex/concave solids

56 Perspective Confusion

57 Hidden Line Removal (show demo – basic3d wireframe surface)

58 Hidden Line Removal No one best algorithm Look at a simple approach for convex solids based upon working out which way a surface is pointing relative to the viewer. convex concave

59 Based on surfaces not lines Need a Surface data structure WireframeSurface –made up of lines

60

61 Flat surfaces Key requirement of our surfaces is that they are FLAT. Easiest way to ensure this is by using only three points to define the surface…. – (any triangle MUST be flat - think about it) …but as long as you promise not to do anything that will bend a flat surface, we can allow them to be defined by as many points as you like. Single sided

62 Which way does a surface point? –Vector mathematics defines the concept of a surface’s normal vector. –A surface’s normal vector is simply an arrow that is perpendicular to that surface (i.e. it sticks straight out)

63 Determining visibility Consider the six faces of a cube and their normal vectors Vectors N 1 and N 2 are are the normals to surfaces 1 and 2 respectively. Vector L points from surface 1 to the viewpoint. It can be seen that surface 1 is visible to the viewer whilst surface 2 cannot be seen from that position.

64 Determining visibility Mathematically, a surface is visible from the position given by L if: Where  is the angle between L and N. Equivalently,

65 Determining visibility Fortunately we can calculate cos  from the direction of L ( l x,l y,l z ) and N ( n x,n y,n z ) This is due to the well known result in vector mathematics - the dot product (or the scalar product) whereby:

66 Determining visibility Alternatively: Where L and N are unit vectors (i.e of length 1)

67 How do we work out L.N?

68 –At this point we know: we need to calculate cos  Values for l x,l y,l z The only things we are missing are n x,n y,n z

69 Calculating the normal vector –If you multiply any two vectors using the vector product, the result is another vector that is perpendicular to the plane (i.e normal) which contained the two original vectors.

70 IMPORTANT We need to adopt the convention that the calculated normal vector points away from the observer when the angle between the two initial vectors is measured in an clockwise direction. Failure to do this will lead to MAJOR confusion when you try and implement this Believe me, I know.

71 Calculating the normal –Where to find two vectors that we can multiply? –Answer: we can manufacture them artificially from the points that define the plane we want the normal of

72 Calculating the normal By subtracting the coordinates of consecutive points we can form vectors which a guaranteed to lie in the plane of the surface under consideration.

73 Calculating the normal We define the vectors to be anti-clockwise, when viewing the surface from the interior (imagine the surface is part of a cube and your looking at it from INSIDE the cube). Following the anticlockwise convention mentioned above we have produced what is known as an outward normal.

74 IMPORTANT An important consequence of this is that when you define the points that define a surface in a program, you MUST add them in anti-clockwise order

75 Calculating the normal This is a definition of the vector product

76 Visibility –At this point we know: we need to calculate cos  Values for l x,l y,l z values for n x,n y,n z

77 Visibility If then draw the surface else don’t! (or draw dashes)

78 Making it easier Actually, in certain cases we can simplify things a little. If the viewpoint lies somewhere on the negative side of z-axis, as it did when we first set up the projection transformations (i.e without any viewpoint transformations) we can forget about L and cos  All we really need to know is whether or not the normal points into the screen or out of it, i.e. is n z positive or negative? In that case, all we need to do is calculate n z and test it

79 An alternative approach Consider where the extension of the surface cuts the z-axis

80 More complex shapes Multiple objects Concave objects

81 More complex shapes In these cases, each surface must be considered individually. Two different types of approach are possible: –Object space algorithms - examine each face in space to determine it visibility –Image space algorithms - at each screen pixel position, determine which face element is visible. Approximately, the relative efficiency of an image space algorithm increases with the complexity of the scene being represented, but often the drawing can be simplified for convex objects by removing surfaces which are invisible even for a single object.

82 The z-buffer (or painter’s) algorithm –based upon sorting the surfaces by their z- coordinates. The algorithm can be summarised thus: –Sort the surfaces into order of increasing depth. Define the maximum z value of the surface and the z-extent. –resolve any depth ambiguities –draw all the surfaces starting with the largest z-value

83 Ambiguities Ambiguities arise when the z-extents of two surfaces overlap.

84 Ambiguities – front view

85 Resolving Ambiguities –An algorithm exists for ambiguity resolution –Where two shapes P and Q have overlapping z-extents, perform the following 5 tests (in sequence of increasing complexity). –If any test fails, draw P first.

86 x - extents overlap?

87 y -extents overlap?

88 Is Q not completely on the side of P nearest the viewer?

89 Is P not completely on the side of Q further from the viewer?

90 Does the projection of the two surfaces overlap?

91 If all tests are passed … then reverse P and Q in the list of surfaces sorted by Z max set a flag to say that the test has been perfomed once. The flag is necessary for the case of intersecting planes. If the tests are all passed a second time, then it is necessary to split the surfaces and repeat the algorithm on the 4 surfaces

92 End up drawing Q2,P1,P2,Q1

93 Summary Need for depth cues and hidden line removal Using surfaces rather than lines Calculating which way a surface is facing (surface normal) Base a decision on visibility on normal vector and observer vector

94 References http://local.cis.strath.ac.uk/teaching/ug/class es/52.359if/

95


Download ppt "Components of illumination that from diffuse illumination (incident rays come from all over, not just one direction) - E d that from a point source which."

Similar presentations


Ads by Google