1 / 27

Hidden Surface & Lighting

Hidden Surface & Lighting. Presentation modified from a presentation at OpenGL.org. Hidden Surface. Hidden Surface Removal is very important in 3D scenes Only surfaces closest to the eye should be seen and objects that are hidden by others should be eliminated.

Download Presentation

Hidden Surface & Lighting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Hidden Surface & Lighting Presentation modified from a presentation at OpenGL.org

  2. Hidden Surface • Hidden Surface Removal is very important in 3D scenes • Only surfaces closest to the eye should be seen and objects that are hidden by others should be eliminated. • The use of a depth buffer facilitates hidden surface removal.

  3. Hidden Surface Removal • To use depth-buffering, you need to enable it: • glutInitDisplayMode (GLUT_DEPTH | ..); • glEnable (GL_DEPTH_TEST);

  4. Hidden Surface Removal • Initialize the depth buffer and color buffer by using: • glClear(GL_DEPTH_BUFFER_BIT | • GL_COLOR_BUFFER_BIT);

  5. Hidden Surface Removal • glutInitDisplayMode (GLUT_DEPTH | ..); • glEnable (GL_DEPTH_TEST); • ... • //in display function • glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); • draw3DObjectA(); • draw3DObjectB();

  6. Lighting Principles • Lighting simulates how objects reflect light • Lighting properties • Light’s color and position • Material composition of object • Global lighting parameters • ambient light • two sided lighting • available in RGBA mode

  7. Lighting Properties: • Light comes from light sources that can be turned on/off • Ambient lighting comes from light that is so scattered there is no way to tell its original location • Example: Backlighting in a room

  8. Lighting Properties: • The diffuse component of lighting is light that comes from one direction. • Once it hits a surface, it is scattered equally in all directions

  9. Lighting Properties: • Specular light comes from a particular direction. • It bounces off the surface in a particular direction

  10. RGB Values for Lights • A light source is characterized by the amount of red, green, & blue light it emits. • Examples: If R=G=B=1.0, the light is the brightest possible white. • If R=G=B=.5, the color is still white, but only at half intensity, so it appears gray. • If R=G=1.0 and B=0.0, the light appears yellow.

  11. Setting Lighting Properties • glLightfv( light, property, value ); • light specifies which light • multiple lights (at least 8), starting with GL_LIGHT0 • properties • Colors for ambient, diffuse, & specular components • position and type • attenuation

  12. Types of Lights • OpenGL supports two types of Lights • Local (Point) light sources • Infinite (Directional) light sources • Type of light controlled by w coordinate

  13. Light Sources (cont.) • Light color properties • GL_AMBIENT • GL_DIFFUSE • GL_SPECULAR

  14. Turning on the Lights • Flip each light’s switch glEnable( GL_LIGHTn ); • Turn on the power glEnable( GL_LIGHTING );

  15. Controlling a Light’s Position • Modelview matrix affects a light’s position • Different effects based on whenposition is specified • eye coordinates • world coordinates • model coordinates • Push and pop matrices to uniquely control a light’s position

  16. Advanced Lighting Features • Spotlights • localize lighting affects • GL_SPOT_DIRECTION • GL_SPOT_CUTOFF • GL_SPOT_EXPONENT

  17. Advanced Lighting Features • Light attenuation • decrease light intensity with distance • GL_CONSTANT_ATTENUATION • GL_LINEAR_ATTENUATION • GL_QUADRATIC_ATTENUATION

  18. Light Model Properties • glLightModelfv( property, value ); • Enabling two sided lighting GL_LIGHT_MODEL_TWO_SIDE • Global ambient color GL_LIGHT_MODEL_AMBIENT • Local viewer mode GL_LIGHT_MODEL_LOCAL_VIEWER • Separate specular color GL_LIGHT_MODEL_COLOR_CONTROL

  19. How OpenGL Simulates Lights • Gourad lighting model • Computed at vertices • Lighting contributors • Light properties • Lighting model properties • Surface material properties

  20. Material Properties • Material’s color depends on % of incoming R,G,B light it reflects. • Material Properties: • Ambient is color of the object from all the undirected light in a scene. • Diffuse is the base color of the object under current lighting. There must be a light shining on the object to get a diffuse contribution. • Specular is the contribution of the shiny highlights on the object. • Emission is the contribution added in if the object emits light (i.e. glows)

  21. Material Properties • Color Components for lights mean something different than for materials. • Example: if R = 1, G = 0.5, and B = 0 for a material, that material reflects all the incoming red light, half the incoming green light, and none of the incoming blue light.

  22. GL_DIFFUSE Base color GL_SPECULAR Highlight Color GL_AMBIENT Low-light Color GL_EMISSION Glow Color GL_SHININESS Surface Smoothness Material Properties • Define the surface properties of a primitive • glMaterialfv( face, property, value ); • separate materials for front and back

  23. Light Material Tutorial

  24. Light Position Tutorial

  25. Per Vertex Poly. Frag FB Raster CPU DL Texture Pixel SurfaceNormals • Normals define how a surface reflects light • glNormal3f( x, y, z ) • Current normal is used to compute vertex’s color • Use unit normals for proper lighting • scaling affects a normal’s length glEnable( GL_NORMALIZE )orglEnable( GL_RESCALE_NORMAL )

  26. Steps for adding lighting • 1. Define normal vectors for each vertex of every object. These normals determine the orientation of the object relative to the light source. • Create, select, and position one or more light sources. • Create and select a lighting model, which defines the level of global ambient light and the effective location of the viewpoint. • Define material properties for the objects in the scene.

  27. Tips for Better Lighting • Recall lighting computed only at vertices • model tessellation heavily affects lighting results • better results but more geometry to process • Use a single infinite light for fastest lighting • minimal computation per vertex

More Related