欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    3D游戏编程OpenGL光照.pdf

    • 资源ID:70322506       资源大小:4.91MB        全文页数:41页
    • 资源格式: PDF        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    3D游戏编程OpenGL光照.pdf

    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?Lighting!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 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 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 illumination 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 Programming 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 incident 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 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 and 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 =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 reflected 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 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(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 Can 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 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(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 Define 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 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 Triangle 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.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 Lights Position Game Programming IIGame Programming II Light Intensity Ambient light:GL_AMBIENT Diffuse light:GL_DIFFUSE Specular light:GL_SPECULAR GLfloat position0=1.0,1.0,1.0,0.0;GLfloat diffuse0=1.0,0.0,0.0,1.0;/Id term-Red GLfloat specular0=1.0,1.0,1.0,1.0;/Is term-White GLfloat ambient0=0.1,0.1,0.1,1.0;/Ia term-Gray glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);glLightfv(GL_LIGHT0,GL_POSITION,position0);glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuse0);glLightfv(GL_LIGHT0,GL_SPECULAR,specular0);glLightfv(GL_LIGHT0,GL_AMBIENT,ambient0);Game Programming IIGame Programming II Point Light A light source originating from a zero-volume point in the scene Casts light in all directions /Light position GLfloat light_position=50.0,100.0,-50.0,1.0;/Apply the light position glLightfv(GL_LIGHT0,GL_POSITION,light_position);Position For Positions this should be 1.0 Game Programming IIGame Programming II Directional Light A light infinitely far away from the drawn scene Used most often for emulating sunlight /Light direction down the negative x axis GLfloat light_direction=-1.0,0.0,0.0,0.0;/Apply the light direction glLightfv(GL_LIGHT0,GL_POSITION,light_direction);Direction-should be normalized-For Directions this should be 0.0 Game Programming IIGame Programming II Spot Light Spot light is a close light source with direction,angle and exponential drop off void glLight*(GLenum light,GLenum param,TYPE value);void glLight*v(GLenum light,GLenum param,TYPE*value);Param:GL_SPOT_DIRECTION:direction of light is focused on GL_SPOT_CUTOFF(default 180o):angle that defines light cone GL_SPOT_EXPONENT(default 0):concentration of the light Game Programming IIGame Programming II Attenuation of Light Real light intensity becomes weaker over distance Attenuation with distance generates a softer and more realistic image:d is the distance computed by OpenGL a=GL_CONSTANT_ATTENUATION(default 1.0)b=GL_LINEAR_ATTENUATION(default 0.0)c=GL_QUADRATIC_ATTENUATION(default 0.0)Default is not attenuation Affects diffuse component Game Programming IIGame Programming II Material You can only see the effect of light source when light reflects off objects surface Material describes the amount of light reflected by surface Material defines the reflection ratio for ambient,diffuse,specular light independently Material defines the reflection ratio for R,G,B components of light source independently Material can be specified for front and back faces Game Programming IIGame Programming II RGB in Light Source and Material Both light source and material use RGB mode Light:RGB represents the intensity (0.5,0.4,0):the intensity of red,green and blue light is 0.5,0.4,0 respectively Material RGB represents reflection ratio (0.5,0.4,0):50%,40%,0%of incident red,green and blue light is reflected respectively If light is(0.5,0.4,0)and material is(0.8,0,0.2),then the reflected light we see is(0.4,0,0)Game Programming IIGame Programming II Specifying a Material 1/2 Main functions to set scalar or vector parameters for OpenGL faces:void glMaterial*(GLenum face,GLenum param,TYPE value);void glMaterial*v(GLenum face,GLenum param,TYPE*value);face:GL_FRONT,GL_BACK,GL_FRONT_AND_BACK Game Programming IIGame Programming II Specifying a Material 2/2 param:GL_AMBIENT /ka term GL_DIFFUSE /kd term GL_SPECULAR /ks term GL_SHININESS /exponent n GL_AMBIENT_AND_DIFFUSE /ka=kd Game Programming IIGame Programming II Front and Back Face Each polygon face has two sides:inside or backside OpenGL has no notion of inside or backside,it can only distinguish between front and back face A face is a front face if its vertices are listed in CounterClockWise(CCW)order as seen by the eye Game Programming IIGame Programming II Specifying a Material:Example/Define GLfloat arrays to hold material data GLfloat mat_ambient=0.3,0.3,0.3,1.0;GLfloat mat_diffuse=0.8,0.8,0.8,1.0;GLfloat mat_specular=1.0,1.0,1.0,1.0;/Shininess will be an array of length 1 GLfloat mat_shininess=50.0;/Apply the material properties to the front facing glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);Game Programming IIGame Programming II Shading Model in OpenGL 1/3 Flat shading:glShadeModel(GL_FLAT)Selects the color of just one vertex and assigns it to all fragments generated by rasterizing a single primitive.Game Programming IIGame Programming II Shading Model in OpenGL 2/3 Smooth shading:glShadeModel(GL_SMOOTH)Default shading model in OpenGL Colors of vertices are interpolated as the primitive is rasterized Game Programming IIGame Programming II Shading Model in OpenGL 3/3 GL_FLAT(middle figure)Low computation cost Bad for smooth surface GL_SMOOTH(right figure)Need more computation Better result Game Programming IIGame Programming II 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 Game Programming IIGame Programming II DEMO Demo program illustrates Render simple geometries by GLUT GL_FLAT and GL_SMOOTH Configure light source Configure material The interaction between light source and material The affection of GL_SHININESS on specular light The relationship between shading results and geometric complexity Specify light sources position in different coordinate system Game Programming IIGame Programming II Assignment Render a scene including three teapots and three light sources Teapots Each teapot has different material Each teapot can be rotated by mouse independently(when one teapot is rotated by mouse,the other two teapots remain static)You can use keyboard to select the current active teapot Game Programming IIGame Programming II Assignment Light sources(turn on them simultaneously)Each light source has different diffuse and specular component Light source 1:Defined in world coordinate system,rotating around the three teapots Light source 2:Defined in camera coordinate system Light source 3:Defined in object coordinate system of teapot 1,it has to rotate with teapot 1 when you rotate teapot 1 with mouse Deadline:2011-10-30 Please submit your assignment to teach assistants by email

    注意事项

    本文(3D游戏编程OpenGL光照.pdf)为本站会员(asd****56)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开