Added simple task shader
This commit is contained in:
parent
c739dac00a
commit
ed406e61a6
5 changed files with 41 additions and 11 deletions
|
|
@ -22,15 +22,31 @@ layout(location = 0) out VertexOutput
|
|||
vec4 color;
|
||||
} vertexOutput[];
|
||||
|
||||
const vec4[3] positions = {
|
||||
vec4( 0.0, -1.0, 0.0, 1.0),
|
||||
vec4(-1.0, 1.0, 0.0, 1.0),
|
||||
vec4( 1.0, 1.0, 0.0, 1.0)
|
||||
};
|
||||
|
||||
const vec4[3] colors = {
|
||||
vec4(0.0, 1.0, 0.0, 1.0),
|
||||
vec4(0.0, 0.0, 1.0, 1.0),
|
||||
vec4(1.0, 0.0, 0.0, 1.0)
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
uint iid = gl_LocalInvocationID.x;
|
||||
|
||||
vec4 offset = vec4(0.0, 0.0, gl_GlobalInvocationID.x, 0.0);
|
||||
|
||||
SetMeshOutputsEXT(3, 1);
|
||||
mat4 mvp = ubo.projection * ubo.view * ubo.model;
|
||||
gl_MeshVerticesEXT[0].gl_Position = mvp * vec4( 0.0, -1.0, 0.0, 1.0);
|
||||
gl_MeshVerticesEXT[1].gl_Position = mvp * vec4(-1.0, 1.0, 0.0, 1.0);
|
||||
gl_MeshVerticesEXT[2].gl_Position = mvp * vec4( 1.0, 1.0, 0.0, 1.0);
|
||||
vertexOutput[0].color = vec4(0.0, 1.0, 0.0, 1.0);
|
||||
vertexOutput[1].color = vec4(0.0, 0.0, 1.0, 1.0);
|
||||
vertexOutput[2].color = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
gl_MeshVerticesEXT[0].gl_Position = mvp * (positions[0] + offset);
|
||||
gl_MeshVerticesEXT[1].gl_Position = mvp * (positions[1] + offset);
|
||||
gl_MeshVerticesEXT[2].gl_Position = mvp * (positions[2] + offset);
|
||||
vertexOutput[0].color = colors[0];
|
||||
vertexOutput[1].color = colors[1];
|
||||
vertexOutput[2].color = colors[2];
|
||||
gl_PrimitiveTriangleIndicesEXT[gl_LocalInvocationIndex] = uvec3(0, 1, 2);
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
13
data/shaders/glsl/meshshader/meshshader.task
Normal file
13
data/shaders/glsl/meshshader/meshshader.task
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/* Copyright (c) 2021, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#version 450
|
||||
#extension GL_EXT_mesh_shader : require
|
||||
|
||||
void main()
|
||||
{
|
||||
EmitMeshTasksEXT(3, 1, 1);
|
||||
}
|
||||
BIN
data/shaders/glsl/meshshader/meshshader.task.spv
Normal file
BIN
data/shaders/glsl/meshshader/meshshader.task.spv
Normal file
Binary file not shown.
|
|
@ -38,8 +38,8 @@ public:
|
|||
timerSpeed *= 0.25f;
|
||||
camera.type = Camera::CameraType::lookat;
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 512.0f);
|
||||
camera.setRotation(glm::vec3(0.0f));
|
||||
camera.setTranslation(glm::vec3(0.0f, 0.0f, -2.0f));
|
||||
camera.setRotation(glm::vec3(0.0f, 15.0f, 0.0f));
|
||||
camera.setTranslation(glm::vec3(0.0f, 0.0f, -5.0f));
|
||||
|
||||
// Extension require at least Vulkan 1.1
|
||||
apiVersion = VK_API_VERSION_1_1;
|
||||
|
|
@ -65,7 +65,7 @@ public:
|
|||
{
|
||||
enabledMeshShaderFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_NV;
|
||||
enabledMeshShaderFeatures.meshShader = VK_TRUE;
|
||||
enabledMeshShaderFeatures.taskShader = VK_FALSE;
|
||||
enabledMeshShaderFeatures.taskShader = VK_TRUE;
|
||||
|
||||
deviceCreatepNextChain = &enabledMeshShaderFeatures;
|
||||
}
|
||||
|
|
@ -158,7 +158,7 @@ public:
|
|||
VkPipelineMultisampleStateCreateInfo multisampleState = vks::initializers::pipelineMultisampleStateCreateInfo(VK_SAMPLE_COUNT_1_BIT, 0);
|
||||
std::vector<VkDynamicState> dynamicStateEnables = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
|
||||
VkPipelineDynamicStateCreateInfo dynamicState = vks::initializers::pipelineDynamicStateCreateInfo(dynamicStateEnables);
|
||||
std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages;
|
||||
std::array<VkPipelineShaderStageCreateInfo, 3> shaderStages;
|
||||
|
||||
VkGraphicsPipelineCreateInfo pipelineCI = vks::initializers::pipelineCreateInfo(pipelineLayout, renderPass, 0);
|
||||
|
||||
|
|
@ -176,7 +176,8 @@ public:
|
|||
pipelineCI.pStages = shaderStages.data();
|
||||
|
||||
shaderStages[0] = loadShader(getShadersPath() + "meshshader/meshshader.mesh.spv", VK_SHADER_STAGE_MESH_BIT_EXT);
|
||||
shaderStages[1] = loadShader(getShadersPath() + "meshshader/meshshader.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
shaderStages[1] = loadShader(getShadersPath() + "meshshader/meshshader.task.spv", VK_SHADER_STAGE_TASK_BIT_EXT);
|
||||
shaderStages[2] = loadShader(getShadersPath() + "meshshader/meshshader.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipeline));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue