1 / 27

第二课

第二课. Lighting enabled. Lighting disabled. Overview of this Section. Lighting ( 光照 ) & Material ( 材质 ) OpenGL Implementation. Lighting. Simple illumination 简单光照模型 简单光照模型是经验模型 计算量相对较小,适合实时绘制要求 OpenGL 、 Direct3D 直接支持 Local illumination 局部光照模型 BRDF( 双向反射分布函数 ) 等

bayle
Télécharger la présentation

第二课

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. 第二课

  2. Lighting enabled Lighting disabled Overview of this Section • Lighting (光照) & Material (材质) • OpenGL Implementation

  3. Lighting • Simple illumination 简单光照模型 • 简单光照模型是经验模型 • 计算量相对较小,适合实时绘制要求 • OpenGL、Direct3D直接支持 • Local illumination 局部光照模型 • BRDF(双向反射分布函数)等 • Global illumination 整体光照模型 • 光线跟踪、辐射度等

  4. Simple Illumination • Reflection, Transmission, Absorption • Reflection • Specular Reflection (镜面反射) • Diffuse Reflection (漫反射) • Phong 模型 • 理想漫反射 + 镜面反射 + 环境光

  5. Phong • Diffuse (理想漫反射) • View Independent (视点无关) • Id = IpKd*(L∙N) • Specular (镜面反射) • View Dependent (视点相关) • Is = IpKs(R∙V)n • Ambient (环境光) • 均匀分布 • Ie = IaKa

  6. Phong • I = IaKa + IpKs(R∙V)n + IpKd*(L∙N) • 实际计算中 • H∙N替代R∙V • H为L和V的平分向量

  7. Phong • 第一个有影响的光照模型,视觉效果接近真实 • 缺乏质感、存在部分失真等

  8. Gourand & Phong 明暗处理 • 同一多边形内部法向一致,颜色相同 • 不同多边形邻接处有明显光强突变 • 双线性光强插值 Gourand明暗处理 • 双线性法向插值 Phong明暗处理

  9. Gourand明暗处理 • 计算多边形顶点平均法向 • Phong模型计算顶点光强 • 插值计算边上的各点光强 • 插值计算多边形内部各点光强

  10. Phong明暗处理 • 计算多边形顶点平均法向 • 插值离散边上各点法向 • 插值多边形内部法向 • 计算各像素光强度

  11. 插值效果 • Gourand插值计算量小,但会影响高光效果绘制 • Phong插值计算量大,真实感更高

  12. Light in OpenGL • Ambient Color • 光源的环境光,一般为 零 • Diffuse Color • 可被认为是光源的颜色 • Specular Color • 一般与Diffuse颜色相当

  13. Light Ambient : Green Diffuse : Red Specular : Blue

  14. Material in OpenGL • Material • 描述对入射光的反射系数 • Diffuse • 描述物体颜色最重要的参数 • Ambient • 受全局环境光以及各光源环境光影响

  15. Material in OpenGL • Specular & Shininess • Shininess控制高光的程度 • Emission • 使物体看上去像是在发光,但实际上并不等于光源,一般用来模拟光源

  16. OpenGL Lighting • 顶点颜色计算模型 • Emission + Global Light Ambient * Material Ambient + ∑(Lighti Ambient * Material Ambient + Lighti Specular * Material Specular + Lighti Diffuse * Material Diffuse) • 材质自发光属性 并不等于光源

  17. Put Light into OpenGL • 绘制步骤 • 为每个物体顶点设定法向 • 创建光源,并设定位置 • 创建和选择光照模型 • 设置物体材质属性

  18. Assign Normal Vector • 设定顶点法向 • glNormal{34}{isfd}[v](TYPE* normal); • Assign normal vector for vertices (the normal vector should be assigned before you assign vertices). • Normal vectors must be normalize. OpenGL can automatically normalize normal vector by glEnable(GL_NORMALIZE);

  19. Sample: Assign Normal Vector glBegin(GL_TRIANGLE); glNormal3f(0.0, 1.0, 0.0); glVertex3f(1.0, 0.0, 0.0); glVertex3f(0.0, 0.0, -1.0); glVertex3f(-1.0, 0.0, 0.0); glEnd();

  20. Light Source • 启用并设置光源参数 • Use glEnable(GL_LIGHT0); to enable light zero. You can use at most 8 light sources in OpenGL spec. (GL_LIGHT0~GL_LIGHT7) • glLight{if}[v](GLenum light, Glenum pname, TYPE param); • Specify the attribute of light • light can be GL_LIGHT0 ~ GL_LIGHT7 • pname is the characteristic of the light • param is the value of pname

  21. Pname Def. Value Meaning GL_AMBIENT (0.0, 0.0, 0.0, 0.0) 环境光颜色 GL_DIFFUSE (1.0, 1.0, 1.0, 1.0) 散射光颜色 GL_SPECULAR (1.0, 1.0, 1.0, 1.0) 镜面反射光颜色 GL_POSITION (0.0, 0.0, 1.0, 0.0) 位置坐标 GL_SPOT_DIRECTION (0.0, 0.0, -1.0) 指定聚光灯方向 GL_SPOT_EXPONENT 0.0 聚光指数 GL_SPOT_CUTOFF 180.0 spotlight cutoff angle GL_CONSTANT_ATTENUATION 1.0 constant attenuation factor GL_LINEAR_ATTENUATION 0.0 linear attenuation factor GL_QUADRATIC_ATTENUATION 0.0 quadratic attenuation factor Light Source

  22. Light Source • Color • The default values listed for GL_DIFFUSE and GL_SPECULAR apply only to GL_LIGHT0. • For other lights, the default value is (0.0, 0.0, 0.0, 1.0 ) for both GL_DIFFUSE and GL_SPECULAR. • Ex. • GLfloat light_ambient[4] = {0.0, 0.0, 1.0, 0.0}; • glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); • Position ( x, y, z, w ) • W is ZERO, Directional light, (x,y,z) specify its direction. • W is NONZERO, Positional light, (x,y,z) specify the location of the light source. • ModelView Enabled

  23. Light Source • Attenuation (衰减系数) • d = 光源到顶点位置 • kc = GL_CONSTANT_ATTENUATION • kl = GL_LINEAR_ATTENUATION • kq = GL_QUADRATIC_ATTENUATION • 方向光源,Attenuation is 1

  24. Material • Define material properties for objects in the scene. • void glMaterial{if}[v](GLenum face, GLenum pname, TYPE[*] param); • Specifies a current material property for use in lighting calculations.

  25. Pname Def. Value Meaning GL_AMBIENT (0.2, 0.2, 0.2, 1.0) ambient color of material GL_DIFFUSE (0.8, 0.8, 0.8, 1.0) diffuse color of material GL_AMBIENT_AND_DIFFUSE ambient and diffuse color of material GL_SPECULAR (0.0, 0.0, 0.0, 1.0) specular color of material GL_SHININESS 0.0 specular exponent GL_EMISSION (0.0, 0.0, 0.0, 1.0) emissive color of material GL_COLOR_INDEXES (0, 1, 1) ambient, diffuse, and specular color indices Material

  26. No Ambient Gray Ambient Blue Ambient Diffuse Only Specular Higher Shininess Emission Material

  27. Light • Demo, Light Position • Demo, Light Material

More Related