diff --git a/Keishiki/ShaderGraph.cpp b/Keishiki/ShaderGraph.cpp index b980c0d..1fe7980 100644 --- a/Keishiki/ShaderGraph.cpp +++ b/Keishiki/ShaderGraph.cpp @@ -3,14 +3,14 @@ #include "srell.hpp" namespace { - K::String build_node(const K::ShaderGraph::NodeInstance& n) { + K::String BuildNode(const K::ShaderGraph::NodeInstance& n) { K::String r = n.node->shader_template; for (u32 i = 0; i < n.node->inputs.size(); i++) { K::String sub{}; if (n.inputs[i] != nullptr) - sub = build_node(*n.inputs[i]); + sub = BuildNode(*n.inputs[i]); else - sub = K::ShaderGraph::var_to_string(n.values[i]); // should be made into uniform instead !! + sub = K::ShaderGraph::VarToString(n.values[i]); // should be made into uniform instead !! r = srell::regex_replace(r, srell::regex("\\{" + std::to_string(i) + "\\}"), sub); } return r; @@ -18,23 +18,23 @@ namespace { } namespace K::ShaderGraph { - String var_to_string(const std::variant& var) { + String VarToString(const T_Map::type& var) { return std::visit([](auto&& arg) -> String { using T = std::decay_t; - if constexpr (std::is_same_v::type>) - return std::to_string(arg); - else if constexpr (std::is_same_v::type>) + if constexpr (std::is_same_v::type>) return std::to_string(arg) + "f"; - else if constexpr (std::is_same_v::type>) - return arg; + else if constexpr (std::is_same_v::type>) + return std::to_string(arg); else if constexpr (std::is_same_v::type>) return "vec4(" + std::to_string(arg.r) + "," + std::to_string(arg.g) + "," + std::to_string(arg.b) + "," + std::to_string(arg.a) + ")"; + else if constexpr (std::is_same_v::type>) + return "vec2(" + std::to_string(arg.x) + "," + std::to_string(arg.y) + ")"; else if constexpr (std::is_same_v::type>) return "vec3(" + std::to_string(arg.x) + "," + std::to_string(arg.y) + "," + std::to_string(arg.z) + ")"; }, var); } String ShaderGraph::generate_shader() const { if (RGBA_node->node->out_types[RGBA_node_out_index] != Type::T_RGBA) return {}; - return build_node(*RGBA_node); + return BuildNode(*RGBA_node); } } diff --git a/Keishiki/UI.cpp b/Keishiki/UI.cpp index 64b33c3..13364f7 100644 --- a/Keishiki/UI.cpp +++ b/Keishiki/UI.cpp @@ -99,6 +99,7 @@ namespace K::UI { for (auto& uniform : layer.track.uniforms) { bgfx::destroy(uniform.second.first); } + layer.track.uniforms.clear(); } } @@ -355,14 +356,14 @@ namespace K::UI { ImGui::TableNextColumn(); std::visit([it](auto&& arg) { using T = std::decay_t; - if constexpr (std::is_same_v::type>) - ImGui::InputInt(("##" + it->first).c_str(), &arg); - else if constexpr (std::is_same_v::type>) + if constexpr (std::is_same_v::type>) ImGui::DragFloat(("##" + it->first).c_str(), &arg, 0.005f); - else if constexpr (std::is_same_v::type>) - ImGui::InputText(("##" + it->first).c_str(), &arg); + else if constexpr (std::is_same_v::type>) + ImGui::InputInt(("##" + it->first).c_str(), &arg); else if constexpr (std::is_same_v::type>) ImGui::InputFloat4(("##" + it->first).c_str(), &arg.r); + else if constexpr (std::is_same_v::type>) + ImGui::InputFloat2(("##" + it->first).c_str(), &arg.x); else if constexpr (std::is_same_v::type>) ImGui::InputFloat3(("##" + it->first).c_str(), &arg.x); }, it->second.second); diff --git a/Keishiki/include/ShaderGraph.h b/Keishiki/include/ShaderGraph.h index 36a8daf..c96a593 100644 --- a/Keishiki/include/ShaderGraph.h +++ b/Keishiki/include/ShaderGraph.h @@ -8,47 +8,48 @@ namespace K::ShaderGraph { enum Type { + T_Float, T_Int, - T_Float, - T_String, T_RGBA, - T_XYZ, + T_XY, + T_XYZ, T_Count }; static const char *Type_To_Str[] = { - "Int", - "Float", - "String", - "RGBA", - "XYZ", - "Error" + "Float", + "Int", + "RGBA", + "XY", + "XYZ", + "Error" }; struct RGBA { f32 r, g, b, a; }; struct XYZ { f32 x, y, z; }; + struct XY { f32 x, y; }; template struct T_Map; + template<> struct T_Map { + using type = f32; + }; template<> struct T_Map { using type = i32; }; - template<> struct T_Map { - using type = f32; - }; - template<> struct T_Map { - using type = String; - }; template<> struct T_Map { using type = RGBA; }; - template<> struct T_Map { - using type = XYZ; - }; + template<> struct T_Map { + using type = XY; + }; + template<> struct T_Map { + using type = XYZ; + }; template<> struct T_Map { - using type = std::variant; + using type = std::variant; }; - String var_to_string(const std::variant& var); + String VarToString(const T_Map::type& var); inline T_Map::type expand_type(Type i) { - static constexpr T_Map::type table[] = {i32{}, f32{}, String{}, ShaderGraph::RGBA{}, ShaderGraph::XYZ{}}; + static constexpr T_Map::type table[] = {f32{}, i32{}, ShaderGraph::RGBA{}, ShaderGraph::XY{}, ShaderGraph::XYZ{}}; return table[i]; } diff --git a/Keishiki/include/VisualTrack.h b/Keishiki/include/VisualTrack.h index 8d48b61..759da69 100644 --- a/Keishiki/include/VisualTrack.h +++ b/Keishiki/include/VisualTrack.h @@ -41,17 +41,19 @@ namespace K { f32 pack[4]{}; std::visit([&pack](auto&& arg) { using T = std::decay_t; - if constexpr (std::is_same_v::type> || std::is_same_v::type>) + if constexpr (std::is_same_v::type> || std::is_same_v::type>) pack[0] = static_cast(arg); - else if constexpr (std::is_same_v::type>) - LogError("String passed to shader, verify specification."); // ??? damn bro else if constexpr (std::is_same_v::type>) { pack[0] = arg.r; pack[1] = arg.g; pack[2] = arg.b; pack[3] = arg.a; } - else if constexpr (std::is_same_v::type>){ + else if constexpr (std::is_same_v::type>) { + pack[0] = arg.x; + pack[1] = arg.y; + } + else if constexpr (std::is_same_v::type>) { pack[0] = arg.x; pack[1] = arg.y; pack[2] = arg.z; @@ -79,20 +81,20 @@ namespace K { f << "uniform vec4 " << "__" << u.first << ";\n"; } for (auto& u : uniforms) { + f << "# define " << u.first << " __" << u.first; std::visit([&u, &f](auto&& arg) { using T = std::decay_t; - if constexpr (std::is_same_v::type>) - f << "int " << u.first << " = __" << u.first << ".x" << ";\n"; - else if constexpr (std::is_same_v::type>) - f << "float " << u.first << " = __" << u.first << ".x" << ";\n"; - else if constexpr (std::is_same_v::type>) - ; + if constexpr (std::is_same_v::type> || std::is_same_v::type>) + f << ".x"; else if constexpr (std::is_same_v::type>) - f << "vec4 " << u.first << " = __" << u.first << ";\n"; + ; + else if constexpr (std::is_same_v::type>) + f << ".xy"; else if constexpr (std::is_same_v::type>) - f << "vec3 " << u.first << " = __" << u.first << ".xyz" << ";\n"; + f << ".xyz"; }, u.second.second); - } + f << "\n"; + } f << shader; f.close();