Computer Graphics and Applications Computer Graphics and Applications IGR201 Kiwon Um CG, IMAGES, IDS 1
What is Computer Graphics (CG)? What is Computer Graphics (CG)? A basic idea: Synthesis of 2D image(s) from scene data Video game Scene data (often 3D data) (3D) geometry and transformations Lights AR Material properties Topics Computer animation VR 3D modeling Image processing Scientific visualization Computer vision Etc. Mobile 3D Kiwon Um IGR201, Telecom Paris 2
What's real? What's real? 3
Were your eyes sharp? Were your eyes sharp? 4
One more chance, what's real? One more chance, what's real? 5
Are you getting better? Are you getting better? 6
Rendering Rendering "The automatic process of generating a photorealistic or non- photorealistic image from a 2D or 3D model by means of computer programs ." – [ Wikipedia ] [Albrecht Dürer: Der Zeichner des liegenden Weibes] Kiwon Um IGR201, Telecom Paris 7
Drawing a Dot Drawing a Dot Hello dot! (Conceptual codes) // ... int main(int argc, char** argv) { // ... drawPixel(x, y, R, G, B, A); // ... } // ... Kiwon Um IGR201, Telecom Paris 8
Drawing a Triangle Drawing a Triangle Hello triangle! (Conceptual codes) // ... int drawTriangle(const Point p1, const Point p2, const Point p3, const Color c) { // ... drawPixel(p1.x, p1.y, c.R, c.G, c.B, c.A); drawPixel(p1.x+1, p1.y-1, c.R, c.G, c.B, c.A); drawPixel(p1.x+2, p1.y-1, c.R, c.G, c.B, c.A); drawPixel(p1.x+3, p1.y-1, c.R, c.G, c.B, c.A); // ... } int main(int argc, char** argv) { // ... drawTriangle(Point(x1, y1), Point(x2, y2), Point(x3, y3), Color(R, G, B, A)); // ... } // ... Kiwon Um IGR201, Telecom Paris 9
Drawing a Model Drawing a Model Hello model! (Conceptual codes) // ... int drawModel(const Point *vs, const int *ts, const Color *cs) { // ... drawTriangle(vs[ts[3*0+0]], vs[ts[3*0+1]], vs[ts[3*0+2]], cs[0]); drawTriangle(vs[ts[3*1+0]], vs[ts[3*1+1]], vs[ts[3*1+2]], cs[1]); drawTriangle(vs[ts[3*2+0]], vs[ts[3*2+1]], vs[ts[3*2+2]], cs[2]); // ... } int main(int argc, char** argv) { // ... drawModel(vertices, triangles, colors); // ... } // ... Kiwon Um IGR201, Telecom Paris 10
If you extend the idea … If you extend the idea … 11
… you can create an image like this. … you can create an image like this. [Rendered by Charles Nandeya Ehouman using LuxCoreRender ] 12
If you extend the idea If you extend the idea further to multiple images … further to multiple images … 13
… you can create a video like this. … you can create a video like this. [ Spring , directed by Andy Goralczyk, rendered using Blender] 14
Programming Guide Programming Guide Good news You do not need to implement all primitive drawing functions. Graphics APIs: OpenGL (or Microsoft DirectX) Interface to GPU Official guide book (also known as OpenGL Red Book ) https://www.glprogramming.com/red/ Programming tools and libraries GLUT, QT, GTK+, etc. Applications For modeling, rendering, animation, etc. E.g., Blender Houdini 3ds Max Maya PBRT LuxCoreRender RenderMan , , , , , , , … Kiwon Um IGR201, Telecom Paris 15
Geometric Objects Geometric Objects Bunny Armadillo Lucy [ ] http://graphics.stanford.edu/data/3Dscanrep/ Let's bring the objects into our computer. How can we model (or represent) these models for computer? Geometry Materials Visualization Physical properties … Kiwon Um IGR201, Telecom Paris 16
Primitives Primitives [ https://www.ntu.edu.sg/home/ehchua/programming/opengl/CG_BasicsTheory.html ] Kiwon Um IGR201, Telecom Paris 17
Polygon Mesh Polygon Mesh A popular modeling technique in CG Usually use triangles for faces (known as triangle mesh) For instance, a box object vertices edges faces polygons surfaces [ Wikipedia ] Kiwon Um IGR201, Telecom Paris 18
Modeling Example (Subdivision) Modeling Example (Subdivision) Let's create a sphere of radius 1. Start from a coarse polygon mesh (e.g., diamond). The center is at origin; all 6 points are of distance 1 from the center. Consider a triangle; subdivide into 4 sub-triangles. Kiwon Um IGR201, Telecom Paris 19
Modeling Example (cont'd) Modeling Example (cont'd) If we recursively do the subdivision for all triangles… … we come closer to a sphere. Accounting for level of details (LOD), i.e., the complexity of a 3D model representation Complexity affects the processing (e.g., rendering) cost. [ http://glasnost.itcarlow.ie/~powerk/3DGraphics2/Theory/Levelofdetail.htm ] Kiwon Um IGR201, Telecom Paris 20
Polygon Mesh Example Polygon Mesh Example A 3D bunny model example: # OBJ file format with ext .obj # vertex count = 2503 # face count = 4968 ... v 7.8152700e-003 5.5050680e-002 5.2750250e-002 v 3.7955090e-002 1.0488710e-001 -3.2031800e-003 v -7.9003790e-002 1.2850550e-001 5.3149340e-002 v -7.9778990e-002 1.3448894e-001 5.0990290e-002 v -5.9129700e-002 1.5039712e-001 3.4489540e-002 v -6.5691790e-002 1.4961818e-001 3.8160980e-002 v -3.1951660e-002 1.2518394e-001 1.9400580e-002 ... f 291 76 292 f 292 237 50 f 2159 1696 1767 f 583 929 850 f 1584 1585 1616 f 1495 1490 1188 f 1557 1489 1660 f 1078 1069 1494 ... [ Frey and Borouchaki ] Kiwon Um IGR201, Telecom Paris 21
Surface Normal Surface Normal The orientation of a surface of a geometric object The vector perpendicular to a plane Vertices Faces (indices) = [1.0, −1.0, 1.0] v 1 f 1 = [1, 2, 3] v 2 = [1.5, 1.0, 1.2] f 2 = ⋯ v 3 = [−1.0, 0.5, 1.0] ⋯ ⋯ Two vectors on the surface: n ^ 1 = ( v 2 − v 1 ) × ( v 3 − v 1 ) : cross product × Normalize: n ^ 1 n 1 = || ^ 1 || n Kiwon Um IGR201, Telecom Paris 22
Back Face Culling Back Face Culling Cull the back faces that are not visible from the viewer. Determine if a polygon is a front face or a back face. Compute normal for each polygon. n Generate a vector connecting the viewer and a vertex of the polygon. v Take the dot product, i.e., . v ⋅ n : back face v ⋅ n > 0 : front face v ⋅ n < 0 : projected as an edge or a silhouette of on a screen v ⋅ n = 0 Kiwon Um IGR201, Telecom Paris 23
Vertex Normal Vertex Normal Defined at vertices … can be given as additional data; e.g., Vertices Normals v 1 = [1.0, −1.0, 1.0] n 1 = [−1.0, 0.0, 0.0] v 2 = [1.5, 1.0, 1.2] n 2 = [0.0, 1.0, 0.0] v 3 = [−1.0, 0.5, 1.0] n 3 = [0.0, 0.0, 1.0] ⋯ ⋯ … or, can be computed from faces Weighted average: ∑ i θ i n i n ^ = ∑ i θ i Angles, areas, etc. Kiwon Um IGR201, Telecom Paris 24
Interpolation Interpolation Construct new data points within the range of a discrete set of known data points. Linear Bilinear x 0 x = (1 − α ) x 00 + α x 01 x 1 x = (1 − α ) x 10 + α x 11 x = (1 − β ) x 0 x + β x 1 x x = (1 − α ) a + α b Kiwon Um IGR201, Telecom Paris 25
Barycentric Coordinates Barycentric Coordinates Represent a point located inside a triangle as a convex v combination of three vertices: . v = λ 0 v 0 + λ 1 v 1 + λ 2 v 2 λ 0 λ 1 λ 2 , , ≥ 0 λ 0 + λ 1 + λ 2 = 1 λ 0 = (( v 2 − v 1 ) × ( v − v 1 )) ⋅ a λ 1 = (( v 0 − v 2 ) × ( v − v 2 )) ⋅ a λ 2 = (( v 1 − v 0 ) × ( v − v 0 )) ⋅ a ( v 1 − v 0 )×( v 2 − v 0 ) a = ||( v 1 − v 0 )×( v 2 − v 0 )|| The barycentric coordinates of the point . v = ( λ 0 λ 1 λ 2 , , ) Kiwon Um IGR201, Telecom Paris 26
Lighting Lighting Handling of interactions between lights and objects Local illumination: only between surfaces and direct lights Global illumination: direct lights + indirect lights such as reflection Shading of faces Light Color Intensity Type: point light, directional light, spotlight, etc. … Surface: Color (or texture) Normal … A shading example Kiwon Um IGR201, Telecom Paris 27
Phong Lighting Model Phong Lighting Model The most popular local illumination model Ambient s a Diffuse s d Specular s s s = s a + s d + s s [ Wikipedia ] Kiwon Um IGR201, Telecom Paris 28
Phong Model: Diffuse Phong Model: Diffuse Reflections from ideally diffuse surfaces (Lambertian surfaces) are scattered with equal intensity in all directions. The amount of perceived reflection: Independent of the view direction Just proportional to the amount of incoming light Lambert's cosine law The amount of light that a surface receives . ∝ n ⋅ l s f , d = ∑ m ∈ lights k d max( n f ⋅ l m ,0) c f , d ⊗ c m , d : diffuse reflection constant k d : diffuse surface color c f , d : diffuse light color c m , d : component-wise multiplication ⊗ Kiwon Um IGR201, Telecom Paris 29
Phong Model: Specular Phong Model: Specular Make a surface look shiny via highlights. Reflection vector r View vector v Highly view-dependent: v ⋅ r How to compute the reflection vector q = n cos θ − l q = r − n cos θ r = 2 n cos θ − l = 2( n ⋅ l ) n − l Modified Phong reflection model (Blinn-Phong reflection model) Use a halfway vector , and then instead of l + v h = n ⋅ h v ⋅ r || l + v || Kiwon Um IGR201, Telecom Paris 30
Recommend
More recommend