【问题标题】:XNA and FBX Coloring ProblemXNA 和 FBX 着色问题
【发布时间】:2011-11-27 02:02:02
【问题描述】:

我的问题是,如果我使用 BasicEffect(并设置 VertexColorEnabled = true)或我自己的着色器,并且只使用彩色(不是纹理!)模型,它会给出缺少 Color0 的错误......不是吗奇怪的是 .fbx 模型不带有 COLOR0 通道?

【问题讨论】:

  • 如果您接受并赞成之前问题的一些答案,那就太好了。
  • 抱歉,我马上就去做
  • 这是我发现的...... (Marshall Belew @ forums.create.msdn.com/forums/p/16066/553792.aspx#553792) 拯救了我的一天......
  • 那么,请随意回答您自己的问题。您甚至可以接受自己的答案。

标签: xna game-development autodesk fbx


【解决方案1】:

这是我发现的......(Marshall Belew @ forums.create.msdn.com/forums/p/16066/553792.aspx#553792)拯救了我的一天......

解决方案很简单:BasicShader 有一个 DiffuseColor 属性。我只是在卡通着色器中添加了一个新字段,只要没有纹理,我就替换颜色值。

我对这个解决方案更满意,因为现在我不必编写大量顶点声明/绘制原始逻辑。

来自 .fx 文件:

// Pixel shader applies a cartoon shading algorithm. 
float4 ToonPixelShader(LightingPixelShaderInput input) : COLOR0 
{ 
    float4 color = TextureEnabled ? tex2D(Sampler, input.TextureCoordinate) : DiffuseColor; 

替换效果(这是来自 NonPhotoRealistic 示例的修改片段)。

// Scan over all the effects currently on the mesh. 
foreach (BasicEffect oldEffect in mesh.Effects) 
{ 
   // If we haven't already seen this effect... 
   if (!effectMapping.ContainsKey(oldEffect)) 
   { 
      // Make a clone of our replacement effect. We can't just use 
      // it directly, because the same effect might need to be 
      // applied several times to different parts of the model using 
      // a different texture each time, so we need a fresh copy each 
      // time we want to set a different texture into it. 
      Effect newEffect = replacementEffect.Clone( 
                                  replacementEffect.GraphicsDevice); 

      // Copy across the texture from the original effect. 
      newEffect.Parameters["Texture"].SetValue(oldEffect.Texture); 

      newEffect.Parameters["TextureEnabled"].SetValue( 
                                          oldEffect.TextureEnabled); 

      Vector4 color = new Vector4(oldEffect.DiffuseColor, 1.0f); 
      newEffect.Parameters["DiffuseColor"].SetValue(color); 

      effectMapping.Add(oldEffect, newEffect); 
   } 
} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-19
    • 2014-08-05
    • 1970-01-01
    • 2010-12-18
    • 2010-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多