Auto Generate MipMap Not Working

Started by
6 comments, last by 21st Century Moose 7 years, 6 months ago

i want to use SampleLevel to use different mipmap levels manually but its not working as below image shows:

Untitled.png

as the picture shows it always use level 0 texture!

here is my code for loading a texture i use Directx Textue tool for loading also i use dx11:


HR(DirectX::CreateDDSTextureFromFileEx(
AngelCore::AngelSubSystemResources::GraphicDeviceResources::Device.Get(),
path.c_str(),MAXSIZE_T,D3D11_USAGE_DEFAULT,
D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE,0,
D3D11_RESOURCE_MISC_GENERATE_MIPS,false,
m_textureResource.GetAddressOf(), m_textureView.GetAddressOf()));

also i create my sampler state with below options:


D3D11_FILTER_ANISOTROPIC,D3D11_TEXTURE_ADDRESS_WRAP, D3D11_TEXTURE_ADDRESS_WRAP
, D3D11_TEXTURE_ADDRESS_WRAP, 
D3D11_COMPARISON_ALWAYS

what is the problem?

Advertisement

You need to explicitly call ID3D11DeviceContext::GenerateMips to generate mipmaps for your texture

https://msdn.microsoft.com/en-us/library/windows/desktop/ff476426(v=vs.85).aspx

I gets all your texture budgets!

You need to explicitly call ID3D11DeviceContext::GenerateMips to generate mipmaps for your texture

https://msdn.microsoft.com/en-us/library/windows/desktop/ff476426(v=vs.85).aspx

i use this function but it didn't fix my problem!

I can't see what parameters you're using when you create the texture and shader resource view since you're using a helper function. Are you creating the texture with a full mipmap chain, or are you creating it with only 1 mip level? Are you creating the shader resource view with a full mipmap chain?

I can't see what parameters you're using when you create the texture and shader resource view since you're using a helper function. Are you creating the texture with a full mipmap chain, or are you creating it with only 1 mip level? Are you creating the shader resource view with a full mipmap chain?

this function doesn't require anything,it will return shaderResourceView.

i also use that d3dx11 function but nothing changed.

What format is your texture? The documentation page for ID3D11DeviceContext::GenerateMips notes a list of supported formats, and also notes that:

For all other unsupported formats, GenerateMips will silently fail.

Assuming that you are actually using a supported format, then you should review the documentation for the helper function you're using; this one I assume (although you really should have said so). Note the discussion around the maxsize parameter, how it interacts with miplevels, and ensure that the behaviour you're requesting is the behaviour you actually want. Also note that you must be calling the overload that takes your context as a param if you wish it to generate mips for you.

Finally, since you're loading a DDS file, why are you generating mips at runtime anyway? DDS is capable of storing pregenerated mips, so you could consider that instead.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

What format is your texture? The documentation page for ID3D11DeviceContext::GenerateMips notes a list of supported formats, and also notes that:

For all other unsupported formats, GenerateMips will silently fail.

Assuming that you are actually using a supported format, then you should review the documentation for the helper function you're using; this one I assume (although you really should have said so). Note the discussion around the maxsize parameter, how it interacts with miplevels, and ensure that the behaviour you're requesting is the behaviour you actually want. Also note that you must be calling the overload that takes your context as a param if you wish it to generate mips for you.

Finally, since you're loading a DDS file, why are you generating mips at runtime anyway? DDS is capable of storing pregenerated mips, so you could consider that instead.

ok. now i use this function:


HR(DirectX::CreateDDSTextureFromFileEx(
AngelCore::AngelSubSystemResources::GraphicDeviceResources::Device.Get(),
AngelCore::AngelSubSystemResources::GraphicDeviceResources::DeviceContext.Get()
,
path.c_str(),D3D10_FLOAT32_MAX,D3D11_USAGE_DEFAULT,
D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE,0,
D3D11_RESOURCE_MISC_GENERATE_MIPS,false,
m_textureResource.GetAddressOf(), m_textureView.GetAddressOf()));

but nothings changed!

how i'm suppose to generate static mipmaps?

Now you're passing a float to a size_t parameter - have you warnings turned off?

Please read the documentation - it's legal to specify 0 for maxsize, which is probably the behaviour you actually want:

If '0', then if the attempt to create the Direct3D 11 resource fails and there are mipmaps present, it will retry assuming a maxsize based on the device's current feature level.

Again, note from the documentation (with my emphasis):

If a d3dContext is given to these functions, they will attempt to use the auto-generation of mipmaps features in the Direct3D 11 API if supported for the pixel format.

You really need to check the pixel format of your DDS file and confirm that it is a format for which automatic mipmap generation is supported.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement