Understanding GPU Derivatives(ddx,ddy)



Complex filtering depends on knowing just how much of the texture (or shading) we need to filter. Modern GPUs such as the GeForce FX provide partial derivative functions to help us. For any value used in shading, we can ask the GPU: "How much does this value change from pixel to pixel, in either the screen-x or the screen-y direction?"

These functions are ddx() and ddy(). Although they are little used, they can be very helpful for filtering and antialiasing operations. These derivative functions provide us with the necessary information to perform procedural filtering or to adroitly modify the filtering inherent in most texture sampling.

For GPUs that do not directly support ddx() and ddy(), you can use the method outlined in Chapter 25 of this book, "Fast Filter-Width Estimates with Texture Maps."

The values returned by the GPU for ddx() and ddy() are numerically iterated values. That is, if you evaluateddx(myVar), the GPU will give you the difference between the value of myVar at the current pixel and its value at the pixel next door. It's a straight linear difference, made efficient by the nature of GPU SIMD architectures (neighboring pixels will be calculated simultaneously). Of course, it should apply to values that interpolate across a polygon, passed from the vertex shader—the derivative of any uniform value will always be zero.

Because these derivatives are always linear, the second derivatives—for example, ddx(ddx(myVar))—will alwaysbe zero. If your shader contains some clever function whose higher-order derivatives could instead be accurately calculated analytically, use that formulation if the value is important (say, for scientific calculation or film-level rendering).

Once we know the amount of change in a given pixel, we're able to determine the appropriate filtering. For a texture, the correct filtering will be to integrate the texture not just at a given u-v coordinate, but across a quadrilateral-shaped window into that texture, whose texture coordinates will be ddx(UV) across and ddy(UV) in height. When we call functions such as tex2D(), this is in fact automatically calculated for us. Cg, for advanced profiles, allows us to optionally specify the size of the filter we want to apply. For example, by specifying:

float2 nilUV = float2(0, 0);
float4 pt = tex2D(myTextureSampler, IN.UV, nilUV, nilUV);

we can force the filter size to be zero—in effect, forcing the sampling of this texture always to use the "nearest-neighbor" method of filtering, regardless of the mode set by the API or the presence of mipmaps.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DDX很有用,用它重新计算DDX后的一大发现,让人着实兴奋不已,现提供图表给大家看一下, 用HprSnap6软件可以打开看,我将4月16日的所有股票都用图表显示,可以看到正确性在98以上, 注意左的图中的线(不是矩形,而是单根的线),跌时5天前已经全在上方很久,涨时5天前就在 下方很久了。本图是用VBA编的,VBA太有用了。 图是以涨幅降序排列的,共二张图,右边写的是涨幅,要看的是左边的图,百分之98的正确。 希望大家对DDX多加研究的话,定有惊喜的收获的。 另外,本人用模糊分析的方法得到的大单重要性的初步结果是如下:好象符合实际。 ddx 7.507214709 小单差% -2.611936371 特大差% -4.118645137 特大买入% -4.470760296 特大差量 -6.141661167 单数比 -6.35653337 特大卖出% -6.414990299 强度 -6.643649985 小单卖出% -7.158680792 大特累计 -8.274703516 60日ddy -8.440081804 大单卖出% -9.459333104 大单买入% -10.01915699 小单买入% -10.70956148 大单差% -10.72609128 ddz -11.10892985 买单均手 -11.30064578 60日ddx -11.56574557 中单差量 -11.62611809 活跃 -11.71759307 中单买入% -11.84260611 小单累计 -12.0672123 卖单均手 -12.19972861 中单差% -12.41499139 小单差股 -14.41325469 中单卖出% -14.51495897 大单差量 -14.56020615 小单差量 -14.65446439 ddy -15.23886754 量比 -16.46188466 次 -16.86515806 涨幅 -17.97181076 买入单数 -19.37005172 资金强度 -19.60573475 卖出单数 -19.85060378 换手率% -21.07516064
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值