XNA 和 FBX 着色问题

发布于 2024-12-06 18:11:01 字数 136 浏览 2 评论 0原文

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

My problem is that, if I use BasicEffect (and setup VertexColorEnabled = true) or my own shader, and use only colored (not textured!) models, it gives the error that Color0 is missing...Isn't it weird that .fbx models do not come with COLOR0 channel ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陈年往事 2024-12-13 18:11:01

这是我发现的......(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); 
   } 
} 

Here is what I found..... (Marshall Belew @ forums.create.msdn.com/forums/p/16066/553792.aspx#553792) Saved my day...

The solution is simple: the BasicShader has a DiffuseColor property. I merely added a new field into the Toon shader, and any time there was no texture, I substituted the color value.

I am happier with this solution because now I don't have to write a ton of vertex declaration / draw primitive logic.

From the .fx file:

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

Replacing the effects (this is a modified snipet from the NonPhotoRealistic sample).

// 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); 
   } 
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文