Is it possible to figure out what value a varying have for a neighbouring pixel in a fragment shader?
I’m setting a varying vec2 in my vertex shader and using it in the fragment shader with texture2d. What I’d like to do in the fragment shader is peek at neighbouring values in the texture. I want to look based on the final window coordinates however. For example if I’m at pixel 10, I want to know what texture value I’d get at 11.
That is, I’d like to know what the stepping value is for a particulary varying, is this possible?
You cannot get any information about the varying (or other variable’s) values of neibouring fragments. But if you just want to know the rate of change of a value, be it a varying or any other variable (in your case probably the color sampled from the texture), between neighbouring fragments, you can use the
dFdxanddFdyfunctions, which will most probably just do finite differencing under the hood for you (since the hardware knows the values of neighbouring fragments).