texture2D lookup bias?

Started by
4 comments, last by alh420 9 years, 5 months ago

I wonder what is the third optional parameter- the floating number bias, in the texture2D lookup function in fragment shader. How does it behave and what does it do?

Advertisement
The bias is a value that get added to the calculated mip map level for the sample. For example, if the sample instruction decides this texture will use mip map level 3, and you give a supply of 0.5, then it will use a mix of mip level 3 and 4.

Thanks Xycaleth. You seem to deeply understand this parameter, do I now understand it correctly that bias of 0.5 will sample from level current level+ 0.5 , meaning it will sample between the current level and lower level and those 2 samples weighted equaly? And that bias of 1.0 will sample exactly at the one level lower and return this sample?

I suppose I simplified it a bit. This only applies to mipmapped textures and I think where the texture sampler is set to use trilinear filtering (GL_LINEAR_MIPMAP_LINEAR), hopefully someone else can agree or disagree with me on that. But yes, the bias is added to the current level, and if you happen to be half way between two levels, then the two samples from the integer level below and above are weighted equally.

Also, a quick look in the spec says that the bias parameter doesn't do anything in any stage apart from the fragment shader.

I still sort of wonder wheather in case of bias not being a whole floating number, the sample is weighted from the two levels. That would be sort of performance hit, since it would require two fetches in a very incoherent memory.

Trilinear means you always sample from two mipmap levels, and weight them together, regardless of bias.

Internally it will calculate "how much" between the mipmap levels the current fragment is, and weight them together by this value.

bias simply adds to that value.

If you are not using trilinear, I would assume the mipmap level will be clamped/rounded to a whole number after the bias have been added.

(so if it internally thinks you are at mipmaplevel 1.42, and you have bias 0.6, the resulting mipmap level will be 2)

This topic is closed to new replies.

Advertisement