gpt4 book ai didi

opengl - dFdxFine 和 dFdxCoarse 的区别

转载 作者:行者123 更新时间:2023-12-04 23:40:18 29 4
gpt4 key购买 nike

从 OpenGL 文档:

dFdxFine and dFdyFine calculate derivatives using local differencing based on on the value of p for the current fragment and its immediate neighbor(s).

dFdxCoarse and dFdyCoarse calculate derivatives using local differencing based on the value of p for the current fragment's neighbors, and will possibly, but not necessarily, include the value for the current fragment. That is, over a given area, the implementation can compute derivatives in fewer unique locations than would be allowed for the corresponding dFdxFine and dFdyFine functions.



它们之间的区别是什么?我什么时候应该关心?

我知道两者都计算关于窗口坐标的值的导数,但我不明白用于计算它们的方法。

我猜它们都是在硬件中实现的,但是你能发布一个 dFdx 伪代码实现吗?

最佳答案

从 GLSL 规范:

It is typical to consider a 2x2 square of fragments or samples, and compute independent dFdxFine per row and independent dFdyFine per column, while computing only a single dFdxCoarse and a single dFdyCoarse for the entire 2x2 square.



基本上计算导数的方式是通过数值微分。为简单起见,假设我们正在渲染到单采样帧缓冲区,并假设我们要计算 dFdx(a) .然后通常会同时着色一个 2x2 正方形的相邻片段(即在同一工作组内):
    a00  a10
a01 a11

从概念上讲,所有着色器调用都将计算它们的值 a ,将其写入共享内存,并发出屏障。然后在障碍之后,导数可以近似为:
dFdxFine(a) = (a10 - a00)/dx       at xy = 00, 10
dFdxFine(a) = (a11 - a01)/dx at xy = 01, 11

对于粗导数,规范明确允许仅计算整个 2x2 像素块的一个导数。因此,符合要求的实现也可以计算:
dFdxCoarse(a) = (a10 - a00)/dx     at xy = 00, 10, 01, 11

两者在性能上是否存在差异取决于硬件。如果它们确实在您的硬件上返回不同的结果,那么“粗略”版本应该更快。但是,通常您不应该关心这些功能。只需使用 dFdxdFdy变体,使用实现默认变体(细或粗)。

关于opengl - dFdxFine 和 dFdxCoarse 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39579150/

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