Archived
1
Fork 0

Fix up IBL stuff on Vulkan

This commit is contained in:
redstrate 2021-02-15 19:01:17 -05:00
parent 6d77396b4d
commit 86efe2abf9
11 changed files with 40 additions and 52 deletions

View file

@ -316,7 +316,7 @@ public:
/// If physics should upate. This is a control indepentent of the pause state.
bool update_physics = true;
#if defined(PLATFORM_TVOS) || defined(PLATFORM_IOS) || defined(PLATFORM_WINDOWS)
#if defined(PLATFORM_TVOS) || defined(PLATFORM_IOS) || defined(PLATFORM_WINDOWS) || defined(PLATFORM_LINUX)
bool debug_enabled = true;
#else
bool debug_enabled = false;

View file

@ -229,6 +229,8 @@ struct GFXRenderPassCreateInfo {
std::string label;
std::vector<GFXPixelFormat> attachments;
bool will_use_in_shader = false;
};
enum class GFXBorderColor {

View file

@ -443,8 +443,8 @@ GFXTexture* GFXVulkan::create_texture(const GFXTextureCreateInfo& info) {
// create sampler
VkSamplerCreateInfo samplerInfo = {};
samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
samplerInfo.magFilter = VK_FILTER_LINEAR;
samplerInfo.minFilter = VK_FILTER_LINEAR;
samplerInfo.magFilter = VK_FILTER_NEAREST;
samplerInfo.minFilter = VK_FILTER_NEAREST;
samplerInfo.addressModeU = samplerMode;
samplerInfo.addressModeV = samplerMode;
samplerInfo.addressModeW = samplerMode;
@ -644,11 +644,15 @@ GFXRenderPass* GFXVulkan::create_render_pass(const GFXRenderPassCreateInfo& info
attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
attachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
if (isDepthAttachment)
attachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
else
attachment.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
if(info.will_use_in_shader) {
attachment.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
} else {
if (isDepthAttachment)
attachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
else
attachment.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
}
VkAttachmentReference attachmentRef = {};
attachmentRef.attachment = i;
@ -1701,11 +1705,7 @@ void GFXVulkan::cacheDescriptorState(GFXVulkanPipeline* pipeline, VkDescriptorSe
GFXVulkanTexture* vulkanTexture = (GFXVulkanTexture*)texture;
VkDescriptorImageInfo imageInfo = {};
imageInfo.imageLayout = vulkanTexture->layout;
// color attachments are not the right layout
if (imageInfo.imageLayout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)
imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
imageInfo.imageView = vulkanTexture->view;
imageInfo.sampler = vulkanTexture->sampler;

View file

@ -23,9 +23,6 @@ public:
void render(GFXCommandBuffer* command_buffer, Scene& scene);
GFXSampler* shadow_sampler = nullptr;
GFXSampler* pcf_sampler = nullptr;
private:
void render_meshes(GFXCommandBuffer* command_buffer, Scene& scene, const Matrix4x4 light_matrix, const Matrix4x4 model, const Vector3 light_position, const Light::Type type, const CameraFrustum& frustum, const int base_instance);

View file

@ -187,10 +187,8 @@ layout(std430, binding = 1) buffer readonly SceneInformation {\n \
Probe probes[max_probes];\n \
int numLights;\n \
} scene;\n \
layout (binding = 2) uniform texture2D sun_shadow;\n \
layout (binding = 4) uniform sampler shadow_sampler;\n \
layout (binding = 5) uniform samplerShadow pcf_sampler;\n \
layout (binding = 6) uniform texture2DArray spot_shadow;\n \
layout (binding = 2) uniform sampler2D sun_shadow;\n \
layout (binding = 6) uniform sampler2DArray spot_shadow;\n \
layout(push_constant, binding = 0) uniform PushConstant {\n \
mat4 model;\n \
};\n";
@ -223,7 +221,7 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo
if(render_options.enable_point_shadows) {
src += "#define POINT_SHADOWS_SUPPORTED\n";
src += "layout (binding = 3) uniform textureCubeArray point_shadow;\n";
src += "layout (binding = 3) uniform samplerCubeArray point_shadow;\n";
}
src += struct_info;

View file

@ -500,8 +500,6 @@ void Renderer::render_camera(GFXCommandBuffer* command_buffer, Scene& scene, Obj
command_buffer->bind_texture(scene.depthTexture, 2);
command_buffer->bind_texture(scene.pointLightArray, 3);
command_buffer->bind_sampler(shadow_pass->shadow_sampler, 4);
command_buffer->bind_sampler(shadow_pass->pcf_sampler, 5);
command_buffer->bind_texture(scene.spotLightArray, 6);
command_buffer->bind_texture(scene.irradianceCubeArray, 7);
command_buffer->bind_texture(scene.prefilteredCubeArray, 8);
@ -725,11 +723,9 @@ void Renderer::create_mesh_pipeline(Material& material) {
pipelineInfo.shader_input.bindings = {
{1, GFXBindingType::StorageBuffer},
{0, GFXBindingType::PushConstant},
{2, GFXBindingType::SampledImage},
{3, GFXBindingType::SampledImage},
{4, GFXBindingType::Sampler},
{5, GFXBindingType::Sampler},
{6, GFXBindingType::SampledImage},
{2, GFXBindingType::Texture},
{3, GFXBindingType::Texture},
{6, GFXBindingType::Texture},
{7, GFXBindingType::Texture},
{8, GFXBindingType::Texture},
{9, GFXBindingType::Texture}
@ -786,6 +782,7 @@ void Renderer::createOffscreenResources() {
renderPassInfo.label = "Offscreen";
renderPassInfo.attachments.push_back(GFXPixelFormat::RGBA_32F);
renderPassInfo.attachments.push_back(GFXPixelFormat::DEPTH_32F);
renderPassInfo.will_use_in_shader = true;
offscreenRenderPass = gfx->create_render_pass(renderPassInfo);
@ -826,6 +823,7 @@ void Renderer::createOffscreenResources() {
GFXRenderPassCreateInfo renderPassInfo = {};
renderPassInfo.label = "Viewport";
renderPassInfo.attachments.push_back(GFXPixelFormat::RGBA8_UNORM);
renderPassInfo.will_use_in_shader = true;
viewportRenderPass = gfx->create_render_pass(renderPassInfo);
@ -1021,6 +1019,7 @@ void Renderer::createBRDF() {
GFXRenderPassCreateInfo renderPassInfo = {};
renderPassInfo.label = "BRDF Gen";
renderPassInfo.attachments.push_back(GFXPixelFormat::R8G8_SFLOAT);
renderPassInfo.will_use_in_shader = true;
brdfRenderPass = gfx->create_render_pass(renderPassInfo);

View file

@ -75,6 +75,7 @@ SceneCapture::SceneCapture(GFX* gfx) {
renderPassInfo.label = "Scene Capture Cube";
renderPassInfo.attachments.push_back(GFXPixelFormat::R8G8B8A8_UNORM);
renderPassInfo.attachments.push_back(GFXPixelFormat::DEPTH_32F);
renderPassInfo.will_use_in_shader = true;
renderPass = gfx->create_render_pass(renderPassInfo);
@ -268,8 +269,6 @@ void SceneCapture::render(GFXCommandBuffer* command_buffer, Scene* scene) {
command_buffer->bind_shader_buffer(sceneBuffer, 0, 1, sizeof(SceneInformation));
command_buffer->bind_texture(scene->depthTexture, 2);
command_buffer->bind_texture(scene->pointLightArray, 3);
command_buffer->bind_sampler(engine->get_renderer()->shadow_pass->shadow_sampler, 4);
command_buffer->bind_sampler(engine->get_renderer()->shadow_pass->pcf_sampler, 5);
command_buffer->bind_texture(scene->spotLightArray, 6);
command_buffer->set_push_constant(&pc, sizeof(PushConstant));
@ -289,11 +288,7 @@ void SceneCapture::render(GFXCommandBuffer* command_buffer, Scene* scene) {
}
// render sky
struct SkyPushConstant {
Matrix4x4 view;
Vector4 sun_position_fov;
float aspect;
} pc;
SkyPushConstant pc;
pc.view = sceneTransforms[face];
pc.aspect = 1.0f;
@ -436,6 +431,7 @@ void SceneCapture::createIrradianceResources() {
GFXRenderPassCreateInfo renderPassInfo = {};
renderPassInfo.label = "Irradiance";
renderPassInfo.attachments.push_back(GFXPixelFormat::R8G8B8A8_UNORM);
renderPassInfo.will_use_in_shader = true;
irradianceRenderPass = gfx->create_render_pass(renderPassInfo);

View file

@ -30,13 +30,6 @@ ShadowPass::ShadowPass(GFX* gfx) {
create_render_passes();
create_pipelines();
create_offscreen_resources();
GFXSamplerCreateInfo sampler_info = {};
sampler_info.samplingMode = SamplingMode::ClampToBorder;
sampler_info.border_color = GFXBorderColor::OpaqueWhite;
shadow_sampler = gfx->create_sampler(sampler_info);
pcf_sampler = gfx->create_sampler(sampler_info); // unused atm
}
void ShadowPass::create_scene_resources(Scene& scene) {
@ -304,6 +297,7 @@ void ShadowPass::create_render_passes() {
GFXRenderPassCreateInfo renderPassInfo = {};
renderPassInfo.label = "Shadow";
renderPassInfo.attachments.push_back(GFXPixelFormat::DEPTH_32F);
renderPassInfo.will_use_in_shader = true;
render_pass = gfx->create_render_pass(renderPassInfo);

View file

@ -102,6 +102,7 @@ void SMAAPass::create_render_pass() {
GFXRenderPassCreateInfo createInfo = {};
createInfo.label = "SMAA";
createInfo.attachments = {GFXPixelFormat::R16G16B16A16_SFLOAT};
createInfo.will_use_in_shader = true;
render_pass = engine->get_gfx()->create_render_pass(createInfo);
}

View file

@ -67,7 +67,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 + PoissonOffsets[i] * uvRadius).r;
const float z = texture(sun_shadow, shadowCoords.xy + PoissonOffsets[i] * uvRadius).r;
sum += (z < (shadowCoords.z - 0.005)) ? 0.0 : 1.0;
}
@ -92,7 +92,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),
const float z = texture(sun_shadow,
shadowCoords.xy + PoissonOffsets[i] * searchWidth).r;
if(z < shadowCoords.z) {
blockerSum += z;
@ -127,7 +127,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);
@ -146,7 +146,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 + PoissonOffsets[i] * uvRadius, index)).r;
const float z = texture(spot_shadow, vec3(shadowCoords.xy + PoissonOffsets[i] * uvRadius, index)).r;
sum += (z < (shadowCoords.z - 0.001)) ? 0.0 : 1.0;
}
@ -161,7 +161,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),
const float z = texture(spot_shadow,
vec3(shadowCoords.xy + PoissonOffsets[i] * searchWidth, index)).r;
if(z < shadowCoords.z) {
blockerSum += z;
@ -198,7 +198,7 @@ ComputedLightInformation calculate_spot(Light light) {
const vec4 shadowCoord = fragPostSpotLightSpace[last_spot_light] / fragPostSpotLightSpace[last_spot_light].w;
#ifdef SHADOW_FILTER_NONE
shadow = (texture(sampler2DArray(spot_shadow, shadow_sampler), vec3(shadowCoord.xy, last_spot_light)).r < shadowCoord.z) ? 0.0 : 1.0;
shadow = (texture(spot_shadow, vec3(shadowCoord.xy, last_spot_light)).r < shadowCoord.z) ? 0.0 : 1.0;
#endif
#ifdef SHADOW_FILTER_PCF
shadow = pcf_spot(shadowCoord, last_spot_light, 0.01);
@ -227,7 +227,7 @@ ComputedLightInformation calculate_spot(Light light) {
float pcf_point(const vec3 shadowCoords, const int index, const float uvRadius) {
float sum = 0;
for(int i = 0; i < 16; i++) {
const float z = texture(samplerCubeArray(point_shadow, shadow_sampler), vec4(shadowCoords.xyz + vec3(PoissonOffsets[i].xy, PoissonOffsets[i].x) * uvRadius, index)).r;
const float z = texture(point_shadow, vec4(shadowCoords.xyz + vec3(PoissonOffsets[i].xy, PoissonOffsets[i].x) * uvRadius, index)).r;
sum += (z < length(shadowCoords) - 0.05) ? 0.0 : 1.0;
}
@ -242,7 +242,7 @@ void blocker_distance_point(const vec3 shadowCoords, const int index, const floa
blockers = 0;
for(int i = 0; i < numBlockerSearchSamples; i++) {
const float z = texture(samplerCubeArray(point_shadow, shadow_sampler),
const float z = texture(point_shadow,
vec4(shadowCoords + vec3(PoissonOffsets[i], PoissonOffsets[i].x) * searchWidth, index)).r;
if(z < length(shadowCoords)) {
blockerSum += z;
@ -283,7 +283,7 @@ ComputedLightInformation calculate_point(Light light) {
#ifdef POINT_SHADOWS_SUPPORTED
if(light.shadowsEnable.x == 1.0) {
#ifdef SHADOW_FILTER_NONE
const float sampledDist = texture(samplerCubeArray(point_shadow, shadow_sampler), vec4(lightVec, last_point_light++)).r;
const float sampledDist = texture(point_shadow, vec4(lightVec, last_point_light++)).r;
const float dist = length(lightVec);
shadow = (dist <= sampledDist + 0.05) ? 1.0 : 0.0;

View file

@ -102,7 +102,8 @@ void DebugPass::initialize() {
GFXRenderPassCreateInfo renderPassInfo = {};
renderPassInfo.label = "Sobel";
renderPassInfo.attachments.push_back(GFXPixelFormat::R8_UNORM);
renderPassInfo.will_use_in_shader = true;
sobelRenderPass = engine->get_gfx()->create_render_pass(renderPassInfo);
// pipeline