CMSC427

Matthias Zwicker Fall 2018 Staff Instructor • Matthias Zwicker ([email protected], https://cs.umd.edu/~zwicker) Teaching assistant • Yue Jiang ([email protected])

2 Today • Course overview • Course organization • Vectors and coordinate systems

3 Computer graphics applications

4 Computer graphics • „Technology to create images using computers“ • This course: underlying algorithms for interactive applications – AR, VR, games, scientific visualization, etc. • Core areas – 3D rendering – Modeling – Animation

5 Rendering • Synthesis of 2D image from 3D scene description http://en.wikipedia.org/wiki/Rendering_(computer_graphics) – Rendering algorithms interpret data structures that represent scenes using geometric primitives, material properties, and lights • Input – Data structures that represent scene (geometry, material properties, lights, virtual camera) • Output – 2D image (array of pixels) – Red, green, blue values for each pixel

6 Photorealistic rendering

See also http://en.wikipedia.org/wiki/Rendering_(computer_graphics) 7 Photorealistic rendering • Physically-based simulation of light, materials, and camera – Physical model expressed using the rendering equation, http://en.wikipedia.org/wiki/Rendering_equation – Shadows, realistic illumination, multiple light bounces • Slow, minutes to hours per image • Special effects, movies • Not in this class

8 Interactive rendering

9 Interactive rendering • Focus of this class • Produce images within milliseconds • Interactive applications (games, …) • Using specialized hardware, graphics processing units (GPUs) • Standardized APIs (OpenGL, DirectX) • Often “as photorealistic as possible” – Hard shadows, fake soft shadows, only single bounce of light

10 Artistic rendering • Also “non-photorealistic rendering” http://en.wikipedia.org/wiki/Non-photorealistic_rendering • Stylized • Artwork, illustrations, data visualization

11 Modeling • Creating 3D geometric data – The “model” or the “scene” • Modeling techniques http://en.wikipedia.org/wiki/3D_modeling – Manually, using software tools – Algorithmic (procedural) – Physical measurements, 3D scanning

12 tools • Similar to plastic arts such as sculpting • Professional tools – Autodesk (Maya, AutoCAD), LightWave 3D, … • Free software – http://www.blender.org/ • Not as easy to use as Notepad…

Maya Screenshot 13 Procedural modeling • By writing programs, algorithms http://en.wikipedia.org/wiki/Procedural_modeling

Procedural city

Procedural tree

See also http://www.esri.com/software/cityengine/ 14 Physical measurements Scanned statue (laser scan) • 3D scanning http://graphics.stanford.edu/data/3Dscanrep/ http://en.wikipedia.org/wiki/3D_scanner • Other imaging devices − Tomography http://en.wikipedia.org/wiki/Ct_scan − Magnetic resonance imaging (MRI scanning) http://en.wikipedia.org/wiki/Mri_scan − Etc.

15 Surface representation • Basic 3D models consist of collections of

triangles (triangle mesh, https://en.wikipedia.org/wiki/Triangle_mesh) • Each triangle consists of 3 vertices • Each vertex contains – xyz position – Optionally other attributes such as color, etc. • Many more sophisticated representations exist http://en.wikipedia.org/wiki/Nonuniform_rational_B-spline http://en.wikipedia.org/wiki/Subdivision_surface

16 Animation • Deforming or editing the data • Change over time • Faces, articulated characters, fire, water, rigid objects, elastic objects, fracturing objects, …

17 Animation

http://www.youtube.com/watch?v=bLiX5d3rC6o 18 Physics simulation

http://www.youtube.com/watch?v=XH28gAb8FiQ

See also http://www.nvidia.com/object/physx_new.html 19 In this class: the basics • 3D rendering for interactive applications – 3D coordinate systems, 3D transformations – Camera simulation, 3D to 2D projection – Interactive viewing – Lighting, shading • 3D modeling – Triangle meshes, smooth surfaces – 3D scanning • AR and VR techniques – Stereoscopic rendering – 3D tracking

20 Skills, learning objectives • Understand and develop interactive 3D graphics applications from the ground up – Games – Virtual and augmented reality (VR, AR) – Etc. • Practical application of linear algebra (matrix calculations) • Java, OpenGL, GPU programming

21 Today • Course overview • Course organization • Vectors and coordinate systems

22 Course organization Lecture • Tue/Thu, 12:30-1:45pm • CSI 1121 Office hours • TA: Fridays, 2pm-4pm, AVWilliams 4101 or 4103 • Instructor: by appointment Course material • ELMS/Canvas, https://umd.instructure.com/ • Syllabus, schedule, slides, assignments, discussion

23 Textbooks • Fundamentals of Computer Graphics, Marschner/Shirley, 4th edition (recommended)

24 Programming assignments Build your own 3D rendering engine • Bi-weekly assignment schedule • Assignment 0: Getting started • Assignment 1: Meshes & Transformations • Assignment 2: User interaction • Assignment 3: Shader programming • Assignment 4: Scene graph • Assignment 5: Surface modeling • Assignment 6: Final project

25 Programming assignments • Assignments and code submission via ELMS/Canvas – Submission deadline Tuesdays noon, unless announced otherwise • Late penalty – 50% of original score • Each student submits own solution • Grading in person with TA – Wednesdays, 11am-5pm, AVWilliams 4101 or 4103 – Demonstrate and explain code submitted to ELMS/Canvas – 15 minute time slots assigned via sign-up lists, see announcements on ELMS/Canvas – Late penalty applies if you do not sign up/show up for grading

26 Grading • Programming assignments (50%) • Midterm exam, October 16 (25%) • Final exam (25%) • Academic integrity – CS department rules http://www.cs.umd.edu/class/resources/academicIntegrity.html – UMD code of academic conduct https://www.president.umd.edu/sites/president.umd.edu/files/documents/policies/III-100A.pdf

27 Today • Course overview • Course organization • Vectors and coordinate systems

28 3D scene representation • Goal: describe 3D scenes – Position, orientation, of objects – Relation of objects to virtual camera – Projection of scene onto image plane • Linear algebra provides mathematical tools – Vectors, coordinate systems, matrices, etc. – As little abstract theory as possible in this class

29 Vectors • Direction and length in 3D – No anchor point • Vectors can describe – Difference between two 3D points – Speed of an object • Vectors are in bold-face

30 Vectors Multiplication by scalar

31 Vectors Addition

32 Vectors Addition

33 Vectors Linear combination

34 Vectors Linear combination

Linearly dependent vectors • A set of vectors is linearly dependent if there exist scalars such that

• Otherwise, they are linearly independent 35 Coordinate systems • Describe any vector with respect to three basis vectors

• The basis vectors form a coordinate system

36 Coordinate systems • Any three vectors that are linearly independent could be used as a basis – Different lengths – Not perpendicular to each other

37 Coordinate systems • Any three vectors that are linearly independent could be used as a basis – Different lengths – Not perpendicular to each other • Why linearly independent? • Why exactly three vectors? • Other coordinate systems?

38 Cartesian coordinate systems http://en.wikipedia.org/wiki/Cartesian_coordinate_system • Basis vectors – Have unit length – Are perpendicular to each other • Called “orthonormal”

39 Poll Claim: Any two Cartesian coordinate systems in 3D are related by a rotation. That is, it is possible to rotate one coordinate system so it becomes identical to the other.

A. True B. False

40 Coordinate Systems Handedness

Right handed Left handed

41 Vector arithmetic using coordinates

ax  bx      a = ay  b = by  az  bz 

ax + bx  ax − bx      a + b = ay + by  a − b = ay − by  az + bz  az − bz 

−ax  sax      −a = −ay  sa = say  −az  saz 

42 Vector Magnitude • The magnitude (length) of a vector is: 2 2 2 2 v = vx + vy + vz

2 2 2 v = vx + vy + vz

• A vector with length=1.0 is called a unit vector • We can also normalize a vector to make it a unit vector v v

43 Dot product Definition: Product of lengths of vectors and cosine of angle between vectors • Definition does not refer to a coordinate system • Value is independent of Cartesian coordinate system

44 Dot product • If a·b > 0 then θ < 90º – Vectors point in the same general direction • If a·b < 0 then θ > 90º – Vectors point in opposite direction • If a·b = 0 then θ = 90º – Vectors are perpendicular – (or one or both of the vectors is degenerate (0,0,0))

45 Dot product using coordinates • Result is independent of coordinate system!

a ⋅ b = ∑aibi

a ⋅ b = axbx + ayby + azbz

a ⋅ b = a b cosθ

• What is the meaning of ?

46 Angle between vectors

a ⋅ b = a b cosθ  a ⋅ b  cosθ =    a b  b

−1  a ⋅ b  θ = cos   a  a b 

47 Dot products with unit vector • If |u|=1.0 then a·u is the length of the orthogonal projection of a onto u

a Orthogonal projection

u a·u

48 Dot products with unit vectors

a·b = 1

a=b

a = b = 1.0 a ⋅ b = cos(θ)

49 Dot products with unit vectors

0 < a·b < 1 a·b = 1 b a a·b

a = b = 1.0 a ⋅ b = cos(θ)

50 Dot products with unit vectors

0 < a·b < 1 a·b = 0 a·b = 1 b a a·b

a = b = 1.0 a ⋅ b = cos(θ)

51 Dot products with unit vectors

0 < a·b < 1 a·b = 0 a·b = 1 b a -1 < a·b < 0 a·b

a = b = 1.0 a ⋅ b = cos(θ)

52 Dot products with unit vectors

0 < a·b < 1 a·b = 0 a·b = 1 b a -1 < a·b < 0 a·b

a·b = -1 a = b = 1.0 a ⋅ b = cos(θ)

53 Surface normals • Vectors are direction and length in 3D • Can describe – Difference between two 3D points – Speed of an object – Surface normals: directions perpendicular to tangent plane of surfaces Normal

Tangent Normal vector plane

Surface normals Surface http://en.wikipedia.org/wiki/Normal_(geometry)

54 Representing planes • A plane can be defined by – Its closest distance to the origin – and its normal vector • How can we determine if a point lies on the plane using the dot product?

55 Cross product • Written as a x b, vectors a and b Definition: – a x b is vector perpendicular to a and b – In the direction defined by the right hand rule – Length is area of parallelogram spanned by a and b • Definition does not refer to coordinate system!

56 Cross product

area of parallelogram ab if a and b are parallel (or one or both degenerate)

57 Cross product • If vectors a, b are unit length and perpendicular, then a, b, a x b is a right handed coordinate system • a x b = -(b x a)

58 Cross product a × b is a vector perpendicular to both a and b, in the direction defined by the right hand rule Vectors lie in the plane of the projection screen. Does point towards you or away from you? What about ?

59 Cross product • Using coordinates

60 Summary • Vectors • Linear combination, linear dependency • Coordinate systems • Dot product, cross product • Normal vectors • Representation of planes using vectors

61 Coming up • Assignment 0 • Next class – Introduction to base code – Bring your laptop with based code installed

62