Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics, Lee Byung-Gook, Dongseo Univ.

Similar presentations


Presentation on theme: "Computer Graphics, Lee Byung-Gook, Dongseo Univ."— Presentation transcript:

1 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

2 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Lighting model Definition: a set of mathematical equations that calculate the color of each pixel that represents an object . Tradeoffs must be made between the speed of the rendering and the quality of the rendering. In general, as the accurately of the model approaches real world lighting effects, the better the graphics but the slower the rendering Speed of rendering Quality of graphics Fast Slow Low High Complex models Simple models 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

3 Light and object interaction
When light strikes an object it is: absorbed and converted to heat, reflected off the surface, or refracted (bent) and passed through (e.g., water, glass, cellophane) For an accurate lighting model, all three interactions must be accounted for, but we will concentrate on reflected light. Reflected light is the light that has bounced off of an object into our eye (or camera). Reflected light is the light we actually see. 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

4 Types of reflected light
Ambient light general light in a room; background light light that has been scattered in so many directions that it's source cannot be determined ambient light determines the color of the portion of an object not in direct light. This is sometimes referred to as an object's "back side," such as the "back side of the moon." the relative position of the object, camera, and light sources has no effect on ambient light 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

5 Types of reflected light
Diffuse light light that comes from one specific direction; scatters in all directions a surface is brighter (scatters more light) if it is perpendicular to the light direction diffuse light is what gives an object its predominate color and what makes an object look "curved" or "rounded." the relative position of the object to the light sources determines diffuse lighting. When a polygon is rendered, it is transformed by the MODELVIEW matrix, then projected on the viewing plane by the PROJECTION matrix, and then converted to screen (pixel) coordinates. After all of the polygon's vertices have been mapped to the screen by this "graphics pipeline," the pixels in the interior of the polygon are filled in, typically by a "scan line" algorithm. If the polygon is texture mapped, the color of each pixel is not the interpolated color from the vertices, but rather the correct color values from the texture image. This requires that the pixels be mapped into their correct position within the texture image. 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

6 Types of reflected light
Specular light light that comes from one specific direction and bounces off in one specific direction the amount of specular light is determined by the smoothness of an object specular light causes a "hot spot" on shiny objects. The "hot spot" moves as the observer moves the relative position of the object, camera, and light sources determine the amount of specular lighting. This is the identical problem we discussed last week-- that of scaling an image. There are two general solutions:After mapping the pixel into the texture imagetake the color of the closest texture pixel (OpenGL calls this GL_NEAREST, which produces fast, but poor graphics)take a linear average of the colors of the surrounding pixels. (OpenGL calls this GL_LINEAR, which produces better, but slower graphics) 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

7 Lighting Calculations
17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

8 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Notation i = the light number, as in {LIGHT0, LIGHT1, LIGHT2, … LIGHT7} d = distance between the light's position and the vertex kc = GL_CONSTANT_ATTENUATION kl = GL_LINEAR_ATTENUATION kq = GL_QUADRATIC_ATTENUATION Note: if the light is a "spotlight", the attenuation factors are ignored spotlight_effect 1, if it is not a spotlight 0, if it is a spotlight and the vertex is outside the cone of illumination max {vd,0}GL_SPOT_EXPONENT where v is the unit vector that points from the spotlight position to the vertex and d is the spotlight direction L = unit vector from the vertex to the light position n = normalized normal vector at the vertex s = (unit vector between the vertex and the light position) + (unit vector between the vertex and the camera position) 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

9 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Lab 20 downloading 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

10 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Shade Model void glShadeModel( GLenum mode ); mode : A symbolic value representing a shading technique. Accepted values are GL_FLAT and GL_SMOOTH. The default is GL_SMOOTH. OpenGL only does lighting calculations at the vertices of a face (not every pixel of the face). If the shade model is set to GL_FLAT, then the color calculated for the last vertex specified for the face will be use to color the entire face If the shade model is set to GL_SMOOTH, then the color is calculated for every vertex of the face and the color of interior pixels of the face are interpolated from the colors at the vertices Compositing occurs when a pixel's color value is determined by using a combination of two (or more) color values. When using texture maps we have 2 colors to deal with -- the color of the face and the color from the texture map. Let Ct - the color defined by the texture map, Cf - the color of the polygon (face), C - the color to be placed in the color buffer 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

11 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
glLightModel[f,i] These functions set the lighting model parameters. void glLightModelf(GLenum pname, GLfloat param); void glLightModeli(GLenum pname, GLint param); pname : A lighting model parameter. The following values are accepted: GL_LIGHT_MODEL_LOCAL_VIEWER GL_LIGHT_MODEL_TWO_SIDE 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

12 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
glLightModel[f,i]v These functions set the lighting model parameters. void glLightModelfv(GLenum pname, const GLfloat*params); void glLightModeliv( GLenum pname, const GLint *params); pname : A lighting model parameter. The following values are accepted: GL_LIGHT_MODEL_AMBIENT GL_LIGHT_MODEL_LOCAL_VIEWER GL_LIGHT_MODEL_TWO_SIDE 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

13 Light model parameters
GL_LIGHT_MODEL_AMBIENT The params parameter contains four integer or floating-point values that specify the ambient RGBA intensity of the entire scene. Integer values are mapped linearly such that the most positive representable value maps to 1.0, and the most negative representable value maps to –1.0. Floating-point values are mapped directly. Neither integer nor floating-point values are clamped. The default ambient scene intensity is (0.2, 0.2, 0.2, 1.0). The ambient of the light model is multiplied by the ambient properties of the material. Think of it as the desired percentage of the material ambient properties The ambient of the material is included for each light source along with the global light model ambient component. Think of the global ambient terms as being the one thing consistent for all objects, totally independent of any light source 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

14 Light model parameters
GL_LIGHT_MODEL_LOCAL_VIEWER The params parameter is a single integer or floating-point value that specifies how specular reflection angles are computed. If params is 0 (or 0.0), specular reflection angles take the view direction to be parallel to and in the direction of the –z axis, regardless of the location of the vertex in eye coordinates. Otherwise specular reflections are computed from the origin of the eye coordinate system. The default is 0. 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

15 Light model parameters
if GL_FALSE, the light vector used in the calculations is always the same. This provides faster rendering but poorer quality rendering if GL_TRUE, a new light vector is calculated for each color vertex calculation. This provides better quality rendering but at a slower speed Light Vectors Object Light Source Object Light Vectors 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

16 Light model parameters
GL_LIGHT_MODEL_TWO_SIDE The params parameter is a single integer or floating-point value that specifies whether one- or two-sided lighting calculations are done for polygons. It has no effect on the lighting calculations for points, lines, or bitmaps. If params is 0 (or 0.0), one-sided lighting is specified, and only the front material parameters are used in the lighting equation. Otherwise, two-sided lighting is specified. In this case, vertices of back-facing polygons are lighted using the back material parameters, and have their normals reversed before the lighting equation is evaluated. Vertices of front-facing polygons are always lighted using the front material parameters, with no change to their normals. The default is 0. 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

17 Light model parameters
if GL_FALSE, the back side of faces will receive no diffuse or specular light. (only ambient light) if GL_TRUE, the back side of faces is rendered just like the front side of faces. (When the back side is rendered, its normal vector is taken as the reverse of the normal vector for the front side.) 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

18 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Lab 21 downloading 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

19 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
glMaterial[f,i] These functions specify material parameters for the lighting model. void glMaterialf( GLenum face, GLenum pname, GLfloat param ); void glMateriali( GLenum face, GLenum pname, GLint param ); face : The face or faces that are being updated. Must be one of GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK. pname : The single-valued material parameter of the face or faces being updated. Must be GL_SHININESS. param : The value that parameter GL_SHININESS will be set to. 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

20 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
glMaterial[f,I]v These functions specify material parameters for the lighting model. void glMaterialfv(GLenum face,GLenum pname,const GLfloat *params); void glMaterialiv(GLenum face,GLenum pname,const GLint *params ); face : The face or faces that are being updated. Must be one of GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK. Pname : The material parameter of the face or faces being updated. The parameters that can be specified using glMaterial, and their interpretations by the lighting equation, are as follows: GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,GL_EMISSION, GL_SHININESS,GL_AMBIENT_AND_DIFFUSE, GL_COLOR_INDEXES 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

21 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Material properties Percentages Treat each value used to specify the material properties as a percentage 0.0 means 0% color 1.0 means 100% color Therefore, texture map coordinates are actually not restricted to the range (0.0, 1.0). They can be any values, but they still represent percentages of distances within texture images. When the values are outside the range (0.0, 1.0), the values refer to duplicate copies of the texture image. For example 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

22 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Material properties Material / Light interaction The ambient, diffuse, and specular components of the material are multiplied by the corresponding properties of light The ambient color is typically a shade of gray, since the human eye cannot see colors in low light. (Shades of gray have equal values of red, green and blue.) e.g., (0.3, 0.3, 0.3) The diffuse values determine the color (hue) of an object. For example, if you want a red ball, set the diffuse values to (1.0, 0.0, 0.0). Therefore, texture map coordinates are actually not restricted to the range (0.0, 1.0). They can be any values, but they still represent percentages of distances within texture images. When the values are outside the range (0.0, 1.0), the values refer to duplicate copies of the texture image. For example 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

23 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Material properties The specular values determine the color (hue) of the hotspot (highlight). Typically the light sources are white, so these values would typically be a shade of white (i.e., all values equal), such as (0.8, 0.8, 0.8). The emission values are added directly to the color calculations without any consideration of the light sources or the object's orientation. If the emission values are large (e.g., > 0.5), the color of every pixel will typically become saturated (1.0) and the object will lose all shading. 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

24 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
glLight[f,i] void glLightf( GLenum light, GLenum pname, GLfloat param ); void glLighti( GLenum light, GLenum pname, GLint param ); light : A light. The number of lights depends on the implementation, but at least eight lights are supported. They are identified by symbolic names of the form GL_LIGHTi where 0 ≤ i < GL_MAX_LIGHTS. pname : A single-valued light source parameter for light. The following values are accepted. GL_SPOT_EXPONENT,GL_SPOT_CUTOFF, GL_CONSTANT_ATTENUATION, GL_LINEAR_ATTENUATION, GL_QUADRATIC_ATTENUATION param : The value to which parameter pname of light source light will be set. 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

25 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
glLight[f,i]v void glLightfv( GLenum light, GLenum pname, const GLfloat *params ); void glLightiv( GLenum light, GLenum pname, const GLint *params ); pname : A light source parameter for light. The following values are accepted: GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR, GL_POSITION ,GL_SPOT_DIRECTION, GL_SPOT_EXPONENT,GL_SPOT_CUTOFF, GL_CONSTANT_ATTENUATION GL_LINEAR_ATTENUATION, GL_QUADRATIC_ATTENUATION params : A pointer to the value or values to which parameter pname of light source light will be set. 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

26 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Light types Directional light a light infinitely far away from the scene all light rays are parallel for example, the sun has a homogeneous coordinate (w) of 0 for example (3.0, 4.0, 2.0, 0.0) 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

27 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Light types Positional light a light inside the scene the light rays go in different directions for example, a table lamp has a homogeneous coordinate (w) of 1 for example (3.0, 4.0, 2.0, 1.0) 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

28 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Light types Spot light a positional light with a restricted cone of illumination GL_SPOT_CUTOFF determines the size of the cone, as in the following diagram GL_POSITION (position) GL_SPOT_DIRECTION (vector) GL_SPOT_CUTOFF (angle; 0-90 degrees) 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

29 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Light types The intensity of the beam varies, depending on the angle between the GL_SPOT_DIRECTION and the light ray. Light rays along the spot direction are calculated at 100% intensity, while the light rays at the periphery of the cone are at lower intensities. A cos curve raised to the GL_SPOT_EXPONENT power is used to calculated the intensity of light at various positions within the cone of illumination. All positions outside of the cone get 0% light 100% light 70% light 5% light 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

30 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Positioning lights Directional lights have no position, only direction The position and direction of a positional light source is multiplied by the current transformation matrix. It is very important that the camera of a scene be established before the position and direction of lights are specified The correct ordering of statements to place positional lights within a scene is Clear buffer (glClear()) Clear transformations (glLoadIdentity()) Set up camera transformations Set the light position (and direction if it is a spotlight) Draw the objects in the scene. 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

31 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Dr. Nate Robins 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

32 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Notes OpenGL is a state machine. Therefore, if a parameter value never changes during the execution of a program, the value should only be set once. This increases the speed of rendering For example, if the linear attenuation of a light source never changes, set the attenuation once in your "init" function void init() { glLightf(GL_LIGHT0, GL_CONSTANT_ATTENTUATION, 1.0); glLightf(GL_LIGHT0, GL_LINEAR_ATTENTUATION, 0.0); glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENTUATION, 0.0); } 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

33 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Notes The exception to this "state machine" concept is lighting. The position and direction of light sources are multiplied by the current transform when they are specified. The position and direction of a light source needs to be specified only once if the camera never moves (and the camera was set up before they are specified). OpenGL only applies the light model calculations to the vertices of a polygon. To increase the accuracy of the lighting effects, you must decrease the sizes of the polygons that define your objects. (Which makes rendering slower.) 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

34 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Notes The shading calculations are very depend on a correct normal vector defined for each face. The face normal vector is expected to be defined in normalized form (of unit length). When an object is transformed by the current transformation matrix, both its vertices and normal vectors are transformed. If any scaling is part of the current transformation, the normal vectors will become un-normalized You need to enable the feature that will re-normalize the normal vectors if: Your normal vectors were not initially specified in normal form Your transformations include scaling glEnable(GL_NORMALIZE); 17 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.


Download ppt "Computer Graphics, Lee Byung-Gook, Dongseo Univ."

Similar presentations


Ads by Google