使用 DirectX (2D) 创建多层渲染

发布于 2025-01-08 10:20:58 字数 564 浏览 2 评论 0原文

我是 DirectX 的新手,所以我对这项技术了解不多。 我想重现 Photoshop 所做的相同渲染。我的意思是能够实时渲染多个图层(每个图层都有 alpha 贴图)。 有人告诉我 Photoshop 使用 DirectX/OpenGl。对于我的项目,我可以使用 DirectX。

我发现这篇文章 Direct3D 使用“乘法”渲染 2D 图像混合模式和 alpha 准确地解释了我想要做什么,但这篇文章相当旧,他使用的是 D3D9。也许,现在有一种更简单/更快的方法可以使用 DirectX 11 和 Direct2D 创建相同的效果。

我希望在我开始任何事情之前你能给我一些建议。

谢谢。

编辑:我不知道我是否足够清楚,我不要求任何代码,只是要求一个方向:如果我应该使用 Direct2D 或 Direct3D 9/10/11。如果我必须对着色器进行编程...那么做这个项目最好的方法是什么?

I'm new on DirectX so I don't know a lot of things about this technology.
I would like to reproduce the same rendering that photoshop is doing. I mean to be able to render in real time several layers (with alpha map for each layer).
Someone told me that photoshop uses DirectX/OpenGl. For my project I can use DirectX.

I found this post Direct3D rendering 2D images with "multiply" blending mode and alpha which explains exactly what i want to do but this post is quite old and he used D3D9. Maybe, there is now a simpler/faster way to create the same effect using DirectX 11 and Direct2D.

I hope you would give me some advice before I start anything.

Thank you.

Edit: I don't know if I was enough clear, I'm not asking for any code, just for a direction: if I shoud use Direct2D or Direct3D 9/10/11. If I will have to program shaders... And what would be the best to do this project ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无人问我粥可暖 2025-01-15 10:20:58

根据您正在寻找的性能,D3D 或 D2D 会更合适。 D3D 是一种更保留的模式,因此需要使用更复杂的 API,但如果性能是绝对关注的,那么它就是您所需要的。 D2D API 是更直接的模式,但这当然会导致 API 更简单且性能更慢。

根据我的经验,我会从 D2D 开始,特别是因为新的 D2D API,例如 ID2D1DeviceContext::DrawImage()ID2D1Effect 支持多种混合和复合模式。 D2D 与 D3D 的交互操作非常好,因此将来您可以根据需要使用 D3D 的部分内容。 D2D还提供了非常漂亮的接口来支持打印,因此可以使用相同的渲染代码来打印。

Depending on the performance you are looking for D3D or D2D would be more appropriate. D3D is much more retained mode, thus a more complex API to use, but it is what you'll want if performance is of absolute concern. D2D API is much more immediate mode, but this of course leads to a simpler API and slower performance.

Based on my experience I'd start with D2D, especially since the new D2D APIs such as ID2D1DeviceContext::DrawImage() and ID2D1Effect supports many blend and composite modes. D2D does inter operate with D3D quite nicely so in the future you can use parts of D3D if you need. D2D also provides a very nice interface to support printing, so the same rendering code can be used to print.

童话 2025-01-15 10:20:58

如果您使用的是当前发布的 Direct2D 版本(不是 Win8 预览版中的更新版本),则可以使用 alpha 蒙版实现“OVER”(又名“正常”)混合。将内容渲染为 PBGRA32 位图,然后将遮罩(如果需要)渲染为 Alpha8 位图。然后,从内容位图创建位图画笔,并使用 ID2D1RenderTarget::FillOpacityMask()。如果不需要遮罩,则只需使用 DrawBitmap() 并跳过位图画笔。

要实现任何其他混合模式,您需要较新的 Direct2D,在 Windows 8 发布之前它不会对所有人可用(我认为它也适用于 Win7)。或者,当然,您可以在软件模式下完成,但您必须从头开始实现一切。

If you're using the currently shipping version of Direct2D (not the updated one in the Win8 previews), you can implement "OVER" (aka Normal) blending with alpha masks. Render the content into a PBGRA32 bitmap, and then render a mask (if needed) into an Alpha8 bitmap. Then, create a bitmap brush from the content bitmap, and use ID2D1RenderTarget::FillOpacityMask(). If the mask isn't needed then just use DrawBitmap() and skip the bitmap brush.

To implement any additional blending modes you'll need the newer Direct2D, which won't be available for everyone until Windows 8 ships (I think it's being made available for Win7 too). Or, of course, you can do it in software mode but you'll have to implement everything from scratch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文