3

In GL ES 2.0 Functions texture2DLod not available in the fragment Shader. I need to port the GLSL Shader.

In GL ES 2.0 I can only use texture2D(sampler2D sampler, vec2 coord, float bias)

Tell me how to calculate the value of a bias equivalent to a known value LOD (level of detail)?

//Example GLSL:
float lod=u_lod;
textureLod(sampler, (uInverseViewMatrix * vec4(r, 0.0)).xy, lod);

//I need GL ES 2.0:
float lod=u_lod;
float bias=?  <-----calc bias from lod
texture2D(sampler,(uInverseViewMatrix * vec4(r, 0.0)).xy,bias)
2
  • What is known about the texture coordinates here? Because, generally speaking, you don't. However, if you know what LOD would be selected by the texture coordinates, then you may be able to make it work. Or, to put it another way, there's a reason why ES 2.0 doesn't support textureLOD; because it can't. Jul 29, 2013 at 6:08
  • In the specification of the Open GL ES 2.0 textureLod only in vertex shader is available.
    – Mixer
    Jul 29, 2013 at 6:11

1 Answer 1

5

What you want is not possible.

The LOD bias is exactly that: a bias. It is added to the LOD that is automatically computed from texture2D.

textureLOD doesn't work that way. It selects a specific LOD, which is not based on anything automatically computed by anyone.

The only way to do what you want would be to perform the automatic LOD computations yourself, then try to compute a bias between that value and the LOD you actually want, and then apply that with texture2D. I would tell you how to do that, but that would require the functions dFdx and dFdy, which are not in OpenGL ES 2.0. So you can't.

But don't feel bad, because even if you could, it wouldn't work. The other problem there is that the LOD bias is clamped within a specific range. Note that you won't find this in the ES 2.0 spec, but that's OK; you also won't find any language about how that bias gets applied to the lambda computed for mipmapping. Yes, really; go ahead and search for it. The closest you get is in the GLSL ES spec, but the OpenGL ES spec says nothing about applying a bias to the lambda.

So yeah, it's just not possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.