Slide 1

Slide 1 text

jgs SER 431 Advanced Graphics Lecture 25: Final Review Javier Gonzalez-Sanchez [email protected] PERALTA 230U Office Hours: By appointment

Slide 2

Slide 2 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 1 jgs Calendar

Slide 3

Slide 3 text

jgs Midterm Topics

Slide 4

Slide 4 text

jgs Noise (Procedural Texture/Surfaces Generation)

Slide 5

Slide 5 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 4 jgs Multi-scale Function Adding Noise over diverse frequencies and amplitudes )) * , * , * ( * ) , , ( 1 r scale t scale s scale noise amplitude r t s f i i i bands i i å = - =

Slide 6

Slide 6 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 5 jgs Sum of Absolute Values Adding Noise over absolute values is Good for fire )) , , ( ( ) , , ( 1 r scale t scale s scale noise amplitude r t s f i i i bands i i å = - =

Slide 7

Slide 7 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 6 jgs Marble Principle ))) , , ( ( * sin( ) , , ( 4 1 r scale t scale s scale noise amplitude s r t s f i i i i i å = - = Using sin( ) function plus noise

Slide 8

Slide 8 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 7 jgs Marble Example § MarbleMap is from black to white § Scale scales [min, max] to [0,1] § u and v are in range [0,1] § Does not look that great, maybe a more complex color ramp is needed )) ) 5 . 11 , * 2 * 5 , * 2 * 5 ( * 2 * 6 * 20 sin ( ( ) , ( 4 1 ÷ ø ö ç è æ + = å = - v u PNoise u Scale MarbleMap v u Texture i i i i

Slide 9

Slide 9 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 8 jgs Graphics https://www.youtube.com/watch?v=aviL3HX3UEc

Slide 10

Slide 10 text

jgs Collision (Axis-aligned bounding box)

Slide 11

Slide 11 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 10 jgs §Axis-aligned Bounding Box (AABB) § An AABB is defined by its minimal and maximal positions in space Pmin=(xmin, ymin, zmin), Pmax = (xmax, ymax, zmax) § Calculate Initialize pmin to +infinite or the first vertex Initialize pmax to –infinite or the first vertex foreach vertex p do { if (p.x < pmin.x) then pmin.x = p.x if (p.y < pmin.y) then pmin.y = p.y if (p.z > pmax.z) then pmax.z = p.z }

Slide 12

Slide 12 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 11 jgs AABB Calculate AABB Draw AABB with lines

Slide 13

Slide 13 text

jgs Shadows, Reflection, and Fog

Slide 14

Slide 14 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 13 jgs Concepts § What is the shadow matrix? § What is the stencil buffer? § What is double blending and how to avoid it?

Slide 15

Slide 15 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 14 jgs Step 2. init() void init() { // ... glClearStencil(0); }

Slide 16

Slide 16 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 15 jgs Step 3. display() void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glEnable(GL_STENCIL_TEST); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // glColorMask controls with Stencil or Color buffer? glStencilFunc(GL_ALWAYS, 1, 1); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); //

Slide 17

Slide 17 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 16 jgs glDisable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-50.0, 50, -50.0, 50.0, 1.0, -1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPushMatrix(); glTranslatef(0, 0, 0); glBegin(GL_TRIANGLES); glVertex2f(-20.0, -20.0); glVertex2f( 20.0, -20.0); glVertex2f( 0.0, 20.0); glEnd(); glPopMatrix(); glEnable(GL_DEPTH_TEST);

Slide 18

Slide 18 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 17 jgs // re-enable color and disable stencil glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glStencilFunc(GL_EQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // draw your colors here glDisable(GL_STENCIL_TEST); glutSwapBuffers(); }

Slide 19

Slide 19 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 18 jgs Fog glEnable(GL_FOG); // specifies the equation to be used to compute the fog blend factor. // GL_LINEAR, GL_EXP, and GL_EXP2. // initial fog mode is GL_EXP glFogi(GL_FOG_MODE, GL_LINEAR); // the fog color. Color components are in the range [0,1]. // the initial fog color is (0, 0, 0, 0). GLfloat fogColor[4] = { 0.5, 0.5, 0.5, 1.0 }; glFogfv(GL_FOG_COLOR, fogColor); //Used in exponential fog equations. The initial fog density is 1. // Only nonnegative densities are accepted. glFogf(GL_FOG_DENSITY, 0.25); // the near distance used in the linear fog equation. The initial near distance is 0 glFogf(GL_FOG_START, 10.0); // the far distance used in the linear fog equation. The initial far distance is 1. glFogf(GL_FOG_END, 6000.0);

Slide 20

Slide 20 text

jgs Particle Systems

Slide 21

Slide 21 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 20 jgs Particles § Emitter § Behavioral parameter of a particle (lifetime, initial velocity, spawning rate, color) § Equations

Slide 22

Slide 22 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 21 jgs Graphics https://www.youtube.com/watch?v=aviL3HX3UEc

Slide 23

Slide 23 text

jgs Curves

Slide 24

Slide 24 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 23 jgs All about Curves

Slide 25

Slide 25 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 24 jgs Curves § What is a Curve? § What is Curvature? § Parametric Representation § Curve equation (general) § Control Graph § Control Point § Tangent

Slide 26

Slide 26 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 25 jgs Curves § Explain C0, C1, C2 continuity § Explain similarities and differences of: Bezier, Hermite, Chaikin and B-spline Curves § What is a Blending Function? § Explain A-frame

Slide 27

Slide 27 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 26 jgs Blending Functions Bezier § B0 (t)=(1-t)3 § B1 (t)=3t(1-t)2 § B2 (t)=3t2(1-t) § B3 (t)=(t)3 Cubic B-Spline § B0 (t)=((1-t)3)/ 6 B1 (t)=(3t3 -6t2 + 4)/ 6 B2 (t)=(-3t3 + 3t2 + 3t + 1) / 6 B3 (t)=(t)3 / 6

Slide 28

Slide 28 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 27 jgs Blending Functions Hermite § B0 (t)= 2*t3 – 3*t2 + 1, § B1 (t)= -2*t3 + 3*t2, § B2 (t)= t3 - 2*t2 + t, § B3 (t)= t3 – t2

Slide 29

Slide 29 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 28 jgs Apply Bezier Algorithm

Slide 30

Slide 30 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 29 jgs Apply B-spline Algorithm

Slide 31

Slide 31 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 30 jgs Apply Chaikin Algorithm Qi=3/4Pi + 1/4Pi+1 Ri=1/4Pi + 3/4Pi+1

Slide 32

Slide 32 text

jgs New Topics

Slide 33

Slide 33 text

jgs NURBS (Procedural Texture/Surfaces Generation)

Slide 34

Slide 34 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 33 jgs Code // control points GLfloat ctlpoints[4][4][3] = { { { 20, 0, 10 },{ 0, 0, 10 },{ -5, 0, 10 },{ -10, 0, 10 } }, { { 20, 0, 5 },{ 0, 15, 5 },{ -5, 15, 5 },{ -10, 0, 5 } }, { { 20, 0, -5 },{ 0, 10, -5 },{ -5, 10, -5 },{ -10, 0, -5 } }, { { 20, 0, -10 },{ 0, 0, -10 },{ -5, 0, -10 },{ -10, 0, -10 } } }; GLfloat knots[8] = { 0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 3.0 }; GLUnurbsObj *theNurb;

Slide 35

Slide 35 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 34 jgs Code // init void init(void) { // Materials and Light GLfloat mat_diffuse[] = { 1.0f, 0.5f, 0.31f, 1. }; GLfloat mat_specular[] = { 0.5f, 0.5f, 0.5f, 1. }; GLfloat mat_ambient[] = { 1.0f, 0.5f, 0.31f, 1. }; GLfloat mat_shininess[] = { 100.0 }; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glEnable(GL_AUTO_NORMAL); glEnable(GL_NORMALIZE); theNurb = gluNewNurbsRenderer(); gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0); gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL); // }

Slide 36

Slide 36 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 35 jgs // display void display(void) { // camera and others configurations here... // NURBS glColor3f(0, 1, 0); gluBeginSurface(theNurb); gluNurbsSurface( ... ); gluEndSurface(theNurb); // more ... }

Slide 37

Slide 37 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 36 jgs Numbers to be considered // V_size curves with U_size control points each // V_size + ORDER knots per curve and // U_size + ORDER knots per inter-curve connection // offsets are V_size*3 and 3 // cubic equations ORDER = 4 GLfloat ctlpoints[U_size][V_size][3] = { … }; GLfloat vknots [V_size + ORDER] = { …}; GLfloat uknots [U_size + ORDER] = { …} gluNurbsSurface(theNurb,U_size + ORDER, uknots, V_size + ORDER, vknots, V_size * 3, 3, &ctlpoints[0][0][0], ORDER, ORDER, GL_MAP2_VERTEX_3);

Slide 38

Slide 38 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 37 jgs Screenshot 6 curves 6 control points each 5 curves 6 control points each 4 curves 6 control points each

Slide 39

Slide 39 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 38 jgs Problem A https://github.com/javiergs/SER431/blob/master/Lecture20/nurbs_surface_controlled.cpp

Slide 40

Slide 40 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 39 jgs Problem A // NURBS // How many curves? How many control points per curve? // How many knots per curve? How many knots per inter-curve connection? // Order for U and V? // Offset for U and V? GLfloat ctlpoints[4][4][3] = { { { 20, 0, 20 } ,{ 0, 0, 20 },{ 0, 0, 20 } ,{ -20, 0, 20 } }, { { 20, 0, 0 } ,{ 0, 20, 0 },{ 0, 20, 0 } ,{ -20, 0, 0 } }, { { 20, 0, 0 } ,{ 0, 20, 0 },{ 0, 20, 0 } ,{ -20, 0, 0 } }, { { 20, 0, -20 } ,{ 0, 0, -20 },{ 0, 0, -20 } ,{ -20, 0, -20 } } }; GLfloat uknots[8] = { 0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 3.0 }; GLfloat vknots[8] = { 0.0, 0.0, 0.0, 0.0, 3.0, 3.0, 3.0, 3.0 };

Slide 41

Slide 41 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 40 jgs Problem B https://github.com/javiergs/SER431/blob/master/Lecture20/nurbs_surface_controlled.cpp * There are 7 squares (i.e., 7 curves)in blue. * You need 8 control points per square; BUT since you want to close the curve. You may should need to add the first one again. Thus 8 + 1

Slide 42

Slide 42 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 41 jgs Problem B // NURBS // How many curves? How many control points per curve? // How many knots per curve? How many knots per inter-curve connection? // Order for U and V? // Offset for U and V? const int V_size = 9; const int U_size = 7; const int ORDER = 4; GLfloat ctlpoints[U_size][V_size][3] = { { { 0, -4, 0 }, { -4, -4, 0 } ,{ -4, 0, 0 }, { -4, 4, 0 }, { 0, 4, 0 }, { 4, 4, 0 }, { 4, 0, 0 }, { 4, -4, 0 }, { 0, -4, 0 } }, { { 0, -2, 4 }, { -2, -2, 4 } ,{ -2, 0, 4 }, { -2, 2, 4 }, { 0, 2, 4 }, { 2, 2, 4 }, { 2, 0, 4 }, { 2, -2, 4 }, { 0, -2, 4 } }, { { 0, -4, 8 }, { -4, -4, 8 } ,{ -4, 0, 8 }, { -4, 4, 8 }, { 0, 4, 8 }, { 4, 4, 8 }, { 4, 0, 8 }, { 4, -4, 8 }, { 0, -4, 8 } }, { { 0, 0, 10 }, { 0, 0, 10 } ,{ 0 , 0, 10 }, { 0, 0, 10 }, { 0, 0, 10 }, { 0, 0, 10 }, { 0, 0, 10 }, { 0, 0, 10 }, { 0, 0, 10 } }, { { 0, -1, 12 }, { -1, -1, 12 } ,{ -1, 0, 12 }, { -1, 1, 12 }, { 0, 1, 12 }, { 1, 1, 12 }, { 1, 0, 12 }, { 1, -1, 12 }, { 0, -1, 12 } }, { { 0, -2, 14 }, { -2, -2, 14 } ,{ -2, 0, 14 }, { -2, 2, 14 }, { 0, 2, 14 }, { 2, 2, 14 }, { 2, 0, 14 }, { 2, -2, 14 }, { 0, -2, 14 } }, { { 0, -4, 16 }, { -4, -4, 16 } ,{ -4, 0, 16 }, { -4, 4, 16 }, { 0, 4, 16 }, { 4, 4, 16 }, { 4, 0, 16 }, { 4, -4, 16 }, { 0, -4, 16 } } }; GLfloat vknots[V_size + ORDER]= {0.0, 0.0, 0.0, 0.0, 2.0, 4.0, 4.0, 4.0, 6.0, 8.0, 8.0, 8.0, 8.0 }; GLfloat uknots[U_size + ORDER]= { 0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 5.0, 6.0, 6.0, 6.0, 6.0 };

Slide 43

Slide 43 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 42 jgs Review This https://github.com/javiergs/SER431/blob/master/Lecture08/reflection.cpp

Slide 44

Slide 44 text

jgs Fractals

Slide 45

Slide 45 text

jgs Case 1: Symmetrical Stack boxes

Slide 46

Slide 46 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 45 jgs Code // create a pile of boxes as fractal void stackBoxes(float x, float y, float z) { if (y >= 0) { glPushMatrix(); glTranslatef(x, y*100, z*100/2); glCallList(display2); glPopMatrix(); stackBoxes(x-50, y-1, z-1); stackBoxes(x-50, y-1, z+1); stackBoxes(x+50, y-1, z-1); stackBoxes(x+50, y-1, z+1); } }

Slide 47

Slide 47 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 46 jgs Case 1 Level = 0 Level = 1 Level = 2 Level = 3 Level = 4

Slide 48

Slide 48 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 47 jgs Code vector thunderbolt; void createBolt(Vec3f p1, Vec3f p2, int level) { thunderbolt.push_back(Line(p1.x,p1.y,p1.z, p2.x,p2.y, p2.z)); for (int t = 0; t < level; t++) { int tam = thunderbolt.size(); Vec3f middle; int i; for (i = 0; i < tam; i++) { p1.x = thunderbolt[0].x1; p1.y = thunderbolt[0].y1; p1.z = thunderbolt[0].z1; p2.x = thunderbolt[0].x2; p2.y = thunderbolt[0].y2; p2.z = thunderbolt[0].z2; thunderbolt.erase(thunderbolt.begin()); middle = calculateMiddle(p1, p2, t); thunderbolt.push_back(Line(p1.x, p1.y, p1.z, middle.x,middle.y, middle.z)); thunderbolt.push_back(Line(middle.x, middle.y, middle.z, p2.x,p2.y, p2.z)); } // extension line Vec3f direction = middle - p1; Vec3f pin = middle + direction * 0.7; thunderbolt.push_back(Line(middle.x, middle.y, middle.z, pin.x, pin.y, pin.z)); } }

Slide 49

Slide 49 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 48 jgs Case 1 Level = 0 Level = 1 Level = 2 Level = 3 Level = 10

Slide 50

Slide 50 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 49 jgs Tree // full tree glNewList(FULLTREE, GL_COMPILE); glPushMatrix(); glTranslatef(0, -1, 0); fractalTree(0); glPopMatrix(); glEndList(); }

Slide 51

Slide 51 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 50 jgs void fractalTree(int level) { long savedseed; if (level == MAX_LEVEL) { glPushMatrix(); glRotatef(random_number() * 180, 0, 1, 0); glCallList(STEMANDLEAVES); glPopMatrix(); } else { glCallList(STEM); glPushMatrix(); glRotatef(random_number() * 180, 0, 1, 0); glTranslatef(0, 1, 0); glScalef(0.7, 0.7, 0.7); glPushMatrix(); glRotatef(110 + random_number() * 40, 0, 1, 0); glRotatef(30 + random_number() * 20, 0, 0, 1); fractalTree(level + 1); glPopMatrix();glPushMatrix(); glRotatef(-130 + random_number() * 40, 0, 1, 0); glRotatef(30 + random_number() * 20, 0, 0, 1); fractalTree(level + 1); glPopMatrix();glPushMatrix(); glRotatef(-20 + random_number() * 40, 0, 1, 0); glRotatef(30 + random_number() * 20, 0, 0, 1); fractalTree(level + 1); glPopMatrix(); glPopMatrix(); } }

Slide 52

Slide 52 text

Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 51 jgs Disclaimer This list of topics is not Comprehensive For a full list of topics review lectures 1 to 24

Slide 53

Slide 53 text

jgs SER431 Advanced Graphics Javier Gonzalez-Sanchez [email protected] Fall 2018 Disclaimer. These slides can only be used as study material for the class SER431 at ASU. They cannot be distributed or used for another purpose.