Sign in to follow this  
PrincessDaisy

When Does A MipMap Change?

Recommended Posts

PrincessDaisy    194
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
paic    645
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
Nik02    4348
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
dave    2187
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
Nik02    4348
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
Nik02    4348
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
dave    2187
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
paic    645
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
paic    645
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this