OpenGL ES 2.0 arbitrary texture

I have an OpenGL ES 2.0 based iPhone application in which I am running a bit of an OpenGL ES issue.

I am trying to complicate a fragment shader that calculates / displays the derivative of an input texture. My shader fragment code:

 varying highp vec2 textureCoordinate;

 uniform sampler2D inputImageTexture;
 uniform sampler2D inputImageTexture2;

 void main(void)
   mediump vec4 derivData = vec4(dFdx(texture2D(inputImageTexture, textureCoordinate).xyz, 0.0);

   gl_FragColor = derivData;


However, this will not compile. If I take out dFdX it compiles just fine.

Does anyone have any experience? Eventually, I would like to calculate the Y derivative and then combine them, seeing how the input texture is an image.

I've been struggling with this for a few days now, so any advice you have would be greatly appreciated!


source to share

1 answer

All iOS hardware supporting ES 2.0 will support the GL_OES_standard_derivatives extension:

However, you will not get it "for free." In your fragment shader, you must add the following at the top (from ):

#extension GL_OES_standard_derivatives : enable


All the information in the comments to the first answer is mostly accurate, but without this part, you will keep getting the following error:

ERROR: 0:15: Call to undeclared function 'dFdx'
ERROR: 0:16: Call to undeclared function 'dFdy'


It got me going for a loop, but as soon as I added the include line it works on both the device and the simulator (not really sure if it works on both, but it compiles).



All Articles