代写代考 CM0304 Graphics I Graphics Hardware I.1 Graphics Systems

CM0304 Graphics I Graphics Hardware I.1 Graphics Systems

CMT107 Visual Computing

Copyright By PowCoder代写 加微信 powcoder

IV.2 Polygon Shading

Xianfang Sun

School of Computer Science & Informatics
Cardiff University

➢ Shading polygons
• Flat shading

• Gouraud shading

• Phong shading

➢Special effects
• Transparency

• Refraction

• Atmospheric effects

➢OpenGL Shading

15:15 2CMT107 Visual Computing

15:15 3CMT107 Visual Computing

➢ The colour of 3D objects is not the same everywhere
• An object drawn in a single colour appears flat
• Light-material interactions cause each point to have a

different colour or shade in 3D
➢ Global shading requires to calculate all reflections between

all objects
• In general this is not computable

➢ We use a simplified local model: Phong illumination

Polygon Shading

15:15 4CMT107 Visual Computing

➢ Use Phong Illumination for polygon shading
(e.g. with scan-line to set colours of pixels)
• Need to compute surface normals
• Polygon approximates 3D shape

(normals may not be normals of actual polygon)
➢ Different approaches to polygon shading:

− Flat shading
− Gouraud shading
− Phong shading

Flat Shading

15:15 5CMT107 Visual Computing

➢ One illumination calculation per polygon
• Each pixel is assigned the same colour
• Usually computed for centroid of polygon:

➢ Good for polyhedral objects, but:
• For point light sources, direction to light varies
• For specular reflections, direction to eye varies

Vertex Normals

15:18 6CMT107 Visual Computing

➢ Introduce surface normals for each vertex
• Usually different from polygon normal
• Either exact normals of surface
• Or average of normals of polygons meeting at a vertex

(good if polygons approximate surface well)

Gouraud Shading

15:18 7CMT107 Visual Computing

➢ Compute illumination for vertices of polygon
• Use vertex normals
• Linearly interpolate colours between vertices

Gouraud Shading Interpolation

15:18 8CMT107 Visual Computing

➢ Bilinearly interpolate colours between vertices down and
across scan lines

A = (1-)I1+I3

B = (1-)I2+I3

I = (1-)A+B

Gouraud Shading Example

15:18 9CMT107 Visual Computing

➢ Creates smoothly shaded polygonal mesh
➢ Artefacts still visible
➢ Need a fine mesh to capture subtle lighting effects

15:18 10CMT107 Visual Computing

➢ One lighting calculation per pixel
• Linearly interpolate vertex normals across polygon

➢ Very smooth appearance, but artefacts along silhouettes
➢ Do not confuse with Phong illumination model!

Interpolation

15:18 11CMT107 Visual Computing

➢ Bilinear interpolation of normals from vertices

Interpolation

15:18 12CMT107 Visual Computing

➢ Bilinear interpolation of normals from vertices

A = (1-)N1+N3

B = (1-)N2+N3

N = (1-)A+B

Shading Notes

15:18 13CMT107 Visual Computing

➢ Be careful when transforming surface normals
• Normals are not points, but a surface property
• Point transformations are different from normal

transformations
(point transformation A becomes (A-1)t for normals)

➢ Advanced shaders implemented on GPU in OpenGL SL

Transparency

15:18 14CMT107 Visual Computing

➢ Opacity coefficient k tells how much light is blocked:
➢ I = kIreflected + (1 – k)Itransmitted

• k  [0,1]: 0 for transparent surface, 1 for opaque surface
• Ireflected is intensity of reflected light
• Itransmitted is intensity of transmitted light from behind the

➢ Requires expansion of visible surface detection to access

polygons further behind
• Use A buffer

Snell’s Law

15:18 15CMT107 Visual Computing

➢ Refraction direction required for physically correct
transparency computation

➢ Snell’s law

−= coscos

= sinsin 

Snell’s Law

15:18 16CMT107 Visual Computing

Vector decomposition:

where S is a vector on the horizontal direction.

−−= sincos NT

−= coscos

= sinsin 

+= sincos NL ( )NL

➢ Refraction of light through glass
• Emerging refracted ray travels along a path parallel to

incoming light ray

➢ Usually ignore refraction
• Assume light travels straight through surface

(good approximation for thin polygonal surfaces)

Refraction

15:18 17CMT107 Visual Computing

No Refraction With Refraction

Refraction Example

15:18 18CMT107 Visual Computing

➢ Similar to transparency, modify light intensities for fog,
smoke, etc.

I = fatmo(d)Iobject + (1 – fatmo(d))Iatmo
• Iobject is intensity from visible object
• Iatmo is intensity for atmospheric effect
• fatmo(d) is function modelling atmospheric effect

depending on distance d from viewer, e.g.:
fatmo,1(d) = e

fatmo,2(d) = e

fatmo,3(d)= (End-d)/(End-Start)

Atmospheric Effects

15:18 19CMT107 Visual Computing

OpenGL Shading

15:18 20CMT107 Visual Computing

➢ Fixed-function pipeline version of OpenGL uses specific
functions to realise flat and Gouraud shading,
transparency, and fog effect

➢ Shader version of OpenGL needs the programmer to
write code in the main program and/or the shaders to
implement these effects

➢More details in the labs …

15:18 21CMT107 Visual Computing

➢ How does flat, Gouraud, Phong shading for polygons
work? What are the differences / similarities between the
different shading algorithms?

➢ Why do we need explicit surface normals for vertices?
➢ How can we add transparency and atmospheric effects to

our lighting computations?
➢ What is refraction / Snell’s law?
➢ Why is refraction usually ignored?

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com