Skip to content

Commit 3adc8ea

Browse files
Merge pull request #234 from slavc/fix_mipmap_lesson
Fix the mipmap lesson: maxLod must be set in SamplerCreateInfo in order for mipmaps to work
2 parents 67901ee + 757453b commit 3adc8ea

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

attachments/29_mipmapping.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,9 @@ class HelloTriangleApplication
686686
.anisotropyEnable = vk::True,
687687
.maxAnisotropy = properties.limits.maxSamplerAnisotropy,
688688
.compareEnable = vk::False,
689-
.compareOp = vk::CompareOp::eAlways};
689+
.compareOp = vk::CompareOp::eAlways,
690+
.minLod = 0.0f,
691+
.maxLod = vk::LodClampNone};
690692
textureSampler = vk::raii::Sampler(device, samplerInfo);
691693
}
692694

en/09_Generating_Mipmaps.adoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,17 @@ void createTextureSampler() {
400400
.anisotropyEnable = vk::True,
401401
.maxAnisotropy = properties.limits.maxSamplerAnisotropy,
402402
.compareEnable = vk::False,
403-
.compareOp = vk::CompareOp::eAlways
403+
.compareOp = vk::CompareOp::eAlways,
404+
.minLod = 0.0f,
405+
.maxLod = vk::LodClampNone
404406
};
405407
...
406408
}
407409
----
408410

409411
In the code above, we've set up the sampler with linear filtering for both minification and magnification, and linear interpolation between mip levels. We've also set the mip level bias to 0.0f.
410412

411-
By default, the full range of mip levels will be used. The default `minLod` is 0.0f, and the default `maxLod` is `VK_LOD_CLAMP_NONE` (which equals 1000.0f), meaning all available mipmap levels in the texture will be sampled.
413+
The `minLod` and `maxLod` are used to effectively set the range of mip levels to be used by clamping the minimum and maximum LOD values. By setting `minLod` to `0.0f` and `maxLod` to `VK_LOD_CLAMP_NONE` we ensure the full range of mip levels will be used.
412414

413415
Now run your program, and you should see the following:
414416

0 commit comments

Comments
 (0)