0

一般问题:

假设您有一个顶点列表,您可以根据着色器参数(例如,激光宽度或其他)传递给效果以绘制某些东西。我想传递相同的顶点,但使用不同的着色器参数 - 但是,这不起作用。

这是有问题的代码:

           foreach (EffectPass pass in quinticFX.CurrentTechnique.Passes)
            {
                quinticFX.Parameters["NumPoints"].SetValue(CurvedVertices.Count());
                pass.Apply();
                GraphicsDevice.SamplerStates[0] = LinearMirrorState;
                GraphicsDevice.Textures[0] = solid;

                quinticFX.Parameters["radiusOfBeam"].SetValue(8);
                GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, CurvedVertices.ToArray(), 0, CurvedVertices.Count() - 2);
                pass.Apply();

                quinticFX.Parameters["radiusOfBeam"].SetValue(4);
                quinticFX.Parameters["P"].SetValue(cp1);
                GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, CurvedVertices.ToArray(), 0, CurvedVertices .Count() - 2);
            }

假设你可以这样做,它会用不同的控制点和宽度绘制(在本例中为曲线)两次。情况并非如此——仅绘制最近的一组图元。任何帮助将不胜感激。

4

1 回答 1

0

原来我是个白痴——设置参数后需要 Apply() 通行证。

修正后的代码如下:

foreach (EffectPass pass in quinticFX.CurrentTechnique.Passes)
{
    quinticFX.Parameters["NumPoints"].SetValue(CurvedVertices.Count());
    //GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
    GraphicsDevice.SamplerStates[0] = LinearMirrorState;
    GraphicsDevice.Textures[0] = solid;

    quinticFX.Parameters["radiusOfBeam"].SetValue(12);
    pass.Apply();
    GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, CurvedVertices.ToArray(), 0, CurvedVertices.Count() - 2);

    quinticFX.Parameters["radiusOfBeam"].SetValue(6);
    quinticFX.Parameters["P"].SetValue(cp1);
    pass.Apply();
    GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, CurvedVertices.ToArray(), 0, CurvedVertices.Count() - 2);

    quinticFX.Parameters["radiusOfBeam"].SetValue(3);
    quinticFX.Parameters["P"].SetValue(cp2);
    pass.Apply();
    GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, CurvedVertices.ToArray(), 0, CurvedVertices.Count() - 2);
}
于 2012-05-11T17:00:54.860 回答