《Unity虚拟现实技术及其应用》 课件 6 render-pipeline-game-engine_第1页
《Unity虚拟现实技术及其应用》 课件 6 render-pipeline-game-engine_第2页
《Unity虚拟现实技术及其应用》 课件 6 render-pipeline-game-engine_第3页
《Unity虚拟现实技术及其应用》 课件 6 render-pipeline-game-engine_第4页
《Unity虚拟现实技术及其应用》 课件 6 render-pipeline-game-engine_第5页
已阅读5页,还剩43页未读 继续免费阅读

下载本文档

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

文档简介

Material,Shader,Texture

材质,着色器,纹理Material:definehowasurfaceshouldberendered.TheavailableoptionsforamaterialdependonwhichShadertheMaterialisusing.Shader:scriptsthatcontainalgorithmsforcalculatingthecolorofeachpixel,basedonlightinginputandthematerialconfiguration.Texture:bitmapimages.AMaterialcancontainreferencestotextures.MaterialAMaterialcanbeconsideredacollectionofelementsthatproducetherenderingeffects.Importantproperties:

color,

texture,

shader创建Material

MaterialProperties

(对应StandardShader)RenderingMode:Opaque,Cutout,Transparent,Fade.AlbedoColorandTransparencyAlbedoparametercontrolsthebasecolorofthesurface.ThealphavalueoftheAlbedocolorcontrolsthetransparencylevelforthematerial.将材质添加到游戏对象Codingformaterials//Createsamaterialfromshaderandtexturereferences.

Shader

shader;Texturetexture;Colorcolor;voidStart(){Rendererrend=GetComponent<Renderer>();

rend.material=newMaterial(shader);

rend.material.mainTexture=texture;

rend.material.color=color;}MaterialnewMat=Resources.Load("DEV_Orange",typeof(Material))asMaterial;gameObject.GetComponent<Renderer>().material=newMat;UsingcolorspublicclassExample:MonoBehaviour{ColorcolorStart=Color.red;ColorcolorEnd=Color.green;floatduration=1.0f;Rendererrend;voidStart(){rend=GetComponent<Renderer>();}voidUpdate(){floatlerp=Mathf.PingPong(Time.time,duration)/duration;rend.material.color=Color.Lerp(colorStart,colorEnd,lerp);}}Parametersoftextures纹理形状(TextureShape):2D,缺省下为2D,用于大多数情形下。所有的图片都作为2D纹理处理,用于3D网格的纹理映射。纹理大小(Dimensionsize):纹理的长和宽应满足2的n次方(2、4、8、…、1024、2048pixels)等等。要注意的是,给定平台能支持的最大纹理大小是有规定的,同时,Unity允许导入的最大纹理为8k,即8192x8192pixels。Unity也支持非2n大小的纹理,但需要更多的内存和计算量进行取样处理,所以尽量将纹理处理为2n要求的大小。重复或拼接模式(Wrapmode):Repeat,重复模式,将贴图重复平铺到物体表面。Clamp,强制拉伸,将纹理拉伸以覆盖物理表面。UsingTexturesOperatingtextureswithcodespublicclassExampleClass:MonoBehaviour

{publicTexture[]textures;publicfloatchangeInterval=0.33F;publicRendererrend;

voidStart(){rend=GetComponent<Renderer>();}

voidUpdate(){if(textures.Length==0)return;

intindex=Mathf.FloorToInt(Time.time/changeInterval);index=index%textures.Length;rend.material.mainTexture=textures[index];}}MeshFilter&MeshRendererTheMeshFilter

takesameshfromyourassets

andpassesittothemeshrendererforrendering

onthescreen.ToseetheMeshinyourscene,youshouldaddaMeshRenderertotheGameObject.MeshAmeshcontainsverticesandtrianglearraysofaGameObject.Twoimportantproperties:verticestrianglesThetrianglearraysaresimplyindicesintothevertexarrays;threeindicesforeachtriangle.MeshFilterAclasstoaccessthemeshofagameobject.Properties:mesh,gameObject,transform,name,MeshRendererAclasstorenderthemeshofagameobject.Properties:material,gameObject,transform,name,drawatrianglevoidStart(){Vector3[]vs=newVector3[3];vs[0]=newVector3(0,0,0);vs[2]=newVector3(1,0,0);vs[1]=newVector3(0,1,0);int[]ts=newint[3];ts[0]=0;ts[1]=1;ts[2]=2;///左手Meshmesh=newMesh();GetComponent<MeshFilter>().mesh=mesh;mesh.vertices=vs;mesh.triangles=ts;}021createandrenderatrianglegameobject,

onlyusingC#codesWriteC#codes,createandrenderageometry014230,3,1,0,1,2,0,2,3,4,1,3,4,2,1,4,3,2MaterialAMaterialcanbeconsideredacollectionofelementsthatproducetherenderingeffects.Importantproperties:

color,

texture,

shader创建Material

将材质添加到游戏对象利用EditorC#RenderingPipeline(渲染管线)DongfengLiuSchoolofInformationEngineeringGuangdongUniversityofTechnologyGuangzhou,ChinaOutline

计算机图形技术:3Dworldto2Dimage;三个步骤:变换(transform),模型变换、视点变换和投影变换裁剪,剔除位于裁剪面之外的物体视口变换,上述变换后的坐标与屏幕像素之间建立对应关系。

geometricalinformation—图元RenderingPipelineCoordinatesystemsinUnity

ZYX1.坐标系统对象坐标系(objectcoordinatesystem:OCS)x,y,z世界坐标系(worldcoordinatesystem:WCS)X,Y,Z相机坐标系(viewingcoordinatesystem:VCS)n,u,v(n的方向是从视点指向center的方向)投影坐标系(clippingcoordinatesystem:CCS)X,Y,Z(规格化设备坐标系,坐标值-1~1之间)窗口坐标系(devicecoordinatesystem:DCS)x,y,z(z:0~1,x,y以窗口左下角为坐标原点)2.模型视点变换场景从世界坐标系到相机坐标系的变换。2.1模型变换在WCS中改变物体的位置、姿态、或缩放2.2视点变换调整相机位置和方向,对场景进行取景3.投影变换场景从相机坐标系到投影坐标系的变换。通过投影矩阵Mprojection来实现:4.视口变换场景从投影坐标系到窗口坐标系的变换。通过投影矩阵Mwindow来实现:ModelTransformOCSMTWCSViewTransformWCSVT(Camera)VCSProjectionTransformVCSPTCCSViewFrustum(视景体)近剪切面远剪切面透视投影,正交投影ViewportTransformCCSVTDCSSomeConcepts

the“camera”you’vecreatedinyour3Dpackageisn’treallyacameraatall.Itjustrepresentsaviewtransformation.Cameraincomputergraphics,wedothisbydefiningwhat’scalleda“viewfrustum”.

Withaviewfrustum,anythinginsidethevolumeofthefrustumisdrawn.Everythingoutsideisexcludedor“clipped”.Projection

Getridofanythingthatisnotintheviewfrustum.ClippingAlloftheoperationsthatwe’vedoneabovearestillin3D(X,Y,Z)coordinates.Weneedtomapthesecoordinatestotheviewpo

温馨提示

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

评论

0/150

提交评论