Commit e39c86f8 authored by Lázár Bence Kis's avatar Lázár Bence Kis
Browse files

Number of bones defined in the shader graph

parent 52bfcad4
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -675,7 +675,7 @@ struct ShaderGraph::CosineNode : public Node {
};

struct ShaderGraph::SkinningUnlitNode : public Node {
    SkinningUnlitNode() : Node(
    SkinningUnlitNode(size_t num_of_joints) : Node(
        "skinning unlit",
        "Abstract parent node for skinning algorithms calculating just the position",
        {
@@ -686,14 +686,16 @@ struct ShaderGraph::SkinningUnlitNode : public Node {
        {
            {"position", "Vertex position with skinning applied.", { DataType::VEC3 }},
        }
    ) {}
    ), m_num_of_joints(num_of_joints) {}

    enum inputs { position, weights, bone_indices };
    enum outputs { skinned_position };
  protected:
    size_t m_num_of_joints;
};

struct ShaderGraph::SkinningNode : public Node {
    SkinningNode() : Node(
    SkinningNode(size_t num_of_joints) : Node(
        "skinning lit",
        "Abstract parent node for skinning algorithms taking normals and tangents into consideration as well",
        {
@@ -708,20 +710,22 @@ struct ShaderGraph::SkinningNode : public Node {
            {"normal", "Vertex normal with skinning applied.", { DataType::VEC3 }},
            {"tangent", "Vertex tangent with skinning applied.", { DataType::VEC3 }},
        }
    ) {}
    ), m_num_of_joints(num_of_joints) {}

    enum inputs { position, normal, tangent, weights, bone_indices };
    enum outputs { skinned_position, skinned_normal, skinned_tangent };
  protected:
    size_t m_num_of_joints;
};

struct ShaderGraph::LinearBlendSkinningUnlitNode : public ShaderGraph::SkinningUnlitNode {
    LinearBlendSkinningUnlitNode() {}
    LinearBlendSkinningUnlitNode(size_t num_of_joints) : ShaderGraph::SkinningUnlitNode(num_of_joints) {}

    void add_code(StagesCode &code, Stage stage) const override;
};

struct ShaderGraph::LinearBlendSkinningNode : public ShaderGraph::SkinningNode {
    LinearBlendSkinningNode() {}
    LinearBlendSkinningNode(size_t num_of_joints) : ShaderGraph::SkinningNode(num_of_joints) {}

    void add_code(StagesCode &code, Stage stage) const override;
};
+2 −5
Original line number Diff line number Diff line
@@ -927,9 +927,8 @@ void ShaderGraph::CosineNode::add_code(StagesCode &code, Stage stage) const {
void ShaderGraph::LinearBlendSkinningUnlitNode::add_code(StagesCode &code, Stage stage) const {
    INVARIANT(stage == Stage::VERTEX);

    const static auto MAX_BONES = 80;
    auto decl = R"(layout(std140) uniform BoneMatrices {
    mat4 bones[)" + std::to_string(MAX_BONES) + R"(]; // MAX_BONES defined in shader
    mat4 bones[)" + std::to_string(m_num_of_joints) + R"(]; // MAX_BONES defined in shader
};

vec3 get_skinned_position(vec3 position, vec4 weights, uvec4 bone_indices) {
@@ -954,12 +953,10 @@ vec3 get_skinned_position(vec3 position, vec4 weights, uvec4 bone_indices) {
void ShaderGraph::LinearBlendSkinningNode::add_code(StagesCode &code, Stage stage) const {
    INVARIANT(stage == Stage::VERTEX);

    const static auto MAX_BONES = 80;

    std::string decl_flag = "// bone matrix UBO declarations";
    if (std::ranges::find(code[stage].decl, decl_flag) == code[stage].decl.end()) {
        std::string ubo_decl = "layout(std140) uniform BoneMatrices {\n"
            "    mat4 bones[" + std::to_string(MAX_BONES) + "]; // MAX_BONES defined in shader\n"
            "    mat4 bones[" + std::to_string(m_num_of_joints) + "]; // MAX_BONES defined in shader\n"
            "}";
        
        code[stage].decl.push_back(decl_flag);