如何获得 HLSL 计算的输出?
我基本上想使用 .NET 将 GPU 结果屏幕捕获到位图文件中。我可能会使用 XNA,我的工作流程将类似于:
- 使用自定义输入数据调用效果
- 让效果运行每像素进程
- 从效果中获取结果 (???)
- 将结果另存为位图
谢谢...
编辑
Liortal回答的摘要:
要使用渲染目标,请创建一个 具有宽度的 RenderTarget2D 对象, 高度,以及您喜欢的其他选项。 然后打电话 GraphicsDevice.SetRenderTarget 来制作 您的渲染目标当前渲染 目标。从此时起,任何抽奖 您拨打的电话将吸引您的 渲染目标。当你完成时 使用渲染目标,调用 GraphicsDevice.SetRenderTarget 为 新的渲染目标(或 null 后台缓冲区)。然后你可以随时 调用RenderTarget2D.GetTexture获取 渲染目标的内容 进一步加工。
I would basically like to screen capture a GPU result into a bitmap file using .NET. I would probably use XNA and my workflow would be something like:
- Call an effect with custom input data
- Have the effect run a per-pixel process
- Get the result from the effect (???)
- Save result as bitmap
Thanks...
Edit
Summary from Liortal's answer:
To use a render target, create a
RenderTarget2D object with the width,
height, and other options you prefer.
Then call
GraphicsDevice.SetRenderTarget to make
your render target the current render
target. From this point on, any Draw
calls you make will draw into your
render target. When you are finished
with the render target, call
GraphicsDevice.SetRenderTarget to a
new render target (or null for the
back buffer). Then at any time you can
call RenderTarget2D.GetTexture to get
the contents of the render target for
further processing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在此处详细了解渲染目标以及如何使用它们:http://msdn.microsoft .com/en-us/library/bb976073.aspx
请注意,该链接引用的是 XNA 3.1,这是由令人敬畏的 Shawn Hargreaves 撰写的关于此版本中所做更改的帖子XNA 4 中的区域:http://blogs.msdn.com/b/shawnhar/archive/2010/03/26/rendertarget-changes-in-xna-game-studio-4-0.aspx
Read more about Render Targets and how to use them here: http://msdn.microsoft.com/en-us/library/bb976073.aspx
Note that the link refers up to XNA 3.1, here's a post by the awesome Shawn Hargreaves about changes made in this area in XNA 4: http://blogs.msdn.com/b/shawnhar/archive/2010/03/26/rendertarget-changes-in-xna-game-studio-4-0.aspx
RenderTarget
就是您在这里所追求的。设置RenderTarget
(graphicsDevice.SetRenderTarget(myRenderTarget);
),绘制场景,然后使用SaveAsJpeg
或SaveAsPng
> 保存输出的方法。这是 RenderTarget 文档。
然而,人们提到了内存泄漏,所以我会使用这个替代方案:
BmpWriter
此链接包含您需要的源代码(正如我上面提到的)。
RenderTarget
's are what you are after here. Set theRenderTarget
(graphicsDevice.SetRenderTarget(myRenderTarget);
), draw your scene and then use eitherSaveAsJpeg
orSaveAsPng
methods to save the output.Here is the XNA 4 version of the RenderTarget documentation.
However, people have mentioned about memory leaks, so I would use this alternative:
BmpWriter
This link has the source code that you require (as I mentioned above).