2b55a4823d
- cpp/vendor/imgui-node-editor: vendorized thedmd/imgui-node-editor v0.9.4 - cpp/functions/gfx/dag_node_editor: new visual pipeline editor replacing dag_panel - DagStep: source_ids[4] + editor_pos + editor_uid (multi-input support) - DagNodeDef: num_inputs explicit; circle reclassified as Op - dag_compile: N inputs per node, topological ordering preserved - main: use node editor; destroy on shutdown - patch imgui_extra_math.inl: guard operator*(float, ImVec2) for imgui >= 18955 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
92 lines
2.8 KiB
C++
92 lines
2.8 KiB
C++
#include "gfx/dag_compile.h"
|
|
#include "gfx/dag_catalog.h"
|
|
#include <algorithm>
|
|
#include <sstream>
|
|
|
|
namespace fn::gfx {
|
|
|
|
static constexpr int MAX_NODES = 16;
|
|
|
|
std::string compile_dag_to_glsl(const std::vector<DagStep>& pipeline) {
|
|
const int n = static_cast<int>(std::min(pipeline.size(), static_cast<size_t>(MAX_NODES)));
|
|
std::ostringstream out;
|
|
|
|
out << "uniform vec4 u_params[16];\n\n";
|
|
|
|
if (n == 0) {
|
|
out << "void main() {\n";
|
|
out << " vec2 uv = gl_FragCoord.xy / u_resolution;\n";
|
|
out << " (void)uv;\n";
|
|
out << " fragColor = vec4(0.04, 0.04, 0.06, 1.0);\n";
|
|
out << "}\n";
|
|
return out.str();
|
|
}
|
|
|
|
// Emit per-node functions with signatures based on num_inputs
|
|
for (int i = 0; i < n; ++i) {
|
|
const DagStep& step = pipeline[static_cast<size_t>(i)];
|
|
const DagNodeDef* def = dag_find(step.name);
|
|
if (!def) continue;
|
|
|
|
int ni = def->num_inputs;
|
|
out << "vec4 node_" << i << "(";
|
|
if (ni >= 1) out << "vec4 a";
|
|
if (ni >= 2) out << ", vec4 b";
|
|
if (ni >= 3) out << ", vec4 c";
|
|
if (ni >= 4) out << ", vec4 d";
|
|
if (ni > 0) out << ", ";
|
|
out << "vec2 uv) {\n";
|
|
out << def->body_glsl(i) << "\n";
|
|
out << "}\n\n";
|
|
}
|
|
|
|
out << "void main() {\n";
|
|
out << " vec2 uv = gl_FragCoord.xy / u_resolution;\n";
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
const DagStep& step = pipeline[static_cast<size_t>(i)];
|
|
const DagNodeDef* def = dag_find(step.name);
|
|
if (!def) {
|
|
if (i == 0) {
|
|
out << " vec4 out_" << i << " = vec4(0.0, 0.0, 0.0, 1.0);\n";
|
|
} else {
|
|
out << " vec4 out_" << i << " = out_" << (i - 1) << ";\n";
|
|
}
|
|
continue;
|
|
}
|
|
|
|
int ni = def->num_inputs;
|
|
|
|
// Resolve each input slot
|
|
// For slot k: look for source_ids[k] in pipeline[0..i-1]; fallback = prev output
|
|
auto resolve = [&](int k) -> std::string {
|
|
const std::string& sid = step.source_ids[static_cast<size_t>(k)];
|
|
if (!sid.empty()) {
|
|
for (int j = 0; j < i; ++j) {
|
|
if (pipeline[static_cast<size_t>(j)].id == sid) {
|
|
return "out_" + std::to_string(j);
|
|
}
|
|
}
|
|
}
|
|
// fallback
|
|
if (i == 0) return "vec4(0.0, 0.0, 0.0, 1.0)";
|
|
return "out_" + std::to_string(i - 1);
|
|
};
|
|
|
|
out << " vec4 out_" << i << " = node_" << i << "(";
|
|
for (int k = 0; k < ni; ++k) {
|
|
if (k > 0) out << ", ";
|
|
out << resolve(k);
|
|
}
|
|
if (ni > 0) out << ", ";
|
|
out << "uv);\n";
|
|
}
|
|
|
|
out << " fragColor = out_" << (n - 1) << ";\n";
|
|
out << "}\n";
|
|
|
|
return out.str();
|
|
}
|
|
|
|
} // namespace fn::gfx
|