3D游戏编程OpenGL光照.pdf
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《3D游戏编程OpenGL光照.pdf》由会员分享,可在线阅读,更多相关《3D游戏编程OpenGL光照.pdf(41页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、OpenGL:Lighting Yanci Zhang Game Programming IIGame Programming II Basic concepts of lighting Lighting in OpenGL Light properties Material properties Game Programming IIGame Programming II Outline Rendering result from last lesson Does it look like a 3D object?Certainly not!What are the problems?Lig
2、hting!Game Programming IIGame Programming II What We Have Now A Lit and an Unlit Sphere It Does Make a Difference!Objects do not have 3D appearance without lighting Lighting simulates how objects reflect light Two different lighting models in graphics Global illumination:high realistic but high cost
3、 Local illumination:low realistic but low cost Game Programming IIGame Programming II Lighting In the real world Light might be reflected multiple times Light might be occluded Global illumination tries to simulate these phenomena Game Programming IIGame Programming II Global Illumination The color
4、of any point on surfaces is only influenced by Its own properties(position,normal,material)Light attributes The color is NOT influenced by any other points in scene Low computation cost but cannot produce shadows,multiple reflections Game Programming IIGame Programming II Local Illumination Local il
5、lumination Vertex-based lighting Lighting is a state which can be switched on or off OpenGL divides lighting into three parts:Material properties Light properties Global lighting parameters ambient light two sided lighting Game Programming IIGame Programming II Lighting in OpenGL 1/3 Game Programmin
6、g IIGame Programming II Lighting in OpenGL 2/3 Light is modeled in four categories:Emission light(always ignored!)Ambient light View-independent Simulate light in the environment Diffuse light View-independent Simulate incident ray is reflected at many angles Specular light View-dependent Simulate i
7、ncident ray from a single incoming direction is reflected into a single outgoing direction Game Programming IIGame Programming II Lighting in OpenGL 3/3 Formula:ambient +diffuse +specular =shading result Game Programming IIGame Programming II Ambient Lighting Approximate low level of light normally
8、presenting everywhere in scene Scattered by many objects before reaching eye Constant terms Applies equally to all points on object Game Programming IIGame Programming II Diffuse Lighting Approximate light scattered by objects with rough surfaces Intensity depends on the angle between light source a
9、nd surface normal Game Programming IIGame Programming II Specular Lighting Approximate light reflected by“shiny”objects with smooth surfaces Intensity depends on the angle between viewer and direction of reflected ray Game Programming IIGame Programming II The Equation I=Iambient+Idiffuse+Ispecular
10、=kaIa+kdId(NL)+ksIs(RV)n illumination of surface ambient light intensity of the ambient light intensity of the diffuse light diffuse reflection of incident light specular reflection of incident light intensity of the specular light surface normal vector from point to light vector from point to eye r
11、eflected ray Game Programming IIGame Programming II Color in OpenGL Two color modes in OpenGL RGBA:Specifies color using either a 3 or 4 tuple value to represent r,g,b or r,g,b,a values glColor3/4b,s,i,f,d,ub,us,ui()Color index mode Color acts as a typical OpenGL state variable,so the color value is
12、 retain until another call to glColor Game Programming IIGame Programming II RGBA Mode Any color is represented by a combination of Red,Green,Blue For computer monitor,each component is represented by 8 bits at most Support 256*256*256=16,777,216 different colors White(255,255,255),black(0,0,0),red(
13、255,0,0)R,G,B can also be represented by 0,1 float in OpenGL Value exceeds 0,1 will be clamped White(1.0,1.0,1.0),black(0,0,0),red(1.0,0,0)Game Programming IIGame Programming II OpenGL Light Source 1/3 Assumptions Light travels in a straight line Ideal point light source Modeled by position+color Ca
14、n take into account decay with respect to distance Ambient light General brightness A rough model for inter-surface reflections from all light sources Game Programming IIGame Programming II OpenGL Light Source 2/3 Must remember to call glEnable(GL_LIGHTING)to turn on lighting Multiple light sources
15、are supported At least eight light sources are supported in OpenGL Each light source has its own status glEnable(GL_LIGHTi)Game Programming IIGame Programming II OpenGL Light Source 3/3 To enable lights from a single source(Light0)glEnable(GL_LIGHTING)glEnable(GL_LIGHTi)Defaults Light 0:white light(
16、1.0,1.0,1.0,1.0)for diffuse and specular components Other lights:black(0.0,0,0,0,0,1.0)Position:(0.0,0.0,1.0,0.0);w=0.0 means a direction,not a point IMPORTANT:Once lighting is enabled,colors assigned by glColor*()are no longer used Game Programming IIGame Programming II Configure Light Source Defin
17、e attributes of light source by glLight(GLenum light,GLenum pname,TYPE param light:light ID.Identified by symbolic names GL_LIGHTi and at least eight light sources are supported pname:name of attributes param:value of attributes Game Programming IIGame Programming II Normals When specifying polygon
18、vertices,the normal vectors to each vertex must be supplied void glNormal3*(TYPE dx,TYPE dy,TYPE dz)Lighting calculations require unitary normals To enable automatic normalization,use:glEnable(GL_NORMALIZE);2D Normal Normal Tangent Tangent Plane 3D Game Programming IIGame Programming II Normal for T
19、riangle Plane:=Normal vector:=Note that right-hand rule determines outward face p0 p1 p2 n p Game Programming IIGame Programming II Specifying Normal Vector Example glBegin(GL_TRIANGLES);glNormal3f(0.0,0.0,1.0);glVertex3f(0.0,0.0,0.0);glNormal3f(0.0,0.0,1.0);glVertex3f(10.0,0.0,0.0);glNormal3f(0.0,0
20、.0,1.0);glVertex3f(0.0,10.0,0.0);glEnd();Modelview matrix affects a lights position Different effects based on when position is specified eye coordinates world coordinates model coordinates Push and pop matrices to uniquely control a lights position Game Programming IIGame Programming II Controlling
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 游戏 编程 OpenGL 光照
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内