2012-05-09 156 views
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); 
      } 

假設你能做到這一點,它會繪製(在這種情況下,曲線)與不同的控制點和寬度的兩倍。情況並非如此 - 只繪製了最近的一組基元。任何幫助將不勝感激。

回答

0

事實證明,我是一個白癡 - 你需要在設置參數後應用()通過。

校正代碼如下:

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); 
}