Introduction to Computer Graphics April 9, 2020 Kenshi Takayama
Course overview • Lecture basic stuff on 4 topics • 2~3 lectures per topic, 12 lectures in total Modeling Animation Rendering Image processing 2
Lecturers Modeling • Kenshi Takayama (Assistant Prof., @NII) Animation • http://research.nii.ac.jp/~takayama/ Image processing • takayama@nii.ac.jp • Toshiya Hachisuka (Associate Prof. @UTokyo) • http://www.ci.i.u-tokyo.ac.jp/~hachisuka/ Rendering • thachisuka@siggraph.org • Move to Waterloo on Sep 2020 • Ryoichi Ando (Assistant Prof., @NII) • http://research.nii.ac.jp/~rand/ Animation (fluids) • rand@nii.ac.jp • Nobuyuki Umetani (Associate Prof. @UTokyo) • http://nobuyuki-umetani.com/ Animation (deformables) • n.umetani@gmail.com TA : Daiki Harada @Igarashi Lab rijicho.cgta2020@gmail.com 3
Grading • Programming assignments only • No exam, no attendance check • Two types of assignments: Basic & Advanced • Basic: 1 assignment per topic (4 in total), very easy • Advanced: For motivated students • Deadline: • Basic: 2 weeks after announcement • Advanced: end of July • Evaluation criteria • 1 assignment submitted è C (bare minimum for the degree) • 4 assignments submitted è B or higher • Distribution of S & A will be decided based on the quality/creativity of submissions and the overall balance in the class • More details explained later 4
References • Course website • http://research.nii.ac.jp/~takayama/teaching/utokyo-iscg-2020/ • Famous textbooks (not used in the class) • Fundamentals of Computer Graphics (9781568814698) • Computer Graphics: Principles and Practice in C (9780201848403) 5
Coordinate transformations 6
Linear transformation 𝑦 ! 𝑏 𝑐 𝑑 𝑦 𝑦 𝑦 ! 𝑏 𝑐 𝑧 ! 𝑒 𝑓 𝑔 𝑧 In 3D: = In 2D: = 𝑧 𝑧 ! 𝑑 𝑒 𝑨 ℎ 𝑗 𝑨 ! • Intuition: Mapping of coordinate axes 𝑏 𝑐, 𝑒 1 𝑏 𝑐 = 𝑑 0 𝑑 𝑒 0, 1 𝑐 𝑏 𝑐 0 = 𝑒 𝑑 𝑒 1 𝑏, 𝑑 • Origin stays put 1, 0 7
Special linear transformations Rotation Scaling Shearing (X dir.) Shearing (Y dir.) 𝑡 " 0 cos 𝜄 − sin 𝜄 1 𝑙 1 0 0 𝑡 # sin 𝜄 cos 𝜄 0 1 𝑙 1 8
Linear transformation + translation = Affine transformation 𝑏 𝑐 𝑢 " 𝑦 𝑦 ! 𝑢 " 𝑦 𝑦 ! 𝑏 𝑐 𝑧 𝑧 ! 𝑑 𝑒 𝑢 # ⟺ = = + 𝑧 𝑢 # 𝑧 ! 𝑑 𝑒 1 1 0 0 1 • Homogeneous coordinates: Use a 3D (4D) vector to represent a 2D (3D) point • Can concisely represent linear transformation & translation as matrix multiplication • Easier implementation 9
Combining affine transformations • Just multiply matrices • Careful with the ordering! 𝐲 ! = 𝑆 𝑈 𝐲 cos 𝜄 − sin 𝜄 0 𝑆 = sin 𝜄 cos 𝜄 0 0 0 1 1 0 𝑢 ! 0 1 𝑢 " 𝐲 ! = 𝑈 𝑆 𝐲 𝑈 = 0 0 1 10
Another role of homogeneous coordinates: Perspective projection • Objects’ apparent sizes on the screen are inversely proportional to the object-camera distance Orthographic projection Perspective projection 11
Another role of homogeneous coordinates: Perspective projection • When w ≠ 0, 4D homogeneous coordinate 𝑦, 𝑧, 𝑨, 𝑥 represents $ & ' a 3D position % , % , % • Camera at the origin, screen on the plane Z=1 ) # ) ! è 𝑞 " , 𝑞 # , 𝑞 ( is projected to 𝑥 " , 𝑥 # = ) " , Z=1 X ) " 𝑞 ! 𝑥 ! 𝑞 ! /𝑞 # 𝑞 ! 1 0 0 0 𝑞 " 𝑞 " 𝑞 " /𝑞 # 𝑥 " 0 1 0 0 = ≡ Z 0 0 1 1 𝑞 # 𝑞 # + 1 1 + 1/𝑞 # 𝑥 # 𝑞 # 0 0 1 0 1 1 Projection matrix • 𝑥 ( (depth value) is used for occlusion test è Z-buffering 12
Orthographic projection • Objects’ apparent sizes don’t depend on the camera position Orthographic Perspective • Simply ignore Z coordinates • Frequently used in CAD 13
Viewing pipeline Projection trans. (4x4 matrix) Modelview trans. (4x4 matrix) Projected coord. system Camera coord. system Viewport trans. w (x, y, w, h) h y x Object (world) coord. system Local coord. system Window coord. system 14
Classical OpenGL code Viewport transform glViewport(0, 0, 640, 480); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective( Projection transform 45.0, // field of view 640 / 480, // aspect ratio 0.1, 100.0); // depth range glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt( Modelview transform 0.5, 0.5, 3.0, // view point 0.0, 0.0, 0.0, // focus point Output 0.0, 1.0, 0.0); // up vector glBegin(GL_LINES); glColor3d(1, 0, 0); glVertex3d(0, 0, 0); glVertex3d(1, 0, 0); Scene content glColor3d(0, 1, 0); glVertex3d(0, 0, 0); glVertex3d(0, 1, 0); glColor3d(0, 0, 1); glVertex3d(0, 0, 0); glVertex3d(0, 0, 1); glEnd(); 15
Z-buffering 16
Hidden surface removal Without hidden surface removal With hidden surface removal • Classic problem in CG 17
Painter’s algorithm • Sort objects according to distances to camera, then draw them in the back- to-front order • Fundamentally ill-suited for many cases • Sorting is also not always straightforward 18
Z-buffering • For each pixel, store distance to the camera (depth) • More memory-consuming, but today’s standard 19
Typical issues with Z-buffering: Z-fighting • Multiple polygons at exact same position • Impossible to determine which is front/back • Strange patterns due to rounding errors 20
Typical issues with Z-buffering: Simultaneous drawing of faces and lines • Dedicated OpenGL trick: glPolygonOffset Without polygon offset With polygon offset 21
Typical issues with Z-buffering: Depth range gluPerspective( 45.0, // field of view 640 / 480, // aspect ratio zNear=0.0001 0.1 , 1000.0 ); // zNear , zFar zFar =1000 • Fixed bits for Z-buffer • Typically, 16~24bits • Larger depth range è Larger drawing space, less accuracy zNear=50 • Smaller depth range zFar =100 è More accuracy, smaller drawing space (clipped) 22
Rasterization vs Ray-tracing Purpose Real-time CG (games) High-quality CG (movies) Idea Per-polygon processing Per-pixel (ray) processing One polygon One ray interacts updates multiple with multiple pixels polygons Z-buffering By nature Hidden surface (OpenGL / DirectX) removal More details by Prof. Hachisuka 23
Quaternions 24
Rotation about arbitrary axis • Needed in various situations (e.g. camera manipulation) about X-axis about Y-axis about Z-axis about arbitrary axis 𝑣 ! , 𝑣 " , 𝑣 # : axis vector • Problems with matrix representation • Overly complex! D egree o f F reedom • Should be represented by 2 DoF (axis direction) + 1 DoF (angle) = 3 DoF • Can’t handle interpolation (blending) well 25
Geometry of axis-angle rotation 𝑤′ ⃗ 𝑣 : axis (unit vector) 𝑣× ⃗ 𝑤 𝜄 : angle 𝜄 𝑤 ⃗ 𝑣(𝑣 H ⃗ 𝑤) 𝑤 : input position ⃗ 𝑤′ : output position ⃗ 𝑣 𝑃 𝑤 ! = ⃗ 𝑤 − 𝑣 𝑣 H ⃗ ⃗ 𝑤 cos 𝜄 + 𝑣× ⃗ 𝑤 sin 𝜄 + 𝑣 𝑣 H ⃗ 𝑤 26
Complex number & quaternion • Complex number • 𝐣 & = −1 • 𝐝 = 𝑏, 𝑐 ≔ 𝑏 + 𝑐 𝐣 • 𝐝 ' 𝐝 & = 𝑏 ' , 𝑐 ' 𝑏 & , 𝑐 & = 𝑏 ' 𝑏 & − 𝑐 ' 𝑐 & + 𝑏 ' 𝑐 & + 𝑐 ' 𝑏 & 𝐣 • Quaternion • 𝐣 & = 𝐤 & = 𝐥 & = 𝐣𝐤𝐥 = −1 • 𝐣𝐤 = −𝐤𝐣 = 𝐥 , 𝐤𝐥 = −𝐥𝐤 = 𝐣 , 𝐥𝐣 = −𝐣𝐥 = 𝐤 Not commutative! • 𝐫 = 𝑏, 𝑐, 𝑑, 𝑒 ≔ 𝑏 + 𝑐 𝐣 + 𝑑 𝐤 + 𝑒 𝐥 • 𝐫 ' 𝐫 & = 𝑏 ' , 𝑐 ' , 𝑑 ' , 𝑒 ' 𝑏 & , 𝑐 & , 𝑑 & , 𝑒 & = 𝑏 ' 𝑏 & − 𝑐 ' 𝑐 & − 𝑑 ' 𝑑 & − 𝑒 ' 𝑒 & + 𝑏 ' 𝑐 & + 𝑐 ' 𝑏 & + 𝑑 ' 𝑒 & − 𝑒 ' 𝑑 & 𝐣 + 𝑏 ' 𝑑 & + 𝑑 ' 𝑏 & + 𝑒 ' 𝑐 & − 𝑐 ' 𝑒 & 𝐤 + 𝑏 ' 𝑒 & + 𝑒 ' 𝑏 & + 𝑐 ' 𝑑 & − 𝑑 ' 𝑐 & 𝐥 27
Notation by scalar + 3D vector • 𝐫 / = 𝑏 / + 𝑐 / 𝐣 + 𝑑 / 𝐤 + 𝑒 / 𝐥 ≔ 𝑏 / + 𝑐 / , 𝑑 / , 𝑒 / = 𝑏 / + 𝑤 / • 𝐫 0 = 𝑏 0 + 𝑐 0 𝐣 + 𝑑 0 𝐤 + 𝑒 0 𝐥 ≔ 𝑏 0 + 𝑐 0 , 𝑑 0 , 𝑒 0 = 𝑏 0 + 𝑤 0 • 𝐫 / 𝐫 0 = 𝑏 / 𝑏 0 − 𝑐 / 𝑐 0 − 𝑑 / 𝑑 0 − 𝑒 / 𝑒 0 + 𝑏 / 𝑐 0 + 𝑏 0 𝑐 / + 𝑑 / 𝑒 0 − 𝑒 / 𝑑 0 𝐣 + 𝑏 / 𝑑 0 + 𝑏 0 𝑑 / + 𝑒 / 𝑐 0 − 𝑐 / 𝑒 0 𝐤 + 𝑏 / 𝑒 0 + 𝑏 0 𝑒 / + 𝑐 / 𝑑 0 − 𝑑 / 𝑐 0 𝐥 = 𝑏 / + 𝑤 / 𝑏 0 + 𝑤 0 = 𝑏 / 𝑏 0 − 𝑤 / H 𝑤 0 + 𝑏 / 𝑤 0 + 𝑏 0 𝑤 / + 𝑤 / ×𝑤 0 28
Rotation using quaternions Note: 𝑣 is a unit vector = 𝑤 − 𝑣 𝑣 H ⃗ ⃗ 𝑤 cos 𝛽 + 𝑣× ⃗ 𝑤 sin 𝛽 + 𝑣 𝑣 H ⃗ 𝑤 • Interesting theory behind • Clifford algebra • Geometric algebra • Also important for physics & robotics https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation 29
Recommend
More recommend