Introduction to Computer Graphics April 7, 2016 Kenshi Takayama
Lecturers • Kenshi Takayama (Assistant Prof., NII) • http://research.nii.ac.jp/~takayama/ • takayama@nii.ac.jp • Toshiya Hachisuka (Junior Associate Prof., U Tokyo) • http://www.ci.i.u-tokyo.ac.jp/~hachisuka/ • thachisuka@siggraph.org • Ryoichi Ando (Assistant Prof., NII) • https://scholar.google.com/citations?user= Ag3RwxUAAAAJ&hl=en TA: Kazutaka Nakashima (Igarashi Lab) http://n-taka.info/intro/ taka@ui.is.s.u-tokyo.ac.jp 2
Course overview Modeling Animation Rendering Image processing • 2~3 lectures per topic, 12 lectures in total • Rendering part by Prof. Hachisuka • Fluid animation part by Prof. Ando 3
Grading • Programming assignments only • No exam, no attendance check • Two tyes of assignments: Basic & Advanced • Basic 1 assignent per topic (4 in total), very easy • Advanced For motivated students • Deadline: The end of July • Evaluation criteria • 1 assignemnt 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-2016/ • Famous textbooks (not used in the class) • Fundamentals of Computer Graphics (9781568814698) • Computer Graphics: Principles and Practice in C (9780201848403) 5
Lecturers’ research topics 6
Coordinate transformations 7
Linear transformation 𝑦 ′ 𝑏 𝑐 𝑑 𝑦 𝑦 ′ 𝑦 𝑏 𝑐 In 2D: In 3D: 𝑧 ′ 𝑒 𝑓 𝑔 𝑧 = = 𝑧 ′ 𝑧 𝑑 𝑒 𝑨 𝑨 ′ ℎ 𝑗 • Intuition: Mapping of coordinate axes 𝑏 𝑐, 𝑒 𝑏 𝑐 1 = 𝑑 𝑑 𝑒 0 0, 1 𝑐 𝑏 𝑐 0 = 𝑒 𝑑 𝑒 1 𝑏, 𝑑 • Origin stays put 1, 0 8
Special linear transformations Rotation Scaling Shearing (X dir.) Shearing (Y dir.) 𝑡 x 0 cos 𝜄 − sin 𝜄 1 𝑙 1 0 0 𝑡 y sin 𝜄 cos 𝜄 0 1 𝑙 1 9
Linear transformation + translation = Affine transformation 𝑦 ′ 𝑦 𝑏 𝑐 𝑢 x 𝑦 ′ 𝑦 𝑢 x 𝑏 𝑐 𝑧 ′ 𝑧 = + ⟺ = 𝑑 𝑒 𝑢 y 𝑧 ′ 𝑧 𝑢 y 𝑑 𝑒 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 10
Combining affine transformations • Just multiply matrices • Careful with the ordering! 𝐲 ′ = 𝑆 𝑈 𝐲 cos 𝜄 − sin 𝜄 0 𝑆 = sin 𝜄 cos 𝜄 0 0 0 1 1 0 𝑢 x 𝑈 = 0 1 𝑢 y 𝐲 ′ = 𝑈 𝑆 𝐲 0 0 1 11
Homogeneous coordinates • When w ≠ 0, 4D homogeneous coordinate 𝑦, 𝑧, 𝑨, 𝑥 represents a 3D 𝑦 𝑧 𝑨 position 𝑥 , 𝑥 , 𝑥 • Can represent projective space := 3D Euclid space + infinity points • When w → 0, the represented 3D point approaches to infinity 𝑦, 𝑧, 𝑨, 0 represents a directional vector pointing toward 𝑦, 𝑧, 𝑨 • Difference of positional vectors is a directional vector: 𝑦, 𝑧, 𝑨, 1 − 𝑦 ′ , 𝑧 ′ , 𝑨 ′ , 1 = 𝑦 − 𝑦 ′ , 𝑧 − 𝑧 ′ , 𝑨 − 𝑨′, 0 • Homogeneous coordinate 0, 0, 0, 0 is undefined • More explanations in Wikipedia 12
Another role of homogeneous coordinates: Perspective projection • An object’s apparent size on the screen is inverse proportional to the object-camera distance Z=1 X • Camera at the origin, screen on the plane Z=1 𝑞 x 𝑞 x 𝑞 x , 𝑞 y , 𝑞 z is projected to 𝑥 x , 𝑥 y = 𝑞 z , 𝑞 z Z 𝑞 x 𝑥 x 𝑞 x /𝑞 z 𝑞 x 1 0 0 0 𝑞 y 𝑞 y 𝑞 y /𝑞 z 𝑥 y 0 1 0 0 = ≡ 0 0 1 1 𝑞 z 𝑞 z + 1 1 + 1/𝑞 z 𝑥 z 0 0 1 0 1 𝑞 z 1 Projection matrix • 𝑥 z (depth value) is used for occlusion test Z-buffering 13
Orthographic projection • Objects’ apparent sizes don’t depend on the camera position Orthographic Perspective • Simply ignore Z coordinates • Frequently used in CAD 14
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 15
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(); 16
Z-buffering 17
Hidden surface removal Without hidden surface removal With hidden surface removal • Classic problem in CG 18
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 19
Z-buffering • For each pixel, store distance to the camera (depth) • More memory- consuming, but today’s standard 20
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 21
Typical issues with Z-buffering: Simultaneous drawing of faces and lines • Dedicated OpenGL trick: glPolygonOffset Without polygon offset With polygon offset 22
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) 23
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 24
Quaternions 25
Rotation about arbitrary axis • Needed in various situations (e.g. camera manipulation) about X-axis about Y-axis about Z-axis about arbitrary axis • Matrix representation is overly complex! D egree o f F reedom • Should be represented by 2 DoF (axis direction) + 1 DoF (angle) = 3 DoF 26
Geometry of axis-angle rotation 𝑤′ 𝑣 : axis (unit vector) 𝑣 × 𝑤 𝜄 : angle 𝜄 𝑤 𝑤 : input position 𝑣(𝑣 ∙ 𝑤) 𝑤′ : output position 𝑣 𝑃 𝑤 ′ = 𝑤 − 𝑣 𝑣 ∙ 𝑤 cos 𝜄 + 𝑣 × 𝑤 sin 𝜄 + 𝑣 𝑣 ∙ 𝑤 27
Complex number & quaternion • Complex number • 𝐣 2 = −1 • 𝐝 = 𝑏, 𝑐 ≔ 𝑏 + 𝑐 𝐣 • 𝐝 1 𝐝 2 = 𝑏 1 , 𝑐 1 𝑏 2 , 𝑐 2 = 𝑏 1 𝑏 2 − 𝑐 1 𝑐 2 + 𝑏 1 𝑐 2 + 𝑐 1 𝑏 2 𝐣 • Quaternion • 𝐣 2 = 𝐤 2 = 𝐥 2 = 𝐣𝐤𝐥 = −1 • 𝐣𝐤 = −𝐤𝐣 = 𝐥 , 𝐤𝐥 = −𝐥𝐤 = 𝐣 , 𝐥𝐣 = −𝐣𝐥 = 𝐤 Not commutative! • 𝐫 = 𝑏, 𝑐, 𝑑, 𝑒 ≔ 𝑏 + 𝑐 𝐣 + 𝑑 𝐤 + 𝑒 𝐥 • 𝐫 1 𝐫 2 = 𝑏 1 , 𝑐 1 , 𝑑 1 , 𝑒 1 𝑏 2 , 𝑐 2 , 𝑑 2 , 𝑒 2 = 𝑏 1 𝑏 2 − 𝑐 1 𝑐 2 − 𝑑 1 𝑑 2 − 𝑒 1 𝑒 2 + 𝑏 1 𝑐 2 + 𝑐 1 𝑏 2 + 𝑑 1 𝑒 2 − 𝑒 1 𝑑 2 𝐣 + 𝑏 1 𝑑 2 + 𝑑 1 𝑏 2 + 𝑒 1 𝑐 2 − 𝑐 1 𝑒 2 𝐤 + 𝑏 1 𝑒 2 + 𝑒 1 𝑏 2 + 𝑐 1 𝑑 2 − 𝑑 1 𝑐 2 𝐥 28
Notation by scalar + 3D vector • 𝐫 = 𝑏 + 𝑐 𝐣 + 𝑑 𝐤 + 𝑒 𝐥 ≔ 𝑏 + 𝑐, 𝑑, 𝑒 = 𝑏 + 𝑤 • 𝐫 1 𝐫 2 = 𝑏 1 𝑏 2 − 𝑐 1 𝑐 2 − 𝑑 1 𝑑 2 − 𝑒 1 𝑒 2 + 𝑏 1 𝑐 2 + 𝑐 1 𝑏 2 + 𝑑 1 𝑒 2 − 𝑒 1 𝑑 2 𝐣 + 𝑏 1 𝑑 2 + 𝑑 1 𝑏 2 + 𝑒 1 𝑐 2 − 𝑐 1 𝑒 2 𝐤 + 𝑏 1 𝑒 2 + 𝑒 1 𝑏 2 + 𝑐 1 𝑑 2 − 𝑑 1 𝑐 2 𝐥 = 𝑏 1 𝑏 2 − 𝑤 1 ∙ 𝑤 2 + 𝑏 1 𝑤 2 + 𝑏 2 𝑤 1 + 𝑤 1 × 𝑤 2 29
Rotation using quaternions Note: 𝑣 is a unit vector = 𝑤 − 𝑣 𝑣 ∙ 𝑤 cos 𝛽 + 𝑣 × 𝑤 sin 𝛽 + 𝑣 𝑣 ∙ 𝑤 • Interesting theory behind (cf. Wikipedia) 30
Recommend
More recommend