Skip to content

Instantly share code, notes, and snippets.

@xeechou
Last active September 23, 2022 17:36
Show Gist options
  • Save xeechou/2dfcf211e0cbf7053ebdeabfeab733eb to your computer and use it in GitHub Desktop.
Save xeechou/2dfcf211e0cbf7053ebdeabfeab733eb to your computer and use it in GitHub Desktop.
use of ssbo and texturebuffer in vertex shader
#version 460
#extension GL_GOOGLE_include_directive : require
// ------------------------------------------------------------------------
// INPUTS -----------------------------------------------------------------
// ------------------------------------------------------------------------
layout(location = 0) in vec3 VS_IN_Position;
layout(location = 1) in vec2 VS_IN_Texcoord;
layout(location = 2) in vec3 VS_IN_Normal;
layout(location = 3) in vec3 VS_IN_Tangent;
layout(location = 4) in vec3 VS_IN_Bitangent;
// // ------------------------------------------------------------------------
// // OUTPUTS ----------------------------------------------------------------
// // ------------------------------------------------------------------------
// layout(location = 0) out vec3 FS_IN_FragPos;
// layout(location = 1) out vec2 FS_IN_Texcoord;
out gl_PerVertex
{
vec4 gl_Position;
};
// ------------------------------------------------------------------------
// PUSH CONSTANTS ---------------------------------------------------------
// ------------------------------------------------------------------------
layout(push_constant) uniform PushConstants
{
mat4 model;
mat4 prev_model;
uint material_idx;
uint mesh_id;
} ubo;
layout (set = 0, binding = 0) uniform samplerBuffer u_bone_idx;
layout (set = 0, binding = 1) uniform samplerBuffer u_bone_weight;
layout (set = 0, binding = 3, std430) readonly buffer Matrices
{
mat4 matrices[];
} Skeletons;
void main()
{
gl_Position = vec4(0.0);
ivec4 bones = ivec4(texelFetch(u_bone_idx, gl_VertexIndex).xyzw);
vec4 weights = texelFetch(u_bone_weight, gl_VertexIndex).xyzw;
for (int i = 0; i < 4; i++)
{
gl_Position += weights[i] * Skeletons.matrices[bones[i]] * vec4(VS_IN_Position, 1.0);
}
}
//to compile with glslc
//glslc -Os --target-env=vulkan1.2 -o sample.vert.spv -fshader-stage=vertex sample.vert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment