我已经阅读了许多关于 dFdX(n)
和 dFdY(n)
行为的描述,并且相信我仍然掌握了学校偏导数。我没有遵循的是在最简单的例子中'n'来自哪里?
在没有数学以外的任何上下文的情况下读取 glsl 内置函数 dFdx(n)
和 dFdy(n)
我会将它们解释为“我有一些 x 和 y 的函数: f(x,y)
,我取该函数的偏导数 x d/dx(x,y)
,然后计算导数x
和 y
的某个值的公式,我假设它是上面的输入参数 n
。
我已经阅读了许多关于 dFdx()
和 dFdy()
如何让您找到输出片段的窗口空间渐变的描述。输出片段情况是我目前最感兴趣的,因为我不是要确定纹理坐标的变化率 w.r.t 纹理是如何被光栅化的。
我希望使用 dFdx(n)
和 dFdy(n)
来查找输出片段的窗口空间颜色渐变。我不完全理解如何在心理上构建被区分的函数以及它与帧缓冲区的关系以及 n
与该函数的关系(例如 n
是否与当前片段的 2x2 片段邻域、整个帧缓冲区的窗口坐标空间有关)这样我正在评估该值的梯度,其他)?
我希望在对这个问题的任何回答中 n
的输入类型是标量(浮点数),我们只讨论一个维度 dFdx()
,以简化讨论。
最佳答案
让我们检查 man page :
genType dFdx( genType p); genType dFdy( genType p);
Available only in the fragment shader, these functions return the partial derivative of expression p with respect to the window x coordinate (for dFdx*) and y coordinate (for dFdy*).
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 returns either dFdxCoarse or dFdxFine. dFdy returns either dFdyCoarse or dFdyFine. The implementation may choose which calculation to perform based upon factors such as performance or the value of the API GL_FRAGMENT_SHADER_DERIVATIVE_HINT hint.
Expressions that imply higher order derivatives such as dFdx(dFdx(n)) have undefined results, as do mixed-order derivatives such as dFdx(dFdy(n)). It is assumed that the expression p is continuous and therefore, expressions evaluated via non-uniform control flow may be undefined.
专注于 Fine 变体。当每个片段进程到达 dFd* 调用时,GPU 将收集传入的值并基于这些值,通常是通过获取相邻值之间的差异并除以片段大小。
换句话说,片段着色器计算了
F(x,y)
用于片段并将其传递到 GPU 以收集它们并根据它旁边的片段传回 dFdX 它将通过 F(x+e, y)
GenType
意味着您可以将浮点数放入其中,也可以传入 vec4 并获取组件方面的 dFd* 值。
关于opengl - 了解 dFdX 和 dFdY 的基础知识,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28246413/