0
我的问题是,如果我使用BasicEffect(和设置VertexColorEnabled = true)或我自己的着色器,并且只使用有色(无纹理)模型,它会给出颜色0缺失的错误.. .fbx模型不带有COLOR0通道,这不奇怪吗?XNA和FBX着色问题
我的问题是,如果我使用BasicEffect(和设置VertexColorEnabled = true)或我自己的着色器,并且只使用有色(无纹理)模型,它会给出颜色0缺失的错误.. .fbx模型不带有COLOR0通道,这不奇怪吗?XNA和FBX着色问题
这里是我发现.....(马歇尔贝尔柳@ 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;
更换的效果(这是来自非照片写实样品改性snipet)。
// 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);
}
}
如果您接受并提出了以前问题的一些答案,那将会非常好。 – thedaian
哎呀抱歉,我马上就会这么做 – JML
这是我发现的...... (Marshall Belew @ http://forums.create.msdn.com/forums/p/16066/553792.aspx# 553792) 保存我的一天... – JML