计算机图形学computer graph(12)
47页1、Shading in OpenGLShandong University Software CollegeInstructor:Zhou Yuanfeng E-mail:yuanfeng.zhougmail ObjectivesIntroduce the OpenGL shading functionsDiscuss polygonal shadingFlatSmoothGouraud2Steps in OpenGL shading1.Enable shading and select model2.Specify normals3.Specify material properties4.Specify lights3NormalsIn OpenGL the normal vector is part of the stateSet by glNormal*()glNormal3f(x,y,z);glNormal3fv(p);Usually we want to set the normal to have unit length so cosine calculations are
2、 correctLength can be affected by transformationsNote that scaling does not preserved lengthglEnable(GL_NORMALIZE)allows for autonormalization at a performance penalty4Normal for Trianglep0p1p2nPlane n (p-p0)=0n=(p2-p0)(p1-p0)normalize n n/|n|pNote that right-hand rule determines outward face5Enabling ShadingShading calculations are enabled byglEnable(GL_LIGHTING)Once lighting is enabled,glColor()ignoredglEnable(GL_COLOR_MATERIAL);Must enable each light source individuallyglEnable(GL_LIGHTi)i=0,
3、1.Can choose light model parametersglLightModeli(parameter,GL_TRUE)GL_LIGHT_MODEL_LOCAL_VIEWER do not use simplifying distant viewer assumption in calculation(infinite viewer)GL_LIGHT_MODEL_TWO_SIDED shades both sides of polygons independently6Defining a Point Light SourceFor each light source,we can set an RGBA for the diffuse,specular,and ambient components,and for the positionGLfloat diffuse0=1.0,0.0,0.0,1.0;GLfloat ambient0=1.0,0.0,0.0,1.0;GLfloat specular0=1.0,0.0,0.0,1.0;Glfloat light0_pos
4、=1.0,2.0,3,0,1.0;glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);glLightv(GL_LIGHT0,GL_POSITION,light0_pos);glLightv(GL_LIGHT0,GL_AMBIENT,ambient0);glLightv(GL_LIGHT0,GL_DIFFUSE,diffuse0);glLightv(GL_LIGHT0,GL_SPECULAR,specular0);7Distance and DirectionThe source colors are specified in RGBAThe position is given in homogeneous coordinatesIf w=1.0,we are specifying a finite locationIf w=0.0,we are specifying a parallel source with the given direction vectorThe coefficients in the distance terms are by
5、default a=1.0(constant terms),b=c=0.0(linear and quadratic terms).Change bya=0.80;glLightf(GL_LIGHT0,GLCONSTANT_ATTENUATION,a);1/(a+bdL+cdL2)8SpotlightsUse glLightv to set Direction GL_SPOT_DIRECTIONCutoff GL_SPOT_CUTOFFAttenuation GL_SPOT_EXPONENTProportional to cosafq-qf9Global Ambient LightAmbient light depends on color of light sourcesA red light in a white room will cause a red ambient term that disappears when the light is turned offOpenGL also allows a global ambient term that is often he
《计算机图形学computer graph(12)》由会员资****亨分享,可在线阅读,更多相关《计算机图形学computer graph(12)》请在金锄头文库上搜索。
输油设备计算机辅助仿真系统
数显式顶板离层仪B
树立科学发展观(1)
数电组合逻辑电路应用举例、竞争冒险
数电实验0GOS6051型二踪示波器实验一常用电子仪器的使用练习
数电84第五版—康华光
数码裂隙灯图像系统操作
数理统计12主成分分析
数控系统的备份与还原训练
数控技术及应用清华版7数控机床进给伺服系统的控制原理
数据解读PPT(BNU金融协会)
数控技术及应用清华版8数控机床的精度
数控机床故障诊断 (2)
数据质量评估与控制体系-刘思琦组
数控技术及应用清华版17数控机床进给伺服系统的控制原理
数控技术2011-2-数控系统
数控加工工艺与设备》电子教案
数控加工的程序编制车床
数据通信与计算机网络第二版》电子教案西南
数据资料的收集方法
2024-05-22 48页
2024-05-22 28页
2024-05-22 22页
2024-05-22 32页
2024-05-22 22页
2024-05-22 31页
2024-05-14 5页
2024-05-14 6页
2024-05-14 40页
2024-05-14 38页