Use new sample building scene for subpass example, added transparent texture

This commit is contained in:
saschawillems 2017-01-14 16:06:44 +01:00
parent 81885abeb6
commit 405c76737c
9 changed files with 1681 additions and 13 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -14,7 +14,7 @@ layout (location = 1) out vec4 outPosition;
layout (location = 2) out vec4 outNormal; layout (location = 2) out vec4 outNormal;
layout (location = 3) out vec4 outAlbedo; layout (location = 3) out vec4 outAlbedo;
layout (constant_id = 0) const int NUM_LIGHTS = 32; layout (constant_id = 0) const int NUM_LIGHTS = 64;
struct Light { struct Light {
vec4 position; vec4 position;
@ -67,9 +67,9 @@ void main()
// Specular map values are stored in alpha of albedo mrt // Specular map values are stored in alpha of albedo mrt
vec3 R = reflect(-L, N); vec3 R = reflect(-L, N);
float NdotR = max(0.0, dot(R, V)); float NdotR = max(0.0, dot(R, V));
vec3 spec = ubo.lights[i].color * albedo.a * pow(NdotR, 32.0) * atten; //vec3 spec = ubo.lights[i].color * albedo.a * pow(NdotR, 32.0) * atten;
fragcolor += diff + spec; fragcolor += diff;// + spec;
} }
outFragcolor = vec4(fragcolor, 1.0); outFragcolor = vec4(fragcolor, 1.0);

View file

@ -4,6 +4,7 @@
#extension GL_ARB_shading_language_420pack : enable #extension GL_ARB_shading_language_420pack : enable
layout (input_attachment_index = 1, binding = 1) uniform subpassInput samplerPositionDepth; layout (input_attachment_index = 1, binding = 1) uniform subpassInput samplerPositionDepth;
layout (binding = 2) uniform sampler2D samplerTexture;
layout (location = 0) in vec3 inColor; layout (location = 0) in vec3 inColor;
layout (location = 1) in vec2 inUV; layout (location = 1) in vec2 inUV;
@ -28,6 +29,5 @@ void main ()
discard; discard;
}; };
outColor.rgb = vec3(0.0, 0.25, 0.86); outColor = texture(samplerTexture, inUV);
outColor.a = 0.5;
} }

Binary file not shown.

View file

@ -24,7 +24,7 @@
#define VERTEX_BUFFER_BIND_ID 0 #define VERTEX_BUFFER_BIND_ID 0
#define ENABLE_VALIDATION false #define ENABLE_VALIDATION false
#define NUM_LIGHTS 32 #define NUM_LIGHTS 64
// Vertex layout for this example // Vertex layout for this example
std::vector<vkMeshLoader::VertexLayout> vertexLayout = std::vector<vkMeshLoader::VertexLayout> vertexLayout =
@ -43,6 +43,10 @@ public:
vkMeshLoader::MeshBuffer transparent; vkMeshLoader::MeshBuffer transparent;
} meshes; } meshes;
struct {
vkTools::VulkanTexture glass;
} textures;
struct { struct {
VkPipelineVertexInputStateCreateInfo inputState; VkPipelineVertexInputStateCreateInfo inputState;
std::vector<VkVertexInputBindingDescription> bindingDescriptions; std::vector<VkVertexInputBindingDescription> bindingDescriptions;
@ -149,6 +153,7 @@ public:
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.composition, nullptr); vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.composition, nullptr);
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.transparent, nullptr); vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.transparent, nullptr);
textures.glass.destroy();
meshes.scene.destroy(); meshes.scene.destroy();
meshes.transparent.destroy(); meshes.transparent.destroy();
uniformBuffers.GBuffer.destroy(); uniformBuffers.GBuffer.destroy();
@ -480,8 +485,9 @@ public:
void loadAssets() void loadAssets()
{ {
loadMesh(getAssetPath() + "models/samplescene.dae", &meshes.scene, vertexLayout, 0.25f); loadMesh(getAssetPath() + "models/samplebuilding.dae", &meshes.scene, vertexLayout, 1.0f);
loadMesh(getAssetPath() + "models/cube.dae", &meshes.transparent, vertexLayout, 3.25f); loadMesh(getAssetPath() + "models/samplebuilding_glass.dae", &meshes.transparent, vertexLayout, 1.0f);
textureLoader->loadTexture(getAssetPath() + "textures/colored_glass_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.glass);
} }
void setupVertexDescriptions() void setupVertexDescriptions()
@ -856,6 +862,7 @@ public:
setLayoutBindings = { setLayoutBindings = {
vkTools::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT, 0), vkTools::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT, 0),
vkTools::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, VK_SHADER_STAGE_FRAGMENT_BIT, 1), vkTools::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, VK_SHADER_STAGE_FRAGMENT_BIT, 1),
vkTools::initializers::descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 2),
}; };
descriptorLayout = vkTools::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings.data(), static_cast<uint32_t>(setLayoutBindings.size())); descriptorLayout = vkTools::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings.data(), static_cast<uint32_t>(setLayoutBindings.size()));
@ -872,6 +879,7 @@ public:
writeDescriptorSets = { writeDescriptorSets = {
vkTools::initializers::writeDescriptorSet(descriptorSets.transparent, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffers.GBuffer.descriptor), vkTools::initializers::writeDescriptorSet(descriptorSets.transparent, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffers.GBuffer.descriptor),
vkTools::initializers::writeDescriptorSet(descriptorSets.transparent, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, &texDescriptorPosition), vkTools::initializers::writeDescriptorSet(descriptorSets.transparent, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, &texDescriptorPosition),
vkTools::initializers::writeDescriptorSet(descriptorSets.transparent, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2, &textures.glass.descriptor),
}; };
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL); vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL);
@ -879,11 +887,7 @@ public:
// Enable blending // Enable blending
blendAttachmentState.blendEnable = VK_TRUE; blendAttachmentState.blendEnable = VK_TRUE;
blendAttachmentState.colorBlendOp = VK_BLEND_OP_ADD; blendAttachmentState.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
blendAttachmentState.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_COLOR;
blendAttachmentState.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR;
blendAttachmentState.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
blendAttachmentState.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; blendAttachmentState.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
blendAttachmentState.colorBlendOp = VK_BLEND_OP_ADD; blendAttachmentState.colorBlendOp = VK_BLEND_OP_ADD;
blendAttachmentState.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; blendAttachmentState.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;