了解dFdX和dFdY的基础 [英] understanding the basics of dFdX and dFdY

查看:547
本文介绍了了解dFdX和dFdY的基础的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了许多关于dFdX(n)dFdY(n)行为的描述,并且确实相信我仍然对学校的偏导数有所了解.我不明白的是,在最简单的示例中"n"是从哪里来的?

在不使用数学的任何上下文的情况下,阅读glsl内置函数dFdx(n)dFdy(n)时,我会将它们解释为我具有x和y的某些函数:f(x,y),我采用了该函数的偏导数wrt x d/dx(x,y),并且我估算了xy的某些值的偏导数公式,我认为这是上面的输入参数n.

我已经阅读了许多关于dFdx()dFdy()如何使您找到输出片段的窗口空间渐变的描述.目前我最感兴趣的是输出碎片情况,因为我试图确定纹理坐标的栅格化速率.

我正在寻找使用dFdx(n)dFdy(n)来查找输出片段的窗口空间颜色渐变.我不完全理解如何从心理上构造要区分的函数,以及与帧缓冲区的关系以及n与该缓冲区的关系(例如,n与当前片段的2x2片段邻域,窗口坐标空间有关)吗?整个帧缓冲区的大小,以便我评估该值的梯度,其他)?

我希望在对此问题的任何回答中,n的输入类型都是标量(浮点型),并且我们只是讨论一个维度dFdx(),以简化讨论.

解决方案

让我们检查f(x,y), I take the partial derivative of that function w.r.t. x d/dx(x,y), and I evaluate the partial derivative formula for some value of x and y which I assume is the input parameter n above.

I've read many descriptions of how dFdx() and dFdy() allow you to find a window-space gradient for output fragments. The output-fragment case is what I'm most interested in at the moment as I'm not trying to determine the rate of change of texture coordinates w.r.t how the texture is being rasterized.

I'm looking to use dFdx(n) and dFdy(n) to find window-space color gradient of output fragments. I don't fully understand how to mentally construct the function being differentiated and how that relates to the frame buffer and how n relates to that (e.g. does n relate to the 2x2 fragment neighborhood of the current fragment, window coordinate space of the entire framebuffer such that I'm evaluating the gradient at that value, other) ?

I'm hoping that the input type of n in any responses to this question is a scalar (float) and that we just discuss one dimension, dFdx(), to simplify the discussion.

解决方案

Lets check the 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.

Concentrating on the Fine variant. As each fragment process reaches the dFd* call the GPU will collect the values passed in and based on those values, typically through getting the difference between neighbouring values and dividing by the fragment size.

In other words the fragment shader has calculated the F(x,y) for the fragment and passes it on to the GPU to collect them and pass back the dFdX based on the fragments right next to it Which would have passed F(x+e, y)

GenType means that you can put floats in it, you can also pass in a vec4 and get the component-wise dFd* value.

这篇关于了解dFdX和dFdY的基础的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆