(SOLVED) Having problem setting the mipmap level

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

Recommended Posts

I have been trying to get the highest mipmap level to show for a long time now but nothing seems to work and the output always shows one of the lower mipmap levels. I tried creating a sampler state like this:

D3D11_SAMPLER_DESC samplerDesc;
ZeroMemory(&samplerDesc, sizeof(D3D11_SAMPLER_DESC));

samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
samplerDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
samplerDesc.MipLODBias = 0.0f;
samplerDesc.MinLOD = 0.0f;
samplerDesc.MaxLOD = 0.0f;

HRESULT HR = device->CreateSamplerState(&samplerDesc, &anisotropicSamplerState);
if(FAILED(HR))
{
MessageBox( nullptr, TEXT("Failed to create rasterizer state"), TEXT("Error"), MB_OK );
return false;
} 

but changing that seems to toggle between the last two mip levels. I have also tried to  do it in the shader

float4 baseColor = Albedo.SampleLevel(samplerState, IN.texCoord, 0);


This also does not have any effect. Am I doing it the right way or is there another method?

Share on other sites

Try just Albedo.Sample(samplerState, IN.texCoord);

See if you're binding the Sampler to the correct place;

Use Intel GFA to Debug everything;

Create an DX11 Debug Layer;

Edited by Irlan

Share on other sites

I have tried Albedo.Sample(samplerState, IN.texCoord); as well and sampler is bound correctly. I am getting the correct output if I edit the dds texture file to contain only the highest mip level. I just want to be able to access the different mip levels in shader

Share on other sites

So I have managed to track the problem to how the textures were created.

hr = DirectX::CreateDDSTextureFromFile( device, L"..\\data\\Cubemaps\\sunsetcube1024.dds", (ID3D11Resource**)&cubeMapTexture, nullptr, 0  );


By specifying the last parameter as 0 I can get the highest mip level but I am still not able to access the different mip levels in hlsl using SampleLevel. Changing the last parameter in SampleLevel does not seem to have any effect and specifying 10 as the last parameter in CreateDDSTextureFromFile gives only the 10th mip level

Share on other sites

Can you show the part of the code which creates the shader resource view?

Cheers!

 You don't seem to store the SRV pointer given by the CreateDDSTextureFromFile ? How do you bind your texture?

[edit 2] Copied from directxtex: If maxsize parameter non-zero, then all mipmap levels larger than the maxsize are ignored before creating the Direct3D 11 resource. This allows for load-time scaling. 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.

Edited by kauna

Share on other sites

Sure:

D3D11_TEXTURE2D_DESC SMTextureDesc;
cubeMapTexture->GetDesc(&SMTextureDesc);

SMViewDesc.Format = SMTextureDesc.Format;
SMViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
SMViewDesc.TextureCube.MipLevels = SMTextureDesc.MipLevels;
SMViewDesc.TextureCube.MostDetailedMip = 0;



Edit:

Yeah went through that earlier. So if I specify 0 then all the mip levels should be loaded which should allow  SampleLevel to work but it does not in this case :(

Share on other sites

Is there a reason not using the SRV from the loading function? (Although I can't see a problem with your SRV desc - you could use -1 for the MipLevels)

Cheers!

Share on other sites

I did it separately in order to do D3D11_SRV_DIMENSION_TEXTURECUBE in the description. If I was creating the SRV at the same time as creating the texture I dont get to specify D3D11_SHADER_RESOURCE_VIEW_DESC

Share on other sites

It seems the various mip levels are loaded correctly because I can set which one to use in the sampler state that I set in c++ using samplerDesc.MipLODBias = 0.0f;

Share on other sites

I did it separately in order to do D3D11_SRV_DIMENSION_TEXTURECUBE in the description. If I was creating the SRV at the same time as creating the texture I dont get to specify D3D11_SHADER_RESOURCE_VIEW_DESC

The texture loading function should define the SRV_DESC correctly - I mean, I think that the loading function defines the SRV_DESC exactly as you do.

Well this starts to be a good mystery - can you show your whole shader code, part of c++ code which binds the sampler ?

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 13
• 14
• 9
• 9
• 9
• Forum Statistics

• Total Topics
632927
• Total Posts
3009242
• Who's Online (See full list)

There are no registered users currently online

×