3

xna でグロー効果を作成しようとしていますが、グローや変更がまったく表示されません。また、私の背中の色は黒ではなく紫で、それも変更できません。

        GraphicsDevice.Clear(Color.Black);
        GraphicsDevice.SetRenderTarget(bulletRenderTarget);
        spriteBatch.Begin();
        foreach (Bullet bullet in bulletList)
        {
            Texture2D bulletTexture = textures[bullet.bulletType];

            spriteBatch.Draw(
                bulletTexture,
                new Rectangle(
                    (int)bullet.position.X,
                    (int)bullet.position.Y,
                    bulletTexture.Width,
                    bulletTexture.Height
                ),
                null,
                Color.White,
                MathHelper.ToRadians(bullet.angle),
                new Vector2(
                    bulletTexture.Width / 2,
                    bulletTexture.Height / 2
                ),
                SpriteEffects.None,
                0
            );
        }
        spriteBatch.End();

        GraphicsDevice.SetRenderTarget(null);
        GraphicsDevice.Clear(Color.Black);
        postProcessEffect.CurrentTechnique = postProcessEffect.Techniques["Blur"];

        spriteBatch.Begin();
            spriteBatch.Draw(
            bulletRenderTarget,
            new Vector2(0, 0),
            Color.White
        );
        GraphicsDevice.BlendState = BlendState.Additive;
        foreach (EffectPass pass in postProcessEffect.CurrentTechnique.Passes)
        {
            pass.Apply();
            spriteBatch.Draw(
                bulletRenderTarget,
                new Vector2(0,0),
                Color.White
            );
        }

        DrawHud();
        foreach (BaseEntity entity in entityList)
        {
            entity.Draw(gameTime);
        }
        spriteBatch.End();

私は弾丸を輝かせようとしているだけです。

シェーダー:

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

 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

1 に答える 1

2

紫色の理由はあなたが持っているからです

GraphicsDevice.Clear(Color.Black);
GraphicsDevice.SetRenderTarget(bulletRenderTarget);

これは逆でなければならないので、それを次のように変更します

GraphicsDevice.SetRenderTarget(bulletRenderTarget);
GraphicsDevice.Clear(Color.Black);

紫色の問題を修正します。シェーダを修正するには、fx ファイルで次のように変更します

sampler ColorMapSampler : register(s0);

そしてあなたspriteBatch.Begin()をに変える

spriteBatch.Begin(SpriteSortMode.Immediate, null);

追加情報:

s0提供するグラフィックス デバイスの最初のテクスチャを指しspriteBatch.Drawます。使用する場合は、次を使用して最初s1に設定する必要があります。GraphicsDevice

GraphicsDevice.Textures[1] = bulletRenderTarget;

は、スプライトをすぐに描画するようSpriteSortMode.Immediateに強制しspriteBatch.Drawます。設定しないと、バッチが作成されて一度に描画されますが、EffectPassが適用されているときに描画する必要があるため、これは遅くなります。

ぼかしに関しては、 の値を下げることができますがBlurDistance、試してみる必要があります。ブルーム シェーダーの実行方法を調べることもできます。通常は、素敵な効果も得られます。

于 2010-12-08T17:21:48.567 に答える