I have recently read an article(http://www.aclockworkberry.com/shader-derivative-functions/) ,which was very informative for me。however,there weren't too much details about how the derivatives actually work by explaining them pixels by pixels under the group, only one example was shown there which was too intuitive. but when i came to other pixels in the group, things got really tricky and confusing.for better illustration of my question, Let's just take an example here, say, i have a rendertarget like this:
According to the article,the horizontal derivative for some value in pixel[0] is obtained by subtracting the value itself from the correspondence in pixel[1]. Since they are in the same group ,both values can be easily fetched.Great!but how about pixel[1]? if same rule is applied the horizontal derivative should be calculated base on pixel[1] itself as well as the value in pixel[2]. but at this time the two pixels are in diffrent groups! similar situations accured when you perform the vertical derivative for pixel[4]. Well, i was originally thinking maybe there was some fancy driver features that can make it happend. unfortunately the result was not what i expected after i made some experiment.
this simple code below failed my assumption:(you can test it and see the result in shadertoy your self )
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
int oddRow = int(fragCoord.x) % 2 == 1 ? 1 : 0; //fragCoord是屏幕空间坐标
float xDerivative = dFdx(float(oddRow));
fragColor = vec4(xDerivative,xDerivative,xDerivative, 1.0);
}
if my supposition is correct, the screen shoud be alternated with white and black tiles alone the horizontal direction like this:
but the result is pure white which is surprisingly not the case.
So,can anyone shed some light about this problem for me. i also goggled a lot of places with no luck, all of them told you the pixels were handled in such a way, but no one really focused on specific situations as i have mentioned above.I think anyone who works with ddx ddy should absolutely have an clear understanding of this.
Much appreciation!