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プロパティがあります。Toonシェーダーに新しいフィールドを追加しただけで、テクスチャがないときはいつでも、色の値を置き換えました。

大量の頂点宣言を記述したり、プリミティブロジックを描画したりする必要がなくなったため、このソリューションに満足しています。

.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 に答える