Different scene, toon shading and separate parameters for color input attachment
This commit is contained in:
parent
bdb9af7ef7
commit
0fb88d5467
8 changed files with 74 additions and 31 deletions
|
|
@ -6,7 +6,7 @@ buildscript {
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.1.1'
|
classpath 'com.android.tools.build:gradle:3.1.3'
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,30 @@ layout (input_attachment_index = 0, binding = 0) uniform subpassInput inputColor
|
||||||
layout (input_attachment_index = 1, binding = 1) uniform subpassInput inputDepth;
|
layout (input_attachment_index = 1, binding = 1) uniform subpassInput inputDepth;
|
||||||
|
|
||||||
layout (binding = 2) uniform UBO {
|
layout (binding = 2) uniform UBO {
|
||||||
|
vec2 brightnessContrast;
|
||||||
vec2 range;
|
vec2 range;
|
||||||
int attachmentIndex;
|
int attachmentIndex;
|
||||||
} ubo;
|
} ubo;
|
||||||
|
|
||||||
layout (location = 0) out vec4 outColor;
|
layout (location = 0) out vec4 outColor;
|
||||||
|
|
||||||
|
vec3 brightnessContrast(vec3 color, float brightness, float contrast) {
|
||||||
|
return (color - 0.5) * contrast + 0.5 + brightness;
|
||||||
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// Read values from previous sub pass
|
// Apply brightness and contrast filer to color input
|
||||||
vec3 col = ubo.attachmentIndex == 0 ? subpassLoad(inputColor).rgb : subpassLoad(inputDepth).rrr;
|
if (ubo.attachmentIndex == 0) {
|
||||||
|
// Read color from previous color input attachment
|
||||||
outColor.rgb = ((col - ubo.range[0]) * 1.0 / (ubo.range[1] - ubo.range[0]));
|
vec3 color = subpassLoad(inputColor).rgb;
|
||||||
|
outColor.rgb = brightnessContrast(color, ubo.brightnessContrast[0], ubo.brightnessContrast[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Visualize depth input range
|
||||||
|
if (ubo.attachmentIndex == 1) {
|
||||||
|
// Read depth from previous depth input attachment
|
||||||
|
float depth = subpassLoad(inputDepth).r;
|
||||||
|
outColor.rgb = vec3((depth - ubo.range[0]) * 1.0 / (ubo.range[1] - ubo.range[0]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
|
@ -1,11 +1,23 @@
|
||||||
#version 450
|
#version 450
|
||||||
|
|
||||||
layout (location = 0) in vec3 inColor;
|
layout (location = 0) in vec3 inColor;
|
||||||
|
layout (location = 1) in vec3 inNormal;
|
||||||
|
layout (location = 2) in vec3 inViewVec;
|
||||||
|
layout (location = 3) in vec3 inLightVec;
|
||||||
|
|
||||||
layout (location = 0) out vec4 outColor;
|
layout (location = 0) out vec4 outColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
outColor = vec4(inColor, 0.0);
|
// Toon shading color attachment output
|
||||||
|
float intensity = dot(normalize(inNormal), normalize(inLightVec));
|
||||||
|
float shade = 1.0;
|
||||||
|
shade = intensity < 0.5 ? 0.75 : shade;
|
||||||
|
shade = intensity < 0.35 ? 0.6 : shade;
|
||||||
|
shade = intensity < 0.25 ? 0.5 : shade;
|
||||||
|
shade = intensity < 0.1 ? 0.25 : shade;
|
||||||
|
|
||||||
|
outColor.rgb = inColor * 3.0 * shade;
|
||||||
|
|
||||||
// Depth attachment does not need to be explicitly written
|
// Depth attachment does not need to be explicitly written
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
|
@ -1,9 +1,6 @@
|
||||||
#version 450
|
#version 450
|
||||||
|
|
||||||
#extension GL_ARB_separate_shader_objects : enable
|
layout (location = 0) in vec3 inPos;
|
||||||
#extension GL_ARB_shading_language_420pack : enable
|
|
||||||
|
|
||||||
layout (location = 0) in vec4 inPos;
|
|
||||||
layout (location = 1) in vec3 inColor;
|
layout (location = 1) in vec3 inColor;
|
||||||
layout (location = 2) in vec3 inNormal;
|
layout (location = 2) in vec3 inNormal;
|
||||||
|
|
||||||
|
|
@ -14,6 +11,9 @@ layout (binding = 0) uniform UBO {
|
||||||
} ubo;
|
} ubo;
|
||||||
|
|
||||||
layout (location = 0) out vec3 outColor;
|
layout (location = 0) out vec3 outColor;
|
||||||
|
layout (location = 1) out vec3 outNormal;
|
||||||
|
layout (location = 2) out vec3 outViewVec;
|
||||||
|
layout (location = 3) out vec3 outLightVec;
|
||||||
|
|
||||||
out gl_PerVertex {
|
out gl_PerVertex {
|
||||||
vec4 gl_Position;
|
vec4 gl_Position;
|
||||||
|
|
@ -21,6 +21,9 @@ out gl_PerVertex {
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = ubo.projection * ubo.view * ubo.model * inPos;
|
gl_Position = ubo.projection * ubo.view * ubo.model * vec4(inPos, 1.0);
|
||||||
outColor = inColor;
|
outColor = inColor;
|
||||||
|
outNormal = inNormal;
|
||||||
|
outLightVec = vec3(0.0f, 5.0f, 15.0f) - inPos;
|
||||||
|
outViewVec = -inPos.xyz;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -36,7 +36,6 @@ public:
|
||||||
vks::VERTEX_COMPONENT_POSITION,
|
vks::VERTEX_COMPONENT_POSITION,
|
||||||
vks::VERTEX_COMPONENT_COLOR,
|
vks::VERTEX_COMPONENT_COLOR,
|
||||||
vks::VERTEX_COMPONENT_NORMAL,
|
vks::VERTEX_COMPONENT_NORMAL,
|
||||||
vks::VERTEX_COMPONENT_UV,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
vks::Model scene;
|
vks::Model scene;
|
||||||
|
|
@ -48,6 +47,7 @@ public:
|
||||||
} uboMatrices;
|
} uboMatrices;
|
||||||
|
|
||||||
struct UBOParams {
|
struct UBOParams {
|
||||||
|
glm::vec2 brightnessContrast = glm::vec2(0.5f, 1.8f);
|
||||||
glm::vec2 range = glm::vec2(0.6f, 1.0f);
|
glm::vec2 range = glm::vec2(0.6f, 1.0f);
|
||||||
int32_t attachmentIndex = 1;
|
int32_t attachmentIndex = 1;
|
||||||
} uboParams;
|
} uboParams;
|
||||||
|
|
@ -68,7 +68,6 @@ public:
|
||||||
} pipelineLayouts;
|
} pipelineLayouts;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
VkDescriptorSet attachmentWrite;
|
|
||||||
VkDescriptorSet attachmentRead;
|
VkDescriptorSet attachmentRead;
|
||||||
} descriptorSets;
|
} descriptorSets;
|
||||||
|
|
||||||
|
|
@ -93,12 +92,9 @@ public:
|
||||||
{
|
{
|
||||||
title = "Input attachments";
|
title = "Input attachments";
|
||||||
camera.type = Camera::CameraType::firstperson;
|
camera.type = Camera::CameraType::firstperson;
|
||||||
camera.movementSpeed = 5.0f;
|
camera.movementSpeed = 2.5f;
|
||||||
#ifndef __ANDROID__
|
camera.setPosition(glm::vec3(1.65f, 1.75f, -6.15f));
|
||||||
camera.rotationSpeed = 0.25f;
|
camera.setRotation(glm::vec3(-12.75f, 380.0f, 0.0f));
|
||||||
#endif
|
|
||||||
camera.setPosition(glm::vec3(-3.2f, 1.0f, 5.9f));
|
|
||||||
camera.setRotation(glm::vec3(0.5f, 210.05f, 0.0f));
|
|
||||||
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f);
|
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f);
|
||||||
settings.overlay = true;
|
settings.overlay = true;
|
||||||
}
|
}
|
||||||
|
|
@ -219,6 +215,7 @@ public:
|
||||||
std::array<VkAttachmentDescription, 3> attachments{};
|
std::array<VkAttachmentDescription, 3> attachments{};
|
||||||
|
|
||||||
// Swap chain image color attachment
|
// Swap chain image color attachment
|
||||||
|
// Will be transitioned to present layout
|
||||||
attachments[0].format = swapChain.colorFormat;
|
attachments[0].format = swapChain.colorFormat;
|
||||||
attachments[0].samples = VK_SAMPLE_COUNT_1_BIT;
|
attachments[0].samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||||
|
|
@ -229,6 +226,9 @@ public:
|
||||||
attachments[0].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
attachments[0].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||||
|
|
||||||
// Input attachments
|
// Input attachments
|
||||||
|
// These will be written in the first subpass, transitioned to input attachments
|
||||||
|
// and then read in the secod subpass
|
||||||
|
|
||||||
// Color
|
// Color
|
||||||
attachments[1].format = this->attachments.color.format;
|
attachments[1].format = this->attachments.color.format;
|
||||||
attachments[1].samples = VK_SAMPLE_COUNT_1_BIT;
|
attachments[1].samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
|
@ -380,7 +380,7 @@ public:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Second sub pass
|
Second sub pass
|
||||||
Reads from the attachments via input attachments
|
Render a full screen quad, reading from the previously written attachments via input attachments
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
vks::debugmarker::beginRegion(drawCmdBuffers[i], "Subpass 1: Reading attachments", glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));
|
vks::debugmarker::beginRegion(drawCmdBuffers[i], "Subpass 1: Reading attachments", glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
|
|
@ -402,7 +402,7 @@ public:
|
||||||
|
|
||||||
void loadAssets()
|
void loadAssets()
|
||||||
{
|
{
|
||||||
scene.loadFromFile(getAssetPath() + "models/samplebuilding.dae", vertexLayout, 1.0f, vulkanDevice, queue);
|
scene.loadFromFile(getAssetPath() + "models/treasure_smooth.dae", vertexLayout, 1.0f, vulkanDevice, queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupDescriptors()
|
void setupDescriptors()
|
||||||
|
|
@ -521,7 +521,6 @@ public:
|
||||||
vks::initializers::vertexInputAttributeDescription(0, 0, VK_FORMAT_R32G32B32_SFLOAT, 0), // Location 0: Position
|
vks::initializers::vertexInputAttributeDescription(0, 0, VK_FORMAT_R32G32B32_SFLOAT, 0), // Location 0: Position
|
||||||
vks::initializers::vertexInputAttributeDescription(0, 1, VK_FORMAT_R32G32B32_SFLOAT, sizeof(float) * 3), // Location 1: Color
|
vks::initializers::vertexInputAttributeDescription(0, 1, VK_FORMAT_R32G32B32_SFLOAT, sizeof(float) * 3), // Location 1: Color
|
||||||
vks::initializers::vertexInputAttributeDescription(0, 2, VK_FORMAT_R32G32B32_SFLOAT, sizeof(float) * 6), // Location 2: Normal
|
vks::initializers::vertexInputAttributeDescription(0, 2, VK_FORMAT_R32G32B32_SFLOAT, sizeof(float) * 6), // Location 2: Normal
|
||||||
vks::initializers::vertexInputAttributeDescription(0, 3, VK_FORMAT_R32G32_SFLOAT, sizeof(float) * 9), // Location 3: UV
|
|
||||||
};
|
};
|
||||||
|
|
||||||
VkPipelineVertexInputStateCreateInfo vertexInputStateCI = vks::initializers::pipelineVertexInputStateCreateInfo();
|
VkPipelineVertexInputStateCreateInfo vertexInputStateCI = vks::initializers::pipelineVertexInputStateCreateInfo();
|
||||||
|
|
@ -624,9 +623,22 @@ public:
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
if (overlay->header("Settings")) {
|
if (overlay->header("Settings")) {
|
||||||
if (overlay->comboBox("Attachment", &uboParams.attachmentIndex, { "color", "depth" })) {
|
overlay->text("Input attachment");
|
||||||
|
if (overlay->comboBox("##attachment", &uboParams.attachmentIndex, { "color", "depth" })) {
|
||||||
updateUniformBuffers();
|
updateUniformBuffers();
|
||||||
}
|
}
|
||||||
|
switch (uboParams.attachmentIndex) {
|
||||||
|
case 0:
|
||||||
|
overlay->text("Brightness");
|
||||||
|
if (overlay->sliderFloat("##b", &uboParams.brightnessContrast[0], 0.0f, 2.0f)) {
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
overlay->text("Contrast");
|
||||||
|
if (overlay->sliderFloat("##c", &uboParams.brightnessContrast[1], 0.0f, 4.0f)) {
|
||||||
|
updateUniformBuffers();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
overlay->text("Visible range");
|
overlay->text("Visible range");
|
||||||
if (overlay->sliderFloat("min", &uboParams.range[0], 0.0f, uboParams.range[1])) {
|
if (overlay->sliderFloat("min", &uboParams.range[0], 0.0f, uboParams.range[1])) {
|
||||||
updateUniformBuffers();
|
updateUniformBuffers();
|
||||||
|
|
@ -634,6 +646,8 @@ public:
|
||||||
if (overlay->sliderFloat("max", &uboParams.range[1], uboParams.range[0], 1.0f)) {
|
if (overlay->sliderFloat("max", &uboParams.range[1], uboParams.range[0], 1.0f)) {
|
||||||
updateUniformBuffers();
|
updateUniformBuffers();
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue