xna中使用自定义的shader来绘制model
2011-12-23 14:36
183 查看
XNA中的 Model.Draw() 函数会使用导入model所使用的Content Processor指定的Effect来进行绘制,因此,如果选择的默认的Content Processor,即Model - XNA Framework,则会使用BasicEffect来进行绘制。
若想用自定义的shader绘制model,需要创建一个自定义的ContentPipeline,在ContentPipeline中指定所用的shader,然后用此ContentPipeline来作为model的Content Processor。
步骤:
1.创建一个Content Pipeline Extension Library 项目,命名为CustomContentProcessor
2.CustomContentProcessor类重写为:
4.自己写一个 MyEffect.fx 文件
5.绘制model的代码
若想用自定义的shader绘制model,需要创建一个自定义的ContentPipeline,在ContentPipeline中指定所用的shader,然后用此ContentPipeline来作为model的Content Processor。
步骤:
1.创建一个Content Pipeline Extension Library 项目,命名为CustomContentProcessor
2.CustomContentProcessor类重写为:
[ContentProcessor(DisplayName = "CustomEffectModelProcessor.CustomContentProcessor")] public class CustomContentProcessor : ModelProcessor { protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { EffectMaterialContent myMaterial = new EffectMaterialContent(); string effectPath = Path.GetFullPath("MyEffect.fx"); myMaterial.Effect = new ExternalReference<EffectContent>(effectPath); return base.ConvertMaterial(myMaterial, context); } }3. 将model 的Content Processor指定为 CustomContentProcessor
4.自己写一个 MyEffect.fx 文件
5.绘制model的代码
foreach (ModelMesh mesh in myModel.Meshes) { foreach (Effect effect in mesh.Effects) { effect.Parameters["View"].SetValue(view); effect.Parameters["Projection"].SetValue(projection); effect.Parameters["World"].SetValue(Matrix.CreateRotationY(roty)); effect.Parameters["ColorMap"].SetValue(bodyTex); } mesh.Draw(); }
相关文章推荐
- 使用 EffectCustomTool 为 Xna 创建自定义 Shader 特效(二)
- 使用 EffectCustomTool 为 Xna 创建自定义 Shader 特效
- U3D Shader去掉全局雾和使用自定义环境光
- Vue 自定义组件使用v-model
- yii2使用Model无刷新验证rule自定义方法
- ASP.NET MVC: 使用自定义 ModelBinder 过滤敏感信息
- 使用WebBrowser控件时在网页元素上绘制文本或其他自定义内容
- Unity shader 官网文档全方位学习(二)————Lighting model及自定义Lighting model
- 使用emguCV/C# opencv绘制自定义直方图
- Android中使用ListView绘制自定义表格
- Android中使用ListView绘制自定义表格(2)
- Android圆形图片不求人,自定义View实现(BitmapShader使用)
- Android使用GridLayout绘制自定义日历控件
- ASP.NET MVC: 使用自定义 ModelBinder 过滤敏感信息
- Android自定义绘制:Shader - 模仿iOS滑动解锁
- 使用CALayer或者drawRect方法来绘制自定义View
- 自定义View——Shader的使用
- 处理模型——使用自定义Effects和纹理绘制模型
- 继承android.view.View自定义view,使用画笔绘制view示例
- Java使用自定义的tableModel,设置可编辑方式