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

SER431 Lecture 07

SER431 Lecture 07

Advanced Graphics
Environment (Fog)
(201809)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez

September 06, 2018
Tweet

Transcript

  1. jgs SER 431 Advanced Graphics Lecture 07: Environment Javier Gonzalez-Sanchez

    javiergs@asu.edu PERALTA 230U Office Hours: By appointment
  2. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 1 jgs

    Fog
  3. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 2 jgs

    Fog
  4. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 3 jgs

    Add this Code to your init() method 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);
  5. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 4 jgs

    Fog Mode and Density
  6. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 5 jgs

    Test Yourselves § Test 1. Add fog to your quiz 2 § Test 2. Add a menu that allows enable/disable the fog
  7. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 6 jgs

    Reflection and Shadows
  8. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 7 jgs

    Reflection and Shadows We will use the Stencil Buffer
  9. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 8 jgs

    Buffers (Color + Depth) § An extra data buffer, in addition to the color buffer and depth buffer § Depth-buffer. it keep track of the depth of every pixel on the screen
  10. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 9 jgs

    Buffers (Stencil) § Stencil-buffer. it is used to limit the area of rendering (stenciling) § Usually contains 8 bits per stencil value that amounts to a total of 256 different stencil values
  11. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 10 jgs

    Example
  12. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 11 jgs

    Step 1. main() // main void main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA | GLUT_STENCIL ); // main as usual here... }
  13. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 12 jgs

    Step 2. init() // init void init() { // init as usual here... //define the value to use as clean. glClearStencil(0); }
  14. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 13 jgs

    Step 3. display() void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //Start using the stencil glEnable(GL_STENCIL_TEST); //Disable writing colors in frame buffer glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glStencilFunc(GL_ALWAYS, 1, 1); //Place a 1 where rendered //Replace where rendered glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); //Render stencil box glDisable(GL_DEPTH_TEST);
  15. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 14 jgs

    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();
  16. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 15 jgs

    // re-enable color glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // where a 1 was not rendered.. try GL_NOTEQUAL glStencilFunc(GL_EQUAL, 1, 1); // keep the pixel glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glEnable(GL_DEPTH_TEST); // display as usual here... glDisable(GL_STENCIL_TEST); glutSwapBuffers(); }
  17. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 16 jgs

    Example
  18. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 17 jgs

    Next step
  19. jgs SER431 Advanced Graphics Javier Gonzalez-Sanchez javiergs@asu.edu 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.