token!
This commit is contained in:
parent
c78087ffe7
commit
6eaa92cdf8
4 changed files with 53 additions and 49 deletions
|
@ -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<i32, f32, String, RGBA, XYZ>& var) {
|
||||
String VarToString(const T_Map<T_Count>::type& var) {
|
||||
return std::visit([](auto&& arg) -> String {
|
||||
using T = std::decay_t<decltype(arg)>;
|
||||
if constexpr (std::is_same_v<T, T_Map<T_Int>::type>)
|
||||
return std::to_string(arg);
|
||||
else if constexpr (std::is_same_v<T, T_Map<T_Float>::type>)
|
||||
if constexpr (std::is_same_v<T, T_Map<T_Float>::type>)
|
||||
return std::to_string(arg) + "f";
|
||||
else if constexpr (std::is_same_v<T, T_Map<T_String>::type>)
|
||||
return arg;
|
||||
else if constexpr (std::is_same_v<T, T_Map<T_Int>::type>)
|
||||
return std::to_string(arg);
|
||||
else if constexpr (std::is_same_v<T, T_Map<T_RGBA>::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<T, T_Map<T_XY>::type>)
|
||||
return "vec2(" + std::to_string(arg.x) + "," + std::to_string(arg.y) + ")";
|
||||
else if constexpr (std::is_same_v<T, T_Map<T_XYZ>::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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<decltype(arg)>;
|
||||
if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_Int>::type>)
|
||||
ImGui::InputInt(("##" + it->first).c_str(), &arg);
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_Float>::type>)
|
||||
if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_Float>::type>)
|
||||
ImGui::DragFloat(("##" + it->first).c_str(), &arg, 0.005f);
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_String>::type>)
|
||||
ImGui::InputText(("##" + it->first).c_str(), &arg);
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_Int>::type>)
|
||||
ImGui::InputInt(("##" + it->first).c_str(), &arg);
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_RGBA>::type>)
|
||||
ImGui::InputFloat4(("##" + it->first).c_str(), &arg.r);
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_XY>::type>)
|
||||
ImGui::InputFloat2(("##" + it->first).c_str(), &arg.x);
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_XYZ>::type>)
|
||||
ImGui::InputFloat3(("##" + it->first).c_str(), &arg.x);
|
||||
}, it->second.second);
|
||||
|
|
|
@ -8,47 +8,48 @@
|
|||
|
||||
namespace K::ShaderGraph {
|
||||
enum Type {
|
||||
T_Int,
|
||||
T_Float,
|
||||
T_String,
|
||||
T_Int,
|
||||
T_RGBA,
|
||||
T_XY,
|
||||
T_XYZ,
|
||||
T_Count
|
||||
};
|
||||
static const char *Type_To_Str[] = {
|
||||
"Int",
|
||||
"Float",
|
||||
"String",
|
||||
"Int",
|
||||
"RGBA",
|
||||
"XY",
|
||||
"XYZ",
|
||||
"Error"
|
||||
};
|
||||
|
||||
struct RGBA { f32 r, g, b, a; };
|
||||
struct XYZ { f32 x, y, z; };
|
||||
struct XY { f32 x, y; };
|
||||
template<Type> struct T_Map;
|
||||
template<> struct T_Map<T_Int> {
|
||||
using type = i32;
|
||||
};
|
||||
template<> struct T_Map<T_Float> {
|
||||
using type = f32;
|
||||
};
|
||||
template<> struct T_Map<T_String> {
|
||||
using type = String;
|
||||
template<> struct T_Map<T_Int> {
|
||||
using type = i32;
|
||||
};
|
||||
template<> struct T_Map<T_RGBA> {
|
||||
using type = RGBA;
|
||||
};
|
||||
template<> struct T_Map<T_XY> {
|
||||
using type = XY;
|
||||
};
|
||||
template<> struct T_Map<T_XYZ> {
|
||||
using type = XYZ;
|
||||
};
|
||||
template<> struct T_Map<T_Count> {
|
||||
using type = std::variant<i32, f32, String, RGBA, XYZ>;
|
||||
using type = std::variant<f32, i32, RGBA, XY, XYZ>;
|
||||
};
|
||||
String var_to_string(const std::variant<i32, f32, String, RGBA, XYZ>& var);
|
||||
String VarToString(const T_Map<T_Count>::type& var);
|
||||
|
||||
inline T_Map<T_Count>::type expand_type(Type i) {
|
||||
static constexpr T_Map<T_Count>::type table[] = {i32{}, f32{}, String{}, ShaderGraph::RGBA{}, ShaderGraph::XYZ{}};
|
||||
static constexpr T_Map<T_Count>::type table[] = {f32{}, i32{}, ShaderGraph::RGBA{}, ShaderGraph::XY{}, ShaderGraph::XYZ{}};
|
||||
return table[i];
|
||||
}
|
||||
|
||||
|
|
|
@ -41,17 +41,19 @@ namespace K {
|
|||
f32 pack[4]{};
|
||||
std::visit([&pack](auto&& arg) {
|
||||
using T = std::decay_t<decltype(arg)>;
|
||||
if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_Int>::type> || std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_Float>::type>)
|
||||
if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_Float>::type> || std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_Int>::type>)
|
||||
pack[0] = static_cast<f32>(arg);
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_String>::type>)
|
||||
LogError("String passed to shader, verify specification."); // ??? damn bro
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_RGBA>::type>) {
|
||||
pack[0] = arg.r;
|
||||
pack[1] = arg.g;
|
||||
pack[2] = arg.b;
|
||||
pack[3] = arg.a;
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_XYZ>::type>){
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_XY>::type>) {
|
||||
pack[0] = arg.x;
|
||||
pack[1] = arg.y;
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_XYZ>::type>) {
|
||||
pack[0] = arg.x;
|
||||
pack[1] = arg.y;
|
||||
pack[2] = arg.z;
|
||||
|
@ -79,19 +81,19 @@ 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<decltype(arg)>;
|
||||
if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_Int>::type>)
|
||||
f << "int " << u.first << " = __" << u.first << ".x" << ";\n";
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_Float>::type>)
|
||||
f << "float " << u.first << " = __" << u.first << ".x" << ";\n";
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_String>::type>)
|
||||
;
|
||||
if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_Float>::type> || std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_Int>::type>)
|
||||
f << ".x";
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_RGBA>::type>)
|
||||
f << "vec4 " << u.first << " = __" << u.first << ";\n";
|
||||
;
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_XY>::type>)
|
||||
f << ".xy";
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_XYZ>::type>)
|
||||
f << "vec3 " << u.first << " = __" << u.first << ".xyz" << ";\n";
|
||||
f << ".xyz";
|
||||
}, u.second.second);
|
||||
f << "\n";
|
||||
}
|
||||
f << shader;
|
||||
f.close();
|
||||
|
|
Loading…
Add table
Reference in a new issue