cs g140 graduate computer graphics

64
July 4, 2022 1 College of Computer and Information Science, Northeastern University CS G140 Graduate Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 5 – February 4, 2009

Upload: ishana

Post on 25-Feb-2016

33 views

Category:

Documents


3 download

DESCRIPTION

CS G140 Graduate Computer Graphics. Prof. Harriet Fell Spring 2009 Lecture 5 – February 4, 2009. Comments. “NOTHING else” means nothing else. Do you want your pictures on the web? If not, please send me an email. Today’s Topics. Bump Maps Texture Maps --------------------------- - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CS G140 Graduate Computer Graphics

April 22, 2023 1College of Computer and Information Science, Northeastern University

CS G140Graduate Computer Graphics

Prof. Harriet FellSpring 2009

Lecture 5 – February 4, 2009

Page 2: CS G140 Graduate Computer Graphics

April 22, 2023 2College of Computer and Information Science, Northeastern University

Comments

• “NOTHING else” means nothing else.• Do you want your pictures on the web?

If not, please send me an email.

Page 3: CS G140 Graduate Computer Graphics

April 22, 2023 3College of Computer and Information Science, Northeastern University

Today’s Topics

• Bump Maps• Texture Maps ---------------------------• 2D-Viewport Clipping

Cohen-Sutherland Liang-Barsky

Page 4: CS G140 Graduate Computer Graphics

April 22, 2023 4College of Computer and Information Science, Northeastern University

Bump Maps - Blinn 1978

u∂∂P

Surface P(u, v)

u

v

v∂∂P

Nu v

∂ ∂= ×

∂ ∂P PN

Page 5: CS G140 Graduate Computer Graphics

April 22, 2023 5College of Computer and Information Science, Northeastern University

One dimensional Example

P(u)

B(u)

Page 6: CS G140 Graduate Computer Graphics

April 22, 2023 6College of Computer and Information Science, Northeastern University

The New Surface

P’(u)= P(u) + B(u)N

B(u)

Page 7: CS G140 Graduate Computer Graphics

April 22, 2023 7College of Computer and Information Science, Northeastern University

The New Surface Normals

P’(u)

Page 8: CS G140 Graduate Computer Graphics

April 22, 2023 8College of Computer and Information Science, Northeastern University

Bump Maps - Formulas

( ) ( ) ( )( ) ( )A parametric Surface , , , , , ,x u v y u v z u v u v= P

u v∂ ∂

= ×∂ ∂P PN

( ) ( ) ( )The new surface ' , , ,u v u v B u v= +P P N

( )( )

' ' '

' ,

' ,

u v

u u u u

v v v v

B B u v

B B u v

= ×

= + +

= + +

N P P

P P N N

P P N N

Page 9: CS G140 Graduate Computer Graphics

April 22, 2023 9College of Computer and Information Science, Northeastern University

The New Normal

( )( ) ( )( )( )

( )( ) ( ) ( )

' , ,

,

,

, , ,

u u u v v v

u v v u u v

u v u v u v

u v v u u v

B B u v B B u v

B B u v

B B B B B u v

B u v B u v B B u v

= + + × + +

= × + × + ×

+ × + × ×

+ × × ×2

N P N N P N N

P P P N P N

N P N N + N N

N P + N N + N N

We use ' u v v u u vB B= × + × + ×N P P P N N P

This term is 0.

These terms are small if B(u, v) is small.

Page 10: CS G140 Graduate Computer Graphics

April 22, 2023 10College of Computer and Information Science, Northeastern University

Tweaking the Normal Vector

'

is the difference vector.

'

u v v u u v

v u u v

v u

u v

B BB B

B B

= × + × + ×= + × + ×

= × = ×=

= +

N P P P N N PN P N N P

A N P B N PD A- B

N N DD lies in the tangent plane to the surface.

Page 11: CS G140 Graduate Computer Graphics

Plane with Spheres Plane with Horizontal Wave

Page 12: CS G140 Graduate Computer Graphics

Plane with Vertical Wave Plane with Ripple

Page 13: CS G140 Graduate Computer Graphics

Plane with Mesh Plane with Waffle

Page 14: CS G140 Graduate Computer Graphics

Plane with Dimples Plane with Squares

Page 15: CS G140 Graduate Computer Graphics

Dots and Dimples

Page 16: CS G140 Graduate Computer Graphics

Plane with Ripples

Page 17: CS G140 Graduate Computer Graphics

Sphere on Plane with Spheres

Sphere on Plane with Horizontal Wave

Page 18: CS G140 Graduate Computer Graphics

Sphere on Plane with Vertical Wave

Sphere on Plane with Ripple

Page 19: CS G140 Graduate Computer Graphics

Sphere on Plane with Mesh

Sphere on Plane with Waffle

Page 20: CS G140 Graduate Computer Graphics

Sphere on Plane with Dimples

Sphere on Plane with Squares

Page 21: CS G140 Graduate Computer Graphics

Sphere on Plane with Ripples

Page 22: CS G140 Graduate Computer Graphics

Wave with Spheres Parabola with Spheres

Page 23: CS G140 Graduate Computer Graphics

Parabola with Dimples Big Sphere with Dimples

Page 24: CS G140 Graduate Computer Graphics

Parabola with Squares Big Sphere with Squares

Page 25: CS G140 Graduate Computer Graphics

Big Sphere with Vertical Wave

Big Sphere with Mesh

Page 26: CS G140 Graduate Computer Graphics

Cone Vertical with Wave Cone with Dimples

Page 27: CS G140 Graduate Computer Graphics

Cone with Ripple Cone with Ripples

Page 28: CS G140 Graduate Computer Graphics

April 22, 2023 28College of Computer and Information Science, Northeastern University

Student Images

Page 29: CS G140 Graduate Computer Graphics

April 22, 2023 29College of Computer and Information Science, Northeastern University

Bump Map - Planex = h - 200;y = v - 200;z = 0;

N.Set(0, 0, 1);Du.Set(-1, 0, 0);Dv.Set(0, 1, 0);uu = h;vv = v;zz = z;

Page 30: CS G140 Graduate Computer Graphics

April 22, 2023 30College of Computer and Information Science, Northeastern University

Bump Map Code – Big Sphere

radius = 280.0;z = sqrt(radius*radius - y*y - x*x);N.Set(x, y, z);N = Norm(N);

Du.Set(z, 0, -x); Du = -1*Norm(Du);Dv.Set(-x*y, x*x +z*z, -y*z);Dv = -1*Norm(Dv);

vv = acos(y/radius)*360/pi;uu = (pi/2 +atan(x/z))*360/pi;zz = z;

Page 31: CS G140 Graduate Computer Graphics

April 22, 2023 31College of Computer and Information Science, Northeastern University

Bump Map Code – Dimples

Bu = 0; Bv = 0;iu = (int)uu % 30 - 15;iv = (int)vv % 30 - 15;r2 = 225.0 - (double)iu*iu - (double)iv*iv;if (r2 > 100) {

if (iu == 0) Bu = 0;else Bu = (iu)/sqrt(r2);if (iv == 0) Bv = 0;else Bv = (iv)/sqrt(r2);

}

Page 32: CS G140 Graduate Computer Graphics

April 22, 2023 32College of Computer and Information Science, Northeastern University

Image as a Bump Map

A bump map is a gray scale image; any image will do. The lighter areas are rendered as raised portions of the surface and darker areas are rendered as depressions. The bumping is sensitive to the direction of light sources.

http://www.cadcourse.com/winston/BumpMaps.html

Page 33: CS G140 Graduate Computer Graphics

April 22, 2023 33College of Computer and Information Science, Northeastern University

Time for a Break

Page 34: CS G140 Graduate Computer Graphics

April 22, 2023 34College of Computer and Information Science, Northeastern University

Bump Map from an ImageVictor Ortenberg

Page 35: CS G140 Graduate Computer Graphics

April 22, 2023 35College of Computer and Information Science, Northeastern University

Simple Textures on Planes Parallel to Coordinate Planes

Page 36: CS G140 Graduate Computer Graphics

April 22, 2023 36College of Computer and Information Science, Northeastern University

Stripes

Page 37: CS G140 Graduate Computer Graphics

April 22, 2023 37College of Computer and Information Science, Northeastern University

Checks

Page 38: CS G140 Graduate Computer Graphics

April 22, 2023 38College of Computer and Information Science, Northeastern University

Stripes and ChecksRed and Blue Stripes

if ((x % 50) < 25) color = redelse color = blue

0 24 49

Cyan and Magenta Checksif (((x % 50) < 25 && (y % 50) < 25)) ||

(((x % 50) >= 25 && (y % 50) >= 25))) color = cyan

else color = magentaWhat happens when you cross x = 0 or y = 0?

Page 39: CS G140 Graduate Computer Graphics

April 22, 2023 39College of Computer and Information Science, Northeastern University

Stripes, Checks, Image

Page 40: CS G140 Graduate Computer Graphics

April 22, 2023 40College of Computer and Information Science, Northeastern University

Mona Scroll

Page 41: CS G140 Graduate Computer Graphics

April 22, 2023 41College of Computer and Information Science, Northeastern University

Textures on 2 Planes

Page 42: CS G140 Graduate Computer Graphics

April 22, 2023 42College of Computer and Information Science, Northeastern University

Mapping a Picture to a Plane

• Use an image in a ppm file.• Read the image into an array of RGB values.

Color myImage[width][height]

• For a point on the plane (x, y, d)theColor(x, y, d) = myImage(x % width, y % height)

• How do you stretch a small image onto a large planar area?

Page 43: CS G140 Graduate Computer Graphics

April 22, 2023 43College of Computer and Information Science, Northeastern University

Other planes and TrianglesN

uN x u = v

Given a normal and 2 points on the plane:

Make u from the two points.

v = N x u

Express P on the plane as

P = P0 + au + bv.

P0

P1

Page 44: CS G140 Graduate Computer Graphics

April 22, 2023 44College of Computer and Information Science, Northeastern University

Image to Triangle - 1

A

B

C

Page 45: CS G140 Graduate Computer Graphics

April 22, 2023 45College of Computer and Information Science, Northeastern University

Image to Triangle - 2

A

B

C

Page 46: CS G140 Graduate Computer Graphics

April 22, 2023 46College of Computer and Information Science, Northeastern University

Image to Triangle - 3

A

B

C

Page 47: CS G140 Graduate Computer Graphics

April 22, 2023 47College of Computer and Information Science, Northeastern University

Mandrill Sphere

Page 48: CS G140 Graduate Computer Graphics

April 22, 2023 48College of Computer and Information Science, Northeastern University

Mona Spheres

Page 49: CS G140 Graduate Computer Graphics

April 22, 2023 49College of Computer and Information Science, Northeastern University

Tova Sphere

Page 50: CS G140 Graduate Computer Graphics

April 22, 2023 50College of Computer and Information Science, Northeastern University

More Textured Spheres

Page 51: CS G140 Graduate Computer Graphics

April 22, 2023 51College of Computer and Information Science, Northeastern University

Spherical Geometry

P = (x, y, z)

x

z

y

= arccos(y/R)R

y

= arctan(x/z)z

x

Page 52: CS G140 Graduate Computer Graphics

// for texture map – in lieu of using sphere colordouble phi, theta; // for spherical coordinatesdouble x, y, z; // sphere vector coordinatesint h, v; // ppm buffer coordinatesVector3D V;

V = SP - theSpheres[hitObject].center;V.Get(x, y, z);phi = acos(y/theSpheres[hitObject].radius);if (z != 0) theta = atan(x/z); else phi = 0; // ???v = (phi)*ppmH/pi; h = (theta + pi/2)*ppmW/pi;

if (v < 0) v = 0; else if (v >= ppmH) v = ppmH - 1; v = ppmH -v -1; //v = (v + 85*ppmH/100)%ppmH;//9if (h < 0) h = 0; else if (h >= ppmW) h = ppmW - 1;h = ppmW -h -1; //h = (h + 1*ppmW/10)%ppmW;

rd = fullFactor*((double)(byte)myImage[h][v][0]/255); clip(rd);gd = fullFactor*((double)(byte)myImage[h][v][1]/255); clip(gd);bd = fullFactor*((double)(byte) myImage[h][v][2]/255); clip(bd);

Page 53: CS G140 Graduate Computer Graphics

Clipping Lines

A

B

CD

E

FF’

G

H

H’

G’

J

K

Page 54: CS G140 Graduate Computer Graphics

April 22, 2023 54College of Computer and Information Science, Northeastern University

Intersections

We know how to find the intersections of a line segment

P + t(Q-P)

with the 4 boundariesx = xminx = xmaxy = yminy = ymax

PQ

Page 55: CS G140 Graduate Computer Graphics

April 22, 2023 55College of Computer and Information Science, Northeastern University

Cohen-Sutherland Clipping

1. Assign a 4 bit outcode to each endpoint.

2. Identify lines that are trivially accepted or trivially rejected.if (outcode(P) = outcode(Q) = 0)

acceptelse if (outcode(P) &

outcode(Q)) 0) rejectelse test further

0000

10001100

0010

above left below right

0100

0110

1001

0001

0011

Page 56: CS G140 Graduate Computer Graphics

April 22, 2023 56College of Computer and Information Science, Northeastern University

Cohen-Sutherland continued

Clip against one boundary at a time, top, left, bottom, right.

Check for trivial accept or reject.

If a line segment PQ falls into the “test further” category then

if (outcode(P) & 1000 0)replace P with PQ intersect y = top

else if (outcode(Q) & 1000 0) replace Q with PQ intersect y = topgo on to next boundary

Page 57: CS G140 Graduate Computer Graphics

G

H

H’

G’’

G’

ACCEPT

Page 58: CS G140 Graduate Computer Graphics

April 22, 2023 58College of Computer and Information Science, Northeastern University

Liang-Barsky Clipping

Clip window interior is defined by:

xleft x xright

ybottom y ytop

Page 59: CS G140 Graduate Computer Graphics

April 22, 2023 59College of Computer and Information Science, Northeastern University

Liang-Barsky continued

V0 = (x0, y0)

V1 = (x1, y1)

x = x0 + tDx Dx = x1 - x0

y = y0 + tDy Dy = y1 - y0

t = 0 at V0 t = 1 at V1

Page 60: CS G140 Graduate Computer Graphics

April 22, 2023 60College of Computer and Information Science, Northeastern University

Liang-Barsky continued

Put the parametric equations into the inequalities:xleft x0 + tDx xright

ybottom y0 + tDy ytop

-tDx x0 - xleft tDx xright - x0

-tDy y0 - ybottom tDy ytop - y0

These decribe the interior of the clip window in terms of t.

Page 61: CS G140 Graduate Computer Graphics

April 22, 2023 61College of Computer and Information Science, Northeastern University

Liang-Barsky continued-tDx x0 - xleft tDx xright - x0

-tDy y0 - ybottom tDy ytop - y0

• These are all of the formtp q

• For each boundary, we decide whether to accept, reject, or which point to change depending on the sign of p and the value of t at the intersection of the line with the boundary.

Page 62: CS G140 Graduate Computer Graphics

x = xleft

V0

V1

p = - Dx

t t (x0 – xleft)/(-Dx) = q/p

t = (x0 – xleft)/(x0 – x1 )

is between 0 and 1.

Dx = x1 – x0 > 0 so p < 0

replace V0V1

V0

tt = (x0 – xleft)/(x0 – x1 )

is between 0 and 1.

Dx = x1 – x0 < 0 so p > 0 replace V1

Page 63: CS G140 Graduate Computer Graphics

x = tleft

V0

V1

p = - Dx

p < 0 so might replace V0

butt = (x0 – xleft)/(x0 – x1 ) < 0

so no change.

t

V1V0 t

p < 0 so might replace V0

but t = (x0 – xleft)/(x0 – x1 ) > 1

so reject.

t V0V1

p > 0 so might replace V1

but t = (x0 – xleft)/(x0 – x1 ) < 0

so reject.

V1

V0 p > 0

t > 1

Page 64: CS G140 Graduate Computer Graphics

April 22, 2023 64College of Computer and Information Science, Northeastern University

Liang-Barsky Rules

• 0 < t < 1, p < 0 replace V0

• 0 < t < 1, p > 0 replace V1

• t < 0, p < 0 no change• t < 0, p > 0 reject

• t > 1, p > 0 no change• t > 1, p < 0 reject