XNA和FBX着色问题
我的问题是,如果我使用BasicFect(并且设置VertexColorEnabled=true)或我自己的着色器,并且只使用彩色(非纹理!)模型,它会给出一个错误,即缺少Color0…fbx模型没有Color0通道不是很奇怪吗?我发现了。。。。。(Marshall Belew@forums.create.msdn.com/forums/p/16066/553792.aspx#553792)拯救了我的一天 解决方案很简单:BasicShader具有DiffuseColor属性。我只是在卡通着色器中添加了一个新字段,任何时候没有纹理,我都会替换颜色值 我更喜欢这个解决方案,因为现在我不必编写大量的顶点声明/绘制基本逻辑 从.fx文件:XNA和FBX着色问题,xna,game-development,autodesk,fbx,Xna,Game Development,Autodesk,Fbx,我的问题是,如果我使用BasicFect(并且设置VertexColorEnabled=true)或我自己的着色器,并且只使用彩色(非纹理!)模型,它会给出一个错误,即缺少Color0…fbx模型没有Color0通道不是很奇怪吗?我发现了。。。。。(Marshall Belew@forums.create.msdn.com/forums/p/16066/553792.aspx#553792)拯救了我的一天 解决方案很简单:BasicShader具有DiffuseColor属性。我只是在卡通着色器
// Pixel shader applies a cartoon shading algorithm.
float4 ToonPixelShader(LightingPixelShaderInput input) : COLOR0
{
float4 color = TextureEnabled ? tex2D(Sampler, input.TextureCoordinate) : DiffuseColor;
替换效果(这是来自非照片真实感示例的修改后的snipet)
如果你接受了之前问题的一些答案并对其进行了投票,那就太好了。哎呀,真的很抱歉,我马上就去做。这是我发现的。。。。。(Marshall Belew@)救了我一天…那么,请随意回答你自己的问题。你甚至可以接受自己的答案。
// 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);
}
}