Color gradient ramp for glowing parts of the mesh
This commit is contained in:
parent
cb5bd093ec
commit
e74e37cc16
11 changed files with 64 additions and 24 deletions
|
|
@ -3,11 +3,22 @@
|
||||||
#extension GL_ARB_separate_shader_objects : enable
|
#extension GL_ARB_separate_shader_objects : enable
|
||||||
#extension GL_ARB_shading_language_420pack : enable
|
#extension GL_ARB_shading_language_420pack : enable
|
||||||
|
|
||||||
|
layout (binding = 1) uniform sampler2D samplerGradientRamp;
|
||||||
|
|
||||||
layout (location = 0) in vec3 inColor;
|
layout (location = 0) in vec3 inColor;
|
||||||
|
layout (location = 1) in vec2 inUV;
|
||||||
|
|
||||||
layout (location = 0) out vec4 outFragColor;
|
layout (location = 0) out vec4 outFragColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
outFragColor.rgb = inColor;
|
// Use max. color channel value to detect bright glow emitters
|
||||||
|
if ((inColor.r >= 0.9) || (inColor.g >= 0.9) || (inColor.b >= 0.9))
|
||||||
|
{
|
||||||
|
outFragColor.rgb = texture(samplerGradientRamp, inUV).rgb;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
outFragColor.rgb = inColor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
|
@ -3,16 +3,18 @@
|
||||||
#extension GL_ARB_separate_shader_objects : enable
|
#extension GL_ARB_separate_shader_objects : enable
|
||||||
#extension GL_ARB_shading_language_420pack : enable
|
#extension GL_ARB_shading_language_420pack : enable
|
||||||
|
|
||||||
layout (location = 0) in vec4 inPos;
|
layout (location = 0) in vec3 inPos;
|
||||||
layout (location = 2) in vec3 inColor;
|
layout (location = 2) in vec3 inColor;
|
||||||
|
|
||||||
layout (binding = 0) uniform UBO
|
layout (binding = 0) uniform UBO
|
||||||
{
|
{
|
||||||
mat4 projection;
|
mat4 projection;
|
||||||
mat4 model;
|
mat4 model;
|
||||||
|
float gradientPos;
|
||||||
} ubo;
|
} ubo;
|
||||||
|
|
||||||
layout (location = 0) out vec3 outColor;
|
layout (location = 0) out vec3 outColor;
|
||||||
|
layout (location = 1) out vec2 outUV;
|
||||||
|
|
||||||
out gl_PerVertex
|
out gl_PerVertex
|
||||||
{
|
{
|
||||||
|
|
@ -22,5 +24,6 @@ out gl_PerVertex
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
outColor = inColor;
|
outColor = inColor;
|
||||||
gl_Position = ubo.projection * ubo.model * inPos;
|
outUV = vec2(ubo.gradientPos, 0.0f);
|
||||||
|
gl_Position = ubo.projection * ubo.model * vec4(inPos, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -3,10 +3,13 @@
|
||||||
#extension GL_ARB_separate_shader_objects : enable
|
#extension GL_ARB_separate_shader_objects : enable
|
||||||
#extension GL_ARB_shading_language_420pack : enable
|
#extension GL_ARB_shading_language_420pack : enable
|
||||||
|
|
||||||
|
layout (binding = 1) uniform sampler2D samplerGradientRamp;
|
||||||
|
|
||||||
layout (location = 0) in vec3 inNormal;
|
layout (location = 0) in vec3 inNormal;
|
||||||
layout (location = 1) in vec3 inColor;
|
layout (location = 1) in vec3 inColor;
|
||||||
layout (location = 2) in vec3 inEyePos;
|
layout (location = 2) in vec3 inEyePos;
|
||||||
layout (location = 3) in vec3 inLightVec;
|
layout (location = 3) in vec3 inLightVec;
|
||||||
|
layout (location = 4) in vec2 inUV;
|
||||||
|
|
||||||
layout (location = 0) out vec4 outFragColor;
|
layout (location = 0) out vec4 outFragColor;
|
||||||
|
|
||||||
|
|
@ -17,7 +20,7 @@ void main()
|
||||||
// to detect bright glow emitters
|
// to detect bright glow emitters
|
||||||
if ((inColor.r >= 0.9) || (inColor.g >= 0.9) || (inColor.b >= 0.9))
|
if ((inColor.r >= 0.9) || (inColor.g >= 0.9) || (inColor.b >= 0.9))
|
||||||
{
|
{
|
||||||
outFragColor.rgb = inColor;
|
outFragColor.rgb = texture(samplerGradientRamp, inUV).rgb;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -11,12 +11,14 @@ layout (binding = 0) uniform UBO
|
||||||
{
|
{
|
||||||
mat4 projection;
|
mat4 projection;
|
||||||
mat4 model;
|
mat4 model;
|
||||||
|
float gradientPos;
|
||||||
} ubo;
|
} ubo;
|
||||||
|
|
||||||
layout (location = 0) out vec3 outNormal;
|
layout (location = 0) out vec3 outNormal;
|
||||||
layout (location = 1) out vec3 outColor;
|
layout (location = 1) out vec3 outColor;
|
||||||
layout (location = 2) out vec3 outEyePos;
|
layout (location = 2) out vec3 outEyePos;
|
||||||
layout (location = 3) out vec3 outLightVec;
|
layout (location = 3) out vec3 outLightVec;
|
||||||
|
layout (location = 4) out vec2 outUV;
|
||||||
|
|
||||||
out gl_PerVertex
|
out gl_PerVertex
|
||||||
{
|
{
|
||||||
|
|
@ -27,6 +29,7 @@ void main()
|
||||||
{
|
{
|
||||||
outNormal = inNormal;
|
outNormal = inNormal;
|
||||||
outColor = inColor;
|
outColor = inColor;
|
||||||
|
outUV = vec2(ubo.gradientPos, 0.0);
|
||||||
gl_Position = ubo.projection * ubo.model * pos;
|
gl_Position = ubo.projection * ubo.model * pos;
|
||||||
outEyePos = vec3(ubo.model * pos);
|
outEyePos = vec3(ubo.model * pos);
|
||||||
vec4 lightPos = vec4(0.0, 0.0, -5.0, 1.0);// * ubo.model;
|
vec4 lightPos = vec4(0.0, 0.0, -5.0, 1.0);// * ubo.model;
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -26,7 +26,7 @@ void main()
|
||||||
vec4 color = vec4(0.0, 0.0, 0.0, 0.0);
|
vec4 color = vec4(0.0, 0.0, 0.0, 0.0);
|
||||||
UV += radialSize * 0.5 - ubo.radialOrigin;
|
UV += radialSize * 0.5 - ubo.radialOrigin;
|
||||||
|
|
||||||
#define samples 16
|
#define samples 32
|
||||||
|
|
||||||
for (int i = 0; i < samples; i++)
|
for (int i = 0; i < samples; i++)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -47,6 +47,10 @@ public:
|
||||||
vkMeshLoader::MeshBuffer quad;
|
vkMeshLoader::MeshBuffer quad;
|
||||||
} meshes;
|
} meshes;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
vkTools::VulkanTexture gradient;
|
||||||
|
} textures;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
VkPipelineVertexInputStateCreateInfo inputState;
|
VkPipelineVertexInputStateCreateInfo inputState;
|
||||||
std::vector<VkVertexInputBindingDescription> bindingDescriptions;
|
std::vector<VkVertexInputBindingDescription> bindingDescriptions;
|
||||||
|
|
@ -59,18 +63,14 @@ public:
|
||||||
vkTools::UniformData fsQuad;
|
vkTools::UniformData fsQuad;
|
||||||
} uniformData;
|
} uniformData;
|
||||||
|
|
||||||
struct {
|
struct UboVS {
|
||||||
glm::mat4 projection;
|
glm::mat4 projection;
|
||||||
glm::mat4 model;
|
glm::mat4 model;
|
||||||
} uboVS;
|
float gradientPos = 0.0f;
|
||||||
|
} uboSceneVS, uboQuadVS;
|
||||||
|
|
||||||
struct {
|
struct UboQuadFS {
|
||||||
glm::mat4 projection;
|
float radialBlurScale = 0.35f;
|
||||||
glm::mat4 model;
|
|
||||||
} uboQuadVS;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
float radialBlurScale = 0.25f;
|
|
||||||
float radialBlurStrength = 0.75f;
|
float radialBlurStrength = 0.75f;
|
||||||
glm::vec2 radialOrigin = glm::vec2(0.5f, 0.5f);
|
glm::vec2 radialOrigin = glm::vec2(0.5f, 0.5f);
|
||||||
} uboQuadFS;
|
} uboQuadFS;
|
||||||
|
|
@ -165,6 +165,8 @@ public:
|
||||||
|
|
||||||
vkFreeCommandBuffers(device, cmdPool, 1, &offscreenPass.commandBuffer);
|
vkFreeCommandBuffers(device, cmdPool, 1, &offscreenPass.commandBuffer);
|
||||||
vkDestroySemaphore(device, offscreenPass.semaphore, nullptr);
|
vkDestroySemaphore(device, offscreenPass.semaphore, nullptr);
|
||||||
|
|
||||||
|
textureLoader->destroyTexture(textures.gradient);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the offscreen framebuffer for rendering the blurred scene
|
// Setup the offscreen framebuffer for rendering the blurred scene
|
||||||
|
|
@ -457,6 +459,7 @@ public:
|
||||||
void loadAssets()
|
void loadAssets()
|
||||||
{
|
{
|
||||||
loadMesh(getAssetPath() + "models/glowsphere.dae", &meshes.example, vertexLayout, 0.05f);
|
loadMesh(getAssetPath() + "models/glowsphere.dae", &meshes.example, vertexLayout, 0.05f);
|
||||||
|
textureLoader->loadTexture(getAssetPath() + "textures/particle_gradient_rgba.ktx", VK_FORMAT_R8G8B8A8_UNORM, &textures.gradient, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup vertices for a single uv-mapped quad
|
// Setup vertices for a single uv-mapped quad
|
||||||
|
|
@ -552,7 +555,7 @@ public:
|
||||||
std::vector<VkDescriptorPoolSize> poolSizes =
|
std::vector<VkDescriptorPoolSize> poolSizes =
|
||||||
{
|
{
|
||||||
vkTools::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 4),
|
vkTools::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 4),
|
||||||
vkTools::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2)
|
vkTools::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 6)
|
||||||
};
|
};
|
||||||
|
|
||||||
VkDescriptorPoolCreateInfo descriptorPoolInfo =
|
VkDescriptorPoolCreateInfo descriptorPoolInfo =
|
||||||
|
|
@ -649,7 +652,14 @@ public:
|
||||||
descriptorSets.scene,
|
descriptorSets.scene,
|
||||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||||
0,
|
0,
|
||||||
&uniformData.vsQuad.descriptor)
|
&uniformData.vsQuad.descriptor),
|
||||||
|
// Binding 1 : Color gradient sampler
|
||||||
|
vkTools::initializers::writeDescriptorSet(
|
||||||
|
descriptorSets.scene,
|
||||||
|
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||||
|
1,
|
||||||
|
&textures.gradient.descriptor)
|
||||||
|
|
||||||
};
|
};
|
||||||
vkUpdateDescriptorSets(device, offScreenWriteDescriptorSets.size(), offScreenWriteDescriptorSets.data(), 0, NULL);
|
vkUpdateDescriptorSets(device, offScreenWriteDescriptorSets.size(), offScreenWriteDescriptorSets.data(), 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
@ -765,8 +775,8 @@ public:
|
||||||
createBuffer(
|
createBuffer(
|
||||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
||||||
sizeof(uboVS),
|
sizeof(uboSceneVS),
|
||||||
&uboVS,
|
&uboSceneVS,
|
||||||
&uniformData.vsScene.buffer,
|
&uniformData.vsScene.buffer,
|
||||||
&uniformData.vsScene.memory,
|
&uniformData.vsScene.memory,
|
||||||
&uniformData.vsScene.descriptor);
|
&uniformData.vsScene.descriptor);
|
||||||
|
|
@ -775,8 +785,8 @@ public:
|
||||||
createBuffer(
|
createBuffer(
|
||||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
|
||||||
sizeof(uboVS),
|
sizeof(uboQuadVS),
|
||||||
&uboVS,
|
&uboQuadVS,
|
||||||
&uniformData.vsQuad.buffer,
|
&uniformData.vsQuad.buffer,
|
||||||
&uniformData.vsQuad.memory,
|
&uniformData.vsQuad.memory,
|
||||||
&uniformData.vsQuad.descriptor);
|
&uniformData.vsQuad.descriptor);
|
||||||
|
|
@ -808,6 +818,11 @@ public:
|
||||||
uboQuadVS.model = glm::rotate(uboQuadVS.model, glm::radians(timer * 360.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
uboQuadVS.model = glm::rotate(uboQuadVS.model, glm::radians(timer * 360.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
uboQuadVS.model = glm::rotate(uboQuadVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
uboQuadVS.model = glm::rotate(uboQuadVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||||
|
|
||||||
|
if (!paused)
|
||||||
|
{
|
||||||
|
uboQuadVS.gradientPos += frameTimer * 0.1f;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t *pData;
|
uint8_t *pData;
|
||||||
VK_CHECK_RESULT(vkMapMemory(device, uniformData.vsQuad.memory, 0, sizeof(uboQuadVS), 0, (void **)&pData));
|
VK_CHECK_RESULT(vkMapMemory(device, uniformData.vsQuad.memory, 0, sizeof(uboQuadVS), 0, (void **)&pData));
|
||||||
memcpy(pData, &uboQuadVS, sizeof(uboQuadVS));
|
memcpy(pData, &uboQuadVS, sizeof(uboQuadVS));
|
||||||
|
|
@ -818,14 +833,19 @@ public:
|
||||||
void updateUniformBuffersScreen()
|
void updateUniformBuffersScreen()
|
||||||
{
|
{
|
||||||
// Vertex shader
|
// Vertex shader
|
||||||
uboVS.projection = glm::ortho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
|
uboSceneVS.projection = glm::ortho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
|
||||||
uboVS.model = glm::mat4();
|
uboSceneVS.model = glm::mat4();
|
||||||
|
|
||||||
uint8_t *pData;
|
uint8_t *pData;
|
||||||
VK_CHECK_RESULT(vkMapMemory(device, uniformData.vsScene.memory, 0, sizeof(uboVS), 0, (void **)&pData));
|
VK_CHECK_RESULT(vkMapMemory(device, uniformData.vsScene.memory, 0, sizeof(uboSceneVS), 0, (void **)&pData));
|
||||||
memcpy(pData, &uboVS, sizeof(uboVS));
|
memcpy(pData, &uboSceneVS, sizeof(uboSceneVS));
|
||||||
vkUnmapMemory(device, uniformData.vsScene.memory);
|
vkUnmapMemory(device, uniformData.vsScene.memory);
|
||||||
|
|
||||||
|
if (!paused)
|
||||||
|
{
|
||||||
|
uboSceneVS.gradientPos += uboQuadVS.gradientPos;
|
||||||
|
}
|
||||||
|
|
||||||
// Fragment shader
|
// Fragment shader
|
||||||
VK_CHECK_RESULT(vkMapMemory(device, uniformData.fsQuad.memory, 0, sizeof(uboQuadFS), 0, (void **)&pData));
|
VK_CHECK_RESULT(vkMapMemory(device, uniformData.fsQuad.memory, 0, sizeof(uboQuadFS), 0, (void **)&pData));
|
||||||
memcpy(pData, &uboQuadFS, sizeof(uboQuadFS));
|
memcpy(pData, &uboQuadFS, sizeof(uboQuadFS));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue