Archived
1
Fork 0

Start to separate combined image samplers

This is to be in line with requirements from HLSL/DX12 and WebGPU,
both of which do not support this. It's probably better to get
started removing our usage of them now :-)
This commit is contained in:
Joshua Goins 2022-03-06 22:45:08 -05:00
parent e1767e9363
commit a0d92be759
16 changed files with 110 additions and 166 deletions

View file

@ -125,7 +125,6 @@ enum class GFXBindingType {
StorageBuffer, StorageBuffer,
StorageImage, StorageImage,
PushConstant, PushConstant,
Texture,
Sampler, Sampler,
SampledImage SampledImage
}; };
@ -263,12 +262,6 @@ struct GFXTextureCreateInfo {
GFXTextureUsage usage; GFXTextureUsage usage;
int array_length = 1; int array_length = 1;
int mip_count = 1; int mip_count = 1;
// sampler
SamplingMode samplingMode = SamplingMode::Repeat;
GFXBorderColor border_color = GFXBorderColor::OpaqueWhite;
bool compare_enabled = false;
GFXCompareFunction compare_function = GFXCompareFunction::Never;
}; };
struct GFXSamplerCreateInfo { struct GFXSamplerCreateInfo {

View file

@ -496,26 +496,6 @@ GFXTexture* GFXVulkan::create_texture(const GFXTextureCreateInfo& info) {
vkCreateImageView(device, &viewInfo, nullptr, &texture->view); vkCreateImageView(device, &viewInfo, nullptr, &texture->view);
const VkSamplerAddressMode samplerMode = toSamplerMode(info.samplingMode);
// create sampler
VkSamplerCreateInfo samplerInfo = {};
samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
samplerInfo.magFilter = VK_FILTER_LINEAR;
samplerInfo.minFilter = VK_FILTER_LINEAR;
samplerInfo.addressModeU = samplerMode;
samplerInfo.addressModeV = samplerMode;
samplerInfo.addressModeW = samplerMode;
samplerInfo.anisotropyEnable = VK_TRUE;
samplerInfo.maxAnisotropy = 16;
samplerInfo.compareEnable = info.compare_enabled;
samplerInfo.borderColor = toBorderColor(info.border_color);
samplerInfo.compareOp = toCompareFunc(info.compare_function);
samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
samplerInfo.maxLod = static_cast<float>(info.mip_count);
vkCreateSampler(device, &samplerInfo, nullptr, &texture->sampler);
return texture; return texture;
} }
@ -1028,11 +1008,6 @@ GFXPipeline* GFXVulkan::create_graphics_pipeline(const GFXGraphicsPipelineCreate
case GFXBindingType::StorageBuffer: case GFXBindingType::StorageBuffer:
descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
break; break;
case GFXBindingType::Texture: {
descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
pipeline->bindings_marked_as_normal_images.push_back(binding.binding);
}
break;
case GFXBindingType::StorageImage: case GFXBindingType::StorageImage:
{ {
descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
@ -1165,11 +1140,6 @@ GFXPipeline* GFXVulkan::create_compute_pipeline(const GFXComputePipelineCreateIn
case GFXBindingType::StorageBuffer: case GFXBindingType::StorageBuffer:
descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
break; break;
case GFXBindingType::Texture: {
descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
pipeline->bindings_marked_as_normal_images.push_back(binding.binding);
}
break;
case GFXBindingType::StorageImage: case GFXBindingType::StorageImage:
{ {
descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
@ -2144,7 +2114,7 @@ void GFXVulkan::createSwapchain(NativeSurface* native_surface, VkSwapchainKHR ol
void GFXVulkan::createDescriptorPool() { void GFXVulkan::createDescriptorPool() {
const std::array<VkDescriptorPoolSize, 2> poolSizes = { { const std::array<VkDescriptorPoolSize, 2> poolSizes = { {
{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 5000}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 5000},
{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 5000} {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 5000}
}}; }};
VkDescriptorPoolCreateInfo poolInfo = {}; VkDescriptorPoolCreateInfo poolInfo = {};
@ -2234,7 +2204,6 @@ void GFXVulkan::cacheDescriptorState(GFXVulkanPipeline* pipeline, VkDescriptorSe
VkDescriptorImageInfo imageInfo = {}; VkDescriptorImageInfo imageInfo = {};
imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
imageInfo.imageView = vulkanTexture->view; imageInfo.imageView = vulkanTexture->view;
imageInfo.sampler = vulkanTexture->sampler;
if((vulkanTexture->usage & GFXTextureUsage::Attachment) == GFXTextureUsage::Attachment) { if((vulkanTexture->usage & GFXTextureUsage::Attachment) == GFXTextureUsage::Attachment) {
if(vulkanTexture->format == VK_FORMAT_D32_SFLOAT) { if(vulkanTexture->format == VK_FORMAT_D32_SFLOAT) {
@ -2253,8 +2222,6 @@ void GFXVulkan::cacheDescriptorState(GFXVulkanPipeline* pipeline, VkDescriptorSe
imageInfo.imageLayout = VK_IMAGE_LAYOUT_GENERAL; imageInfo.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
} else if (utility::contains(pipeline->bindings_marked_as_sampled_images, i)) { } else if (utility::contains(pipeline->bindings_marked_as_sampled_images, i)) {
descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
} else {
descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
} }
descriptorWrite.pImageInfo = &imageInfo; descriptorWrite.pImageInfo = &imageInfo;

View file

@ -9,7 +9,6 @@ public:
VkImage handle = VK_NULL_HANDLE; VkImage handle = VK_NULL_HANDLE;
VkDeviceMemory memory = VK_NULL_HANDLE; VkDeviceMemory memory = VK_NULL_HANDLE;
VkImageView view = VK_NULL_HANDLE; VkImageView view = VK_NULL_HANDLE;
VkSampler sampler = VK_NULL_HANDLE;
int width = 0, height = 0; int width = 0, height = 0;

View file

@ -14,6 +14,7 @@
#include "shadercompiler.hpp" #include "shadercompiler.hpp"
#include "rendertarget.hpp" #include "rendertarget.hpp"
#include "platform.hpp" #include "platform.hpp"
#include "gfx_sampler.hpp"
class GFX; class GFX;
class GFXBuffer; class GFXBuffer;
@ -145,6 +146,8 @@ namespace prism {
GFXBuffer* histogram_buffer = nullptr; GFXBuffer* histogram_buffer = nullptr;
GFXTexture* average_luminance_texture = nullptr; GFXTexture* average_luminance_texture = nullptr;
GFXSampler* global_sampler = nullptr;
std::unique_ptr<SMAAPass> smaa_pass; std::unique_ptr<SMAAPass> smaa_pass;
std::unique_ptr<DoFPass> dof_pass; std::unique_ptr<DoFPass> dof_pass;

View file

@ -58,4 +58,6 @@ private:
// point // point
GFXPipeline* static_point_pipeline = nullptr; GFXPipeline* static_point_pipeline = nullptr;
GFXPipeline* skinned_point_pipeline = nullptr; GFXPipeline* skinned_point_pipeline = nullptr;
GFXSampler* shadow_sampler = nullptr;
}; };

View file

@ -34,8 +34,8 @@ DoFPass::DoFPass(GFX* gfx) {
create_info.shader_input.bindings = { create_info.shader_input.bindings = {
{0, GFXBindingType::StorageImage}, {0, GFXBindingType::StorageImage},
{1, GFXBindingType::Texture}, {1, GFXBindingType::SampledImage},
{3, GFXBindingType::Texture}, {3, GFXBindingType::SampledImage},
{2, GFXBindingType::PushConstant} {2, GFXBindingType::PushConstant}
}; };
@ -59,7 +59,6 @@ DoFPass::DoFPass(GFX* gfx) {
textureInfo.height = extent.height; textureInfo.height = extent.height;
textureInfo.format = GFXPixelFormat::RGBA_32F; textureInfo.format = GFXPixelFormat::RGBA_32F;
textureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::Sampled; textureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::Sampled;
textureInfo.samplingMode = SamplingMode::ClampToEdge;
normal_field = gfx->create_texture(textureInfo); normal_field = gfx->create_texture(textureInfo);

View file

@ -63,7 +63,7 @@ void ImGuiPass::create_render_target_resources(RenderTarget& target) {
createInfo.shader_input.bindings = { createInfo.shader_input.bindings = {
{1, GFXBindingType::PushConstant}, {1, GFXBindingType::PushConstant},
{2, GFXBindingType::Texture} {2, GFXBindingType::SampledImage}
}; };
pipeline = engine->get_gfx()->create_graphics_pipeline(createInfo); pipeline = engine->get_gfx()->create_graphics_pipeline(createInfo);

View file

@ -151,8 +151,9 @@ layout(std430, binding = 1) buffer readonly SceneInformation {{
Probe probes[max_probes]; Probe probes[max_probes];
int numLights; int numLights;
}} scene; }} scene;
layout (binding = 2) uniform sampler2D sun_shadow; layout (binding = 2) uniform texture2D sun_shadow;
layout (binding = 6) uniform sampler2DArray spot_shadow; layout (binding = 6) uniform texture2DArray spot_shadow;
layout (binding = 10) uniform sampler shadow_sampler;
layout(push_constant) uniform PushConstant {{ layout(push_constant) uniform PushConstant {{
mat4 model; mat4 model;
}}; }};
@ -186,7 +187,7 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo
if(render_options.enable_point_shadows) { if(render_options.enable_point_shadows) {
format_to(std::back_inserter(src), format_to(std::back_inserter(src),
R"(#define POINT_SHADOWS_SUPPORTED R"(#define POINT_SHADOWS_SUPPORTED
layout (binding = 3) uniform samplerCubeArray point_shadow; layout (binding = 3) uniform textureCubeArray point_shadow;
)"); )");
} }
@ -194,9 +195,9 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo
if(use_ibl) { if(use_ibl) {
format_to(std::back_inserter(src), format_to(std::back_inserter(src),
R"(layout (binding = 7) uniform samplerCubeArray irrandianceSampler; R"(layout (binding = 7) uniform textureCubeArray irrandianceSampler;
layout (binding = 8) uniform samplerCubeArray prefilterSampler; layout (binding = 8) uniform textureCubeArray prefilterSampler;
layout (binding = 9) uniform sampler2D brdfSampler; layout (binding = 9) uniform texture2D brdfSampler;
)"); )");
} }
@ -212,17 +213,17 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo
material.bound_textures.clear(); material.bound_textures.clear();
// insert samplers as needed // insert samplers as needed
int sampler_index = 10; int sampler_index = 11;
if(material.colorProperty.type == DataType::AssetTexture) { if(material.colorProperty.type == DataType::AssetTexture) {
material.bound_textures[sampler_index] = material.colorProperty.value_tex; material.bound_textures[sampler_index] = material.colorProperty.value_tex;
format_to(std::back_inserter(src), "layout(binding = {}) uniform sampler2D colorTexture;\n", sampler_index++); format_to(std::back_inserter(src), "layout(binding = {}) uniform texture2D colorTexture;\n", sampler_index++);
} }
if(material.normalProperty.type == DataType::AssetTexture) { if(material.normalProperty.type == DataType::AssetTexture) {
material.bound_textures[sampler_index] = material.normalProperty.value_tex; material.bound_textures[sampler_index] = material.normalProperty.value_tex;
format_to(std::back_inserter(src), "layout(binding = {}) uniform sampler2D normalTexture;\n", sampler_index++); format_to(std::back_inserter(src), "layout(binding = {}) uniform texture2D normalTexture;\n", sampler_index++);
} }
if(use_ibl) { if(use_ibl) {
@ -262,7 +263,7 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo
pos = step - step * noise.x; pos = step - step * noise.x;
float shadow = 0.0; float shadow = 0.0;
while(pos <= 1.0) {{ while(pos <= 1.0) {{
vec3 tmp_normal = texture(normal_map, in_uv + dir * pos).rgb; vec3 tmp_normal = texture(sampler2D(normal_map, shadow_sampler), in_uv + dir * pos).rgb;
tmp_normal = in_tbn * (tmp_normal * 2.0 - 1.0); tmp_normal = in_tbn * (tmp_normal * 2.0 - 1.0);
float tmp_lighting = dot(light_dir, tmp_normal); float tmp_lighting = dot(light_dir, tmp_normal);
float shadowed = -tmp_lighting; float shadowed = -tmp_lighting;
@ -283,9 +284,9 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo
R"(vec3 ibl(const int probe, const ComputedSurfaceInfo surface_info, const float intensity) {{ R"(vec3 ibl(const int probe, const ComputedSurfaceInfo surface_info, const float intensity) {{
const vec3 F = fresnel_schlick_roughness(surface_info.NdotV, surface_info.F0, surface_info.roughness); const vec3 F = fresnel_schlick_roughness(surface_info.NdotV, surface_info.F0, surface_info.roughness);
const vec3 R = get_reflect(probe, surface_info.N); const vec3 R = get_reflect(probe, surface_info.N);
const vec2 brdf = texture(brdfSampler, vec2(surface_info.NdotV, surface_info.roughness)).rg; const vec2 brdf = texture(sampler2D(brdfSampler, shadow_sampler), vec2(surface_info.NdotV, surface_info.roughness)).rg;
const vec3 sampledIrradiance = texture(irrandianceSampler, vec4(surface_info.N, probe)).xyz; const vec3 sampledIrradiance = texture(samplerCubeArray(irrandianceSampler, shadow_sampler), vec4(surface_info.N, probe)).xyz;
const vec3 prefilteredColor = textureLod(prefilterSampler, vec4(R, probe), surface_info.roughness * 4).xyz; const vec3 prefilteredColor = textureLod(samplerCubeArray(prefilterSampler, shadow_sampler), vec4(R, probe), surface_info.roughness * 4).xyz;
const vec3 diffuse = sampledIrradiance * surface_info.diffuse_color; const vec3 diffuse = sampledIrradiance * surface_info.diffuse_color;
const vec3 specular = prefilteredColor * (F * brdf.x + brdf.y); const vec3 specular = prefilteredColor * (F * brdf.x + brdf.y);
return (diffuse + specular) * intensity; return (diffuse + specular) * intensity;
@ -298,7 +299,7 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo
if(material.colorProperty.type == DataType::Vector3) { if(material.colorProperty.type == DataType::Vector3) {
format_to(std::back_inserter(src), "vec3 Color = vec3({}, {}, {});\n", material.colorProperty.value.x, material.colorProperty.value.y, material.colorProperty.value.z); format_to(std::back_inserter(src), "vec3 Color = vec3({}, {}, {});\n", material.colorProperty.value.x, material.colorProperty.value.y, material.colorProperty.value.z);
} else if(material.colorProperty.type == DataType::AssetTexture) { } else if(material.colorProperty.type == DataType::AssetTexture) {
format_to(std::back_inserter(src), "vec3 Color = texture(colorTexture, in_uv).rgb;\n"); format_to(std::back_inserter(src), "vec3 Color = texture(sampler2D(colorTexture, shadow_sampler), in_uv).rgb;\n");
} else if(material.colorProperty.type == DataType::Float) { } else if(material.colorProperty.type == DataType::Float) {
format_to(std::back_inserter(src),"vec3 Color = vec3({}});\n", material.colorProperty.float_value); format_to(std::back_inserter(src),"vec3 Color = vec3({}});\n", material.colorProperty.float_value);
} }
@ -313,7 +314,7 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo
prism::log("enabling normal mapping on material.."); prism::log("enabling normal mapping on material..");
format_to(std::back_inserter(src), format_to(std::back_inserter(src),
R"(vec3 final_normal = texture(normalTexture, in_uv).rgb; R"(vec3 final_normal = texture(sampler2D(normalTexture, shadow_sampler), in_uv).rgb;
final_normal = final_normal * 2.0 - 1.0; final_normal = final_normal * 2.0 - 1.0;
final_normal = in_tbn * final_normal; final_normal = in_tbn * final_normal;
)"); )");

View file

@ -88,6 +88,10 @@ renderer::renderer(GFX* gfx, const bool enable_imgui) : gfx(gfx) {
unorm_render_pass = gfx->create_render_pass(renderPassInfo); unorm_render_pass = gfx->create_render_pass(renderPassInfo);
create_sky_pipeline(); create_sky_pipeline();
GFXSamplerCreateInfo sampler_create_info = {};
global_sampler = gfx->create_sampler(sampler_create_info);
} }
renderer::~renderer() = default; renderer::~renderer() = default;
@ -277,6 +281,8 @@ void renderer::render(GFXCommandBuffer* commandbuffer, Scene* scene, RenderTarge
else else
commandbuffer->bind_texture(dummy_texture, 7); commandbuffer->bind_texture(dummy_texture, 7);
commandbuffer->bind_sampler(global_sampler, 8);
PostPushConstants pc; PostPushConstants pc;
pc.options.x = render_options.enable_aa; pc.options.x = render_options.enable_aa;
pc.options.z = render_options.exposure; pc.options.z = render_options.exposure;
@ -412,6 +418,7 @@ void renderer::render_camera(GFXCommandBuffer* command_buffer, Scene& scene, Obj
command_buffer->bind_texture(scene.irradianceCubeArray, 7); command_buffer->bind_texture(scene.irradianceCubeArray, 7);
command_buffer->bind_texture(scene.prefilteredCubeArray, 8); command_buffer->bind_texture(scene.prefilteredCubeArray, 8);
command_buffer->bind_texture(brdf_texture, 9); command_buffer->bind_texture(brdf_texture, 9);
command_buffer->bind_sampler(global_sampler, 10);
if(!mesh.mesh->bones.empty()) if(!mesh.mesh->bones.empty())
command_buffer->bind_shader_buffer(part.bone_batrix_buffer, 0, 14, sizeof(Matrix4x4) * 128); command_buffer->bind_shader_buffer(part.bone_batrix_buffer, 0, 14, sizeof(Matrix4x4) * 128);
@ -488,12 +495,13 @@ void renderer::create_mesh_pipeline(Material& material) const {
pipelineInfo.shader_input.bindings = { pipelineInfo.shader_input.bindings = {
{1, GFXBindingType::StorageBuffer}, {1, GFXBindingType::StorageBuffer},
{0, GFXBindingType::PushConstant}, {0, GFXBindingType::PushConstant},
{2, GFXBindingType::Texture}, {2, GFXBindingType::SampledImage},
{3, GFXBindingType::Texture}, {3, GFXBindingType::SampledImage},
{6, GFXBindingType::Texture}, {6, GFXBindingType::SampledImage},
{7, GFXBindingType::Texture}, {7, GFXBindingType::SampledImage},
{8, GFXBindingType::Texture}, {8, GFXBindingType::SampledImage},
{9, GFXBindingType::Texture} {9, GFXBindingType::SampledImage},
{10, GFXBindingType::Sampler}
}; };
pipelineInfo.render_pass = offscreen_render_pass; pipelineInfo.render_pass = offscreen_render_pass;
@ -507,7 +515,7 @@ void renderer::create_mesh_pipeline(Material& material) const {
for (auto [index, texture] : material.bound_textures) { for (auto [index, texture] : material.bound_textures) {
GFXShaderBinding binding; GFXShaderBinding binding;
binding.binding = index; binding.binding = index;
binding.type = GFXBindingType::Texture; binding.type = GFXBindingType::SampledImage;
pipelineInfo.shader_input.bindings.push_back(binding); pipelineInfo.shader_input.bindings.push_back(binding);
} }
@ -550,7 +558,6 @@ void renderer::create_render_target_resources(RenderTarget& target) {
textureInfo.height = extent.height; textureInfo.height = extent.height;
textureInfo.format = GFXPixelFormat::RGBA_32F; textureInfo.format = GFXPixelFormat::RGBA_32F;
textureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::Sampled | GFXTextureUsage::Storage; textureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::Sampled | GFXTextureUsage::Storage;
textureInfo.samplingMode = SamplingMode::ClampToEdge;
target.offscreenColorTexture = gfx->create_texture(textureInfo); target.offscreenColorTexture = gfx->create_texture(textureInfo);
@ -568,27 +575,7 @@ void renderer::create_render_target_resources(RenderTarget& target) {
target.offscreenFramebuffer = gfx->create_framebuffer(framebufferInfo); target.offscreenFramebuffer = gfx->create_framebuffer(framebufferInfo);
if(post_pipeline == nullptr) { if(post_pipeline == nullptr) {
GFXGraphicsPipelineCreateInfo pipelineInfo = {}; create_post_pipelines();
pipelineInfo.label = "Post";
pipelineInfo.shaders.vertex_src = ShaderSource(prism::path("post.vert"));
pipelineInfo.shaders.fragment_src = ShaderSource(prism::path("post.frag"));
pipelineInfo.shader_input.bindings = {
{4, GFXBindingType::PushConstant},
{1, GFXBindingType::Texture},
{2, GFXBindingType::Texture},
{3, GFXBindingType::Texture},
{5, GFXBindingType::Texture},
{6, GFXBindingType::Texture},
{7, GFXBindingType::Texture}
};
pipelineInfo.shader_input.push_constants = {
{sizeof(PostPushConstants), 0}
};
post_pipeline = gfx->create_graphics_pipeline(pipelineInfo);
} }
target.sceneBuffer = gfx->create_buffer(nullptr, sizeof(SceneInformation), true, GFXBufferUsage::Storage); target.sceneBuffer = gfx->create_buffer(nullptr, sizeof(SceneInformation), true, GFXBufferUsage::Storage);
@ -603,12 +590,13 @@ void renderer::create_post_pipelines() {
pipelineInfo.shader_input.bindings = { pipelineInfo.shader_input.bindings = {
{4, GFXBindingType::PushConstant}, {4, GFXBindingType::PushConstant},
{1, GFXBindingType::Texture}, {1, GFXBindingType::SampledImage},
{2, GFXBindingType::Texture}, {2, GFXBindingType::SampledImage},
{3, GFXBindingType::Texture}, {3, GFXBindingType::SampledImage},
{5, GFXBindingType::Texture}, {5, GFXBindingType::SampledImage},
{6, GFXBindingType::Texture}, {6, GFXBindingType::SampledImage},
{7, GFXBindingType::Texture} {7, GFXBindingType::SampledImage},
{8, GFXBindingType::Sampler}
}; };
pipelineInfo.shader_input.push_constants = { pipelineInfo.shader_input.push_constants = {

View file

@ -84,7 +84,6 @@ SceneCapture::SceneCapture(GFX* gfx) {
textureInfo.height = scene_cubemap_resolution; textureInfo.height = scene_cubemap_resolution;
textureInfo.format = GFXPixelFormat::R8G8B8A8_UNORM; textureInfo.format = GFXPixelFormat::R8G8B8A8_UNORM;
textureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::TransferSrc | GFXTextureUsage::Sampled; textureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::TransferSrc | GFXTextureUsage::Sampled;
textureInfo.samplingMode = SamplingMode::ClampToEdge;
offscreenTexture = gfx->create_texture(textureInfo); offscreenTexture = gfx->create_texture(textureInfo);
@ -94,7 +93,6 @@ SceneCapture::SceneCapture(GFX* gfx) {
depthTextureInfo.height = scene_cubemap_resolution; depthTextureInfo.height = scene_cubemap_resolution;
depthTextureInfo.format = GFXPixelFormat::DEPTH_32F; depthTextureInfo.format = GFXPixelFormat::DEPTH_32F;
depthTextureInfo.usage = GFXTextureUsage::Attachment; depthTextureInfo.usage = GFXTextureUsage::Attachment;
depthTextureInfo.samplingMode = SamplingMode::ClampToEdge;
offscreenDepth = gfx->create_texture(depthTextureInfo); offscreenDepth = gfx->create_texture(depthTextureInfo);
@ -111,7 +109,6 @@ SceneCapture::SceneCapture(GFX* gfx) {
cubeTextureInfo.height = scene_cubemap_resolution; cubeTextureInfo.height = scene_cubemap_resolution;
cubeTextureInfo.format = GFXPixelFormat::R8G8B8A8_UNORM; cubeTextureInfo.format = GFXPixelFormat::R8G8B8A8_UNORM;
cubeTextureInfo.usage = GFXTextureUsage::Sampled | GFXTextureUsage::TransferDst | GFXTextureUsage::TransferSrc; // dst used for cubemap copy, src used for mipmap gen cubeTextureInfo.usage = GFXTextureUsage::Sampled | GFXTextureUsage::TransferDst | GFXTextureUsage::TransferSrc; // dst used for cubemap copy, src used for mipmap gen
cubeTextureInfo.samplingMode = SamplingMode::ClampToEdge;
cubeTextureInfo.mip_count = mipLevels; cubeTextureInfo.mip_count = mipLevels;
environmentCube = gfx->create_texture(cubeTextureInfo); environmentCube = gfx->create_texture(cubeTextureInfo);
@ -134,7 +131,6 @@ void SceneCapture::create_scene_resources(Scene& scene) {
cubeTextureInfo.height = irradiance_cubemap_resolution; cubeTextureInfo.height = irradiance_cubemap_resolution;
cubeTextureInfo.format = GFXPixelFormat::R8G8B8A8_UNORM; cubeTextureInfo.format = GFXPixelFormat::R8G8B8A8_UNORM;
cubeTextureInfo.usage = GFXTextureUsage::Sampled | GFXTextureUsage::TransferDst; cubeTextureInfo.usage = GFXTextureUsage::Sampled | GFXTextureUsage::TransferDst;
cubeTextureInfo.samplingMode = SamplingMode::ClampToEdge;
cubeTextureInfo.array_length = max_environment_probes; cubeTextureInfo.array_length = max_environment_probes;
scene.irradianceCubeArray = gfx->create_texture(cubeTextureInfo); scene.irradianceCubeArray = gfx->create_texture(cubeTextureInfo);
@ -146,7 +142,6 @@ void SceneCapture::create_scene_resources(Scene& scene) {
cubeTextureInfo.height = scene_cubemap_resolution; cubeTextureInfo.height = scene_cubemap_resolution;
cubeTextureInfo.format = GFXPixelFormat::R8G8B8A8_UNORM; cubeTextureInfo.format = GFXPixelFormat::R8G8B8A8_UNORM;
cubeTextureInfo.usage = GFXTextureUsage::Sampled | GFXTextureUsage::TransferDst; cubeTextureInfo.usage = GFXTextureUsage::Sampled | GFXTextureUsage::TransferDst;
cubeTextureInfo.samplingMode = SamplingMode::ClampToEdge;
cubeTextureInfo.array_length = max_environment_probes; cubeTextureInfo.array_length = max_environment_probes;
cubeTextureInfo.mip_count = mipLevels; cubeTextureInfo.mip_count = mipLevels;
@ -436,7 +431,6 @@ void SceneCapture::createIrradianceResources() {
textureInfo.height = irradiance_cubemap_resolution; textureInfo.height = irradiance_cubemap_resolution;
textureInfo.format = GFXPixelFormat::R8G8B8A8_UNORM; textureInfo.format = GFXPixelFormat::R8G8B8A8_UNORM;
textureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::TransferSrc; textureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::TransferSrc;
textureInfo.samplingMode = SamplingMode::ClampToEdge;
irradianceOffscreenTexture = gfx->create_texture(textureInfo); irradianceOffscreenTexture = gfx->create_texture(textureInfo);
@ -474,7 +468,7 @@ void SceneCapture::createIrradianceResources() {
pipelineInfo.shader_input.bindings = { pipelineInfo.shader_input.bindings = {
{1, GFXBindingType::PushConstant}, {1, GFXBindingType::PushConstant},
{2, GFXBindingType::Texture} {2, GFXBindingType::SampledImage}
}; };
pipelineInfo.render_pass = irradianceRenderPass; pipelineInfo.render_pass = irradianceRenderPass;
@ -491,7 +485,6 @@ void SceneCapture::createPrefilterResources() {
textureInfo.height = scene_cubemap_resolution; textureInfo.height = scene_cubemap_resolution;
textureInfo.format = GFXPixelFormat::R8G8B8A8_UNORM; textureInfo.format = GFXPixelFormat::R8G8B8A8_UNORM;
textureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::TransferSrc; textureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::TransferSrc;
textureInfo.samplingMode = SamplingMode::ClampToEdge;
prefilteredOffscreenTexture = gfx->create_texture(textureInfo); prefilteredOffscreenTexture = gfx->create_texture(textureInfo);
@ -528,7 +521,7 @@ void SceneCapture::createPrefilterResources() {
pipelineInfo.shader_input.bindings = { pipelineInfo.shader_input.bindings = {
{1, GFXBindingType::PushConstant}, {1, GFXBindingType::PushConstant},
{2, GFXBindingType::Texture} {2, GFXBindingType::SampledImage}
}; };
pipelineInfo.render_pass = irradianceRenderPass; pipelineInfo.render_pass = irradianceRenderPass;

View file

@ -42,8 +42,6 @@ void ShadowPass::create_scene_resources(Scene& scene) {
textureInfo.height = render_options.shadow_resolution; textureInfo.height = render_options.shadow_resolution;
textureInfo.format = GFXPixelFormat::DEPTH_32F; textureInfo.format = GFXPixelFormat::DEPTH_32F;
textureInfo.usage = GFXTextureUsage::Sampled | GFXTextureUsage::Attachment; textureInfo.usage = GFXTextureUsage::Sampled | GFXTextureUsage::Attachment;
textureInfo.samplingMode = SamplingMode::ClampToBorder;
textureInfo.border_color = GFXBorderColor::OpaqueWhite;
scene.depthTexture = gfx->create_texture(textureInfo); scene.depthTexture = gfx->create_texture(textureInfo);
@ -64,8 +62,6 @@ void ShadowPass::create_scene_resources(Scene& scene) {
cubeTextureInfo.format = GFXPixelFormat::R_32F; cubeTextureInfo.format = GFXPixelFormat::R_32F;
cubeTextureInfo.usage = GFXTextureUsage::Sampled; cubeTextureInfo.usage = GFXTextureUsage::Sampled;
cubeTextureInfo.array_length = max_point_shadows; cubeTextureInfo.array_length = max_point_shadows;
cubeTextureInfo.samplingMode = SamplingMode::ClampToBorder;
cubeTextureInfo.border_color = GFXBorderColor::OpaqueWhite;
scene.pointLightArray = gfx->create_texture(cubeTextureInfo); scene.pointLightArray = gfx->create_texture(cubeTextureInfo);
} }
@ -80,11 +76,15 @@ void ShadowPass::create_scene_resources(Scene& scene) {
spotTextureInfo.format = GFXPixelFormat::DEPTH_32F; spotTextureInfo.format = GFXPixelFormat::DEPTH_32F;
spotTextureInfo.usage = GFXTextureUsage::Sampled; spotTextureInfo.usage = GFXTextureUsage::Sampled;
spotTextureInfo.array_length = max_spot_shadows; spotTextureInfo.array_length = max_spot_shadows;
spotTextureInfo.samplingMode = SamplingMode::ClampToBorder;
spotTextureInfo.border_color = GFXBorderColor::OpaqueWhite;
scene.spotLightArray = gfx->create_texture(spotTextureInfo); scene.spotLightArray = gfx->create_texture(spotTextureInfo);
} }
GFXSamplerCreateInfo sampler_create_info = {};
sampler_create_info.samplingMode = SamplingMode::ClampToBorder;
sampler_create_info.border_color = GFXBorderColor::OpaqueWhite;
shadow_sampler = gfx->create_sampler(sampler_create_info);
} }
void ShadowPass::render(GFXCommandBuffer* command_buffer, Scene& scene) { void ShadowPass::render(GFXCommandBuffer* command_buffer, Scene& scene) {
@ -391,7 +391,6 @@ void ShadowPass::create_offscreen_resources() {
textureInfo.height = render_options.shadow_resolution; textureInfo.height = render_options.shadow_resolution;
textureInfo.format = GFXPixelFormat::R_32F; textureInfo.format = GFXPixelFormat::R_32F;
textureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::Sampled; textureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::Sampled;
textureInfo.samplingMode = SamplingMode::ClampToEdge;
offscreen_color_texture = gfx->create_texture(textureInfo); offscreen_color_texture = gfx->create_texture(textureInfo);
@ -401,7 +400,6 @@ void ShadowPass::create_offscreen_resources() {
depthTextureInfo.height = render_options.shadow_resolution; depthTextureInfo.height = render_options.shadow_resolution;
depthTextureInfo.format = GFXPixelFormat::DEPTH_32F; depthTextureInfo.format = GFXPixelFormat::DEPTH_32F;
depthTextureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::Sampled; depthTextureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::Sampled;
depthTextureInfo.samplingMode = SamplingMode::ClampToEdge;
offscreen_depth = gfx->create_texture(depthTextureInfo); offscreen_depth = gfx->create_texture(depthTextureInfo);

View file

@ -101,7 +101,6 @@ void SMAAPass::create_textures() {
areaInfo.height = AREATEX_HEIGHT; areaInfo.height = AREATEX_HEIGHT;
areaInfo.format = GFXPixelFormat::R8G8_UNORM; areaInfo.format = GFXPixelFormat::R8G8_UNORM;
areaInfo.usage = GFXTextureUsage::Sampled | GFXTextureUsage::TransferDst; areaInfo.usage = GFXTextureUsage::Sampled | GFXTextureUsage::TransferDst;
areaInfo.samplingMode = SamplingMode::ClampToEdge;
area_image = gfx->create_texture(areaInfo); area_image = gfx->create_texture(areaInfo);
@ -114,7 +113,6 @@ void SMAAPass::create_textures() {
searchInfo.height = SEARCHTEX_HEIGHT; searchInfo.height = SEARCHTEX_HEIGHT;
searchInfo.format = GFXPixelFormat::R8_UNORM; searchInfo.format = GFXPixelFormat::R8_UNORM;
searchInfo.usage = GFXTextureUsage::Sampled | GFXTextureUsage::TransferDst; searchInfo.usage = GFXTextureUsage::Sampled | GFXTextureUsage::TransferDst;
searchInfo.samplingMode = SamplingMode::ClampToEdge;
search_image = gfx->create_texture(searchInfo); search_image = gfx->create_texture(searchInfo);
@ -145,8 +143,8 @@ void SMAAPass::create_pipelines() {
}; };
createInfo.shader_input.bindings = { createInfo.shader_input.bindings = {
{0, GFXBindingType::Texture}, {0, GFXBindingType::SampledImage},
{1, GFXBindingType::Texture}, {1, GFXBindingType::SampledImage},
{2, GFXBindingType::PushConstant} {2, GFXBindingType::PushConstant}
}; };
@ -155,7 +153,7 @@ void SMAAPass::create_pipelines() {
createInfo.label = "SMAA Blend"; createInfo.label = "SMAA Blend";
createInfo.shaders.vertex_src = ShaderSource(prism::path("blend.vert")); createInfo.shaders.vertex_src = ShaderSource(prism::path("blend.vert"));
createInfo.shaders.fragment_src = ShaderSource(prism::path("blend.frag")); createInfo.shaders.fragment_src = ShaderSource(prism::path("blend.frag"));
createInfo.shader_input.bindings.push_back({3, GFXBindingType::Texture}); createInfo.shader_input.bindings.push_back({3, GFXBindingType::SampledImage});
blend_pipeline = gfx->create_graphics_pipeline(createInfo); blend_pipeline = gfx->create_graphics_pipeline(createInfo);
} }

View file

@ -7,11 +7,12 @@ layout(push_constant) uniform readonly PushConstant{
vec4 color; vec4 color;
}; };
layout (binding = 2) uniform sampler2D colorSampler; layout (binding = 2) uniform texture2D colorSampler;
layout (binding = 3) uniform sampler testSampler;
void main() { void main() {
if(inUV.y < 0.0 || inUV.x > 1.0) if(inUV.y < 0.0 || inUV.x > 1.0)
discard; discard;
outColor = texture(colorSampler, inUV) * color; outColor = texture(sampler2D(colorSampler, testSampler), inUV) * color;
} }

View file

@ -3,8 +3,9 @@ layout(location = 1) in vec2 in_uv;
layout(location = 0) out vec4 out_color; layout(location = 0) out vec4 out_color;
layout(binding = 2) uniform sampler2D bound_texture; layout(binding = 2) uniform texture2D bound_texture;
layout(binding = 3) uniform sampler testSampler;
void main() { void main() {
out_color = in_color * texture(bound_texture, in_uv); out_color = in_color * texture(sampler2D(bound_texture, testSampler), in_uv);
} }

View file

@ -19,30 +19,31 @@ layout(location = 1) in vec4 inOffset;
layout (location = 0) out vec4 outColor; layout (location = 0) out vec4 outColor;
layout (binding = 1) uniform sampler2D colorSampler; layout (binding = 1) uniform texture2D colorSampler;
layout (binding = 2) uniform sampler2D backSampler; layout (binding = 2) uniform texture2D backSampler;
layout (binding = 3) uniform sampler2D blendSampler; layout (binding = 3) uniform texture2D blendSampler;
layout (binding = 5) uniform sampler2D sobelSampler; layout (binding = 5) uniform texture2D sobelSampler;
layout (binding = 6) uniform sampler2D averageLuminanceSampler; layout (binding = 6) uniform texture2D averageLuminanceSampler;
layout (binding = 7) uniform sampler2D farFieldSampler; layout (binding = 7) uniform texture2D farFieldSampler;
layout (binding = 8) uniform sampler global_sampler;
float calculate_sobel() { float calculate_sobel() {
float x = 1.0 / viewport.z; float x = 1.0 / viewport.z;
float y = 1.0 / viewport.w; float y = 1.0 / viewport.w;
vec4 horizEdge = vec4( 0.0 ); vec4 horizEdge = vec4( 0.0 );
horizEdge -= texture( sobelSampler, vec2( inUV.x - x, inUV.y - y ) ) * 1.0; horizEdge -= texture(sampler2D(sobelSampler, global_sampler), vec2( inUV.x - x, inUV.y - y ) ) * 1.0;
horizEdge -= texture( sobelSampler, vec2( inUV.x - x, inUV.y ) ) * 2.0; horizEdge -= texture(sampler2D(sobelSampler, global_sampler), vec2( inUV.x - x, inUV.y ) ) * 2.0;
horizEdge -= texture( sobelSampler, vec2( inUV.x - x, inUV.y + y ) ) * 1.0; horizEdge -= texture(sampler2D(sobelSampler, global_sampler), vec2( inUV.x - x, inUV.y + y ) ) * 1.0;
horizEdge += texture( sobelSampler, vec2( inUV.x + x, inUV.y - y ) ) * 1.0; horizEdge += texture(sampler2D(sobelSampler, global_sampler), vec2( inUV.x + x, inUV.y - y ) ) * 1.0;
horizEdge += texture( sobelSampler, vec2( inUV.x + x, inUV.y ) ) * 2.0; horizEdge += texture(sampler2D(sobelSampler, global_sampler), vec2( inUV.x + x, inUV.y ) ) * 2.0;
horizEdge += texture( sobelSampler, vec2( inUV.x + x, inUV.y + y ) ) * 1.0; horizEdge += texture(sampler2D(sobelSampler, global_sampler), vec2( inUV.x + x, inUV.y + y ) ) * 1.0;
vec4 vertEdge = vec4( 0.0 ); vec4 vertEdge = vec4( 0.0 );
vertEdge -= texture( sobelSampler, vec2( inUV.x - x, inUV.y - y ) ) * 1.0; vertEdge -= texture(sampler2D(sobelSampler, global_sampler), vec2( inUV.x - x, inUV.y - y ) ) * 1.0;
vertEdge -= texture( sobelSampler, vec2( inUV.x , inUV.y - y ) ) * 2.0; vertEdge -= texture(sampler2D(sobelSampler, global_sampler), vec2( inUV.x , inUV.y - y ) ) * 2.0;
vertEdge -= texture( sobelSampler, vec2( inUV.x + x, inUV.y - y ) ) * 1.0; vertEdge -= texture(sampler2D(sobelSampler, global_sampler), vec2( inUV.x + x, inUV.y - y ) ) * 1.0;
vertEdge += texture( sobelSampler, vec2( inUV.x - x, inUV.y + y ) ) * 1.0; vertEdge += texture(sampler2D(sobelSampler, global_sampler), vec2( inUV.x - x, inUV.y + y ) ) * 1.0;
vertEdge += texture( sobelSampler, vec2( inUV.x , inUV.y + y ) ) * 2.0; vertEdge += texture(sampler2D(sobelSampler, global_sampler), vec2( inUV.x , inUV.y + y ) ) * 2.0;
vertEdge += texture( sobelSampler, vec2( inUV.x + x, inUV.y + y ) ) * 1.0; vertEdge += texture(sampler2D(sobelSampler, global_sampler), vec2( inUV.x + x, inUV.y + y ) ) * 1.0;
return sqrt((horizEdge.rgb * horizEdge.rgb) + (vertEdge.rgb * vertEdge.rgb)).r; return sqrt((horizEdge.rgb * horizEdge.rgb) + (vertEdge.rgb * vertEdge.rgb)).r;
} }
@ -106,31 +107,31 @@ float reinhard2(float _x, float _whiteSqr)
void main() { void main() {
// passthrough // passthrough
if(options.w == 1) { if(options.w == 1) {
outColor = texture(colorSampler, inUV); outColor = texture(sampler2D(colorSampler, global_sampler), inUV);
return; return;
} }
bool enable_dof = options.w == 2; bool enable_dof = options.w == 2;
vec3 sceneColor = vec3(0); vec3 sceneColor = vec3(0);
if(enable_dof) { if(enable_dof) {
sceneColor = texture(farFieldSampler, inUV).rgb; sceneColor = texture(sampler2D(farFieldSampler, global_sampler), inUV).rgb;
sceneColor += texture(colorSampler, inUV).rgb; sceneColor += texture(sampler2D(colorSampler, global_sampler), inUV).rgb;
} else { } else {
if(options.x == 1) // enable AA //if(options.x == 1) // enable AA
sceneColor = SMAANeighborhoodBlendingPS(inUV, inOffset, colorSampler, blendSampler).rgb; // sceneColor = SMAANeighborhoodBlendingPS(inUV, inOffset, colorSampler, blendSampler).rgb;
else //else
sceneColor = texture(colorSampler, inUV).rgb; sceneColor = texture(sampler2D(colorSampler, global_sampler), inUV).rgb;
} }
float sobel = 0.0; float sobel = 0.0;
if(textureSize(sobelSampler, 0).x > 1) if(textureSize(sampler2D(sobelSampler, global_sampler), 0).x > 1)
sobel = calculate_sobel(); sobel = calculate_sobel();
vec3 sobelColor = vec3(0, 1, 1); vec3 sobelColor = vec3(0, 1, 1);
vec3 hdrColor = sceneColor; // fading removed vec3 hdrColor = sceneColor; // fading removed
float avg_lum = texture(averageLuminanceSampler, inUV).r; float avg_lum = texture(sampler2D(averageLuminanceSampler, global_sampler), inUV).r;
vec3 transformed_color = hdrColor; vec3 transformed_color = hdrColor;

View file

@ -66,7 +66,7 @@ struct ComputedLightInformation {
float pcf_sun(const vec4 shadowCoords, const float uvRadius) { float pcf_sun(const vec4 shadowCoords, const float uvRadius) {
float sum = 0; float sum = 0;
for(int i = 0; i < 16; i++) { for(int i = 0; i < 16; i++) {
const float z = texture(sun_shadow, shadowCoords.xy + PoissionPCFDisk[i] * uvRadius).r; const float z = texture(sampler2D(sun_shadow, shadow_sampler), shadowCoords.xy + PoissionPCFDisk[i] * uvRadius).r;
sum += (z < (shadowCoords.z - 0.005)) ? 0.0 : 1.0; sum += (z < (shadowCoords.z - 0.005)) ? 0.0 : 1.0;
} }
@ -91,7 +91,7 @@ void blocker_distance_sun(const vec3 shadowCoords, const float uvLightSize, inou
blockers = 0; blockers = 0;
for(int i = 0; i < numBlockerSearchSamples; i++) { for(int i = 0; i < numBlockerSearchSamples; i++) {
const float z = texture(sun_shadow, shadowCoords.xy + PoissionPCFDisk[i] * searchWidth).r; const float z = texture(sampler2D(sun_shadow, shadow_sampler), shadowCoords.xy + PoissionPCFDisk[i] * searchWidth).r;
if(z < shadowCoords.z) { if(z < shadowCoords.z) {
blockerSum += z; blockerSum += z;
blockers++; blockers++;
@ -126,7 +126,7 @@ ComputedLightInformation calculate_sun(Light light) {
if(shadowCoords.z > -1.0 && shadowCoords.z < 1.0) { if(shadowCoords.z > -1.0 && shadowCoords.z < 1.0) {
#ifdef SHADOW_FILTER_NONE #ifdef SHADOW_FILTER_NONE
shadow = (texture(sun_shadow, shadowCoords.xy).r < shadowCoords.z - 0.005) ? 0.0 : 1.0; shadow = (texture(sampler2D(sun_shadow, shadow_sampler), shadowCoords.xy).r < shadowCoords.z - 0.005) ? 0.0 : 1.0;
#endif #endif
#ifdef SHADOW_FILTER_PCF #ifdef SHADOW_FILTER_PCF
shadow = pcf_sun(shadowCoords, 0.1); shadow = pcf_sun(shadowCoords, 0.1);
@ -145,7 +145,7 @@ ComputedLightInformation calculate_sun(Light light) {
float pcf_spot(const vec4 shadowCoords, const int index, const float uvRadius) { float pcf_spot(const vec4 shadowCoords, const int index, const float uvRadius) {
float sum = 0; float sum = 0;
for(int i = 0; i < 16; i++) { for(int i = 0; i < 16; i++) {
const float z = texture(spot_shadow, vec3(shadowCoords.xy + PoissionPCFDisk[i] * uvRadius, index)).r; const float z = texture(sampler2DArray(spot_shadow, shadow_sampler), vec3(shadowCoords.xy + PoissionPCFDisk[i] * uvRadius, index)).r;
sum += (z < (shadowCoords.z - 0.001)) ? 0.0 : 1.0; sum += (z < (shadowCoords.z - 0.001)) ? 0.0 : 1.0;
} }
@ -160,7 +160,7 @@ void blocker_distance_spot(const vec3 shadowCoords, const int index, const float
blockers = 0; blockers = 0;
for(int i = 0; i < numBlockerSearchSamples; i++) { for(int i = 0; i < numBlockerSearchSamples; i++) {
const float z = texture(spot_shadow, vec3(shadowCoords.xy + PoissionPCFDisk[i] * searchWidth, index)).r; const float z = texture(sampler2DArray(spot_shadow, shadow_sampler), vec3(shadowCoords.xy + PoissionPCFDisk[i] * searchWidth, index)).r;
if(z < shadowCoords.z) { if(z < shadowCoords.z) {
blockerSum += z; blockerSum += z;
blockers++; blockers++;
@ -197,7 +197,7 @@ ComputedLightInformation calculate_spot(Light light) {
const vec4 shadowCoord = fragPostSpotLightSpace[last_spot_light] / fragPostSpotLightSpace[last_spot_light].w; const vec4 shadowCoord = fragPostSpotLightSpace[last_spot_light] / fragPostSpotLightSpace[last_spot_light].w;
#ifdef SHADOW_FILTER_NONE #ifdef SHADOW_FILTER_NONE
shadow = (texture(spot_shadow, vec3(shadowCoord.xy, last_spot_light)).r < shadowCoord.z - 0.005) ? 0.0 : 1.0; shadow = (texture(sampler2D(spot_shadow, shadow_sampler), vec3(shadowCoord.xy, last_spot_light)).r < shadowCoord.z - 0.005) ? 0.0 : 1.0;
#endif #endif
#ifdef SHADOW_FILTER_PCF #ifdef SHADOW_FILTER_PCF
shadow = pcf_spot(shadowCoord, last_spot_light, 0.01); shadow = pcf_spot(shadowCoord, last_spot_light, 0.01);
@ -235,7 +235,7 @@ vec3 sampleOffsetDirections[20] = vec3[]
float pcf_point(const vec3 shadowCoords, const int index, const float uvRadius) { float pcf_point(const vec3 shadowCoords, const int index, const float uvRadius) {
float sum = 0; float sum = 0;
for(int i = 0; i < 20; i++) { for(int i = 0; i < 20; i++) {
const float z = texture(point_shadow, vec4(shadowCoords.xyz + sampleOffsetDirections[i] * uvRadius, index)).r; const float z = texture(samplerCubeArray(point_shadow, shadow_sampler), vec4(shadowCoords.xyz + sampleOffsetDirections[i] * uvRadius, index)).r;
sum += (z < length(shadowCoords) - 0.05) ? 0.0 : 1.0; sum += (z < length(shadowCoords) - 0.05) ? 0.0 : 1.0;
} }
@ -250,7 +250,7 @@ void blocker_distance_point(const vec3 shadowCoords, const int index, const floa
blockers = 0; blockers = 0;
for(int i = 0; i < 20; i++) { for(int i = 0; i < 20; i++) {
const float z = texture(point_shadow, vec4(shadowCoords + sampleOffsetDirections[i] * 0.05, index)).r; const float z = texture(samplerCubeArray(point_shadow, shadow_sampler), vec4(shadowCoords + sampleOffsetDirections[i] * 0.05, index)).r;
if(z < length(shadowCoords)) { if(z < length(shadowCoords)) {
blockerSum += z; blockerSum += z;
blockers++; blockers++;
@ -289,7 +289,7 @@ ComputedLightInformation calculate_point(Light light) {
#ifdef POINT_SHADOWS_SUPPORTED #ifdef POINT_SHADOWS_SUPPORTED
if(light.shadowsEnable.x == 1.0) { if(light.shadowsEnable.x == 1.0) {
#ifdef SHADOW_FILTER_NONE #ifdef SHADOW_FILTER_NONE
const float sampledDist = texture(point_shadow, vec4(lightVec, int(light.shadowsEnable.z))).r; const float sampledDist = texture(sampler2D(point_shadow, shadow_sampler), vec4(lightVec, int(light.shadowsEnable.z))).r;
const float dist = length(lightVec); const float dist = length(lightVec);
shadow = (dist <= sampledDist + 0.05) ? 1.0 : 0.0; shadow = (dist <= sampledDist + 0.05) ? 1.0 : 0.0;