所有像素的高效像素着色器总和
如何使用 HSLS 像素着色器有效计算图像中所有像素的总和?我对 Pixel Shader 2.0 感兴趣,我可以将其作为 WPF 着色器效果进行调用。
How can I efficiently calculate the sum of all pixels in an image, by using a HSLS pixel shader? I'm interested in Pixel Shader 2.0, that I could invoke as a WPF shader effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有一个更简单的解决方案,不使用着色器:将图像加载为纹理,创建 mipmap 链并读回最后一个 mipmap 的值(1x1 像素)。此技巧在游戏中广泛用于计算场景的平均亮度等(以便应用 HDR 色调映射)。如果您重视简单性和效率而不是准确性,那么这是一个很好的技巧。
There is a much simpler solution that doesn't use shaders: load the image as a texture, create a mipmap chain and read back the value of the last mipmap (1x1 pixel). This trick is used in games extensively to calculate, for example, the average brigthness of a scene (in order to apply HDR tonemapping). It's a great trick if you value simplicity and efficiency over accuracy.
假设您想要对图像中的 r/g/b 通道值求和(并假设您可以破坏原始像素) - 这是我的部分解决方案:
。
在这种情况下,与仅在 CPU 端求和像素值相比,我们获得了约 10 倍的加速。
Assuming that you want to sum r/g/b channel values in image (and assuming that you can destroy original pixels) - here is my partial solution:
of each 10th pixel.
In this case we get about 10x speed-up compared to summing pixel values only in CPU side.
WPF 中的效果更适合产生视觉效果。听起来您想将它们用于不同类型的计算,为此您需要将图像结果视为数据,这需要 RenderTargetBitmap ,无论如何这都将在软件中完成。
您可能想看看这些为 GPGPU 设计的项目。
加速器
Brahma
OpenTK 我不知道 OpenCL 的状态OpenTK 中的绑定。 DirectCompute 和 CUDA 等其他技术也可能值得一看。
Effects in WPF are much more suited to producing visual result. It sounds like you want to use them for a different type of calculation, to do this you would need to treat the image result as data this would need RenderTargetBitmap which would be done in software anyway.
You might want to look at these projects designed for GPGPU.
Accelerator
Brahma
OpenTK I dont know the state of the OpenCL bindings in OpenTK. Other technologies such as DirectCompute and CUDA might be worth a look too.