Top Banner
16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects
36

16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

Mar 28, 2015

Download

Documents

Irea Armstrong
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.1Si23_03

SI23Introduction to Computer

Graphics

SI23Introduction to Computer

Graphics

Lecture 16 – Some Special Rendering Effects

Page 2: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.2Si23_03

Where were we…?Where were we…?

Phong reflection model tells us how light reflects from surfaces…

Page 3: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.3Si23_03

Phong Reflection ModelPhong Reflection Model

lightsourceN

LR

Veye

surface

I() = Ka()Ia() + ( Kd()( L . N ) + Ks( R . V )n ) I*() / dist

In practice, we evaluate IRED, IGREEN, IBLUE for red, green, blue intensities:IRED= Ka

REDIaRED + ( Kd

RED( L . N ) + Ks( R . V )n ) I*RED/dist

dist = distance attenuation factor

Page 4: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.4Si23_03

Interpolated ShadingInterpolated Shading

Polygons can be efficiently shaded using:

– Flat shading– Gouraud shading– Phong shading

Visible surfaces are determined using the z-buffer algorithm

flat

Gouraud

Phong

Page 5: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.5Si23_03

Flat, Gouraud and Phong Shading

Flat, Gouraud and Phong Shading

Page 6: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.6Si23_03

Phong versus Gouraud Shading

Phong versus Gouraud Shading

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

Also Mach banding greatly reduced The cost is a substantial increase in

processing time because reflection model applied per pixel

OpenGL only supports Gouraud shading

Page 7: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.7Si23_03

Adding Realism Through Texture Effects

Page 8: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.8Si23_03

Adding RealismAdding Realism

Objects rendered using Phong reflection model and Gouraud or Phong interpolated shading often appear rather ‘plastic’ ‘plastic’ and ‘floating in air’‘floating in air’

Texture exture effects can be added to give more realistic looking surface appearance– Simple texture– Bumps– Light maps

Page 9: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.9Si23_03

Adding Surface DetailAdding Surface Detail

The most obvious solution is not the best– breaking the scene into smaller and

smaller polygonal objects increases the detail

– ..BUT it is very hard to model and very time-consuming to render

Preferred solution is texture mapping – typically a 2D image ‘painted’ ‘painted’ onto

objects

Page 10: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.10Si23_03

A Simple ExampleA Simple Example

Suppose we have a 2D image...

.. and a 3D box

.. we can paint the image on a face of the box

Page 11: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.11Si23_03

… or a teapot… or a teapot

Page 12: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.12Si23_03

Basic ConceptBasic Concept

Replace the shading calculation with a look-up into a texture map (ie 2D image) to get the colour of a pixel

May replace shaded value - or modulate it in some way

Page 13: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.13Si23_03

QuestionQuestion

We could apply the texture in screen space (ie after projection)

... or we could apply it in object space (ie before projection)

Which is more sensible?

Page 14: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.14Si23_03

Texture Mapping - Overview

Texture Mapping - Overview

screen space

I

J

object space

during scan conversionof each polygon, findcorresponding positionof pixel on object

texture space

V

U

X

Y

Z

paint textureon to object

Page 15: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.15Si23_03

Mapping Texture to Polygons

Mapping Texture to Polygons

For polygon texture mapping, we explicitly define the (u,v) co-ordinates of the polygon vertices

That is, we pin the texture at the vertices

We interpolate within the triangle at the time of scan converting into screen space

X

Z

Y

object

texture space

V

U

Page 16: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.16Si23_03

Texture Mapping TrianglesTexture Mapping Triangles

(x1,y1,z1)

(x2,y2,z2) (x3,y3,z3)

(u1,v1)

(u2,v2) (u3,v3)

(i1,j1)

(i2,j2) (i3,j3)

Interpolation is doneduring scan conversion,similar as is done forGouraud interpolatedshading

But rather than interpolateto get RGB values, weget (u,v) values whichpoint to elements of texturemap.

Page 17: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.17Si23_03

Interpolation in Texture Space

Interpolation in Texture Space

The interpolation in texture space has to be done carefully

Equal steps in screen space do not correspond to equal steps in object space (and hence texture space)

Why?

U

V

I

Jscreen

texture

A line is a line in all 3 spaces

X

Z

Y

object

Page 18: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.18Si23_03

Interpolation in Texture Space

Interpolation in Texture Space

The rate of change in texture space will depend on the depth of the points from the viewer

Correct approach is to scale by the distance (zP, zQ) of the points from the viewer

U

Vtexture

I

Jscreen

P Q

P’Q’

If Q further away than P, then as we take equal steps from P towards Q, we want to take increasingly large steps in (U,V) space from P’ to Q’.

Page 19: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.19Si23_03

Interpolation in Texture Space

Interpolation in Texture Space

Suppose (uP, vP) and (uQ,vQ) are texture co-ords at end-points P, Q

Linear interpolation would be:

– u = uQ + (1-)uP with increasing from 0 to

1 (similarly for v) Correct texture

interpolation is:u = [ uQ / zQ + (1-)uP / zP ] /

Dwhere D = [ / zQ + (1-)/ zP ]

U

Vtexture

P’Q’

I

Jscreen

P Q

Note: this is equivalentto a linear interpolationin projective space

Page 20: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.20Si23_03

Check for YourselfCheck for Yourself

Suppose P is one unit from viewer, and Q is two units from viewer

Show that the mid-point in screen space is equivalent to one-third of the distance along the line in texture space

Page 21: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.21Si23_03

Summing UpSumming Up

We have seen how a 2D texture image can be mapped to an object, at the rendering stage– for a polygon, we pin texture to vertices

and interpolate (correctly!) at scan conversion time

The texture value is used to modifymodify the colour that would otherwise be drawn– options include replacing completely, or

modulating (eg by multiplying shaded value with texture value)

Page 22: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.22Si23_03

Bump Mapping

Page 23: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.23Si23_03

Bump MappingBump Mapping

This is another texturing technique

Aims to simulate a dimpled or wrinkled surface– for example, surface of an orange

Like Gouraud and Phong shading, it is a tricktrick– surface stays the same– but the true normal is perturbed, or

jittered, to give the illusion of surface ‘bumps’

Page 24: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.24Si23_03

Bump MappingBump Mapping

Page 25: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.25Si23_03

How Does It Work?How Does It Work?

Looking at it in 1D:

original surface P(u)

bump map b(u)

add b(u) to P(u)in surface normal direction, N(u)

new surface normalN’(u) for reflectionmodel

Page 26: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.26Si23_03

Bump MappingA Bump Map

Bump MappingA Bump Map

Page 27: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.27Si23_03

Bump MappingResulting ImageBump Mapping

Resulting Image

Page 28: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.28Si23_03

Bump Mapping - Another Example

Bump Mapping - Another Example

Page 29: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.29Si23_03

Bump MappingAnother ExampleBump Mapping

Another Example

Page 30: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.30Si23_03

Bump MappingProcedurally Defined Bump

Map

Bump MappingProcedurally Defined Bump

Map

Page 31: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.31Si23_03

Another pioneerAnother pioneer

Jim Blinn– Creator of bump

mapping and many other graphics effects

Page 32: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.32Si23_03

Light Maps

Page 33: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.33Si23_03

The Problem with Gouraud….

The Problem with Gouraud….

Gouraud shading is established technique for rendering but has well known limitations– Vertex lighting only works well for

small polygons…– … but we don’t want lots of

polygons!

Page 34: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.34Si23_03

Pre-Compute the LightingPre-Compute the Lighting

Solution is to pre-compute some canonical light effects as texture maps

For example…

Page 35: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.35Si23_03

Rendering using Light Maps

Rendering using Light Maps

Suppose we want to show effect of a wall light

– Create wall as a single polygon

– Apply vertex lighting

– Apply texture map

– In a second rendering pass, apply light map to the wall

Page 36: 16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.

16.36Si23_03

Light MapsLight Maps

Widely used in games industry

Latest graphics cards will allow multiple texture maps per pixel