Jump to content
  • Advertisement
Sign in to follow this  
JohnnyCode

texture2D lookup bias?

This topic is 1509 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Edited by JohnnyCode

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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)

Edited by Olof Hedman

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!