它会融合吗?开始认为这根本不可能

时间:2014-01-01 21:56:01

标签: c# windows-phone-7 rendering xna-4.0

我已经被困了好几天了。我想要实现的目标不应该那么难,但我无法弄明白。

enter image description here

我想将两个精灵混合在一起,只得到重叠的部分(图像中的蓝色部分)。我的限制是它必须在Reach-profile下(有限的混合选项和没有着色器)。因此,我无法弄清楚如何混合两个精灵来获得结果。

我确实为两个精灵都有模板掩模,图像中的白色是透明的(在结果图像中也应该是透明的)。

这是我到目前为止的代码:

//Set the render target
spriteBatch.GraphicsDevice.SetRenderTarget(rtFinal);

//Clear the renderTarget
spriteBatch.GraphicsDevice.Clear(Color.Transparent); //I need transparent result

//Clear the stencil's buffer
spriteBatch.GraphicsDevice.Clear(ClearOptions.Stencil, Color.White, 0, 0);

spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive); //Adding the two sprites together

spriteBatch.Draw((rtCutOut as Texture2D), Vector2.Zero, Color.White); //Unsure about this color
spriteBatch.Draw(ent.StencilTex, Vector2.Zero, Color.Blue); //Using the other stencil

spriteBatch.End();

此代码导致(不是我想要的):

enter image description here

我明白为什么我得到这个结果(因为它只是一个附加渲染),但我不知道如何正确(切割非重叠部分)。

我也可以得到以下结果:

http://i43.tinypic.com/2d9tz7n.png

但这是使用白色背景而不是透明的模板之一。

请在我失去理智之前帮忙......

0 个答案:

没有答案