您可以在效果文件中定义不同的技术,如下所示:
// shading code ...
technique Technique1
{
pass Pass1
{
// VertexShader = ...
// PixelShader = ...
}
pass Pass2
{
// VertexShader = ...
// PixelShader = ...
}
// more passes if you want
}
technique Technique2
{
pass Pass1
{
// VertexShader = ...
// PixelShader = ...
}
// more Passes if you want ...
}
从您的 C# 代码中使用您的效果文件,如下所示:
// declar your variable by loading the effect file from the content pipeline
Effect effect = ContentManager.Load<Effect>("NameOfMyEffectFile");
// use a particular technique
effect.CurrentTechnique = effect.Techniques["Technique1"];
// apply a particular pass
effect.CurrentTechnique.Passes[1].Apply();
// begin some drawing
effect.Begin();
// draw ...
// end some drawing
effect.End();
如果您想应用多个通道,只需像这样迭代所有通道:
foreach(EffectPass p in effect.CurrentTechnique.Passes)
{
// begin some drawing
p.Begin();
// draw ...
// end some drawing
p.End();
}