下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
永威国际道州本土游戏永威国际道州本土游戏第13章:HLSL基础问答答案1.?在HLSL中,如何获取一个float4对象的第一个元素??如果您想要获取一个叫做color的float4对象中的第一个元素,您可以用数组符号(color[0])或者您也可以使用颜色和位置的命名空间(color.r或者color.x)?2.?什么叫做混合(swizzling)??Swizzling是指从颜色或位置的命名空间(如color.rb或color.xyz)取两个或多个元素来获取一个float4或类似数据类型的多个元素。?3.?在HLSL,如何规定使用顶点、像素着色器的哪一个版本??在HLSL效果文件处理技巧中,您可以通过提供带有着色器版本的compile关键字来指定一个VertexShader(顶点着色器)和/或PixelShader(像素着色器)。对于顶点着色器,您可以用vs_2_0句法,而对于像素着色器,您则可以用ps_2_0语法。?4.?若没有HLSL,您不能实现哪些效果??HLSL允许开发人员连接到硬件功能,而XNA框架是不提供这些的。原因:图形硬件变得越来越复杂,如果XNA框架被扩展来处理所有显卡(graphics?card)的话,XNA框架会变得很庞大。所以,HLSL与XNA协作,允许您为显卡本身编写代码。?5.?在HLSL,怎样将那个两个矩阵相乘??HLSL中的mul函数可以将两个矩阵相乘。?6.?语义(semantic)在HLSL扮演什么角色??一个语义标记一个变量的特定用途。对于输入参数(input?parameters),语义意味着该参数会被自动赋予由语义指定的一个值;对于输出参数(output?parameters),语义是一种标记特定391变量含有特定信息的方式,这种信息会在着色器(shader)执行完之后被处理。?练习答案使用本章所创建的代码,绘制一个六面体,用树木图像作为每面的纹理。在六面体的每面上,使用本章创建的四种纹理特效(一般纹理、模糊纹理、反相纹理、灰度纹理)的其中一种,每种效果必须被至少使用一次。?本练习和第9章的练习很相似,在那里您做了一个每个面纹理都不同的六面体。不同之处在于,您现在要对每个面应用相同的纹理,再对那些面应用不同的HLSL效果。?首先,根据本章所介绍的方法创建不同的效果文件,然后使用与下面类似的代码来创建这个六面体并为其应用您所创建的效果:?usingusingusingusingusingusingusingusingusingusingSystem;System.Collections.Generic;System.Linq;Microsoft.Xna.Framework;Microsoft.Xna.Framework.Audio;Microsoft.Xna.Framework.Content;Microsoft.Xna.Framework.GamerServices;Microsoft.Xna.Framework.Graphics;Microsoft.Xna.Framework.Input;Microsoft.Xna.Framework.Media;namespace_3D_Madness{//////Thisisthemaintypeforyourgame.///publicclassGame1:Microsoft.Xna.Framework.Game{GraphicsDeviceManagergraphics;SpriteBatchspriteBatch;//GamecameraCameracamera;//VertexdataVertexPositionTexture[]verts;VertexBuffervertexBuffer;//EffectEffectnormalEffect;EffectblurEffect;EffectnegativeEffect;EffectgrayscaleEffect;//MovementandrotationstuffMatrixworldTranslation=Matrix.Identity;MatrixworldRotation=Matrix.Identity;//TextureinfoTexture2Dtexture;publicGame1(){graphics=newGraphicsDeviceManager(this);Content.RootDirectory="Content";}392??//////Allowsthegametoperformanyinitializationit///needstobeforestartingtorun.Thisiswhereitcanqueryfor///anyrequiredservicesandloadcontent.///protectedoverridevoidInitialize(){//Initializecameracamera=newCamera(this,newVector3(0,0,5),Vector3.Zero,Vector3.Up);Components.Add(camera);base.Initialize();}//////LoadContentwillbecalledoncepergameandistheplacetoload///allofyourcontent.///protectedoverridevoidLoadContent(){//CreateanewSpriteBatch,whichcanbeusedtodrawtextures.spriteBatch=newSpriteBatch(GraphicsDevice);//initializeverticesverts=newVertexPositionTexture[24];//FRONTverts[0]=newVertexPositionTexture(newVector3(-1,1,1),newVector2(0,0));verts[1]=newVertexPositionTexture(newVector3(1,1,1),newVector2(1,0));verts[2]=newVertexPositionTexture(newVector3(-1,-1,1),newVector2(0,1));verts[3]=newVertexPositionTexture(newVector3(1,-1,1),newVector2(1,1));//BACKverts[4]=newVertexPositionTexture(newVector3(1,1,-1),newVector2(0,0));verts[5]=newVertexPositionTexture(newVector3(-1,1,-1),newVector2(1,0));verts[6]=newVertexPositionTexture(newVector3(1,-1,-1),newVector2(0,1));verts[7]=newVertexPositionTexture(newVector3(-1,-1,-1),newVector2(1,1));//LEFTverts[8]=newVertexPositionTexture(newVector3(-1,1,-1),newVector2(0,0));verts[9]=newVertexPositionTexture(newVector3(-1,1,1),newVector2(1,0));verts[10]=newVertexPositionTexture(newVector3(-1,-1,-1),newVector2(0,1));verts[11]=newVertexPositionTexture(newVector3(-1,-1,1),newVector2(1,1));//RIGHTverts[12]=newVertexPositionTexture(newVector3(1,1,1),newVector2(0,0));verts[13]=newVertexPositionTexture(newVector3(1,1,-1),newVector2(1,0));verts[14]=newVertexPositionTexture(newVector3(1,-1,1),newVector2(0,1));verts[15]=newVertexPositionTexture(?393newVector3(1,-1,-1),newVector2(1,1));//TOPverts[16]=newVertexPositionTexture(newVector3(-1,1,-1),newVector2(0,0));verts[17]=newVertexPositionTexture(newVector3(1,1,-1),newVector2(1,0));verts[18]=newVertexPositionTexture(newVector3(-1,1,1),newVector2(0,1));verts[19]=newVertexPositionTexture(newVector3(1,1,1),newVector2(1,1));//BOTTOMverts[20]=newVertexPositionTexture(newVector3(-1,-1,1),newVector2(0,0));verts[21]=newVertexPositionTexture(newVector3(1,-1,1),newVector2(1,0));verts[22]=newVertexPositionTexture(newVector3(-1,-1,-1),newVector2(0,1));verts[23]=newVertexPositionTexture(newVector3(1,-1,-1),newVector2(1,1));//SetvertexdatainVertexBuffervertexBuffer=newVertexBuffer(GraphicsDevice,typeof(VertexPositionTexture),verts.Length,BufferUsage.None);vertexBuffer.SetData(verts);//LoadeffectnormalEffect=Content.Load<Effect>(@"effects\Red");grayscaleEffect=Content.Load<Effect>(@"effects\Grayscale");negativeEffect=Content.Load<Effect>(@"effects\Negative");blurEffect=Content.Load<Effect>(@"effects\Blur");//Loadtexturetexture=Content.Load<Texture2D>(@"Textures\trees");}//////UnloadContentwillbecalledoncepergameandis///theplacetounloadallcontent.///protectedoverridevoidUnloadContent(){//TODO:Unloadanynon-ContentManagercontenthere}//////Allowsthegametorunlogicsuchasupdatingtheworld,///checkingforcollisions,gatheringinput,andplayingaudio.//////Providesasnapshotoftimingvalues.protectedoverridevoidUpdate(GameTimegameTime){//Allowsthegametoexitif(GamePad.GetState(PlayerIndex.One).Buttons.Back==ButtonState.Pressed)this.Exit();//TranslationKeyboardStatekeyboardState=Keyboard.GetState();if(keyboardState.IsKeyDown(Keys.Left))worldTranslation*=Matrix.CreateTranslation(-.01f,0,0);if(keyboardState.IsKeyDown(Keys.Right))394??worldTranslation*=Matrix.CreateTranslation(.01f,0,0);//RotationworldRotation*=Matrix.CreateFromYawPitchRoll(MathHelper.PiOver4/60,0,0);base.Update(gameTime);}//////Thisiscalledwhenthegameshoulddrawitself.//////Providesasnapshotoftimingvalues.///protectedoverridevoidDraw(GameTimegameTime){GraphicsDevice.Clear(Color.CornflowerBlue);//SetthevertexbufferontheGraphicsDeviceGraphicsDevice.SetVertexBuffer(vertexBuffer);//DrawfrontDrawVerts(normalEffect,0,2);//DrawbackDraw
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024-2025学年北京市清华附中八年级(下)期中数学试卷及答案解析
- 亲子活动免责协议书
- 《窦娥冤(节选)》核心素养分层练(含解析)统编版高中语文必修下册
- S公司的配送管理优化
- 机修承包合同
- 艾特森实业(深圳)有限公司 风力灭火机森林消防应用规范
- 广东省韶关市2026年七年级下学期期中数学试题附答案
- 粪便检验操作与结果报告专家共识2026
- 2026年经鼻蝶垂体瘤切除术的出院指导课件
- 运动场上的成功之路-规划、训练与学业的平衡
- 2025年国家药品监督管理局药品审评中心考试真题(附答案)
- 09中药炮制学第12章炙法
- 检验科室内质控操作
- GB/T 156-2017标准电压
- 模拟CMOS集成电路设计(拉扎维)第九章运算放大器课件
- 代谢性酸中毒-课件
- 循环经济导论课件
- 动脉血气分析六步法
- 学校政府采购内控制度
- 国家艾滋病随访指南
- 证人证言(模板)
评论
0/150
提交评论