Texture sampling: Calculation of BIAS value from the LOD value

烂漫一生 提交于 2019-12-10 19:54:08

问题


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)

回答1:


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.



来源:https://stackoverflow.com/questions/17916967/texture-sampling-calculation-of-bias-value-from-the-lod-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!