2010-12-08 22 views
3

xnaにグロー効果を加えようとしましたが、グローや変化が全く表示されません。また、私の背中の色が紫の代わりに黒であり、私はどちらかのことを変更することはできません:私は唯一の輝き弾丸を取得しようとしている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(); 
    } 
} 
+0

エラーは何ですか? –

+0

なし、それはちょうど正常なゲームプレイを示しています。ブラックのバックスクリーンを除いて、それは紫に変わります。 – Xyro

答えて

2

あなたがそう

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

修正紫にそのを変え、他の方法で回避する必要があります

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

を持っているので、それは紫だ理由は、問題は、fxファイルの次の変更をシェイダーを修正するには

sampler ColorMapSampler : register(s0); 

そして、あなたのspriteBatch.Begin()

spriteBatch.Begin(SpriteSortMode.Immediate, null); 

にいくつかの余分な情報変更:あなたがしたい場合は、 spriteBatch.Drawによって提供されるものですグラフィックスデバイス上の最初のテクスチャに

s0ポイントs1を使用するには、まずGraphicsDeviceに設定する必要があります。

GraphicsDevice.Textures[1] = bulletRenderTarget; 

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

BlurDistanceの値を低くすることはできますが、試してみる必要があります。また、ブルームシェイダーを行う方法を調べることもできます。

+0

これですべてが修正されました。レジスタとspritesortmodeについて詳しく説明できますか? また、私はぼやけを減らすことができますが、私は弾丸が輝くようにするためにbluredしましたが、今弾丸が光ってぼやけています – Xyro

+0

@Quincy答えに – Doggett

+0

を追加しました。 ) – Xyro

関連する問題