Computer Graphics and Applications Computer Graphics and Applications
IGR201
Kiwon Um
CG, IMAGES, IDS
1
Computer Graphics and Applications Computer Graphics and - - PowerPoint PPT Presentation
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
CG, IMAGES, IDS
1
Video game AR VR Mobile 3D
Synthesis of 2D image(s) from scene data
(3D) geometry and transformations Lights Material properties
Computer animation 3D modeling Image processing Scientific visualization Computer vision Etc.
Kiwon Um IGR201, Telecom Paris 2
3
4
5
6
[Albrecht Dürer: Der Zeichner des liegenden Weibes]
Kiwon Um IGR201, Telecom Paris 7
// ... int main(int argc, char** argv) { // ... drawPixel(x, y, R, G, B, A); // ... } // ...
Kiwon Um IGR201, Telecom Paris 8
// ... 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
// ... 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
11
[Rendered by Charles Nandeya Ehouman using ]
LuxCoreRender
12
13
[ , directed by Andy Goralczyk, rendered using Blender]
Spring
14
You do not need to implement all primitive drawing functions.
Interface to GPU
(also known as OpenGL Red Book)
GLUT, QT, GTK+, etc.
For modeling, rendering, animation, etc. E.g., , , , , , , , …
https://www.glprogramming.com/red/ Blender Houdini 3ds Max Maya PBRT LuxCoreRender RenderMan
Kiwon Um IGR201, Telecom Paris 15
Bunny Armadillo Lucy
[ ]
Geometry Materials
Visualization Physical properties
…
http://graphics.stanford.edu/data/3Dscanrep/
Kiwon Um IGR201, Telecom Paris 16
[ ] https://www.ntu.edu.sg/home/ehchua/programming/opengl/CG_BasicsTheory.html
Kiwon Um IGR201, Telecom Paris 17
edges vertices faces polygons surfaces
[ ] Wikipedia
Kiwon Um IGR201, Telecom Paris 18
Start from a coarse polygon mesh (e.g., diamond). The center is at origin; all 6 points are of distance 1 from the center.
Kiwon Um IGR201, Telecom Paris 19
Accounting for level of details (LOD), i.e., the complexity of a 3D model representation
[ ] http://glasnost.itcarlow.ie/~powerk/3DGraphics2/Theory/Levelofdetail.htm
Kiwon Um IGR201, Telecom Paris 20
[ ] Frey and Borouchaki
# 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 ...
Kiwon Um IGR201, Telecom Paris 21
: cross product
Kiwon Um IGR201, Telecom Paris 22
Compute normal for each polygon. Generate a vector connecting the viewer and a vertex of the polygon. Take the dot product, i.e., .
: back face : front face : projected as an edge or a silhouette of on a screen
v ⋅ n > 0 v ⋅ n < 0 v ⋅ n = 0
Kiwon Um IGR201, Telecom Paris 23
Vertices Normals
Angles, areas, etc. = [1.0, −1.0, 1.0] v1 = [1.5, 1.0, 1.2] v2 = [−1.0, 0.5, 1.0] v3 ⋯ = [−1.0, 0.0, 0.0] n1 = [0.0, 1.0, 0.0] n2 = [0.0, 0.0, 1.0] n3 ⋯
Kiwon Um IGR201, Telecom Paris 24
Kiwon Um IGR201, Telecom Paris 25
( − )×( − ) v1 v0 v2 v0 ||( − )×( − )|| v1 v0 v2 v0
Kiwon Um IGR201, Telecom Paris 26
Local illumination: only between surfaces and direct lights Global illumination: direct lights + indirect lights such as reflection
A shading example
Light
Color Intensity Type: point light, directional light, spotlight, etc. …
Surface:
Color (or texture) Normal …
Kiwon Um IGR201, Telecom Paris 27
Ambient Diffuse Specular
[ ]
Wikipedia
Kiwon Um IGR201, Telecom Paris 28
The amount of perceived reflection:
Independent of the view direction Just proportional to the amount of incoming light
The amount of light that a surface receives . : diffuse reflection constant : diffuse surface color : diffuse light color : component-wise multiplication
Kiwon Um IGR201, Telecom Paris 29
Reflection vector View vector
Use a halfway vector , and then instead of
l+v ||l+v||
Kiwon Um IGR201, Telecom Paris 30
: specular reflection constant : shininess : specular surface color : specular light color
From low (left) to high (right)
[ ]
https://www.scratchapixel.com/lessons/3d-basic-rendering/phong-shader-BRDF
Kiwon Um IGR201, Telecom Paris 31
Calculate lighting for each polygon
Gouraud shading
Calculate lighting for each vertex, and then interpolate the colors
Phong shading
Interpolate normal, and then calculate lighting for each fragment Flat, Gouraud, and Phong shading [ ] GPC
Kiwon Um IGR201, Telecom Paris 32
[ ]
Map pixels from a texture (usually an image) to a 3D surface
: axes of the 2D texture coordinates
[ ]
Wikipedia
Wikipedia
Kiwon Um IGR201, Telecom Paris 33
Light Source Scene Object Shadow Ray View Ray Image Camera
[ ]
Reflection/refraction Scattering Dispersion phenomena …
Wikipedia
Kiwon Um IGR201, Telecom Paris 34
35
36
Colinearity between points Parallelism Convexity of sets Ratios of lengths of parallel line segments Barycenters
[ ]
Wikipedia
Kiwon Um IGR201, Telecom Paris 37
Kiwon Um IGR201, Telecom Paris 38
Kiwon Um IGR201, Telecom Paris 39
Hint 1: when the distance is Hint 2:
Trigonometric addition formulas sin(α ± β) = sinαcos β ± cos αsinβ cos(α ± β) = cos αcos β ∓ sinαsinβ
Kiwon Um IGR201, Telecom Paris 40
[ ] = [ ] + [ ] x′ y′ x y dx dy [ ] = [ ] [ ] x′ y′ sx sy x y [ ] = [ ] [ ] x′ y′ cosθ sin θ − sin θ cosθ x y
Kiwon Um IGR201, Telecom Paris 41
Translation: vector addition Scaling and rotation: matrix composition
Yes!!! Homogeneous coordinates!
E.g., typically, .
Treat transformations uniformly Deal with perspective projection (… later)
Kiwon Um IGR201, Telecom Paris 42
three transformations compose a matrix as where
= ⎡ ⎣ ⎢ x′ y′ 1 ⎤ ⎦ ⎥ ⎡ ⎣ ⎢ 1 1 dx dy 1 ⎤ ⎦ ⎥ ⎡ ⎣ ⎢ x y 1 ⎤ ⎦ ⎥
= & = ⎡ ⎣ ⎢ x′ y′ 1 ⎤ ⎦ ⎥ ⎡ ⎣ ⎢ sx sy 1 ⎤ ⎦ ⎥ ⎡ ⎣ ⎢ x y 1 ⎤ ⎦ ⎥ ⎡ ⎣ ⎢ x′ y′ 1 ⎤ ⎦ ⎥ ⎡ ⎣ ⎢ cos θ sin θ − sin θ cos θ 1 ⎤ ⎦ ⎥ ⎡ ⎣ ⎢ x y 1 ⎤ ⎦ ⎥
Kiwon Um IGR201, Telecom Paris 43
, e.g.,
= ⎡ ⎣ ⎢ ⎢ ⎢ x′ y′ z′ 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ 1 1 1 dx dy dz 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ x y z 1 ⎤ ⎦ ⎥ ⎥ ⎥ = ⎡ ⎣ ⎢ ⎢ ⎢ x′ y′ z′ 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ sx sy sz 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ x y z 1 ⎤ ⎦ ⎥ ⎥ ⎥
Kiwon Um IGR201, Telecom Paris 44
= ⎡ ⎣ ⎢ ⎢ ⎢ x′ y′ z′ 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ cosθz sinθz − sinθz cosθz 1 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ x y z 1 ⎤ ⎦ ⎥ ⎥ ⎥
Kiwon Um IGR201, Telecom Paris 45
Remind!!! Rotation about the z-axis :
Hint: permutation
= x cos − y sin x′ θz θz = x sin + y cos y′ θz θz = z z′
⇒ = ⎡ ⎣ ⎢ ⎢ ⎢ x′ y′ z′ 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ 1 cos θx sin θx − sin θx cos θx 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ x y z 1 ⎤ ⎦ ⎥ ⎥ ⎥
Kiwon Um IGR201, Telecom Paris 46
[ ] https://www.ntu.edu.sg/home/ehchua/programming/opengl/CG_BasicsTheory.html
Kiwon Um IGR201, Telecom Paris 47
Rendering Pipeline [ ]
Vertex shader (programmable) Primitive tessellation stages (programmable) Geometry shader (programmable)
Generates fragments
Processes each fragment.
Scissor test, stencil test, depth test, blending, logical
OpenGL Wiki
Kiwon Um IGR201, Telecom Paris 48
[ ] https://www.ntu.edu.sg/home/ehchua/programming/opengl/CG_BasicsTheory.html
Kiwon Um IGR201, Telecom Paris 49
Its polygons are defined in its model space (a.k.a. local space or object space).
Model space
Affine transformations!
Translation, scaling, rotation, etc.
World space
Kiwon Um IGR201, Telecom Paris 50
Eye position: Look at point: Up vector:
Eye Up At World space
Defined by a basis that consists of three unit vectors
Eye Up At World space Camera space
Eye−At ||Eye−At||
Up×zc ||Up× || zc
Kiwon Um IGR201, Telecom Paris 51
Kiwon Um IGR201, Telecom Paris 52
[ ]
http://www.codinglabs.net/article_world_view_projection_matrix.aspx
Kiwon Um IGR201, Telecom Paris 53
A view frustum: (l)eft, (r)ight, (t)op, (b)ottom, (n)ear, and (f)ar NDC:
[ ]
http://www.songho.ca/opengl/gl_projectionmatrix.html
= Mproj,ortho ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢
2 r−l 2 t−b
−
2 f−n
− r+l
r−l
− t+b
t−b
− f+n
f−n
1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥
Kiwon Um IGR201, Telecom Paris 54
[ ]
[ ] http://www.songho.ca/opengl/gl_projectionmatrix.html
= Mproj,persp ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢
2n r−l 2n t−b
− f+n
f−n
−1 − r+l
r−l
− t+b
t−b
− 2fn
f−n
⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥
OpenGL Red Book
= Mproj,persp ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ( ) tan−1
fovx 2
( ) tan−1
fovy 2
− f+n
f−n
−1 − 2fn
f−n
⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥
Kiwon Um IGR201, Telecom Paris 55
Recall homogeneous coordinates!
and
= Mproj,persp ⎡ ⎣ ⎢ ⎢ ⎢ 1 1 −3 −1 −4 ⎤ ⎦ ⎥ ⎥ ⎥
2
= → ⎡ ⎣ ⎢ ⎢ ⎢ 1 1 −3 −1 −4 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ ⎢
3 2
− 3
2
1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢
3 2 1 2 3 2
⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ 1
1 3
1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ = → ⎡ ⎣ ⎢ ⎢ ⎢ 1 1 −3 −1 −4 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ −2 1 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ 2 2 ⎤ ⎦ ⎥ ⎥ ⎥ ⎡ ⎣ ⎢ ⎢ ⎢ 1 1 ⎤ ⎦ ⎥ ⎥ ⎥
Kiwon Um IGR201, Telecom Paris 56
Perspective vs. Orthographic [ ] Reflect CGI
Kiwon Um IGR201, Telecom Paris 57
with the width and height
[ ]
OpenGL Red Book
Kiwon Um IGR201, Telecom Paris 58
Stages of Vertex Transformation [ ] OpenGL Red Book
Kiwon Um IGR201, Telecom Paris 59
[ ]
Z-culling: early pixel elimination
Wikipedia
Kiwon Um IGR201, Telecom Paris 60
A is a user-defined program.
Designed to run on some stage of a graphics processor (GPU) Execute one of the programmable stages of the rendering pipeline
Different shading languages:
…
Programmable stages
and Shaders
… not only for Computer Graphics!
General-Purpose Computation on Graphics Processing Units (GPGPU) But, we also have .
Shader
HLSL Cg Vertex Shaders Tessellation Control Evaluation Geometry Shaders Fragment Shaders Compute Shaders CUDA
Kiwon Um IGR201, Telecom Paris 61
// simpleVS.glsl uniform mat4 uMvpMat; // model-view-projection matrix in vec4 iPos; // input vertex position void main () { gl_Position = u_matMVP * iPos; // gl_Position: predefined in VS } // main.cpp // ... // const GLchar *shaderSource = ...; // load the shader codes "simpleVS.glsl" as string void initializeShaderPrograms() { program = glCreateProgram(); // Create a GPU program GLuint shader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(shader, 1, &shaderSource, NULL); // load the VS source codes glCompileShader(shader); // Compile the codes glAttachShader(program, shader); // Attatch the VS glDeleteShader(shader); // ... may load/compile/attatch other shaders glLinkProgram(program); // the GPU program is ready to handle streams of polygons ... } // ...
Kiwon Um IGR201, Telecom Paris 62
63
Encapsulation Abstraction Information hiding Inheritance Polymorphism …
Kiwon Um IGR201, Telecom Paris 64
Member variables and methods
class Vector2D { private: float x, y; public: explicit Vector2D(const float v) : x(v), y(v) {} Vector2D(const float a, const float b) : x(a), y(b) {} void setX(const float x_new) { x = x_new; } void setY(const float y_new) { y = y_new; } float length() const { return std::sqrt(x*x + y*y); } Vector2D& rotate(const float radian) { const float cost=std::cos(radian), sint=std::sin(radian); const Vector2D v_new(cost*x-sint*y, sint*x+cost*y); return (*this) = v_new; } }; Vector2D v(3.0, 3.0); // a 2D vector instance v.y = 4.0; // ERROR! private! v.setY(4.0); // OK! call a member method updating the member variable y v = Vector2D(3.0, 4.0); // OK! assign a new instance float len = v.length(); // len = 5.0 v.rotate(0.5*PI); // v = [-4.0, 3.0]
Kiwon Um IGR201, Telecom Paris 65
class Vector2D { // ... // assignmet operator Vector2D& operator+=(const Vector2D& r) { x+=r.x; y+=r.y; return *this; } // ... // unary operator Vector2D operator-() const { return Vector2D(-x, -y); } // ... // binary operator Vector2D operator+(const Vector2D& r) const { return Vector2D(*this)+=r; } // ... }; Vector2D v(1.0, 2.0); // v = [1.0, 2.0] v += Vector2D(1.0, 1.0); // v = [2.0, 3.0] v = -v; // v = [-2.0, -3.0] v = v + Vector2D(1.0, 1.0); // v = [-1.0, -2.0]
Kiwon Um IGR201, Telecom Paris 66
#include <iostream> // Call by Value method void doNothing(Vector2D v) { v.setX(1.0); } // Call by Reference methods void doSomethingWithReference(Vector2D &v) { v.setX(4.0); } void doSomethingWithPointer(Vector2D *v) { v->setX(5.0); } int main(int argc, const char *argv[]) { Vector2D v(2.0, 3.0); doNothing(v); // v = (2.0, 3.0) doSomethingWithReference(v); // v = (4.0, 3.0) doSomethingWithPointer(v); // v = (5.0, 3.0) return 0; }
Kiwon Um IGR201, Telecom Paris 67
Algorithms: sort, find, … Containers: list, vector, set, queue, … Functions: Functors, … Iterators: forward, random-access, …
#include <vector> // Vec3f and Vec3i classes ... int main(int argc, char** argv) { std::vector<Vec3f> vbuffer; vbuffer.push_back(Vec3f(0.0, 0.0, 0.0)); vbuffer.push_back(Vec3f(1.0, 0.0, 0.0)); vbuffer.push_back(Vec3f(1.0, 1.0, 0.0)); std::vector<Vec3i> ibuffer; ibuffer.push_back(Vec3i(0, 1, 2)); // ... }
Kiwon Um IGR201, Telecom Paris 68
69
Conferences
SIGGRAPH / SIGGRAPH Asia Eurographics (EG) Symposium on Computer Animation (SCA) Pacific Graphics (PG) Conference on Computer Animation and Social Agents (CASA) Computer Graphics International (CGI) …
Journals
ACM Transactions of Graphics (TOG) IEEE Transactions on Visualization and Computer Graphics (TVCG) Computer Graphics Forum (CGF) Computer Animation and Virtual Worlds (CAVW) The Visual Computer (TVC) Computer-Aided Design (CAD) …
Kiwon Um IGR201, Telecom Paris 70
71
72
We are here in the , , .
Associate Professor Associate Professor
Do not hesitate contact us! We are looking for great team members for PhD/master students as well as undergraduate students! Computer Graphics Group IMAGES IDS Department Telecom Paris Institut Polytechnique de Paris
Kiwon Um IGR201, Telecom Paris 73