@@ -258,6 +258,15 @@ void ViewDependentState::init(ResourceRequirements& requirements)
258258 descriptor = DescriptorBuffer::create (BufferInfoList{lightDataBufferInfo, viewportDataBufferInfo}, 0 ); // hardwired position for now
259259
260260 // set up ShadowMaps
261+ auto shadowMapDirectSampler = Sampler::create ();
262+ shadowMapDirectSampler->minFilter = VK_FILTER_NEAREST;
263+ shadowMapDirectSampler->magFilter = VK_FILTER_NEAREST;
264+ shadowMapDirectSampler->mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
265+ shadowMapDirectSampler->addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
266+ shadowMapDirectSampler->addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
267+ shadowMapDirectSampler->addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
268+ shadowMapDirectSamplerDescriptor = createSamplerDescriptor (shadowMapDirectSampler, 3 );
269+
261270 auto shadowMapSampler = Sampler::create ();
262271#define HARDWARE_PCF 1
263272#if HARDWARE_PCF == 1
@@ -277,6 +286,7 @@ void ViewDependentState::init(ResourceRequirements& requirements)
277286 shadowMapSampler->addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
278287 shadowMapSampler->addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
279288#endif
289+ shadowMapShadowSamplerDescriptor = createSamplerDescriptor (shadowMapSampler, 4 );
280290
281291 if (maxShadowMaps > 0 )
282292 {
@@ -289,9 +299,9 @@ void ViewDependentState::init(ResourceRequirements& requirements)
289299 depthImageView->subresourceRange .baseArrayLayer = 0 ;
290300 depthImageView->subresourceRange .layerCount = maxShadowMaps;
291301
292- auto depthImageInfo = ImageInfo::create (shadowMapSampler , depthImageView, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL);
302+ auto depthImageInfo = ImageInfo::create (vsg::ref_ptr<Sampler>() , depthImageView, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL);
293303
294- shadowMapImages = DescriptorImage::create (ImageInfoList{depthImageInfo}, 2 );
304+ shadowMapImages = DescriptorImage::create (ImageInfoList{depthImageInfo}, 2 , 0 , VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE );
295305 }
296306 else
297307 {
@@ -313,19 +323,21 @@ void ViewDependentState::init(ResourceRequirements& requirements)
313323 depthImageView->subresourceRange .baseArrayLayer = 0 ;
314324 depthImageView->subresourceRange .layerCount = 1 ;
315325
316- auto depthImageInfo = ImageInfo::create (shadowMapSampler , depthImageView, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL);
326+ auto depthImageInfo = ImageInfo::create (vsg::ref_ptr<Sampler>() , depthImageView, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL);
317327
318- shadowMapImages = DescriptorImage::create (ImageInfoList{depthImageInfo}, 2 );
328+ shadowMapImages = DescriptorImage::create (ImageInfoList{depthImageInfo}, 2 , 0 , VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE );
319329 }
320330
321331 DescriptorSetLayoutBindings descriptorBindings{
322332 VkDescriptorSetLayoutBinding{0 , VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1 , VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, nullptr }, // lightData
323333 VkDescriptorSetLayoutBinding{1 , VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1 , VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, nullptr }, // viewportData
324- VkDescriptorSetLayoutBinding{2 , VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1 , VK_SHADER_STAGE_FRAGMENT_BIT, nullptr }, // shadow map 2D texture array
334+ VkDescriptorSetLayoutBinding{2 , VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1 , VK_SHADER_STAGE_FRAGMENT_BIT, nullptr }, // shadow map 2D texture array
335+ VkDescriptorSetLayoutBinding{3 , VK_DESCRIPTOR_TYPE_SAMPLER, 1 , VK_SHADER_STAGE_FRAGMENT_BIT, nullptr }, // shadow map direct sampler
336+ VkDescriptorSetLayoutBinding{4 , VK_DESCRIPTOR_TYPE_SAMPLER, 1 , VK_SHADER_STAGE_FRAGMENT_BIT, nullptr }, // shadow map shadow sampler
325337 };
326338
327339 descriptorSetLayout = DescriptorSetLayout::create (descriptorBindings);
328- descriptorSet = DescriptorSet::create (descriptorSetLayout, Descriptors{descriptor, shadowMapImages});
340+ descriptorSet = DescriptorSet::create (descriptorSetLayout, Descriptors{descriptor, shadowMapImages, shadowMapDirectSamplerDescriptor, shadowMapShadowSamplerDescriptor });
329341
330342 // if not active then don't enable shadow maps
331343 if (maxShadowMaps == 0 ) return ;
0 commit comments