2010-12-08 5 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에서 제공하는 하나 그래픽 장치의 첫 번째 질감에 s0s1을 사용하려면 먼저 GraphicsDevice에 다음을 사용하여 설정해야합니다.

GraphicsDevice.Textures[1] = bulletRenderTarget; 

SpriteSortMode.ImmediatespriteBatch.Draw이 스프라이트를 즉시 그리도록 강요합니다. 설정하지 않으면 배치를 만들고 한 번에 모두 그릴 수 있지만, EffectPass 적용되고 있습니다.

흐림 효과에 관해서는 BlurDistance의 값을 낮출 수는 있지만, 시도해야 할 것입니다. 블룸 쉐이더를 수행하는 방법을 찾아 볼 수도 있습니다. 대개 좋은 효과도줍니다.

+0

고마워요, 그것을 모두 고정시킬 수있는 레지스터와 spritesortmode에 정교한, 그게 정확히 무엇합니까? 또한 내가 어떻게 총알이 빛나고 싶었 기 때문에 나는 블러 털을 줄일 수는 있겠지만, 이제는 내 총알이 빛나고 희미 해졌습니다. – Xyro

+0

@Quincy 대답에 – Doggett

+0

을 추가했습니다. 꽃이 조금 더 나아 졌으면 좋겠습니다.) – Xyro