From dbc03078de8093bde2388fbfd110fbbede2dda92 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 10 Mar 2022 10:21:03 -0500 Subject: [PATCH] Revert "Start to separate combined image samplers" This reverts commit a0d92be759450f09343bb04f4da913ccef505bbd. --- engine/gfx/public/gfx.hpp | 7 +++ engine/gfx/vulkan/src/gfx_vulkan.cpp | 35 +++++++++++- engine/gfx/vulkan/src/gfx_vulkan_texture.hpp | 1 + engine/renderer/include/renderer.hpp | 3 - engine/renderer/include/shadowpass.hpp | 2 - engine/renderer/src/dofpass.cpp | 7 ++- engine/renderer/src/imguipass.cpp | 2 +- engine/renderer/src/materialcompiler.cpp | 31 +++++------ engine/renderer/src/renderer.cpp | 58 ++++++++++++-------- engine/renderer/src/scenecapture.cpp | 19 +++++-- engine/renderer/src/shadowpass.cpp | 16 +++--- engine/renderer/src/smaapass.cpp | 12 ++-- engine/shaders/billboard.frag.glsl | 5 +- engine/shaders/imgui.frag.glsl | 5 +- engine/shaders/post.frag.glsl | 55 +++++++++---------- engine/shaders/rendering.nocompile.glsl | 18 +++--- 16 files changed, 166 insertions(+), 110 deletions(-) diff --git a/engine/gfx/public/gfx.hpp b/engine/gfx/public/gfx.hpp index 180d972..49186f9 100755 --- a/engine/gfx/public/gfx.hpp +++ b/engine/gfx/public/gfx.hpp @@ -125,6 +125,7 @@ enum class GFXBindingType { StorageBuffer, StorageImage, PushConstant, + Texture, Sampler, SampledImage }; @@ -262,6 +263,12 @@ struct GFXTextureCreateInfo { GFXTextureUsage usage; int array_length = 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 { diff --git a/engine/gfx/vulkan/src/gfx_vulkan.cpp b/engine/gfx/vulkan/src/gfx_vulkan.cpp index 8d1dfb0..fdce4bc 100755 --- a/engine/gfx/vulkan/src/gfx_vulkan.cpp +++ b/engine/gfx/vulkan/src/gfx_vulkan.cpp @@ -496,6 +496,26 @@ GFXTexture* GFXVulkan::create_texture(const GFXTextureCreateInfo& info) { 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(info.mip_count); + + vkCreateSampler(device, &samplerInfo, nullptr, &texture->sampler); + return texture; } @@ -1008,6 +1028,11 @@ GFXPipeline* GFXVulkan::create_graphics_pipeline(const GFXGraphicsPipelineCreate case GFXBindingType::StorageBuffer: descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; 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: { descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; @@ -1140,6 +1165,11 @@ GFXPipeline* GFXVulkan::create_compute_pipeline(const GFXComputePipelineCreateIn case GFXBindingType::StorageBuffer: descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; 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: { descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; @@ -2114,7 +2144,7 @@ void GFXVulkan::createSwapchain(NativeSurface* native_surface, VkSwapchainKHR ol void GFXVulkan::createDescriptorPool() { const std::array poolSizes = { { {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 5000}, - {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 5000} + {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 5000} }}; VkDescriptorPoolCreateInfo poolInfo = {}; @@ -2204,6 +2234,7 @@ void GFXVulkan::cacheDescriptorState(GFXVulkanPipeline* pipeline, VkDescriptorSe VkDescriptorImageInfo imageInfo = {}; imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; imageInfo.imageView = vulkanTexture->view; + imageInfo.sampler = vulkanTexture->sampler; if((vulkanTexture->usage & GFXTextureUsage::Attachment) == GFXTextureUsage::Attachment) { if(vulkanTexture->format == VK_FORMAT_D32_SFLOAT) { @@ -2222,6 +2253,8 @@ void GFXVulkan::cacheDescriptorState(GFXVulkanPipeline* pipeline, VkDescriptorSe imageInfo.imageLayout = VK_IMAGE_LAYOUT_GENERAL; } else if (utility::contains(pipeline->bindings_marked_as_sampled_images, i)) { descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; + } else { + descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; } descriptorWrite.pImageInfo = &imageInfo; diff --git a/engine/gfx/vulkan/src/gfx_vulkan_texture.hpp b/engine/gfx/vulkan/src/gfx_vulkan_texture.hpp index c43ec24..c1f1acc 100755 --- a/engine/gfx/vulkan/src/gfx_vulkan_texture.hpp +++ b/engine/gfx/vulkan/src/gfx_vulkan_texture.hpp @@ -9,6 +9,7 @@ public: VkImage handle = VK_NULL_HANDLE; VkDeviceMemory memory = VK_NULL_HANDLE; VkImageView view = VK_NULL_HANDLE; + VkSampler sampler = VK_NULL_HANDLE; int width = 0, height = 0; diff --git a/engine/renderer/include/renderer.hpp b/engine/renderer/include/renderer.hpp index 9b13396..f781853 100755 --- a/engine/renderer/include/renderer.hpp +++ b/engine/renderer/include/renderer.hpp @@ -14,7 +14,6 @@ #include "shadercompiler.hpp" #include "rendertarget.hpp" #include "platform.hpp" -#include "gfx_sampler.hpp" class GFX; class GFXBuffer; @@ -144,8 +143,6 @@ namespace prism { GFXBuffer* histogram_buffer = nullptr; GFXTexture* average_luminance_texture = nullptr; - GFXSampler* global_sampler = nullptr; - std::unique_ptr smaa_pass; std::unique_ptr dof_pass; diff --git a/engine/renderer/include/shadowpass.hpp b/engine/renderer/include/shadowpass.hpp index 02f498d..c72bda0 100755 --- a/engine/renderer/include/shadowpass.hpp +++ b/engine/renderer/include/shadowpass.hpp @@ -58,6 +58,4 @@ private: // point GFXPipeline* static_point_pipeline = nullptr; GFXPipeline* skinned_point_pipeline = nullptr; - - GFXSampler* shadow_sampler = nullptr; }; diff --git a/engine/renderer/src/dofpass.cpp b/engine/renderer/src/dofpass.cpp index 95432c2..a4027b4 100755 --- a/engine/renderer/src/dofpass.cpp +++ b/engine/renderer/src/dofpass.cpp @@ -34,8 +34,8 @@ DoFPass::DoFPass(GFX* gfx) { create_info.shader_input.bindings = { {0, GFXBindingType::StorageImage}, - {1, GFXBindingType::SampledImage}, - {3, GFXBindingType::SampledImage}, + {1, GFXBindingType::Texture}, + {3, GFXBindingType::Texture}, {2, GFXBindingType::PushConstant} }; @@ -59,7 +59,8 @@ DoFPass::DoFPass(GFX* gfx) { textureInfo.height = extent.height; textureInfo.format = GFXPixelFormat::RGBA_32F; textureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::Sampled; - + textureInfo.samplingMode = SamplingMode::ClampToEdge; + normal_field = gfx->create_texture(textureInfo); textureInfo.label = "Far Field"; diff --git a/engine/renderer/src/imguipass.cpp b/engine/renderer/src/imguipass.cpp index 8eba875..86bbfb2 100755 --- a/engine/renderer/src/imguipass.cpp +++ b/engine/renderer/src/imguipass.cpp @@ -63,7 +63,7 @@ void ImGuiPass::create_render_target_resources(RenderTarget& target) { createInfo.shader_input.bindings = { {1, GFXBindingType::PushConstant}, - {2, GFXBindingType::SampledImage} + {2, GFXBindingType::Texture} }; pipeline = engine->get_gfx()->create_graphics_pipeline(createInfo); diff --git a/engine/renderer/src/materialcompiler.cpp b/engine/renderer/src/materialcompiler.cpp index 21c7a10..c4a2953 100755 --- a/engine/renderer/src/materialcompiler.cpp +++ b/engine/renderer/src/materialcompiler.cpp @@ -147,9 +147,8 @@ layout(std430, binding = 1) buffer readonly SceneInformation {{ Probe probes[MAX_PROBES]; int numLights; }} scene; -layout (binding = 2) uniform texture2D sun_shadow; -layout (binding = 6) uniform texture2DArray spot_shadow; -layout (binding = 10) uniform sampler shadow_sampler; +layout (binding = 2) uniform sampler2D sun_shadow; +layout (binding = 6) uniform sampler2DArray spot_shadow; layout(push_constant) uniform PushConstant {{ mat4 model; }}; @@ -183,7 +182,7 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo if(render_options.enable_point_shadows) { format_to(std::back_inserter(src), R"(#define POINT_SHADOWS_SUPPORTED - layout (binding = 3) uniform textureCubeArray point_shadow; + layout (binding = 3) uniform samplerCubeArray point_shadow; )"); } @@ -191,9 +190,9 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo if(use_ibl) { format_to(std::back_inserter(src), - R"(layout (binding = 7) uniform textureCubeArray irrandianceSampler; - layout (binding = 8) uniform textureCubeArray prefilterSampler; - layout (binding = 9) uniform texture2D brdfSampler; + R"(layout (binding = 7) uniform samplerCubeArray irrandianceSampler; + layout (binding = 8) uniform samplerCubeArray prefilterSampler; + layout (binding = 9) uniform sampler2D brdfSampler; )"); } @@ -209,17 +208,17 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo material.bound_textures.clear(); // insert samplers as needed - int sampler_index = 11; + int sampler_index = 10; if(material.colorProperty.type == DataType::AssetTexture) { material.bound_textures[sampler_index] = material.colorProperty.value_tex; - format_to(std::back_inserter(src), "layout(binding = {}) uniform texture2D colorTexture;\n", sampler_index++); + format_to(std::back_inserter(src), "layout(binding = {}) uniform sampler2D colorTexture;\n", sampler_index++); } if(material.normalProperty.type == DataType::AssetTexture) { material.bound_textures[sampler_index] = material.normalProperty.value_tex; - format_to(std::back_inserter(src), "layout(binding = {}) uniform texture2D normalTexture;\n", sampler_index++); + format_to(std::back_inserter(src), "layout(binding = {}) uniform sampler2D normalTexture;\n", sampler_index++); } if(use_ibl) { @@ -259,7 +258,7 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo pos = step - step * noise.x; float shadow = 0.0; while(pos <= 1.0) {{ - vec3 tmp_normal = texture(sampler2D(normal_map, shadow_sampler), in_uv + dir * pos).rgb; + vec3 tmp_normal = texture(normal_map, in_uv + dir * pos).rgb; tmp_normal = in_tbn * (tmp_normal * 2.0 - 1.0); float tmp_lighting = dot(light_dir, tmp_normal); float shadowed = -tmp_lighting; @@ -280,9 +279,9 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo 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 R = get_reflect(probe, surface_info.N); - const vec2 brdf = texture(sampler2D(brdfSampler, shadow_sampler), vec2(surface_info.NdotV, surface_info.roughness)).rg; - const vec3 sampledIrradiance = texture(samplerCubeArray(irrandianceSampler, shadow_sampler), vec4(surface_info.N, probe)).xyz; - const vec3 prefilteredColor = textureLod(samplerCubeArray(prefilterSampler, shadow_sampler), vec4(R, probe), surface_info.roughness * 4).xyz; + const vec2 brdf = texture(brdfSampler, vec2(surface_info.NdotV, surface_info.roughness)).rg; + const vec3 sampledIrradiance = texture(irrandianceSampler, vec4(surface_info.N, probe)).xyz; + const vec3 prefilteredColor = textureLod(prefilterSampler, vec4(R, probe), surface_info.roughness * 4).xyz; const vec3 diffuse = sampledIrradiance * surface_info.diffuse_color; const vec3 specular = prefilteredColor * (F * brdf.x + brdf.y); return (diffuse + specular) * intensity; @@ -295,7 +294,7 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo 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); } else if(material.colorProperty.type == DataType::AssetTexture) { - format_to(std::back_inserter(src), "vec3 Color = texture(sampler2D(colorTexture, shadow_sampler), in_uv).rgb;\n"); + format_to(std::back_inserter(src), "vec3 Color = texture(colorTexture, in_uv).rgb;\n"); } else if(material.colorProperty.type == DataType::Float) { format_to(std::back_inserter(src),"vec3 Color = vec3({}});\n", material.colorProperty.float_value); } @@ -310,7 +309,7 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo prism::log("enabling normal mapping on material.."); format_to(std::back_inserter(src), - R"(vec3 final_normal = texture(sampler2D(normalTexture, shadow_sampler), in_uv).rgb; + R"(vec3 final_normal = texture(normalTexture, in_uv).rgb; final_normal = final_normal * 2.0 - 1.0; final_normal = in_tbn * final_normal; )"); diff --git a/engine/renderer/src/renderer.cpp b/engine/renderer/src/renderer.cpp index bb306c4..9ff7620 100755 --- a/engine/renderer/src/renderer.cpp +++ b/engine/renderer/src/renderer.cpp @@ -88,10 +88,6 @@ renderer::renderer(GFX* gfx, const bool enable_imgui) : gfx(gfx) { unorm_render_pass = gfx->create_render_pass(renderPassInfo); create_sky_pipeline(); - - GFXSamplerCreateInfo sampler_create_info = {}; - - global_sampler = gfx->create_sampler(sampler_create_info); } renderer::~renderer() = default; @@ -282,8 +278,6 @@ void renderer::render(GFXCommandBuffer* commandbuffer, Scene* scene, RenderTarge else commandbuffer->bind_texture(dummy_texture, 7); - commandbuffer->bind_sampler(global_sampler, 8); - PostPushConstants pc; pc.options.x = render_options.enable_aa; pc.options.z = render_options.exposure; @@ -419,7 +413,6 @@ void renderer::render_camera(GFXCommandBuffer* command_buffer, Scene& scene, Obj command_buffer->bind_texture(scene.irradianceCubeArray, 7); command_buffer->bind_texture(scene.prefilteredCubeArray, 8); command_buffer->bind_texture(brdf_texture, 9); - command_buffer->bind_sampler(global_sampler, 10); if(!mesh.mesh->bones.empty()) command_buffer->bind_shader_buffer(part.bone_batrix_buffer, 0, 14, sizeof(Matrix4x4) * 128); @@ -496,13 +489,12 @@ void renderer::create_mesh_pipeline(Material& material) const { pipelineInfo.shader_input.bindings = { {1, GFXBindingType::StorageBuffer}, {0, GFXBindingType::PushConstant}, - {2, GFXBindingType::SampledImage}, - {3, GFXBindingType::SampledImage}, - {6, GFXBindingType::SampledImage}, - {7, GFXBindingType::SampledImage}, - {8, GFXBindingType::SampledImage}, - {9, GFXBindingType::SampledImage}, - {10, GFXBindingType::Sampler} + {2, GFXBindingType::Texture}, + {3, GFXBindingType::Texture}, + {6, GFXBindingType::Texture}, + {7, GFXBindingType::Texture}, + {8, GFXBindingType::Texture}, + {9, GFXBindingType::Texture} }; pipelineInfo.render_pass = offscreen_render_pass; @@ -516,7 +508,7 @@ void renderer::create_mesh_pipeline(Material& material) const { for (auto [index, texture] : material.bound_textures) { GFXShaderBinding binding; binding.binding = index; - binding.type = GFXBindingType::SampledImage; + binding.type = GFXBindingType::Texture; pipelineInfo.shader_input.bindings.push_back(binding); } @@ -559,6 +551,7 @@ void renderer::create_render_target_resources(RenderTarget& target) { textureInfo.height = extent.height; textureInfo.format = GFXPixelFormat::RGBA_32F; textureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::Sampled | GFXTextureUsage::Storage; + textureInfo.samplingMode = SamplingMode::ClampToEdge; target.offscreenColorTexture = gfx->create_texture(textureInfo); @@ -576,7 +569,27 @@ void renderer::create_render_target_resources(RenderTarget& target) { target.offscreenFramebuffer = gfx->create_framebuffer(framebufferInfo); if(post_pipeline == nullptr) { - create_post_pipelines(); + GFXGraphicsPipelineCreateInfo pipelineInfo = {}; + 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); @@ -591,13 +604,12 @@ void renderer::create_post_pipelines() { pipelineInfo.shader_input.bindings = { {4, GFXBindingType::PushConstant}, - {1, GFXBindingType::SampledImage}, - {2, GFXBindingType::SampledImage}, - {3, GFXBindingType::SampledImage}, - {5, GFXBindingType::SampledImage}, - {6, GFXBindingType::SampledImage}, - {7, GFXBindingType::SampledImage}, - {8, GFXBindingType::Sampler} + {1, GFXBindingType::Texture}, + {2, GFXBindingType::Texture}, + {3, GFXBindingType::Texture}, + {5, GFXBindingType::Texture}, + {6, GFXBindingType::Texture}, + {7, GFXBindingType::Texture} }; pipelineInfo.shader_input.push_constants = { diff --git a/engine/renderer/src/scenecapture.cpp b/engine/renderer/src/scenecapture.cpp index f145753..a54d586 100755 --- a/engine/renderer/src/scenecapture.cpp +++ b/engine/renderer/src/scenecapture.cpp @@ -84,7 +84,8 @@ SceneCapture::SceneCapture(GFX* gfx) { textureInfo.height = scene_cubemap_resolution; textureInfo.format = GFXPixelFormat::R8G8B8A8_UNORM; textureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::TransferSrc | GFXTextureUsage::Sampled; - + textureInfo.samplingMode = SamplingMode::ClampToEdge; + offscreenTexture = gfx->create_texture(textureInfo); GFXTextureCreateInfo depthTextureInfo = {}; @@ -93,7 +94,8 @@ SceneCapture::SceneCapture(GFX* gfx) { depthTextureInfo.height = scene_cubemap_resolution; depthTextureInfo.format = GFXPixelFormat::DEPTH_32F; depthTextureInfo.usage = GFXTextureUsage::Attachment; - + depthTextureInfo.samplingMode = SamplingMode::ClampToEdge; + offscreenDepth = gfx->create_texture(depthTextureInfo); GFXFramebufferCreateInfo info; @@ -109,6 +111,7 @@ SceneCapture::SceneCapture(GFX* gfx) { cubeTextureInfo.height = scene_cubemap_resolution; cubeTextureInfo.format = GFXPixelFormat::R8G8B8A8_UNORM; 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; environmentCube = gfx->create_texture(cubeTextureInfo); @@ -131,6 +134,7 @@ void SceneCapture::create_scene_resources(Scene& scene) { cubeTextureInfo.height = irradiance_cubemap_resolution; cubeTextureInfo.format = GFXPixelFormat::R8G8B8A8_UNORM; cubeTextureInfo.usage = GFXTextureUsage::Sampled | GFXTextureUsage::TransferDst; + cubeTextureInfo.samplingMode = SamplingMode::ClampToEdge; cubeTextureInfo.array_length = max_environment_probes; scene.irradianceCubeArray = gfx->create_texture(cubeTextureInfo); @@ -142,6 +146,7 @@ void SceneCapture::create_scene_resources(Scene& scene) { cubeTextureInfo.height = scene_cubemap_resolution; cubeTextureInfo.format = GFXPixelFormat::R8G8B8A8_UNORM; cubeTextureInfo.usage = GFXTextureUsage::Sampled | GFXTextureUsage::TransferDst; + cubeTextureInfo.samplingMode = SamplingMode::ClampToEdge; cubeTextureInfo.array_length = max_environment_probes; cubeTextureInfo.mip_count = mipLevels; @@ -431,7 +436,8 @@ void SceneCapture::createIrradianceResources() { textureInfo.height = irradiance_cubemap_resolution; textureInfo.format = GFXPixelFormat::R8G8B8A8_UNORM; textureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::TransferSrc; - + textureInfo.samplingMode = SamplingMode::ClampToEdge; + irradianceOffscreenTexture = gfx->create_texture(textureInfo); GFXRenderPassCreateInfo renderPassInfo = {}; @@ -468,7 +474,7 @@ void SceneCapture::createIrradianceResources() { pipelineInfo.shader_input.bindings = { {1, GFXBindingType::PushConstant}, - {2, GFXBindingType::SampledImage} + {2, GFXBindingType::Texture} }; pipelineInfo.render_pass = irradianceRenderPass; @@ -485,7 +491,8 @@ void SceneCapture::createPrefilterResources() { textureInfo.height = scene_cubemap_resolution; textureInfo.format = GFXPixelFormat::R8G8B8A8_UNORM; textureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::TransferSrc; - + textureInfo.samplingMode = SamplingMode::ClampToEdge; + prefilteredOffscreenTexture = gfx->create_texture(textureInfo); GFXFramebufferCreateInfo info; @@ -521,7 +528,7 @@ void SceneCapture::createPrefilterResources() { pipelineInfo.shader_input.bindings = { {1, GFXBindingType::PushConstant}, - {2, GFXBindingType::SampledImage} + {2, GFXBindingType::Texture} }; pipelineInfo.render_pass = irradianceRenderPass; diff --git a/engine/renderer/src/shadowpass.cpp b/engine/renderer/src/shadowpass.cpp index ee9f6da..be6606a 100755 --- a/engine/renderer/src/shadowpass.cpp +++ b/engine/renderer/src/shadowpass.cpp @@ -42,6 +42,8 @@ void ShadowPass::create_scene_resources(Scene& scene) { textureInfo.height = render_options.shadow_resolution; textureInfo.format = GFXPixelFormat::DEPTH_32F; textureInfo.usage = GFXTextureUsage::Sampled | GFXTextureUsage::Attachment; + textureInfo.samplingMode = SamplingMode::ClampToBorder; + textureInfo.border_color = GFXBorderColor::OpaqueWhite; scene.depthTexture = gfx->create_texture(textureInfo); @@ -62,6 +64,8 @@ void ShadowPass::create_scene_resources(Scene& scene) { cubeTextureInfo.format = GFXPixelFormat::R_32F; cubeTextureInfo.usage = GFXTextureUsage::Sampled; cubeTextureInfo.array_length = max_point_shadows; + cubeTextureInfo.samplingMode = SamplingMode::ClampToBorder; + cubeTextureInfo.border_color = GFXBorderColor::OpaqueWhite; scene.pointLightArray = gfx->create_texture(cubeTextureInfo); } @@ -76,15 +80,11 @@ void ShadowPass::create_scene_resources(Scene& scene) { spotTextureInfo.format = GFXPixelFormat::DEPTH_32F; spotTextureInfo.usage = GFXTextureUsage::Sampled; spotTextureInfo.array_length = max_spot_shadows; + spotTextureInfo.samplingMode = SamplingMode::ClampToBorder; + spotTextureInfo.border_color = GFXBorderColor::OpaqueWhite; 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) { @@ -391,6 +391,7 @@ void ShadowPass::create_offscreen_resources() { textureInfo.height = render_options.shadow_resolution; textureInfo.format = GFXPixelFormat::R_32F; textureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::Sampled; + textureInfo.samplingMode = SamplingMode::ClampToEdge; offscreen_color_texture = gfx->create_texture(textureInfo); @@ -400,7 +401,8 @@ void ShadowPass::create_offscreen_resources() { depthTextureInfo.height = render_options.shadow_resolution; depthTextureInfo.format = GFXPixelFormat::DEPTH_32F; depthTextureInfo.usage = GFXTextureUsage::Attachment | GFXTextureUsage::Sampled; - + depthTextureInfo.samplingMode = SamplingMode::ClampToEdge; + offscreen_depth = gfx->create_texture(depthTextureInfo); GFXFramebufferCreateInfo info; diff --git a/engine/renderer/src/smaapass.cpp b/engine/renderer/src/smaapass.cpp index ef8bcd7..8b9e0f6 100755 --- a/engine/renderer/src/smaapass.cpp +++ b/engine/renderer/src/smaapass.cpp @@ -101,7 +101,8 @@ void SMAAPass::create_textures() { areaInfo.height = AREATEX_HEIGHT; areaInfo.format = GFXPixelFormat::R8G8_UNORM; areaInfo.usage = GFXTextureUsage::Sampled | GFXTextureUsage::TransferDst; - + areaInfo.samplingMode = SamplingMode::ClampToEdge; + area_image = gfx->create_texture(areaInfo); gfx->copy_texture(area_image, (void*)areaTexBytes, AREATEX_SIZE); @@ -113,7 +114,8 @@ void SMAAPass::create_textures() { searchInfo.height = SEARCHTEX_HEIGHT; searchInfo.format = GFXPixelFormat::R8_UNORM; searchInfo.usage = GFXTextureUsage::Sampled | GFXTextureUsage::TransferDst; - + searchInfo.samplingMode = SamplingMode::ClampToEdge; + search_image = gfx->create_texture(searchInfo); gfx->copy_texture(search_image, (void*)searchTexBytes, SEARCHTEX_SIZE); @@ -143,8 +145,8 @@ void SMAAPass::create_pipelines() { }; createInfo.shader_input.bindings = { - {0, GFXBindingType::SampledImage}, - {1, GFXBindingType::SampledImage}, + {0, GFXBindingType::Texture}, + {1, GFXBindingType::Texture}, {2, GFXBindingType::PushConstant} }; @@ -153,7 +155,7 @@ void SMAAPass::create_pipelines() { createInfo.label = "SMAA Blend"; createInfo.shaders.vertex_src = ShaderSource(prism::path("blend.vert")); createInfo.shaders.fragment_src = ShaderSource(prism::path("blend.frag")); - createInfo.shader_input.bindings.push_back({3, GFXBindingType::SampledImage}); + createInfo.shader_input.bindings.push_back({3, GFXBindingType::Texture}); blend_pipeline = gfx->create_graphics_pipeline(createInfo); } diff --git a/engine/shaders/billboard.frag.glsl b/engine/shaders/billboard.frag.glsl index 2a42a17..f195420 100644 --- a/engine/shaders/billboard.frag.glsl +++ b/engine/shaders/billboard.frag.glsl @@ -7,12 +7,11 @@ layout(push_constant) uniform readonly PushConstant{ vec4 color; }; -layout (binding = 2) uniform texture2D colorSampler; -layout (binding = 3) uniform sampler testSampler; +layout (binding = 2) uniform sampler2D colorSampler; void main() { if(inUV.y < 0.0 || inUV.x > 1.0) discard; - outColor = texture(sampler2D(colorSampler, testSampler), inUV) * color; + outColor = texture(colorSampler, inUV) * color; } diff --git a/engine/shaders/imgui.frag.glsl b/engine/shaders/imgui.frag.glsl index d2f07b0..3db777c 100644 --- a/engine/shaders/imgui.frag.glsl +++ b/engine/shaders/imgui.frag.glsl @@ -3,9 +3,8 @@ layout(location = 1) in vec2 in_uv; layout(location = 0) out vec4 out_color; -layout(binding = 2) uniform texture2D bound_texture; -layout(binding = 3) uniform sampler testSampler; +layout(binding = 2) uniform sampler2D bound_texture; void main() { - out_color = in_color * texture(sampler2D(bound_texture, testSampler), in_uv); + out_color = in_color * texture(bound_texture, in_uv); } diff --git a/engine/shaders/post.frag.glsl b/engine/shaders/post.frag.glsl index b79b801..36e1d4a 100644 --- a/engine/shaders/post.frag.glsl +++ b/engine/shaders/post.frag.glsl @@ -19,31 +19,30 @@ layout(location = 1) in vec4 inOffset; layout (location = 0) out vec4 outColor; -layout (binding = 1) uniform texture2D colorSampler; -layout (binding = 2) uniform texture2D backSampler; -layout (binding = 3) uniform texture2D blendSampler; -layout (binding = 5) uniform texture2D sobelSampler; -layout (binding = 6) uniform texture2D averageLuminanceSampler; -layout (binding = 7) uniform texture2D farFieldSampler; -layout (binding = 8) uniform sampler global_sampler; +layout (binding = 1) uniform sampler2D colorSampler; +layout (binding = 2) uniform sampler2D backSampler; +layout (binding = 3) uniform sampler2D blendSampler; +layout (binding = 5) uniform sampler2D sobelSampler; +layout (binding = 6) uniform sampler2D averageLuminanceSampler; +layout (binding = 7) uniform sampler2D farFieldSampler; float calculate_sobel() { float x = 1.0 / viewport.z; float y = 1.0 / viewport.w; vec4 horizEdge = vec4( 0.0 ); - horizEdge -= texture(sampler2D(sobelSampler, global_sampler), vec2( inUV.x - x, inUV.y - y ) ) * 1.0; - horizEdge -= texture(sampler2D(sobelSampler, global_sampler), vec2( inUV.x - x, inUV.y ) ) * 2.0; - horizEdge -= texture(sampler2D(sobelSampler, global_sampler), 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(sampler2D(sobelSampler, global_sampler), vec2( inUV.x + x, inUV.y ) ) * 2.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( sobelSampler, vec2( inUV.x - x, inUV.y ) ) * 2.0; + horizEdge -= texture( sobelSampler, vec2( inUV.x - x, inUV.y + y ) ) * 1.0; + horizEdge += texture( sobelSampler, vec2( inUV.x + x, inUV.y - y ) ) * 1.0; + horizEdge += texture( sobelSampler, vec2( inUV.x + x, inUV.y ) ) * 2.0; + horizEdge += texture( sobelSampler, vec2( inUV.x + x, inUV.y + y ) ) * 1.0; vec4 vertEdge = vec4( 0.0 ); - vertEdge -= texture(sampler2D(sobelSampler, global_sampler), vec2( inUV.x - x, inUV.y - y ) ) * 1.0; - vertEdge -= texture(sampler2D(sobelSampler, global_sampler), vec2( inUV.x , inUV.y - y ) ) * 2.0; - vertEdge -= texture(sampler2D(sobelSampler, global_sampler), 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(sampler2D(sobelSampler, global_sampler), vec2( inUV.x , inUV.y + y ) ) * 2.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( sobelSampler, vec2( inUV.x , inUV.y - y ) ) * 2.0; + vertEdge -= texture( sobelSampler, vec2( inUV.x + x, inUV.y - y ) ) * 1.0; + vertEdge += texture( sobelSampler, vec2( inUV.x - x, inUV.y + y ) ) * 1.0; + vertEdge += texture( sobelSampler, vec2( inUV.x , inUV.y + y ) ) * 2.0; + vertEdge += texture( sobelSampler, vec2( inUV.x + x, inUV.y + y ) ) * 1.0; return sqrt((horizEdge.rgb * horizEdge.rgb) + (vertEdge.rgb * vertEdge.rgb)).r; } @@ -107,31 +106,31 @@ float reinhard2(float _x, float _whiteSqr) void main() { // passthrough if(options.w == 1) { - outColor = texture(sampler2D(colorSampler, global_sampler), inUV); + outColor = texture(colorSampler, inUV); return; } bool enable_dof = options.w == 2; vec3 sceneColor = vec3(0); if(enable_dof) { - sceneColor = texture(sampler2D(farFieldSampler, global_sampler), inUV).rgb; - sceneColor += texture(sampler2D(colorSampler, global_sampler), inUV).rgb; + sceneColor = texture(farFieldSampler, inUV).rgb; + sceneColor += texture(colorSampler, inUV).rgb; } else { - //if(options.x == 1) // enable AA - // sceneColor = SMAANeighborhoodBlendingPS(inUV, inOffset, colorSampler, blendSampler).rgb; - //else - sceneColor = texture(sampler2D(colorSampler, global_sampler), inUV).rgb; + if(options.x == 1) // enable AA + sceneColor = SMAANeighborhoodBlendingPS(inUV, inOffset, colorSampler, blendSampler).rgb; + else + sceneColor = texture(colorSampler, inUV).rgb; } float sobel = 0.0; - if(textureSize(sampler2D(sobelSampler, global_sampler), 0).x > 1) + if(textureSize(sobelSampler, 0).x > 1) sobel = calculate_sobel(); vec3 sobelColor = vec3(0, 1, 1); vec3 hdrColor = sceneColor; // fading removed - float avg_lum = texture(sampler2D(averageLuminanceSampler, global_sampler), inUV).r; + float avg_lum = texture(averageLuminanceSampler, inUV).r; vec3 transformed_color = hdrColor; diff --git a/engine/shaders/rendering.nocompile.glsl b/engine/shaders/rendering.nocompile.glsl index 9d7a40a..d579267 100644 --- a/engine/shaders/rendering.nocompile.glsl +++ b/engine/shaders/rendering.nocompile.glsl @@ -66,7 +66,7 @@ struct ComputedLightInformation { float pcf_sun(const vec4 shadowCoords, const float uvRadius) { float sum = 0; for(int i = 0; i < 16; i++) { - const float z = texture(sampler2D(sun_shadow, shadow_sampler), shadowCoords.xy + PoissionPCFDisk[i] * uvRadius).r; + const float z = texture(sun_shadow, shadowCoords.xy + PoissionPCFDisk[i] * uvRadius).r; 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; for(int i = 0; i < numBlockerSearchSamples; i++) { - const float z = texture(sampler2D(sun_shadow, shadow_sampler), shadowCoords.xy + PoissionPCFDisk[i] * searchWidth).r; + const float z = texture(sun_shadow, shadowCoords.xy + PoissionPCFDisk[i] * searchWidth).r; if(z < shadowCoords.z) { blockerSum += z; blockers++; @@ -126,7 +126,7 @@ ComputedLightInformation calculate_sun(Light light) { if(shadowCoords.z > -1.0 && shadowCoords.z < 1.0) { #ifdef SHADOW_FILTER_NONE - shadow = (texture(sampler2D(sun_shadow, shadow_sampler), shadowCoords.xy).r < shadowCoords.z - 0.005) ? 0.0 : 1.0; + shadow = (texture(sun_shadow, shadowCoords.xy).r < shadowCoords.z - 0.005) ? 0.0 : 1.0; #endif #ifdef SHADOW_FILTER_PCF 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 sum = 0; for(int i = 0; i < 16; i++) { - const float z = texture(sampler2DArray(spot_shadow, shadow_sampler), vec3(shadowCoords.xy + PoissionPCFDisk[i] * uvRadius, index)).r; + const float z = texture(spot_shadow, vec3(shadowCoords.xy + PoissionPCFDisk[i] * uvRadius, index)).r; 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; for(int i = 0; i < numBlockerSearchSamples; i++) { - const float z = texture(sampler2DArray(spot_shadow, shadow_sampler), vec3(shadowCoords.xy + PoissionPCFDisk[i] * searchWidth, index)).r; + const float z = texture(spot_shadow, vec3(shadowCoords.xy + PoissionPCFDisk[i] * searchWidth, index)).r; if(z < shadowCoords.z) { blockerSum += z; blockers++; @@ -197,7 +197,7 @@ ComputedLightInformation calculate_spot(Light light) { const vec4 shadowCoord = fragPostSpotLightSpace[last_spot_light] / fragPostSpotLightSpace[last_spot_light].w; #ifdef SHADOW_FILTER_NONE - shadow = (texture(sampler2D(spot_shadow, shadow_sampler), vec3(shadowCoord.xy, last_spot_light)).r < shadowCoord.z - 0.005) ? 0.0 : 1.0; + shadow = (texture(spot_shadow, vec3(shadowCoord.xy, last_spot_light)).r < shadowCoord.z - 0.005) ? 0.0 : 1.0; #endif #ifdef SHADOW_FILTER_PCF 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 sum = 0; for(int i = 0; i < 20; i++) { - const float z = texture(samplerCubeArray(point_shadow, shadow_sampler), vec4(shadowCoords.xyz + sampleOffsetDirections[i] * uvRadius, index)).r; + const float z = texture(point_shadow, vec4(shadowCoords.xyz + sampleOffsetDirections[i] * uvRadius, index)).r; 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; for(int i = 0; i < 20; i++) { - const float z = texture(samplerCubeArray(point_shadow, shadow_sampler), vec4(shadowCoords + sampleOffsetDirections[i] * 0.05, index)).r; + const float z = texture(point_shadow, vec4(shadowCoords + sampleOffsetDirections[i] * 0.05, index)).r; if(z < length(shadowCoords)) { blockerSum += z; blockers++; @@ -289,7 +289,7 @@ ComputedLightInformation calculate_point(Light light) { #ifdef POINT_SHADOWS_SUPPORTED if(light.shadowsEnable.x == 1.0) { #ifdef SHADOW_FILTER_NONE - const float sampledDist = texture(sampler2D(point_shadow, shadow_sampler), vec4(lightVec, int(light.shadowsEnable.z))).r; + const float sampledDist = texture(point_shadow, vec4(lightVec, int(light.shadowsEnable.z))).r; const float dist = length(lightVec); shadow = (dist <= sampledDist + 0.05) ? 1.0 : 0.0;