gpt4 book ai didi

ios - 如何在 glsl 的 texture2D 中正确采样 textureCoordinate

转载 作者:行者123 更新时间:2023-11-28 17:38:40 24 4
gpt4 key购买 nike

我想在特定像素周围采样 8 个像素,并从中计算出一堆信息以用于阈值处理程序。

这是在 iOS 中使用 glsl 顶点和片段着色器。

这是我的片段着色器采样代码:

p00 = texture2D(videoFrame, textureCoordinate+vec2(-1.0*extent, -1.0*extent)); 
p01 = texture2D(videoFrame, textureCoordinate+vec2( 0.0, -1.0*extent));
p02 = texture2D(videoFrame, textureCoordinate+vec2(+1.0*extent, -1.0*extent));
p10 = texture2D(videoFrame, textureCoordinate+vec2(-1.0*extent, 0.0));
p11 = texture2D(videoFrame, textureCoordinate);
p12 = texture2D(videoFrame, textureCoordinate+vec2(+1.0*extent, 0.0));
p20 = texture2D(videoFrame, textureCoordinate+vec2(-1.0*extent, +1.0*extent));
p21 = texture2D(videoFrame, textureCoordinate+vec2( 0.0, +1.0*extent));
p22 = texture2D(videoFrame, textureCoordinate+vec2(+1.0*extent, +1.0*extent));

extent 只是一个数字,目前设置为 20.0。我希望在本地合理地进行采样。

这编译正常,但是根据我的例程结果,我怀疑这不是在当前像素周围采样像素,而是似乎是在沿一行延伸的像素采样。

有什么办法可以解决这个问题吗?

我不确定这是否有效的另一个原因是在 iOS 文档中 Apple 指出这应该打包在一个图像单元中并且使用 regionofinterest 函数。如果可能的话,我宁愿将它全部保存在 glsl 着色器中。

最佳答案

如果范围为 20,您将对当前像素周围 8 个主要方向上的 8 个像素进行采样,但距离 20 像素。 (所以 20 个像素“北”,20 个像素“东北”,等等)如果它是 1.0,那么你所写的应该对当前像素周围的 8 个像素进行采样。 (我还假设 textureCoordinate 是当前像素的坐标。确保是这种情况。)

关于ios - 如何在 glsl 的 texture2D 中正确采样 textureCoordinate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9016117/

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