混合两个精灵以获得重叠 [英] Blending two sprites to get the overlap

查看:95
本文介绍了混合两个精灵以获得重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


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

I'm stuck for several days now. What I'm trying to achieve shouldn't be that hard, but I cannot figure it out.

http://i.stack.imgur.com/TjOZI.png

http://i.stack.imgur.com/TjOZI.png

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

I want to blend two sprites together and only get the overlapping part as a result (the blue part in the image). The limitation that I have is it must be under the Reach-profile (limited blending options and no shaders). Because of that I cannot figure out how to blend both sprites to get the result.

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

I do have stencilmasks for both sprites and the white in the image is transparent (and should also be transparent in the resulting image).

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

This is the code I have so far:

//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();

此代码导致(不是我想要的):http://i43.tinypic.com/ 2u9oldw.png

This code results in (not what I want): http://i43.tinypic.com/2u9oldw.png

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

I do understand why I get this result (because it's just an additive render), but I don't know how to get it right (cutting of the non-overlapping parts).

我还可以得到以下结果:http://i43.tiny pic.com/2d9tz7n.png

I can also get the following result: http://i43.tinypic.com/2d9tz7n.png

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

But that's with one of the stencils using a white background instead of a transparent one.

推荐答案

这不是Windows Phone API。

This is not a Windows Phone API.

您可以在此获得有关该工具包的帮助:
http://directxtk.codeplex.com/

You can get help with that toolkit here: http://directxtk.codeplex.com/

有一个问题和讨论部分供您使用有调查。

There is an issues and discussions section for you there to investigate.


这篇关于混合两个精灵以获得重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆