Presentation is loading. Please wait.

Presentation is loading. Please wait.

7.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 7 Polygon Shading Techniques.

Similar presentations

Presentation on theme: "7.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 7 Polygon Shading Techniques."— Presentation transcript:

1 7.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 7 Polygon Shading Techniques

2 7.2 si31_2001 Reflection Models n We have seen how the reflected intensity at a point may be calculated – either by the Phong model or the physically-based Cook and Torrance model n A reminder of the Phong reflection model...

3 7.3 si31_2001 Phong Reflection Model light source N L R V eye surface I( ) = K a ( )I a ( ) + ( K d ( )( L. N ) + K s ( R. V ) n ) I*( ) / dist In practice, we evaluate I RED, I GREEN, I BLUE for red, green, blue intensities: I RED = K a RED I a RED + ( K d RED ( L. N ) + K s ( R. V ) n ) I* RED /dist Note: R.V calculation replaced by H.N for speed - H = (L+V)/2 dist = distance attenuation factor

4 7.4 si31_2001 Phong Reflection Model n Remember calculation depends on: – surface normal at a point – light source intensity and position – material properties – viewer position n L.N and H.N constant if L, V taken to be far away

5 7.5 si31_2001 Viewing Polygons n We have also seen how a 3D polygon can be projected to screen space via a sequence of transformations This lecture looks at how we shade the polygon, using our reflection model

6 7.6 si31_2001 Constant (or Flat) Shading n Calculate normal (how?) n Assume L.N and R.V constant (light & viewer at infinity) n Calculate I RED, I GREEN, I BLUE using Phong reflection model n Use scan line conversion to fill polygon N light viewer

7 7.7 si31_2001 2D Graphics - Filling a Polygon n Scan line methods used to fill 2D polygons with a constant colour – find ymin, ymax of vertices – from ymin to ymax do: – find intersection with polygon edges – fill in pixels between intersections using specified colour See: Hearn&Baker, Ch 3 - or try applet at: ~chinkw/FillPoly

8 7.8 si31_2001 Polygonal Models n Recall that we use polygonal models to approximate curved surfaces Constant shading will emphasise this approximation because each facet will be constant shaded, with sudden change from facet to facet

9 7.9 si31_2001 Flat Shading

10 7.10 si31_2001 Gouraud Shading n Gouraud shading attempts to smooth out the shading across the polygon facets n Begin by calculating the normal at each vertex N

11 7.11 si31_2001 Gouraud Shading averaging n A feasible way to do this is by averaging the normals from surrounding facets intensities n Then apply the reflection model to calculate intensities at each vertex N

12 7.12 si31_2001 Gouraud Shading linear interpolation n We use linear interpolation to calculate intensity at edge intersection P I P RED = (1- I P1 RED + I P2 RED where P divides P1P2 in the ratio n Similarly for Q P4 P2 P1 P3 P Q 1-

13 7.13 si31_2001 Gouraud Shading n Then we do further linear interpolation to calculate colour of pixels on scanline PQ P2 P1 P3 P Q

14 7.14 si31_2001 Gouraud Shading

15 7.15 si31_2001 Gouraud Shading Limitations - Specular Highlights n Gouraud shading gives intensities within a polygon which are a weighted average of the intensities at vertices – a specular highlight at a vertex tends to be smoothed out over a larger area than it should cover – a specular highlight in the middle of a polygon will never be shown

16 7.16 si31_2001 Gouraud Shading Limitations - Mach Bands n The rate of change of pixel intensity is even across any polygon, but changes as boundaries are crossed Mach banding n This discontinuity is accentuated by the human visual system, so that we see either light or dark lines at the polygon edges - known as Mach banding

17 7.17 si31_2001 Phong Shading n Phong shading has a similar first step, in that vertex normals are calculated - typically as average of normals of surrounding faces N

18 7.18 si31_2001 Phong Shading n However rather than calculate intensity at vertices and then interpolate intensities as we do in Gouraud shading... n In Phong shading we interpolate normals at each pixel... P4 P2 P1 P3 P Q N2 N1 N

19 7.19 si31_2001 Phong Shading n... and apply the reflection model at each pixel to calculate the intensity - I RED, I GREEN, I BLUE P4 P2 P1 P3 P Q N2 N1 N

20 7.20 si31_2001 Phong Shading

21 7.21 si31_2001 Phong versus Gouraud Shading n A major advantage of Phong shading over Gouraud is that specular highlights tend to be much more accurate – vertex highlight is much sharper – a highlight can occur within a polygon n Also Mach banding greatly reduced n The cost is a substantial increase in processing time because reflection model applied per pixel n But there are limitations to both Gouraud and Phong

22 7.22 si31_2001 Gouraud versus Phong

23 7.23 si31_2001 Interpolated Shading Limitations - Perspective Effects n Anomalies occur because interpolation is carried out in screen space, after the perspective transformation n Suppose P2 much more distant than P1. P is midway in screen space so gets 50 : 50 intensity (Gouraud) or normal (Phong) n... but in world coordinates it is much nearer P1 than P2 P4 P2 P1 P3 P Q

24 7.24 si31_2001 Interpolated Shading Limitations - Averaging Normals n Averaging the normals of adjacent faces usually works reasonably well n But beware corrugated surfaces where the averaging unduly smooths out the surface

25 7.25 si31_2001 Wall Lights

26 7.26 si31_2001 Wall Lights with Fewer Polygons

27 7.27 si31_2001 Final Note on Normals n If a sharp polygon boundary is required, we calculate two vertex normals for each side of the joint N LEFT N RIGHT

28 7.28 si31_2001 Simple Shading - Without Taking Account of Normals

29 7.29 si31_2001 Constant or Flat Shading - Each Polygon has Constant Shade

30 7.30 si31_2001 Gouraud Shading

31 7.31 si31_2001 Phong Shading

32 7.32 si31_2001 Phong Shading with Curved Surfaces

33 7.33 si31_2001 Better Illumination Model

34 7.34 si31_2001 Further Study n Hearn and Baker, section 14-5 n Watt, chapter 6 n Think about the relative computational costs of flat, Gouraud and Phong

35 7.35 si31_2001 Acknowledgements n Thanks again to Alan Watt for the images n The following sequence is the famous Shutterbug from Foley et al

Download ppt "7.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 7 Polygon Shading Techniques."

Similar presentations

Ads by Google