Commit dfdabc8c authored by Nicholas Milef's avatar Nicholas Milef

ENH: added HMD tracking for Vulkan VR

parent cd7c146f
......@@ -33,6 +33,7 @@ function(CopyAndCompileShaders)
compileShaders(PostProcessing/sss_frag.frag PostProcessing/sss_frag.spv)
compileShaders(PostProcessing/lens_distortion_frag.frag PostProcessing/lens_distortion_frag.spv)
compileShaders(PostProcessing/composite_frag.frag PostProcessing/composite_frag.spv)
compileShaders(PostProcessing/vr_composite_frag.frag PostProcessing/vr_composite_frag.spv)
compileShaders(PostProcessing/bloom_threshold_frag.frag PostProcessing/bloom_threshold_frag.spv)
compileShaders(PostProcessing/blur_horizontal_frag.frag PostProcessing/blur_horizontal_frag.spv)
compileShaders(PostProcessing/blur_vertical_frag.frag PostProcessing/blur_vertical_frag.spv)
......
......@@ -26,13 +26,13 @@
using namespace imstk;
///
/// \brief This example demonstrates configuring the rendered
/// \brief This example demonstrates configuring the renderer
/// objects, lights etc.
///
int main()
{
// SDK and Scene
auto sdk = std::make_shared<SimulationManager>();
auto sdk = std::make_shared<SimulationManager>(false, true);
auto scene = sdk->createNewScene("Rendering");
// Add IBL Probe
......
......@@ -25,17 +25,19 @@
namespace imstk
{
VulkanPostProcess::VulkanPostProcess(VulkanRenderer * renderer, unsigned int level)
VulkanPostProcess::VulkanPostProcess(VulkanRenderer * renderer, uint32_t numViews, unsigned int level)
{
m_downsampleLevels = level;
m_numViews = numViews;
auto width = renderer->m_width >> level;
auto height = renderer->m_height >> level;
this->createFramebuffer(renderer, width, height);
}
VulkanPostProcess::VulkanPostProcess(VulkanRenderer * renderer, unsigned int width, unsigned int height)
VulkanPostProcess::VulkanPostProcess(VulkanRenderer * renderer, uint32_t numViews, unsigned int width, unsigned int height)
{
m_downsampleLevels = 0;
m_numViews = numViews;
this->createFramebuffer(renderer, width, height);
}
......@@ -540,9 +542,15 @@ VulkanPostProcess::createRenderPass(VulkanRenderer * renderer)
dependencies[1].dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
dependencies[1].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
uint32_t viewMask = m_numViews == 2 ? 3 : 1;
uint32_t correlationMask = m_numViews == 2 ? 3 : 1;
VkRenderPassMultiviewCreateInfo multiviewInfo;
VulkanRenderPassGenerator::generateRenderPassMultiviewCreateInfo(multiviewInfo, viewMask, correlationMask);
VkRenderPassCreateInfo renderPassInfo;
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
renderPassInfo.pNext = nullptr;
renderPassInfo.pNext = &multiviewInfo;
renderPassInfo.flags = 0;
renderPassInfo.attachmentCount = (uint32_t)attachments.size();
renderPassInfo.pAttachments = &attachments[0];
......@@ -608,7 +616,9 @@ VulkanPostProcess::updateImageLayouts()
}
void
VulkanPostProcess::setAttachmentsToReadLayout(VkCommandBuffer * commandBuffer, uint32_t queueFamily)
VulkanPostProcess::setAttachmentsToReadLayout(VkCommandBuffer * commandBuffer,
uint32_t queueFamily,
const uint32_t numViews)
{
if (m_framebuffer->m_colorFormat != VK_FORMAT_UNDEFINED)
{
......@@ -616,7 +626,8 @@ VulkanPostProcess::setAttachmentsToReadLayout(VkCommandBuffer * commandBuffer, u
queueFamily,
m_framebuffer->m_colorImage,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
numViews);
}
if (m_framebuffer->m_depthFormat != VK_FORMAT_UNDEFINED)
......@@ -625,7 +636,8 @@ VulkanPostProcess::setAttachmentsToReadLayout(VkCommandBuffer * commandBuffer, u
queueFamily,
m_framebuffer->m_depthImage,
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL);
VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
numViews);
}
if (m_framebuffer->m_normalFormat != VK_FORMAT_UNDEFINED)
......@@ -634,7 +646,8 @@ VulkanPostProcess::setAttachmentsToReadLayout(VkCommandBuffer * commandBuffer, u
queueFamily,
m_framebuffer->m_normalImage,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
numViews);
}
if (m_framebuffer->m_specularFormat != VK_FORMAT_UNDEFINED)
......@@ -643,7 +656,8 @@ VulkanPostProcess::setAttachmentsToReadLayout(VkCommandBuffer * commandBuffer, u
queueFamily,
m_framebuffer->m_specularImage,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
numViews);
}
}
......
......@@ -43,8 +43,8 @@ public:
///
/// \brief Constructor
///
VulkanPostProcess(VulkanRenderer * renderer, unsigned int level = 0);
VulkanPostProcess(VulkanRenderer * renderer, unsigned int width, unsigned int height);
VulkanPostProcess(VulkanRenderer * renderer, uint32_t numViews, unsigned int level = 0);
VulkanPostProcess(VulkanRenderer * renderer, uint32_t numViews, unsigned int width, unsigned int height);
void addInputImage(
VkSampler * sampler,
......@@ -81,7 +81,9 @@ protected:
///
/// \brief Set image attachments to a readable layout
///
void setAttachmentsToReadLayout(VkCommandBuffer * commandBuffer, uint32_t queueFamily);
void setAttachmentsToReadLayout(VkCommandBuffer * commandBuffer,
uint32_t queueFamily,
const uint32_t numViews);
void createDescriptors(VulkanRenderer * renderer);
void createDescriptorSetLayouts(VulkanRenderer * renderer);
......@@ -111,6 +113,7 @@ protected:
unsigned int m_downsampleLevels = 0;
unsigned int m_outputIndex = 0;
uint32_t m_numViews;
std::vector<VkAttachmentReference> m_colorAttachments;
VkRenderPass m_renderPass;
......
......@@ -33,7 +33,7 @@ VulkanPostProcessingChain::VulkanPostProcessingChain(VulkanRenderer * renderer)
{
int sssSamples = 5;
auto sssHorizontalBlurPass = std::make_shared<VulkanPostProcess>(renderer, 0);
auto sssHorizontalBlurPass = std::make_shared<VulkanPostProcess>(renderer, renderer->m_numViews, 0);
sssHorizontalBlurPass->addInputImage(&renderer->m_HDRImageSampler, &renderer->m_HDRImageView[0][0]);
sssHorizontalBlurPass->addInputImage(&renderer->m_HDRImageSampler, &renderer->m_depthImageView[0], VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL);
sssHorizontalBlurPass->addInputImage(&renderer->m_HDRImageSampler, &renderer->m_normalImageView);
......@@ -54,7 +54,7 @@ VulkanPostProcessingChain::VulkanPostProcessingChain(VulkanRenderer * renderer)
renderer->m_farPlane);
m_postProcesses.push_back(sssHorizontalBlurPass);
auto sssVerticalBlurPass = std::make_shared<VulkanPostProcess>(renderer, 0);
auto sssVerticalBlurPass = std::make_shared<VulkanPostProcess>(renderer, renderer->m_numViews, 0);
sssVerticalBlurPass->addInputImage(&renderer->m_HDRImageSampler, &renderer->m_HDRImageView[2][0]);
sssVerticalBlurPass->addInputImage(&renderer->m_HDRImageSampler, &renderer->m_depthImageView[0], VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL);
sssVerticalBlurPass->addInputImage(&renderer->m_HDRImageSampler, &renderer->m_normalImageView);
......@@ -77,7 +77,7 @@ VulkanPostProcessingChain::VulkanPostProcessingChain(VulkanRenderer * renderer)
}
// Accumulation composition pass
auto accumulationCompositePass = std::make_shared<VulkanPostProcess>(renderer);
auto accumulationCompositePass = std::make_shared<VulkanPostProcess>(renderer, renderer->m_numViews);
accumulationCompositePass->addInputImage(&renderer->m_HDRImageSampler, &renderer->m_HDRImageView[0][0]);
accumulationCompositePass->addInputImage(&renderer->m_HDRImageSampler, &renderer->m_HDRImageView[1][0]);
accumulationCompositePass->m_framebuffer->setColor(renderer->m_HDRImage[2][0], &renderer->m_HDRImageView[2][0], VK_FORMAT_R16G16B16A16_SFLOAT);
......@@ -90,14 +90,14 @@ VulkanPostProcessingChain::VulkanPostProcessingChain(VulkanRenderer * renderer)
int level = 1;
int bloomSamples = 5;
auto bloomThresholdPass = std::make_shared<VulkanPostProcess>(renderer, level);
auto bloomThresholdPass = std::make_shared<VulkanPostProcess>(renderer, renderer->m_numViews, level);
bloomThresholdPass->addInputImage(&renderer->m_HDRImageSampler, &renderer->m_HDRImageView[m_lastOutput][0]);
bloomThresholdPass->m_framebuffer->setColor(renderer->m_HDRImage[m_lastInput][level],
&renderer->m_HDRImageView[m_lastInput][level], VK_FORMAT_R16G16B16A16_SFLOAT);
bloomThresholdPass->initialize(renderer, "./Shaders/VulkanShaders/PostProcessing/bloom_threshold_frag.spv");
m_postProcesses.push_back(bloomThresholdPass);
auto bloomHorizontalBlurPass = std::make_shared<VulkanPostProcess>(renderer, level);
auto bloomHorizontalBlurPass = std::make_shared<VulkanPostProcess>(renderer, renderer->m_numViews, level);
bloomHorizontalBlurPass->addInputImage(&renderer->m_HDRImageSampler, &renderer->m_HDRImageView[m_lastInput][level]);
bloomHorizontalBlurPass->m_framebuffer->setColor(renderer->m_HDRImage[m_lastOutput][level],
&renderer->m_HDRImageView[m_lastOutput][level], VK_FORMAT_R16G16B16A16_SFLOAT);
......@@ -110,7 +110,7 @@ VulkanPostProcessingChain::VulkanPostProcessingChain(VulkanRenderer * renderer)
&bloomHorizontalBlurPass->m_pushConstantData[13]);
m_postProcesses.push_back(bloomHorizontalBlurPass);
auto bloomVerticalBlurPass = std::make_shared<VulkanPostProcess>(renderer, level);
auto bloomVerticalBlurPass = std::make_shared<VulkanPostProcess>(renderer, renderer->m_numViews, level);
bloomVerticalBlurPass->addInputImage(&renderer->m_HDRImageSampler, &renderer->m_HDRImageView[m_lastOutput][level]);
bloomVerticalBlurPass->m_framebuffer->setColor(renderer->m_HDRImage[m_lastInput][level],
&renderer->m_HDRImageView[m_lastInput][level], VK_FORMAT_R16G16B16A16_SFLOAT);
......@@ -123,7 +123,7 @@ VulkanPostProcessingChain::VulkanPostProcessingChain(VulkanRenderer * renderer)
&bloomVerticalBlurPass->m_pushConstantData[13]);
m_postProcesses.push_back(bloomVerticalBlurPass);
auto bloomCompositePass = std::make_shared<VulkanPostProcess>(renderer);
auto bloomCompositePass = std::make_shared<VulkanPostProcess>(renderer, renderer->m_numViews);
bloomCompositePass->addInputImage(&renderer->m_HDRImageSampler, &renderer->m_HDRImageView[m_lastOutput][0]);
bloomCompositePass->addInputImage(&renderer->m_HDRImageSampler, &renderer->m_HDRImageView[m_lastInput][level]);
bloomCompositePass->m_framebuffer->setColor(renderer->m_HDRImage[m_lastInput][0],
......@@ -136,7 +136,7 @@ VulkanPostProcessingChain::VulkanPostProcessingChain(VulkanRenderer * renderer)
// Lens distortion
if (renderer->m_enableLensDistortion)
{
auto lensDistortionPass = std::make_shared<VulkanPostProcess>(renderer);
auto lensDistortionPass = std::make_shared<VulkanPostProcess>(renderer, renderer->m_numViews);
lensDistortionPass->addInputImage(&renderer->m_HDRImageSampler, &renderer->m_HDRImageView[m_lastOutput][0]);
lensDistortionPass->addInputImage(&renderer->m_HDRImageSampler, &renderer->m_HDRImageView[m_lastInput][0]);
lensDistortionPass->m_framebuffer->setColor(renderer->m_HDRImage[m_lastInput][0],
......
......@@ -93,8 +93,8 @@ VulkanDecalRenderDelegate::update(const uint32_t frameIndex, std::shared_ptr<Cam
for (auto decal : geometry->getDecals())
{
decal->updateDecal(viewMatrix);
m_decalVertexUniforms.transform[index] = decal->m_transform;
m_decalFragmentUniforms.inverse[index] = decal->m_inverse;
m_decalVertexUniforms.transforms[index] = decal->m_transform;
m_decalFragmentUniforms.inverses[index] = decal->m_inverse;
index++;
}
......
#version 450
#version 460
layout (set = 0, binding = 0) uniform sampler2D colorTexture;
layout (set = 0, binding = 0) uniform sampler2DArray colorTexture;
layout (location = 0) out vec4 finalColor;
layout (location = 3) in vertexData{
vec2 uv;
flat uint view;
}vertex;
layout(push_constant) uniform pushConstants
{
float index;
}
constants;
// Reinhard tonemapping
vec3 tonemap(vec3 color)
{
......@@ -43,6 +50,6 @@ vec3 tonemapTwo(vec3 color)
void main(void)
{
vec4 inputColor = texture(colorTexture, vertex.uv);
vec4 inputColor = texture(colorTexture, vec3(vertex.uv, constants.index));
finalColor = vec4(tonemapTwo(inputColor.rgb), inputColor.a);
}
\ No newline at end of file
#version 450
#version 460
layout (set = 0, binding = 0) uniform sampler2D depthTexture;
layout (set = 0, binding = 0) uniform sampler2DArray depthTexture;
layout (set = 0, binding = 1) uniform sampler2D noiseTexture;
layout (location = 0) out vec4 finalColor;
layout (location = 3) in vertexData{
vec2 uv;
flat uint view;
}vertex;
layout (push_constant) uniform pushConstants
......@@ -30,7 +31,7 @@ void main(void)
float ambientValue = 0.0;
float samples = constants.numSamples;
float width = constants.kernelWidth;
float depth = getLinearDepth(texture(depthTexture, vertex.uv).r);
float depth = getLinearDepth(texture(depthTexture, vec3(vertex.uv, vertex.view)).r);
float fragmentSize = 1.0 / (tan(constants.fov / 2.0) * depth);
float fragmentStepSize = fragmentSize * (constants.kernelWidth / samples);
float realStepSize = constants.kernelWidth / samples;
......@@ -38,10 +39,10 @@ void main(void)
vec4 noise = texelFetch(noiseTexture, sampleLocation, 0);
vec2 neighborOffset = vec2(1.0) / constants.resolution;
float x_up = getLinearDepth(texture(depthTexture, vertex.uv + vec2(neighborOffset.x, 0)).r);
float x_down = getLinearDepth(texture(depthTexture, vertex.uv + vec2(-neighborOffset.x, 0)).r);
float y_up = getLinearDepth(texture(depthTexture, vertex.uv + vec2(0, neighborOffset.y)).r);
float y_down = getLinearDepth(texture(depthTexture, vertex.uv + vec2(0, -neighborOffset.y)).r);
float x_up = getLinearDepth(texture(depthTexture, vec3(vertex.uv + vec2(neighborOffset.x, 0), vertex.view)).r);
float x_down = getLinearDepth(texture(depthTexture, vec3(vertex.uv + vec2(-neighborOffset.x, 0), vertex.view)).r);
float y_up = getLinearDepth(texture(depthTexture, vec3(vertex.uv + vec2(0, neighborOffset.y), vertex.view)).r);
float y_down = getLinearDepth(texture(depthTexture, vec3(vertex.uv + vec2(0, -neighborOffset.y), vertex.view)).r);
float dx, dy;
......@@ -106,7 +107,7 @@ float computeAO(vec2 direction, float fragmentStepSize, float realStepSize, floa
realOffset += realStepSize;
vec2 textureOffset = direction * fragmentOffset;
float depthSample = getLinearDepth(texture(depthTexture, vertex.uv + textureOffset).r);
float depthSample = getLinearDepth(texture(depthTexture, vec3(vertex.uv + textureOffset, vertex.view)).r);
float depthDifference = depthSample - depth;
float horizonAngle = atan(-depthDifference, -realOffset);
......
#version 450
#version 460
layout (set = 0, binding = 0) uniform sampler2D colorTexture;
layout (set = 0, binding = 1) uniform sampler2D depthTexture;
layout (set = 0, binding = 0) uniform sampler2DArray colorTexture;
layout (set = 0, binding = 1) uniform sampler2DArray depthTexture;
layout (location = 0) out float finalColor;
layout (location = 3) in vertexData{
vec2 uv;
flat uint view;
}vertex;
layout (push_constant) uniform pushConstants
......@@ -27,22 +28,22 @@ float getLinearDepth(float depth);
void main(void)
{
float inputColor = 0;
inputColor += texture(colorTexture, vertex.uv).r * constants.values[0];
inputColor += texture(colorTexture, vec3(vertex.uv, vertex.view)).r * constants.values[0];
float centerDepth = getLinearDepth(texture(depthTexture, vertex.uv).r);
float centerDepth = getLinearDepth(texture(depthTexture, vec3(vertex.uv, vertex.view)).r);
float total = constants.values[0];
for (int i = 1; i < constants.numSamples; i++)
{
float depth = getLinearDepth(texture(depthTexture, vertex.uv + vec2(constants.offsets[i] / constants.height), 0).r);
float color = texture(colorTexture, vertex.uv + vec2(constants.offsets[i] / constants.height), 0).r;
float depth = getLinearDepth(texture(depthTexture, vec3(vertex.uv + vec2(constants.offsets[i] / constants.height, 0), vertex.view)).r);
float color = texture(colorTexture, vec3(vertex.uv + vec2(constants.offsets[i] / constants.height, 0), vertex.view)).r;
float factor = constants.values[i] * max(radius - abs(centerDepth - depth), 0) / radius;
total += factor;
inputColor += color * factor;
depth = getLinearDepth(texture(depthTexture, vertex.uv - vec2(constants.offsets[i] / constants.height), 0).r);
color = texture(colorTexture, vertex.uv - vec2(constants.offsets[i] / constants.height), 0).r;
depth = getLinearDepth(texture(depthTexture, vec3(vertex.uv - vec2(constants.offsets[i] / constants.height, 0), vertex.view)).r);
color = texture(colorTexture, vec3(vertex.uv - vec2(constants.offsets[i] / constants.height, 0), vertex.view)).r;
factor = constants.values[i] * max(radius - abs(centerDepth - depth), 0) / radius;
total += factor;
inputColor += color * factor;
......
#version 450
#version 460
layout (set = 0, binding = 0) uniform sampler2D colorTexture;
layout (set = 0, binding = 1) uniform sampler2D depthTexture;
layout (set = 0, binding = 0) uniform sampler2DArray colorTexture;
layout (set = 0, binding = 1) uniform sampler2DArray depthTexture;
layout (location = 0) out float finalColor;
layout (location = 3) in vertexData{
vec2 uv;
flat uint view;
}vertex;
layout (push_constant) uniform pushConstants
......@@ -27,22 +28,22 @@ float getLinearDepth(float depth);
void main(void)
{
float inputColor = 0;
inputColor += texture(colorTexture, vertex.uv).r * constants.values[0];
inputColor += texture(colorTexture, vec3(vertex.uv,vertex.view)).r * constants.values[0];
float centerDepth = getLinearDepth(texture(depthTexture, vertex.uv).r);
float centerDepth = getLinearDepth(texture(depthTexture, vec3(vertex.uv, vertex.view)).r);
float total = constants.values[0];
for (int i = 1; i < constants.numSamples; i++)
{
float depth = getLinearDepth(texture(depthTexture, vertex.uv + vec2(0, constants.offsets[i] / constants.height)).r);
float color = texture(colorTexture, vertex.uv + vec2(0, constants.offsets[i] / constants.height)).r;
float depth = getLinearDepth(texture(depthTexture, vec3(vertex.uv + vec2(0, constants.offsets[i] / constants.height), vertex.view)).r);
float color = texture(colorTexture, vec3(vertex.uv + vec2(0, constants.offsets[i] / constants.height), vertex.view)).r;
float factor = constants.values[i] * max(radius - abs(centerDepth - depth), 0) / radius;
total += factor;
inputColor += color * factor;
depth = getLinearDepth(texture(depthTexture, vertex.uv - vec2(0, constants.offsets[i] / constants.height)).r);
color = texture(colorTexture, vertex.uv - vec2(0, constants.offsets[i] / constants.height)).r;
depth = getLinearDepth(texture(depthTexture, vec3(vertex.uv - vec2(0, constants.offsets[i] / constants.height), vertex.view)).r);
color = texture(colorTexture, vec3(vertex.uv - vec2(0, constants.offsets[i] / constants.height), vertex.view)).r;
factor = constants.values[i] * max(radius - abs(centerDepth - depth), 0) / radius;
total += factor;
inputColor += color * factor;
......
#version 450
#version 460
layout (set = 0, binding = 0) uniform sampler2D colorTexture;
layout (set = 0, binding = 0) uniform sampler2DArray colorTexture;
layout (location = 0) out vec4 finalColor;
layout (location = 3) in vertexData{
vec2 uv;
flat uint view;
}vertex;
void main(void)
{
vec3 inputColor = texture(colorTexture, vertex.uv).rgb;
vec3 inputColor = texture(colorTexture, vec3(vertex.uv, vertex.view)).rgb;
finalColor = vec4(inputColor.rgb * vec3(0.05), 1);
}
\ No newline at end of file
#version 450
#version 460
layout (set = 0, binding = 0) uniform sampler2D colorTexture;
layout (set = 0, binding = 0) uniform sampler2DArray colorTexture;
layout (location = 0) out vec4 finalColor;
layout (location = 3) in vertexData{
vec2 uv;
flat uint view;
}vertex;
layout (push_constant) uniform pushConstants
......@@ -20,13 +21,13 @@ layout (push_constant) uniform pushConstants
void main(void)
{
vec3 inputColor = vec3(0);
inputColor += texture(colorTexture, vertex.uv).rgb * constants.values[0];
inputColor += texture(colorTexture, vec3(vertex.uv, vertex.view)).rgb * constants.values[0];
for (int i = 1; i < constants.numSamples; i++)
{
vec3 color = texture(colorTexture, vertex.uv + vec2(constants.offsets[i] / constants.width, 0) ).rgb;
vec3 color = texture(colorTexture, vec3(vertex.uv + vec2(constants.offsets[i] / constants.width, 0), vertex.view)).rgb;
inputColor += color * constants.values[i];
color = texture(colorTexture, vertex.uv - vec2(constants.offsets[i] / constants.width, 0) ).rgb;
color = texture(colorTexture, vec3(vertex.uv - vec2(constants.offsets[i] / constants.width, 0),vertex.view)).rgb;
inputColor += color * constants.values[i];
}
......
#version 450
#version 460
layout (set = 0, binding = 0) uniform sampler2D colorTexture;
layout (set = 0, binding = 0) uniform sampler2DArray colorTexture;
layout (location = 0) out vec4 finalColor;
layout (location = 3) in vertexData{
vec2 uv;
flat uint view;
}vertex;
layout (push_constant) uniform pushConstants
layout(push_constant) uniform pushConstants
{
float width;
float height;
......@@ -20,13 +21,13 @@ layout (push_constant) uniform pushConstants
void main(void)
{
vec3 inputColor = vec3(0);
inputColor += texture(colorTexture, vertex.uv).rgb * constants.values[0];
inputColor += texture(colorTexture, vec3(vertex.uv, vertex.view)).rgb * constants.values[0];
for (int i = 1; i < constants.numSamples; i++)
{
vec3 color = texture(colorTexture, vertex.uv + vec2(0, constants.offsets[i] / constants.height) ).rgb;
vec3 color = texture(colorTexture, vec3(vertex.uv + vec2(0, constants.offsets[i] / constants.height), vertex.view)).rgb;
inputColor += color * constants.values[i];
color = texture(colorTexture, vertex.uv - vec2(0, constants.offsets[i] / constants.height) ).rgb;
color = texture(colorTexture, vec3(vertex.uv - vec2(0, constants.offsets[i] / constants.height),vertex.view)).rgb;
inputColor += color * constants.values[i];
}
......
#version 450
#version 460
layout (set = 0, binding = 0) uniform sampler2D colorTexture1;
layout (set = 0, binding = 1) uniform sampler2D colorTexture2;
layout (set = 0, binding = 0) uniform sampler2DArray colorTexture1;
layout (set = 0, binding = 1) uniform sampler2DArray colorTexture2;
layout (location = 0) out vec4 finalColor;
layout (location = 3) in vertexData{
vec2 uv;
flat uint view;
}vertex;
void main(void)
{
vec4 color1 = texture(colorTexture1, vertex.uv);
vec4 color2 = texture(colorTexture2, vertex.uv);
vec4 color1 = texture(colorTexture1, vec3(vertex.uv, vertex.view));
vec4 color2 = texture(colorTexture2, vec3(vertex.uv, vertex.view));
finalColor = vec4(color1.rgb + color2.rgb, color1.a);
}
\ No newline at end of file
#version 450
#version 460
layout (set = 0, binding = 0) uniform sampler2D depthTexture;
layout (set = 0, binding = 0) uniform sampler2DArray depthTexture;
layout (location = 0) out float finalColor;
layout (location = 3) in vertexData{
vec2 uv;
flat uint view;
}vertex;
void main(void)
{
ivec2 resolution = textureSize(depthTexture, 0);
ivec2 offset = ivec2(vertex.uv * resolution);
ivec2 resolution = textureSize(depthTexture, 0).xy;
ivec3 offset = ivec3(vertex.uv * resolution, vertex.view);
float minDepth;
float depth0 = texelFetch(depthTexture, offset + ivec2(0,0), 0).r;
float depth1 = texelFetch(depthTexture, offset + ivec2(0,1), 0).r;
float depth2 = texelFetch(depthTexture, offset + ivec2(1,0), 0).r;
float depth3 = texelFetch(depthTexture, offset + ivec2(1,1), 0).r;
float depth0 = texelFetch(depthTexture, offset + ivec3(0,0,0), 0).r;
float depth1 = texelFetch(depthTexture, offset + ivec3(0,1,0), 0).r;
float depth2 = texelFetch(depthTexture, offset + ivec3(1,0,0), 0).r;
float depth3 = texelFetch(depthTexture, offset + ivec3(1,1,0), 0).r;
minDepth = min(depth0, depth1);
minDepth = min(minDepth, depth2);
......
#version 450
#version 460
#extension GL_OVR_multiview : enable
layout (location = 0) in vec3 vertexPosition;
layout (location = 1) in vec2 vertexUV;
layout (location = 3) out vertexData{
vec2 uv;
flat uint view;
}vertex;
void main(void)
{
vertex.uv = vertexUV;
vertex.view = gl_ViewID_OVR;
gl_Position = vec4(vertexPosition, 1.0);
}
\ No newline at end of file
#version 450
#version 460
layout (set = 0, binding = 0) uniform sampler2D colorTexture;
layout (set = 0, binding = 1) uniform sampler2D depthTexture;
layout (set = 0, binding = 2) uniform sampler2D normalTexture;
layout (set = 0, binding = 0) uniform sampler2DArray colorTexture;
layout (set = 0, binding = 1) uniform sampler2DArray depthTexture;
layout (set = 0, binding = 2) uniform sampler2DArray normalTexture;
layout (location = 0) out vec4 finalColor;
layout (location = 3) in vertexData{
vec2 uv;
flat uint view;
}vertex;
layout (push_constant) uniform pushConstants
......@@ -39,13 +40,13 @@ void main(void)
{
vec3 inputColor = vec3(0);
vec4 normal = texture(normalTexture, vertex.uv);
vec4 normal = texture(normalTexture, vec3(vertex.uv, vertex.view));
float sss = normal.a;
if (sss >= 0.001)
{
float depth = getLinearDepth(texture(depthTexture, vertex.uv).r);
float depth = getLinearDepth(texture(depthTexture, vec3(vertex.uv, vertex.view)).r);
float dx = 0.001 / (tan(constants.fov / 2.0) * depth);
dx = dx * normal.a / (constants.kernelWidth);
......@@ -54,37 +55,37 @@ void main(void)
for (int i = 1; i < constants.numSamples; i++)
{
vec2 offset = vec2(i * dx) * constants.direction;
float partOfMeshPos = texture(normalTexture, vertex.uv + offset).a;
float partOfMeshNeg = texture(normalTexture, vertex.uv - offset).a;
float partOfMeshPos = texture(normalTexture, vec3(vertex.uv + offset, vertex.view)).a;
float partOfMeshNeg = texture(normalTexture, vec3(vertex.uv - offset, vertex.view)).a;
depth = getLinearDepth(texture(depthTexture, vertex.uv + offset).r);
depth = getLinearDepth(texture(depthTexture, vec3(vertex.uv + offset, vertex.view)).r);
maxValue += separableKernel(i/(constants.numSamples), w, near, far, depth) * partOfMeshPos;
depth = getLinearDepth(texture(depthTexture, vertex.uv - offset).r);