是否可以使用 Xna 在一次传递中将场景渲染为多个纹理?
我想知道是否可以在一次传递中将场景渲染到多个渲染目标(或者比通过客户端代码多次绘制场景更快)。我想优化一些渲染为不同尺寸的多个纹理(例如 512 x 512、256 x 256、128 x 128 和 64 x 64)的代码。
我意识到我可以使用从原始目标派生的 mip 贴图,但我不想混合颜色。我怀疑 mip 映射将从几个纹理像素中取平均值,但出于我的目的,我只想要未修饰的渲染,如显卡渲染的那样。如果 mipmap 有任何设置允许这样做,那么它作为一个可行的解决方案也是相当重要的。
顺便说一句,有谁知道 mipmap 是在 CPU 还是 GPU 上生成的?
感谢您的阅读。
I am wondering if it is possible to render a scene to multiple render targets in a single pass (or anything faster than drawing it several times through client code). I want to optimize some code that is being rendered to several textures of varying dimensions (512 by 512, 256 by 256, 128 by 128 and 64 by 64 for example).
I realize I could use mip maps derived from the original target, but I don't want to blend colors. I suspect that mip mapping will take average from a few texels, but for my purposes I just want the unretouched rendering, as rendered by the graphics card. If there is any setting for mipmaps that allow this, then it's also considerable as a feasible solution.
On a side note, does anyone know if mipmaps are generated on the CPU or GPU?
Thanks for reading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题没有可能的解决方案。 MRT 无法使用不同的分辨率。 Mipmaping 无法生成看起来与原始纹理完全相同的较小纹理。事实上,据我所知,绝对没有办法做到这一点。使用新显卡时,mipmap 是在 GPU 上生成的。
一个问题:为什么要渲染到方形目标?
There is no possible solution for your question. MRTs can't work with different resolutions. Mipmaping can't produces smaller textures that look exacly the same as the original. Actually, there is absolutely no way to do that AFAIK. With new graphics cards, mipmaps are generated on GPU.
One question: why are you rendering to square targets?
正如 Quang Anh 所说 - 没有办法完全按照你的要求去做。那么你到底想实现什么目标呢?
如果您担心缩小 mipmap 时发生的混合,为什么不使用渲染目标并将其(在“全屏”四边形上)渲染到另一个渲染目标 点采样? (并对您想要的每个尺寸重复该操作。)
添加了以下注释:
如果您正在做的事情涉及深度(或与深度类似的数据),并且您需要知道每个像素的最大(或最小)深度,并且您将减半每次图像的分辨率:
您可以使用相同的缩放技术,通过点采样将一个渲染目标渲染到另一个渲染目标(如上面我的原始答案中所述)。在像素着色器中,对将成为输出图像中的一个像素的四个像素进行采样。只需从四个像素中选择最大(或最小)值像素作为要输出的像素即可。
(我将把排列样本所需的数学作为练习。)
As Quang Anh says - there's no way to do exactly what you are asking for. So what are you actually trying to achieve?
If you are concerned about the blending that takes place when scaling down for mipmaps, why not take your render target, and render it (on a "full-screen" quad) to another render target using point sampling? (And repeat that for each size you want.)
Added following comments:
If what you are doing involves depth (or data similar to depth), and you need to know the maximum (or minimum) depth per pixel, and you are halving the resolution of your image each time:
You could use the same technique of scaling by rendering one render-target to another with point sampling (as described in my original answer, above). And in a pixel shader sample the four pixels that will become one pixel in the output image. Simply select the maximum (or minimum) valued pixel from the four as the one to output.
(I will leave the maths required to get samples lined up as an exercise.)