2013-07-22 1 views
0

Overwritten Alpha Mask추가 할 때 다시 작성되는 알파 마스크는 어떻게 만듭니 까? I는 (흰색 위의 예에서) 텍스쳐 투명하게 응용에서 안개 같은 효과를 만들려고하고

부터 멀어지는 농도의 계조와 스프라이트 주위 (이하 흑 텍스처를 표시) 그들의 중심. 그러나 알파 마스크에 새 원을 추가 할 때마다 마스크 텍스쳐에 대한 이전 추가 내용을 덮어 쓰면서 위에 그린 불쾌감 효과를 만듭니다. 이전의 추가 작업과 잘 조화되도록 마스크 텍스처에 새로운 추가 작업을 시도했지만 어떻게 처리 할 수 ​​있습니까?

나는 마스크를 만들기 위해 마스크를 만드는 것과 같은 일을 시도했지만 아무 것도 보이지 않고 나오거나 알파 쉐이더 fx 파일 (매우 이상한 시각적 효과를 내기도한다)을 사용하여 내 알파 마스크로 그려 넣었다.

알파 마스크에 추가 된 내용을 서로 섞어서 어떻게 겹쳐 쓰지 않으려면 어떻게해야합니까?

도움을 주시면 감사하겠습니다.

는 ------------- 코드 : 알파 마스크의 -------------

업데이트는이 방법으로 이루어집니다 :

public void mainTextureDraw() 
     { 
      //alpha shader is the fx file (below) 
      alphaShader.Parameters["MaskTexture"] 
           .SetValue(alphaMask); 
     // start a spritebatch for our effect 
     spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, 
      null, null, null, alphaShader); 

     play.game.spriteBatch.Draw(mainTexture, 
      position, 
      null, Color.White, 0f, 
      new Vector2(0, 0), 
      1f, SpriteEffects.None, 1f); 

     spriteBatch.End(); 
    } 

그리고 FX 파일의 중요한 방법 :

,691,363 주요 질감에 그리기
public void createLightSource(Vector2 RemovePosition, Texture2D circleTexture) 
    { 

      // Create a render target, which we will draw to instead of the screen 
      RenderTarget2D target = new RenderTarget2D(graphics.GraphicsDevice, mainTexture.Width, mainTexture.Height); 

      // set the RenderTarget2D as the target for all future Draw calls untill we say otherwise 
      graphics.GraphicsDevice.SetRenderTarget(target); 

      // start our batch as usual.. 
      spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); 

      // start with a transparent canvas 
      graphics.GraphicsDevice.Clear(Color.Transparent); 

      // add in the previously drawn dots from the current alpha map. 
      spriteBatch.Draw(alphaMask, new Vector2(0, 0), null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 1f); 

      // add a new dot to the map. 
      play.game.spriteBatch.Draw(circleTexture, 
        new Vector2((float)(RemovePosition.X - mainTexture.x), (float)(RemovePosition.Y - mainTexture.y)), 
        null, 
        Color.White, 
        0f, 
        new Vector2(circleTexture.Width/2f, circleTexture.Height/2f), 
        1f, 
        SpriteEffects.None, 
        1f); 

      // end the draw call 
      spriteBatch.End(); 

      // start drawing to the screen again 
      graphics.GraphicsDevice.SetRenderTarget(null); 

      // set our Texture2D Alpha Mask to equal the current render target (the new mask). 
      // RenderTarget2D can be cast to a Texture2D without a problem 
      alphaMask = target; 
     } 

이 방법으로 이루어집니다210

float4 PixelShaderFunction(float2 inCoord: TEXCOORD0) : COLOR 
{ 
    // we retrieve the color in the original texture at 
    // the current coordinate remember that this function 
    // is run on every pixel in our texture. 
    float4 color = tex2D(mainTexture, inCoord); 

    // Since we are using a black and white mask the black 
    // area will have a value of 0 and the white areas will 
    // have a value of 255. Hence the black areas will subtract 
    // nothing from our original color, and the white areas of 
    // our mask will subtract all color from the color. 
    color.rgba = color.rgba - tex2D(alphaMask, inCoord).r; 

    // return the new color of the pixel. 
    return color; 
} 

답변

1

실제 결과가 어떻게 보이는지 알지 못하기 때문에 어떤 방향으로 접근해야하는지 확신 할 수 없습니다. 다음은 내가 말하는 것에 대한 몇 가지 예입니다.

https://plus.google.com/photos/117280483756658540406/albums/5903487202722042913?authkey=CK-_kZvo2Iqy9wE

는 그러나, 나는 가장 좋은 방법은 PixelShaderFunction 보는 것입니다 생각합니다. 기존 질감은 color이고 빨간색 구성 요소는 tex2D()입니다. 내가 유용한 접근법이 될지 궁금한 점은 tex2D(). r을 사용하여 color.r보다 큰지 확인하고, 그렇다면 tex2D()를 빼는 대신 색상의 값을 사용하는 것입니다.

기본적으로 유지하려는 임계 값이 있습니다. 픽셀에서 조건을 테스트 한 다음, 어떻게 변경해야하는지 결정해야합니다.

+0

두 번째 질문 : https://lh3.googleusercontent.com/-jPUqW89ZRk4/Ue1mViaBgTI/AAAAAAAAAAAA/JL7-5GDHf8/s400-no/multiply.png는 내가 찾고있는 것입니다. 나는 BlendState를 사용하여 그와 비슷한 것을 얻었습니다.하지만 여러분이 위에 제안한 것을 시도해 보았을 때 화면 전체가 완전히 흰색이되었습니다. 두 번째 주에 대한 해결책을 볼 수 있을까요? – user2457072

+0

http://i.imgur.com/F8DhKZC.png 이것은 혼합 첨가제 첨가제로 얻는 것입니다. 그러나 볼 수 있듯이 흰색의 코로나가 여전히 다른 원의 원으로 퍼져 있습니다. – user2457072

+0

음 ... 나는 그 두 가지를 만들기 위해 Photoshop을 사용했습니다. 두 번째는 Multiply를 사용했는데, (color1.r * color2.r)/255 –

관련 문제