• Advertisement
Sign in to follow this  

When Does A MipMap Change?

This topic is 4505 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 am in the process of adding mip mapping to my game, but I am don't know how to change the distance at which the mip map changes. How does DX know when to start applying the second, third etc mipmap? It seems to be affected by the scale of the object matrix I am using to render the model, but what else, and how can I change this? Thanks Daisy

Share this post


Link to post
Share on other sites
Advertisement
Hi,

You can decal the mipmaps away / toward the user by user the mipmap lod bias render state :

m_pd3dDevice->SetSamplerState(i, D3DSAMP_MIPMAPLODBIAS, *((DWORD *)&m_MipMapLodBias));


where i is the texture channel (0 to 7 in most hardware) and m_MipMapLodBias is a float value. For example, let's say the first mipmap is used at 10 units from the user by default. Then, using a mipmap lod bias of -2.0 will make the first mipmap starting at 12 units from the user.

Share this post


Link to post
Share on other sites
To be exact, the mipmap level gets chosen based on the screen-space derivative of the texture coordinates at any given pixel biased by the lod bias value.

So, if the rate of change of a texture coordinate along a pixel is more or equal to 1, the topmost mip level is chosen. If less, the lower mips get mixed to the equation depending on whether mip and/or anisotropic filtering are enabled. The bias value effectively shifts the choice of level lower or higher.

In addition to what paic said, you can control the derivatives per-pixel if you're using newer pixel shader models (>=2.a). For this, the texture reading procedures take two extra parameters, ddx and ddy, which correspond to the desired mip level.

Share this post


Link to post
Share on other sites
Supposing that you have a texture loaded with a default mipmap chain and now it is time to set the states, would someone mind giving an example of the typical states needed for mipmapping to work?

Only i havn't done this in ages and i'm getting some wierd graphical bork!

Thanks,

ace

Share this post


Link to post
Share on other sites
IDirect3DDevice9::SetSamplerState (samplerIndex, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR)

The default value for this sampler state is D3DTEXF_NONE, which disables mipmapping altogether. D3DTEXF_POINT enables it, but doesn't filter between the levels. D3DTEXF_LINEAR takes into account the derivative's fractional part and blends two nearest mip levels linearly based on this fraction, thus ensuring better quality mip transitions.

Share this post


Link to post
Share on other sites
See thats what i had, but once i had that set the textures became really blocky and distorted, strange.

ace

Share this post


Link to post
Share on other sites
Do you also use the minification and magnification filters? If not, things can look "blocky" regardless of whether mipmapping is on or off.

If this doesn't correct the problem, are you sure that the mip levels are filled correctly?

Share this post


Link to post
Share on other sites
Well when i load the texture it loads with 0 as the mipmap levels so that should be the full chain.

I set both the min and mag to linear.

ace

Share this post


Link to post
Share on other sites
By default, mipmap gives quite ugly results, especially on terrains and surfaces that are almost parallel to the viewer direction.

To increase the quality a little bit, I use a mipmap lod bias of approx -2.0 / -1.8. But that's not really good either.

So what I use is : anisotropic filtering if available ^^


m_pd3dDevice->SetSamplerState(i, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
m_pd3dDevice->SetSamplerState(i, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);
m_pd3dDevice->SetSamplerState(i, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
m_pd3dDevice->SetSamplerState(i, D3DSAMP_MIPMAPLODBIAS, 0);
m_pd3dDevice->SetSamplerState(i, D3DSAMP_MAXANISOTROPY, 14);



That's what gives the best results in my config.

Share this post


Link to post
Share on other sites
ace_lovegrove here:

Well the problem i was having was uber-distorted! I'm wondering if this was because maybe the texture didnt load with levels.

ace

Share this post


Link to post
Share on other sites
If you can post a screenshot ...
Normally, mipmap shouldn't distort the textures, and specifying 0 in the correct parameter when loading a texture with D3DXCreateTextureFromFileEx() should generate the correct mipmap levels.

Share this post


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

  • Advertisement