计算机图形学computer-graphics课件13_第1页
计算机图形学computer-graphics课件13_第2页
计算机图形学computer-graphics课件13_第3页
计算机图形学computer-graphics课件13_第4页
计算机图形学computer-graphics课件13_第5页
已阅读5页,还剩58页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、1Shading IShandong University Software CollegeInstructor: Zhou YuanfengE-mail: yuanfeng.zhou1Shading IShandong University 2ObjectivesLearn to shade objects so their images appear three-dimensionalIntroduce the types of light-material interactionsBuild a simple reflection model-the Phong model- that

2、can be used with real time graphics hardware2ObjectivesLearn to shade objeSimpleLighting modelWithSpecularlightingGouraudshadingWireframePolygonWhy we need shading3WithshadowWithTextureSimpleWithGouraudWireframeWhy 4Why we need shadingSuppose we build a scene using many polygons and color it with gl

3、Color. We get something likeWhich is the best?4Why we need shadingSuppose we5ShadingWhy does the image of a real sphere look likeLight-material interactions cause each point to have a different color or shadeNeed to consider Light sourcesMaterial propertiesLocation of viewerSurface orientationWhy?5S

4、hadingWhy does the image of 6Scattering Light strikes A Some scatteredSome absorbedSome of scattered light strikes BSome scatteredSome absorbedSome of this scattered light strikes Aand so on6Scattering Light strikes A 7Rendering EquationThe infinite scattering and absorption of light can be describe

5、d by the rendering equation Cannot be solved in general waysRay tracing is a special case for perfectly reflecting surfacesRendering equation is global and includesShadowsMultiple scattering from object to object7Rendering EquationThe infinit8Global Effectstranslucent surfaceshadowmultiple reflectio

6、n8Global Effectstranslucent sur9Local vs Global RenderingCorrect shading requires a global calculation involving all objects and light sourcesIncompatible with pipeline model which shades each polygon independently (local rendering)However, in computer graphics, especially real time graphics, we are

7、 happy if things “look right”Exist many techniques for approximating global effects9Local vs Global RenderingCorr10Light-Material InteractionLight that strikes an object is partially absorbed and partially scattered (reflected)The amount reflected determines the color and brightness of the objectA s

8、urface appears red under white light because the red component of the light is reflected and the rest is absorbedThe reflected light is scattered in a manner that depends on the smoothness and orientation of the surface10Light-Material InteractionLi11Light Sources General light sources are difficult

9、 to work with because we must integrate light coming from all points on the sourceLight color: I = Ir, Ig, Ib, RGB mode, CMY mode11Light Sources General light 12Simple Light SourcesPoint sourceModel with position and colorDistant source = infinite distance away (parallel)I(p0) = Ir(p0), Ig(p0), Ib(p

10、0)12Simple Light SourcesPoint soSimple Light SourcesEasy to use (in computer)Realistic is poor:Image contrast is high, some parts are bright and others are dark; In real world, the lights will be large.We can add ambient light to solvethis problem.13umbrapenumbraSimple Light SourcesEasy to usSimple

11、Light SourcesSpotlightRestrict light from ideal point source14Why use cos function? Simple Light SourcesSpotlight1Simple Light SourcesInfinite light: Sun light- Just know the light direction;- The intensity is constant.Ambient lightSame amount of light everywhere in sceneCan model contribution of ma

12、ny sources and reflecting surfaces15Ia = Iar, Iag, Iab the same value at each point on surfacesSimple Light SourcesInfinite l16Surface TypesThe smoother a surface, the more reflected light is concentrated in the direction a perfect mirror would reflected the lightA very rough surface scatters light

13、in all directionssmooth surfacerough surfaceSuch as mirrorsSuch as a walltranslucent surfaceSuch as water16Surface TypesThe smoother a 17Phong ModelA simple model that can be computed rapidlyHas three componentsDiffuseSpecularAmbientUses four vectors To light sourceTo viewerNormalPerfect reflector17

14、Phong ModelA simple model th18Ambient LightAmbient light is the result of multiple interactions between (large) light sources and the objects in the environmentAmount and color depend on both the color of the light(s) and the material properties of the objectAdd ka Ia to diffuse and specular termsre

15、flection coefintensity of ambient light=18Ambient LightAmbient light i19Diffuse ReflectionAn ideal diffuse surface is, at the microscopic level, a very rough surface. Chalk is a good approximation to an ideal diffuse surface. Because of the microscopic variations in the surface, an incoming ray of l

16、ight is equally likely to be reflected in any direction over the hemisphere.19Diffuse ReflectionAn ideal d20Lambertian Surface(朗伯面)Perfectly diffuse reflectorLight scattered equally in all directionsAmount of light reflected is proportional to the vertical component of incoming lightreflected light

17、cos qicos qi = l n if vectors normalizedThere are also three coefficients, kr, kb, kg that show how much of each color component is reflected, related with the materials20Lambertian Surface(朗伯面)Perfe21Lamberts Cosine LawLamberts law determines how much of the incident light energy is reflected. Reme

18、mber that the amount of energy that is reflected in any one direction is constant in this model. In other words, the reflected intensity is independent of the viewing direction.IpdIpd cosqqCAB=21Lamberts Cosine LawLambert22Illumination effectsShaded using a diffuse-reflection model,from left to righ

19、t kd=0.4, 0.55, 0.77, 0.85, 1.0. Shaded using a ambient and diffuse-reflection model,Ia =Ilight = 1.0, kd = 0.4. From left to right ka=0.0, 0.15, 0.30, 0.45, 0.60 22Illumination effectsShaded u23Specular SurfacesMost surfaces are neither ideal diffusers nor perfectly specular (ideal reflectors)Smoot

20、h surfaces show specular highlights due to incoming light being reflected in directions concentrated close to the direction of a perfect reflection specularhighlight23Specular SurfacesMost surfac24Ideal ReflectorNormal is determined by local orientationAngle of incidence = angle of relectionThe thre

21、e vectors must be coplanarr = 2 (l n ) n - lrlHow to compute rnliv24Ideal ReflectorNormal is det25Modeling Specular RelectionsPhong proposed using a term that dropped off as the angle between the viewer and the ideal reflection increasedfIr ks I cosafshininess coefabsorption coefincoming intensityre

22、flectedintensity25Modeling Specular Relections26The Shininess CoefficientValues of a between 100 and 200 correspond to metals Values between 5 and 10 give surface that look like plasticcosa ff90-9026The Shininess CoefficientVal27Spheres shaded using phong illumination model27Spheres shaded using pho

23、ng iRefract lightSnell lawt, i are the refract factors28Refract lightSnell law28Refract factor29Refract factor2930Distance TermsThe light from a point source that reaches a surface is inversely proportional to the square of the distance between themWe can add a factor of theform 1/(c1+c2dL+c3dL2) to

24、the diffuse and specular termsThe constant and linear terms soften the effect of the point source30Distance TermsThe light from31Light source attenuation(衰减)I = Iaka+fattIlightkd(N.L)fatt=1/dL2fatt = (1/min(c1+c2dL+c3dL2), 1);Distance 1 1.375 1.75 2.125 2.5C 0 0 1.25.25.501031Light source attenuatio

25、n(衰减)32Light SourcesIn the Phong Model, we add the results from each light sourceEach light source has separate diffuse, specular, and ambient terms to allow for maximum flexibility even though this form does not have a physical justificationSeparate red, green and blue componentsHence, 9 coefficien

26、ts for each point sourceIdr, Idg, Idb, Isr, Isg, Isb, Iar, Iag, Iab32Light SourcesIn the Phong Mo33Material PropertiesMaterial properties match light source propertiesNine absorbtion coefficientskdr, kdg, kdb, ksr, ksg, ksb, kar, kag, kabShininess coefficient a 33Material PropertiesMaterial 34Adding

27、 up the ComponentsFor each light source and each color component, the Phong model can be written (without the distance terms) asI =kd Id l n + ks Is (v r )a + ka IaFor each color componentwe add contributions fromall sources34Adding up the ComponentsFor Phong light model35Phong light model3536Modifi

28、ed Phong ModelThe specular term in the Phong model is problematic because it requires the calculation of a new reflection vector and view vector for each vertexBlinn suggested an approximation using the halfway vector(分向量) that is more efficient36Modified Phong ModelThe spec37Calculating the reflect

29、ion vectorR =Ncosq + S =Ncosq + Ncosq - L =2N (N.L) - LCalculating N.H instead of R.V,in which H = (L+V)/|L+V|2*b=a37Calculating the reflection v38Using the halfway angleReplace (v r )a by (n h )b b is chosen to match shinenessNote that halfway angle is half of angle between r and v if vectors are c

30、oplanarResulting model is known as the modified Phong or Blinn lighting modelSpecified in OpenGL standard38Using the halfway angleRepla39ExampleOnly differences in these teapots are the parametersin the modifiedPhong model39ExampleOnly differences in 40Computation of Vectors l and v are specified by

31、 the applicationCan computer r from l and nProblem is determining nFor simple surfaces, it can be determined but how we determine n differs depending on underlying representation of surfaceOpenGL leaves determination of normal to applicationException for GLU quadrics and Bezier surfaces (Chapter 11)

32、40Computation of Vectors l and41Plane NormalsEquation of plane: ax+by+cz+d = 0From Chapter 4 we know that plane is determined by three points p0, p2, p3 or normal n and p0Normal can be obtained byn = (p2-p0) (p1-p0)p1p0p241Plane NormalsEquation of pla42Normal to SphereImplicit function f(x,y.z)=0Nor

33、mal given by gradientSphere f(p)=x2 + y2 + z2 -1=0 n = f/x, f/y, f/zT = p42Normal to SphereImplicit fun43Parametric FormFor sphere Tangent plane determined by vectorsNormal given by cross productx=x(u,v)=cos u sin vy=y(u,v)=cos u cos vz= z(u,v)=sin up/u = x/u, y/u, z/uTp/v = x/v, y/v, z/vTn = p/u p/

34、v 43Parametric FormFor spherex=x44General CaseWe can compute parametric normals for other simple casesQuadricsParameteric polynomial surfacesBezier surface patches (Chapter 11)44General CaseWe can compute p45Polygonal ShadingShading calculations are done for each vertexVertex colors become vertex sh

35、adesBy default, vertex shades are interpolated across the polygon:glShadeModel(GL_SMOOTH);If we use glShadeModel(GL_FLAT); the color at the first vertex will determine the shade of the whole polygon45Polygonal ShadingShading calFlat shadingNormal is same in each polygon;Infinite viewer;Infinite ligh

36、t;For flat shading, we only need compute the color of one point in this polygon.46Flat shadingNormal is same in 47Polygon NormalsPolygons have a single normalShades at the vertices as computed by the Phong model can be almost same Identical for a distant viewer (default) or if there is no specular c

37、omponent Infinite viewer and lightConsider model of sphereWant different normal at each vertex even though this concept is not quite correct mathematically47Polygon NormalsPolygons haveCharacteristicIts bad for polygon approximate smooth surface. The color in polygons is different.48CharacteristicIt

38、s bad for polView of humanMach bandHow to avoid thisband? We should usesmooth shading.49View of humanMach band4950Smooth ShadingWe can set a new normal at each vertexEasy for sphere model If centered at origin n = p Now smooth shading worksNote silhouette edge50Smooth ShadingWe can set a n51Mesh ShadingThe previous example is not general because we knew the normal at each vertex analyticallyFor polygonal models, Gouraud proposed we use the average of the normals around a mesh vertexn = (n1+n2+n3+n4)/ |n1+n2+n3+n4|51Mesh ShadingThe previous exaData structure for

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论