1. Trang chủ
  2. » Giáo Dục - Đào Tạo

Lighting (đồ họa máy TÍNH SLIDE)

32 19 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Lighting Calculating the color of objects • The incident light – – – • Direction Color The object – • Position of light source Reflectance Viewer – Position Overview  Illumination: how to calculate the colour?  Shading: how to colour the whole surface? Illumination • Simple parameter model – The sum of illumination terms: • • • Ambient : 'background' illumination Specular : bright, shiny reflections Diffuse : non-shiny illumination and shadows + = + Ambient Diffuse Specular (colour) (directional) (highlights) R c Ambient Lighting • • • Light from the environment – – – Light reflected or scattered from other objects Coming uniformly from all directions and then reflected equally to all directions Ex: – Backlighting in a room has a large ambient component, since most of the light that bounced off many surfaces Example: sphere Result: globally uniform colour for object I = kaIa I = resulting intensity Ia = light intensity Object ka = reflectance Diffuse Lighting • • Light reflected to all directions – – – the light that comes from one direction considers the angle of incidence of light on surface scattered equally in all directions, no matter where the eye is located Result: lighting varies over surface with orientation to light Example: sphere (lit from left) Infinite point I = Ip kd cosθ Ip : Light Intensity N light source Ln V θ θ : the angle between the normal vector and direction toward the light Object No dependence on camera angle! kd : diffuse reflectivity Specular Lighting • • Direct reflections of light source off shiny object – specular intensity n = shiny reflectance of object Result: specular highlight on object I = Ip ks cosnα Infinite point N light source R (Reflection) Ip: light intensity I : output color Ln θ θ α V R : reflection vector V : direction towards the camera α : angle between R and V No dependence on object colour Object Specular Light • Specular light with different n values Combined Lighting Models • Summing it altogether : Phong Illumination Model n Iλ = Ia ka + Ip (kd cosθ + ks cos α ) + = + Ambient Diffuse Specular (colour) (directional) (highlights) R c When you implement it … • Use dot product of the vectors instead of calculating the angles Iλ = Ia ka + Ip (kd N• L + ks (V• R)n) V : Vector from the surface to the viewer N : Normal vector at the colored point R : Normalized reflection vector L : Normalized vector from the coloured point towards the light source Infinite point N light source R (Reflection) Ln θ θ α V Object 10 Material Properties Example float mat_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f }; float mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f }; float mat_shininess[] = { 50.0f }; gl.glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); gl.glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); gl.glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); 18 19 Light Material Demo 21 Light Properties • OpenGL approximates light and lighting as if light can be broken into red, green, and blue components – • Thus, the color of a light source is characterized by the amounts of red, green, and blue light it emits glLightfv(light, property, value); – – light specifies which light • multiple lights, starting with GL_LIGHT0 glGetIntegerv(GL_MAX_LIGHTS, n); property • • • colors position and type attenuation 22 Light Sources (cont.) • Light color properties – – – GL_AMBIENT GL_DIFFUSE GL_SPECULAR float light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; float light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; float light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; float light_position[] = { 1.0, 1.0, 1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT0, GL_POSITION, light_position); 23 24 Turning on the Lights • Flip each light’s switch – • glEnable( GL_LIGHTn ); Turn on the power – glEnable( GL_LIGHTING ); 25 Types of Lights • OpenGL supports two types of Lights – – • Local (Point) light sources Infinite (Directional) light sources Type of light controlled by w coordinate w light = 0source Infinite Local w≠0 Light directed along ( x Local Light positioned at float light_position[] = { 1.0f, 1.0f, 1.0f, 1.0f }; gl.glLightfv(GL_LIGHT0, GL_POSITION,light_position); (xw y Infinite light source float light_position[] = { 1.0f, 1.0f, 1.0f, 0.0f }; gl.glLightfv(GL_LIGHT0, GL_POSITION, light_position); 26 z) y w z w ) Controlling a Light’s Position • • Modelview matrix affects a light’s position Different effects based on when position is specified – – – • eye coordinates world coordinates model coordinates Push and pop matrices to uniquely control a light’s position 27 Controlling a Light’s Position • • Modelview matrix affects a light’s position Three different effects by changing the point in the program at which the light position is set, relative to modeling or viewing transformations: – – – A light position that remains fixed A light that moves around a stationary object A light that moves along with the viewpoint 28 Light Position Tutorial 29 Advanced Lighting Features • Spotlights Click to edit Master text styles Second level Third level – Fourth level localize lighting affects • • • Fifth level GL_SPOT_DIRECTION GL_SPOT_CUTOFF GL_SPOT_EXPONENT float[] spot_direction = { -1.0, -1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spot_direction ); 30 Advanced Lighting Features • Light attenuation – decrease light intensity with distance • • • GL_CONSTANT_ATTENUATION GL_LINEAR_ATTENUATION GL_QUADRATIC_ATTENUATION fi = kc + kl d + k q d 31 Selecting a Lighting Model glLightModelfv(property, value); • • • • Enabling two sided lighting: uses the front and back material properties for illuminating a primitive – GL_LIGHT_MODEL_TWO_SIDE Global ambient color: ambient RGBA intensity of the entire scene – GL_LIGHT_MODEL_AMBIENT Local viewer mode: how specular reflection angles are computed – GL_LIGHT_MODEL_LOCAL_VIEWER Separate specular color – GL_LIGHT_MODEL_COLOR_CONTROL 32 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 33 ... Simulates Lights • Phong lighting model – • Computed at vertices Lighting contributors – – – Surface material properties Light properties Lighting model properties 14 Adding Lighting to Your Scene... Principles • Lighting simulates how objects reflect light – – – material composition of object light’s color and position global lighting parameters • • • ambient light two sided lighting available... – GL_LIGHT_MODEL_COLOR_CONTROL 32 Tips for Better Lighting • Recall lighting computed only at vertices – model tessellation heavily affects lighting results • • better results but more geometry

Ngày đăng: 29/03/2021, 08:20

Xem thêm:

TỪ KHÓA LIÊN QUAN

Mục lục

    Calculating the color of objects

    When you implement it …

    How OpenGL Simulates Lights

    Adding Lighting to Your Scene

    Turning on the Lights

    Controlling a Light’s Position

    Controlling a Light’s Position

    Selecting a Lighting Model

    Tips for Better Lighting

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w