gpt4 book ai didi

ios - 打开 : can I write to multiple locations in the output buffer when using a shader?

转载 作者:行者123 更新时间:2023-11-29 13:21:56 25 4
gpt4 key购买 nike

我在基于 CPU 的程序中运行了一些方程式来处理 iOS 图像。输出的形式是:

for (y = 0; y < rows; ++y){
for (x = 0; x < cols; ++x){
<do math>
outputImage[y*cols + x] += <some result>
outputImage[y*cols + (x+1)] += <some result>
outputImage[(y+1)*cols + x] += <some result>
}
}

我认为这段代码可以(并且应该)被扔到 GPU 上,可能是通过 GPUImage。诀窍在于输出——根据我的理解,我只能将着色器的结果放入 gl_FragColor。是否可以编写一个片段着色器,将结果放入输出的多个像素中?我在哪里可以找到该技术的示例?

最佳答案

Is it possible to write a fragment shader that puts results into more than one pixel on the output?

没有。着色器旨在单独工作。这就是为什么他们如此之快。

您应该将算法重构为“着色器友好”。尝试提取输入,以便它们可以为计算单个片段的单个值的算法提供数据。尽量避免分支和循环,否则将计算保留在 CPU 上可能是个好主意。

假设<do math>将 x 和 y 作为输入,这些可以从 gl_FragCoord 获得.如果<some result><do math> 的输出你的着色器程序看起来像这样:

vec4 location = getLocation(gl_FragCoord);
gl_FragColor += do_math(location.x, location.y);
gl_FragColor += do_math(location.x-1, location.y);
gl_FragColor += do_math(location.x, location.y-1);

注意减法而不是加法。以这种方式,片段完全计算自己的值(value),而不是修改邻居。

关于ios - 打开 : can I write to multiple locations in the output buffer when using a shader?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14167256/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com