The shader presented does not use the tex2Dgrad function. It uses tex2Dbias, the equivalent of which GLSL has had since version OpenGL 2.0 / GLSL 1.0. It’s an overload of the default texture sampling function with the bias as a third parameter after the texture and uv coordinates. The use of tex2Dgrad is only presented as an optional replacement for tex2Dbias in cases where the later is for some reason unavailable (specifically Unreal Engine’s material system).

I do use derivatives for knowing the sample offset, but that shouldn’t be a problem for OpenGL 2.1 either as the equivalentdFdx and dFdy functions are both required core features.

If you were using OpenGL ES 2.0 or WebGL 1.0, neither of those have guaranteed derivative support. You would need to pre-compute the approximate isotropic derivatives on the CPU in those cases. Or at the very least the texel size to view linear depth ratio and get the offset based on the depth. But both of those APIs have the same bias overload for the texture function as OpenGL 2.0 has.

Tech Artist & Graphics Programmer lately focused on Unity VR game dev.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store