Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SER431 Lecture 25

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

SER431 Lecture 25

Advanced Graphics
Final Review
(201812)

Javier Gonzalez-Sanchez PRO

November 29, 2018

Transcript

53 slides
  1. jgs SER 431 Advanced Graphics Lecture 25: Final Review Javier

    Gonzalez-Sanchez [email protected] PERALTA 230U Office Hours: By appointment
  2. 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 å = - =
  3. 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 å = - =
  4. 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
  5. 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
  6. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 8 jgs

    Graphics https://www.youtube.com/watch?v=aviL3HX3UEc
  7. 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 }
  8. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 11 jgs

    AABB Calculate AABB Draw AABB with lines
  9. 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?
  10. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 14 jgs

    Step 2. init() void init() { // ... glClearStencil(0); }
  11. 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); // <Render stencil box>
  12. 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);
  13. 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(); }
  14. 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);
  15. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 20 jgs

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

    Graphics https://www.youtube.com/watch?v=aviL3HX3UEc
  17. 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
  18. 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
  19. 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
  20. 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
  21. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 30 jgs

    Apply Chaikin Algorithm Qi=3/4Pi + 1/4Pi+1 Ri=1/4Pi + 3/4Pi+1
  22. 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;
  23. 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); // }
  24. 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 ... }
  25. 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);
  26. 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
  27. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 38 jgs

    Problem A https://github.com/javiergs/SER431/blob/master/Lecture20/nurbs_surface_controlled.cpp
  28. 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 };
  29. 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
  30. 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 };
  31. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 42 jgs

    Review This https://github.com/javiergs/SER431/blob/master/Lecture08/reflection.cpp
  32. 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); } }
  33. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 46 jgs

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

    Code vector <Line> 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)); } }
  35. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 48 jgs

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

    Tree // full tree glNewList(FULLTREE, GL_COMPILE); glPushMatrix(); glTranslatef(0, -1, 0); fractalTree(0); glPopMatrix(); glEndList(); }
  37. 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(); } }
  38. 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
  39. 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.

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming