0

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

4

1 回答 1

0

这是我发现的......(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); 
   } 
} 
于 2011-09-30T09:24:04.070 回答