college of computer and information science, northeastern universitynovember 16, 20151 cs 4300...

51
College of Computer and Information Science, Northeastern University June 20, 2022 1 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31 – November 16, 2011

Upload: estella-miller

Post on 05-Jan-2016

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 1

CS 4300Computer Graphics

Prof. Harriet FellFall 2011

Lecture 31 – November 16, 2011

Page 2: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 2

Today’s Topics

• Bump Maps

• Texture Maps

Page 3: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 3

Bump Maps - Blinn 1978

u

∂∂P

Surface P(u, v)

u

v

v

∂∂P

Nu v

∂ ∂= ×

∂ ∂P P

N

Page 4: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 4

One dimensional Example

P(u)

B(u)

Page 5: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 5

The New Surface

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

B(u)

Page 6: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 6

The New Surface Normals

P’(u)

Page 7: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 7

Bump Maps - Formulas

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

u v

∂ ∂= ×

∂ ∂P P

N

( ) ( ) ( )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 8: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 8

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 9: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 9

Tweaking the Normal Vector

'

is the difference vector.

'

u v v u u v

v u u v

v u

u v

B B

B 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 10: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

Plane with Spheres Plane with Horizontal Wave

Page 11: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

Plane with Vertical Wave Plane with Ripple

Page 12: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

Plane with Mesh Plane with Waffle

Page 13: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

Plane with Dimples Plane with Squares

Page 14: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

Dots and Dimples

Page 15: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

Plane with Ripples

Page 16: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

Sphere on Plane with Spheres

Sphere on Plane with Horizontal Wave

Page 17: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

Sphere on Plane with Vertical Wave

Sphere on Plane with Ripple

Page 18: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

Sphere on Plane with Mesh

Sphere on Plane with Waffle

Page 19: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

Sphere on Plane with Dimples

Sphere on Plane with Squares

Page 20: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

Sphere on Plane with Ripples

Page 21: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

Wave with Spheres Parabola with Spheres

Page 22: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

Parabola with Dimples Big Sphere with Dimples

Page 23: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

Parabola with Squares Big Sphere with Squares

Page 24: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

Big Sphere with Vertical Wave

Big Sphere with Mesh

Page 25: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

Cone Vertical with Wave Cone with Dimples

Page 26: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

Cone with Ripple Cone with Ripples

Page 27: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 27

Student Images

Page 28: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 28

Bump Map

Bump Maps in PovRay

Page 29: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 29

Bump Map - Plane

x = 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: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 30

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: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 31

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: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 32

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: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 33

Bump Map from an ImageVictor Ortenberg

Page 34: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 34

Simple Textures on Planes Parallel to Coordinate Planes

Page 35: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 35

Stripes

Page 36: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 36

Checks

Page 37: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 37

Stripes and Checks

Red and Blue Stripes

if ((x % 50) < 25) color = red

else 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 38: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 38

Stripes, Checks, Image

Page 39: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 39

Mona Scroll

Page 40: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 40

Textures on 2 Planes

Page 41: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 41

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 42: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 42

Other planes and Triangles

N

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 43: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 43

Image to Triangle - 1

A

B

C

Page 44: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 44

Image to Triangle - 2

A

B

C

Page 45: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 45

Image to Triangle - 3

A

B

C

Page 46: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 46

Mandrill Sphere

Page 47: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 47

Mona Spheres

Page 48: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 48

Tova Sphere

Page 49: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 49

More Textured Spheres

Page 50: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

College of Computer and Information Science, Northeastern UniversityApril 20, 2023 50

Spherical Geometry

P = (x, y, z)

φ

θx

z

y

φ = arccos(y/R)R

y

θ = arctan(x/z)z

x

Page 51: College of Computer and Information Science, Northeastern UniversityNovember 16, 20151 CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 31

// 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);