Direct2D 中的颜色衰减/色调
有人知道如何在使用 Direct2D 渲染时更改位图的颜色吗?使用 Direct3D,指定不同的顶点颜色或者在使用精灵批处理时提供颜色是一件简单的事情。我想使用 Direct2D 来完成此操作。预先感谢您的任何帮助。
Has anyone figured out how to change the color of bitmaps when rendering with Direct2D? With Direct3D it's a simple matter of specifying different vertex colors or, when using the sprite batch, providing a color. I would like to do this using Direct2D. Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我尝试过使用 CLSID_D2D1ColorMatrix 效果对位图进行着色,它确实有效,但性能非常糟糕(如果您需要每帧都这样做)。
如果颜色会发生很大变化,我可以缓存输出,但我喜欢在精灵上的色调上制作动画以实现闪烁/损坏效果,因此缓存没有帮助。
我的下一步行动是将渲染器切换到 D3D,并仅实现 SpriteBatch 着色器,包括着色(或基于 DirectX 工具包实现):
http://blogs.msdn.com/b/shawnhar/archive/2012/06 /18/directx-tool-kit-is-now-on-codeplex.aspx
I have tried using the CLSID_D2D1ColorMatrix effect to tint the bitmap and it does work but the performance is pretty terrible (if you need to do it every frame).
I could cache the output if the color is going to change a lot but I like to do animations over the tint on my sprites to do flashing/damage effects and so caching wouldn't help.
My next course of action is to switch my renderer to D3D and just implement the SpriteBatch shader including tinting (or base it off of DirectX Tool Kit implementation):
http://blogs.msdn.com/b/shawnhar/archive/2012/06/18/directx-tool-kit-is-now-on-codeplex.aspx
使用当前的 API,在绘制的图像上绘制半透明的几何体是最简单的方法。
如果您愿意使用预览API:
它不像XNA的SpriteBatch那么方便,但是使用ID2D1DeviceContext::SetPrimitiveBlend()来设置您想要的混合类型(additive或source over alpha blend),然后您可以在上面绘制或在图像下方模拟您正在寻找的色调效果。
或者,您可以使用 DImage 的 ID2D1Effects (D2D 的新组件)使用内置效果或自定义效果来绘制图像。
DImage 效果可以链接在一起形成“效果图”,想想基于节点的着色器编辑器。
最后,您可以使用 ID2D1GpuTransform< /a>.它允许在 ID2D1GpuTransform 中设置像素着色器。该变压器可以插入到效果图中。
Using the current API, drawing a semitransparent geometry over the drawn image is the easiest method.
If you are willing to use the preview APIs:
It isn't as convenient as XNA's SpriteBatch, but using ID2D1DeviceContext::SetPrimitiveBlend() to set the type of blending you want (additive or source over alpha blend) then you can draw on top or below the image to simulate the tint effect you are looking for.
Alternatively you can use the DImage's ID2D1Effects (new component to D2D) to use a built in effect or custom effect to draw an image.
DImage effects can be chained together to from an "effect graph", think node based shader editors.
Finally you have available the ID2D1GpuTransform. It allows pixel shader to be set in the ID2D1GpuTransform. This transformer can be plugged into the effect graph.