0

我正在开发一个 XNA/MonoGame 游戏,我有这个粒子引擎,它可以模拟爆炸。所以,这是粒子引擎的 Draw 方法:

spriteBatch.Draw(Texture, Position, sourceRectangle, Color, 0, origin, Size, SpriteEffects.None, 0f);

其中 Color 是随机颜色(因为纹理是白色的)

问题是,我想为每个粒子设置一个效果,但我不能,因为效果会使粒子变回原来的白色!

我究竟做错了什么???

这是着色器之一(但我也测试了其他效果)

float BlurDistance = 0.002f;
 sampler ColorMapSampler : register(s0);

 float4 PixelShaderFunction(float2 Tex: TEXCOORD0) : COLOR
 {
  float4 Color;

  // Get the texel from ColorMapSampler using a modified texture coordinate. This
  // gets the texels at the neighbour texels and adds it to Color.
  Color  = tex2D( ColorMapSampler, float2(Tex.x+BlurDistance, Tex.y+BlurDistance));
  Color += tex2D( ColorMapSampler, float2(Tex.x-BlurDistance, Tex.y-BlurDistance));
  Color += tex2D( ColorMapSampler, float2(Tex.x+BlurDistance, Tex.y-BlurDistance));
  Color += tex2D( ColorMapSampler, float2(Tex.x-BlurDistance, Tex.y+BlurDistance));
  // We need to devide the color with the amount of times we added
  // a color to it, in this case 4, to get the avg. color
  Color = Color / 4; 

  // returned the blurred color
  return Color;
 }

 technique Blur
 {
  pass Pass1
  {
   PixelShader = compile ps_2_0 PixelShaderFunction();
  }
 }
4

0 回答 0