Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions modules/editor/shadertools/converter/functions/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CameraPosition : public ShaderNode {
m_outputs.push_back(std::make_pair("Output", MetaType::VECTOR3));
}

int32_t build(QString &code, QStack<QString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
int32_t build(TString &code, std::stack<TString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push("g.cameraPosition.xyz");
return ShaderNode::build(code, stack, link, depth, type);
}
Expand All @@ -33,7 +33,7 @@ class CameraDirection : public ShaderNode {
m_outputs.push_back(std::make_pair("Output", MetaType::VECTOR3));
}

int32_t build(QString &code, QStack<QString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
int32_t build(TString &code, std::stack<TString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push("g.cameraTarget.xyz");
return ShaderNode::build(code, stack, link, depth, type);
}
Expand All @@ -55,15 +55,15 @@ class ScreenSize : public ShaderNode {
m_outputs.push_back(std::make_pair("1/Height", MetaType::FLOAT));
}

int32_t build(QString &code, QStack<QString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
int32_t build(TString &code, std::stack<TString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
if(link.oport->m_name == "Width") {
stack.append("g.cameraScreen.x");
stack.push("g.cameraScreen.x");
} else if(link.oport->m_name == "Height") {
stack.append("g.cameraScreen.y");
stack.push("g.cameraScreen.y");
} else if(link.oport->m_name == "1/Width") {
stack.append("g.cameraScreen.z");
stack.push("g.cameraScreen.z");
} else if(link.oport->m_name == "1/Height") {
stack.append("g.cameraScreen.w");
stack.push("g.cameraScreen.w");
}

return ShaderNode::build(code, stack, link, depth, type);
Expand All @@ -89,21 +89,21 @@ class ScreenPosition : public ShaderNode {
m_outputs.push_back(std::make_pair(w, MetaType::FLOAT));
}

int32_t build(QString &code, QStack<QString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
int32_t build(TString &code, std::stack<TString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
if(m_position == -1) {
code += QString("\tvec4 local%1 = gl_FragCoord").arg(depth) + (m_normalized ? " / g.cameraScreen;\n" : ";\n");
code += TString("\tvec4 local%1 = gl_FragCoord").arg(TString::number(depth)) + (m_normalized ? " / g.cameraScreen;\n" : ";\n");
}

int32_t result = ShaderNode::build(code, stack, link, depth, type);

if(link.oport->m_name == x) {
stack.append(convert("local" + QString::number(m_position), MetaType::VECTOR4, MetaType::FLOAT, 0));
stack.push(convert(TString("local") + TString::number(m_position), MetaType::VECTOR4, MetaType::FLOAT, 0));
} else if(link.oport->m_name == y) {
stack.append(convert("local" + QString::number(m_position), MetaType::VECTOR4, MetaType::FLOAT, 1));
stack.push(convert(TString("local") + TString::number(m_position), MetaType::VECTOR4, MetaType::FLOAT, 1));
} else if(link.oport->m_name == z) {
stack.append(convert("local" + QString::number(m_position), MetaType::VECTOR4, MetaType::FLOAT, 2));
stack.push(convert(TString("local") + TString::number(m_position), MetaType::VECTOR4, MetaType::FLOAT, 2));
} else if(link.oport->m_name == w) {
stack.append(convert("local" + QString::number(m_position), MetaType::VECTOR4, MetaType::FLOAT, 3));
stack.push(convert(TString("local") + TString::number(m_position), MetaType::VECTOR4, MetaType::FLOAT, 3));
}

return result;
Expand Down Expand Up @@ -138,7 +138,7 @@ class ProjectionMatrix : public ShaderNode {
m_outputs.push_back(std::make_pair("Output", MetaType::MATRIX4));
}

int32_t build(QString &code, QStack<QString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
int32_t build(TString &code, std::stack<TString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
if(m_inverted) {
stack.push("g.cameraProjectionInv");
} else {
Expand Down
40 changes: 21 additions & 19 deletions modules/editor/shadertools/converter/functions/constvalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ConstPi : public ShaderNode {
setName("PI");
}

int32_t build(QString &code, QStack<QString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
int32_t build(TString &code, std::stack<TString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push("3.141592653589793");
return ShaderNode::build(code, stack, link, depth, type);
}
Expand All @@ -37,7 +37,7 @@ class ConstEuler : public ShaderNode {
setName("Euler");
}

int32_t build(QString &code, QStack<QString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
int32_t build(TString &code, std::stack<TString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push("2.718281828459045");
return ShaderNode::build(code, stack, link, depth, type);
}
Expand All @@ -57,7 +57,7 @@ class ConstGoldenRatio : public ShaderNode {
setName("GoldenRatio");
}

int32_t build(QString &code, QStack<QString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
int32_t build(TString &code, std::stack<TString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push("1.618033988749895");
return ShaderNode::build(code, stack, link, depth, type);
}
Expand Down Expand Up @@ -89,8 +89,8 @@ class ConstFloat : public ShaderNode {
m_value = value;
}

int32_t build(QString &code, QStack<QString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push(QString::number(m_value));
int32_t build(TString &code, std::stack<TString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push(TString::number(m_value));
return ShaderNode::build(code, stack, link, depth, type);
}

Expand Down Expand Up @@ -125,8 +125,8 @@ class ConstInt : public ShaderNode {
m_value = value;
}

int32_t build(QString &code, QStack<QString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push(QString::number(m_value));
int32_t build(TString &code, std::stack<TString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push(TString::number(m_value));
return ShaderNode::build(code, stack, link, depth, type);
}

Expand Down Expand Up @@ -159,8 +159,8 @@ class ConstVector2 : public ShaderNode {
m_value = value;
}

int32_t build(QString &code, QStack<QString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push(QString("vec2(%1, %2)").arg(m_value.x).arg(m_value.y));
int32_t build(TString &code, std::stack<TString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push(TString("vec2(%1, %2)").arg(TString::number(m_value.x), TString::number(m_value.y)));
return ShaderNode::build(code, stack, link, depth, type);
}

Expand Down Expand Up @@ -193,8 +193,8 @@ class ConstVector3 : public ShaderNode {
m_value = value;
}

int32_t build(QString &code, QStack<QString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push(QString("vec3(%1, %2, %3)").arg(m_value.x).arg(m_value.y).arg(m_value.z));
int32_t build(TString &code, std::stack<TString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push(TString("vec3(%1, %2, %3)").arg(TString::number(m_value.x), TString::number(m_value.y), TString::number(m_value.z)));
return ShaderNode::build(code, stack, link, depth, type);
}

Expand Down Expand Up @@ -229,8 +229,9 @@ class ConstVector4 : public ShaderNode {
m_value = value;
}

int32_t build(QString &code, QStack<QString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push(QString("vec4(%1, %2, %3, %4)").arg(m_value.x).arg(m_value.y).arg(m_value.z).arg(m_value.w));
int32_t build(TString &code, std::stack<TString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push(TString("vec4(%1, %2, %3, %4)").arg(TString::number(m_value.x), TString::number(m_value.y),
TString::number(m_value.z), TString::number(m_value.w)));
return ShaderNode::build(code, stack, link, depth, type);
}

Expand Down Expand Up @@ -265,8 +266,9 @@ class ConstColor : public ShaderNode {
m_value = value;
}

int32_t build(QString &code, QStack<QString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push(QString("vec4(%1, %2, %3, %4)").arg(m_value.x).arg(m_value.y).arg(m_value.z).arg(m_value.w));
int32_t build(TString &code, std::stack<TString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push(TString("vec4(%1, %2, %3, %4)").arg(TString::number(m_value.x), TString::number(m_value.y),
TString::number(m_value.z), TString::number(m_value.w)));
return ShaderNode::build(code, stack, link, depth, type);
}

Expand Down Expand Up @@ -321,11 +323,11 @@ class ConstMatrix3 : public ShaderNode {
m_value2 = value;
}

int32_t build(QString &code, QStack<QString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
int32_t build(TString &code, std::stack<TString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push(QString("mat3(%1, %2, %3, %4, %5, %6, %7, %8, %9)")
.arg(m_value0.x).arg(m_value0.y).arg(m_value0.z)
.arg(m_value1.x).arg(m_value1.y).arg(m_value1.z)
.arg(m_value2.x).arg(m_value2.y).arg(m_value2.z));
.arg(m_value2.x).arg(m_value2.y).arg(m_value2.z).toStdString());

return ShaderNode::build(code, stack, link, depth, type);
}
Expand Down Expand Up @@ -393,12 +395,12 @@ class ConstMatrix4 : public ShaderNode {
m_value3 = value;
}

int32_t build(QString &code, QStack<QString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
int32_t build(TString &code, std::stack<TString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push(QString("mat4(%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12, %13, %14, %15, %16)")
.arg(m_value0.x).arg(m_value0.y).arg(m_value0.z).arg(m_value0.w)
.arg(m_value1.x).arg(m_value1.y).arg(m_value1.z).arg(m_value1.w)
.arg(m_value2.x).arg(m_value2.y).arg(m_value2.z).arg(m_value2.w)
.arg(m_value3.x).arg(m_value3.y).arg(m_value3.z).arg(m_value3.w));
.arg(m_value3.x).arg(m_value3.y).arg(m_value3.z).arg(m_value3.w).toStdString());

return ShaderNode::build(code, stack, link, depth, type);
}
Expand Down
20 changes: 10 additions & 10 deletions modules/editor/shadertools/converter/functions/coordinates.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class ProjectionCoord : public ShaderNode {
m_outputs.push_back(std::make_pair("Output", MetaType::VECTOR3));
}

int32_t build(QString &code, QStack<QString> &stack,const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
int32_t build(TString &code, std::stack<TString> &stack,const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
if(m_position == -1) {
code += QString("\tvec3 local%1 = (0.5 *( _vertex.xyz / _vertex.w ) + 0.5);\n").arg(depth);
code += TString("\tvec3 local%1 = (0.5 *( _vertex.xyz / _vertex.w ) + 0.5);\n").arg(TString::number(depth));
}
return ShaderNode::build(code, stack, link, depth, type);
}
Expand All @@ -41,8 +41,8 @@ class TexCoord : public ShaderNode {
m_outputs.push_back(std::make_pair("Output", MetaType::VECTOR2));
}

int32_t build(QString &code, QStack<QString> &stack,const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push(QString("_uv%1").arg(m_index));
int32_t build(TString &code, std::stack<TString> &stack,const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
stack.push(TString("_uv%1").arg(TString::number((int)m_index)));

return ShaderNode::build(code, stack, link, depth, type);
}
Expand Down Expand Up @@ -72,14 +72,14 @@ class CoordPanner : public ShaderNode {
m_outputs.push_back(std::make_pair("Output", MetaType::VECTOR2));
}

int32_t build(QString &code, QStack<QString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
int32_t build(TString &code, std::stack<TString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
if(m_position == -1) {
QStringList args = getArguments(code, stack, depth, type);
if(!args.isEmpty()) {
QString value = args[0];
value.append(QString(" + vec2(%1, %2) * g.time").arg(QString::number(m_speed.x), QString::number(m_speed.y)));
std::vector<TString> args = getArguments(code, stack, depth, type);
if(!args.empty()) {
TString value = args[0];
value.append(TString(" + vec2(%1, %2) * g.time").arg(TString::number(m_speed.x), TString::number(m_speed.y)));

code.append(QString("\tvec2 local%1 = %2;\n").arg(QString::number(depth), value));
code.append(TString("\tvec2 local%1 = %2;\n").arg(TString::number(depth), value));
} else {
reportMessage(TString("Missing argument ") + UV);
return m_position;
Expand Down
21 changes: 11 additions & 10 deletions modules/editor/shadertools/converter/functions/customfunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ class CustomFunction : public ShaderNode {
void exposeFunction(const TString &path) {
QFile file(path.data());
if(file.open(QFile::ReadOnly | QFile::Text)) {
QByteArray byteData = file.readAll();
pugi::xml_document doc;
if(doc.load_string(file.readAll().data()).status == pugi::status_ok) {
if(doc.load_string(byteData.data()).status == pugi::status_ok) {
pugi::xml_node function = doc.document_element();

m_funcName = Url(function.attribute("name").as_string()).baseName();
Expand Down Expand Up @@ -111,19 +112,19 @@ class CustomFunction : public ShaderNode {
return Variant();
}

int32_t build(QString &code, QStack<QString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
int32_t build(TString &code, std::stack<TString> &stack, const AbstractNodeGraph::Link &link, int32_t &depth, int32_t &type) override {
if(m_position == -1) {
if(!m_func.isEmpty()) {
static_cast<ShaderGraph *>(m_graph)->addFragmentFunction(m_funcName, m_func);

int l_type = 0;
QStringList arguments = getArguments(code, stack, depth, l_type);
std::vector<TString> args = getArguments(code, stack, depth, l_type);

if(link.oport->m_type != MetaType::INVALID) {
type = link.oport->m_type;
}

QString expr = QString("%1(%2)").arg(m_funcName.data(), arguments.join(", "));
TString expr = TString("%1(%2)").arg(m_funcName, TString::join(StringList(args.begin(), args.end()), ", "));
if(m_graph->isSingleConnection(link.oport)) {
stack.push(expr);
} else {
Expand All @@ -135,7 +136,7 @@ class CustomFunction : public ShaderNode {
return ShaderNode::build(code, stack, link, depth, type);
}

QString defaultValue(const TString &key, uint32_t &type) const override {
TString defaultValue(const TString &key, uint32_t &type) const override {
Variant value = property(key.data());

if(value.type() == MetaType::STRING) {
Expand All @@ -152,24 +153,24 @@ class CustomFunction : public ShaderNode {

switch(type) {
case MetaType::FLOAT: {
return QString::number(value.toFloat());
return TString::number(value.toFloat());
}
case MetaType::VECTOR2: {
Vector2 v = value.value<Vector2>();
return QString("vec2(%1, %2)").arg(v.x).arg(v.y);
return TString("vec2(%1, %2)").arg(TString::number(v.x), TString::number(v.y));
}
case MetaType::VECTOR3: {
Vector3 v = value.value<Vector3>();
return QString("vec3(%1, %2, %3)").arg(v.x).arg(v.y).arg(v.z);
return TString("vec3(%1, %2, %3)").arg(TString::number(v.x), TString::number(v.y), TString::number(v.z));
}
case MetaType::VECTOR4: {
Vector4 v = value.value<Vector4>();
return QString("vec4(%1, %2, %3, %4)").arg(v.x).arg(v.y).arg(v.z).arg(v.w);
return TString("vec4(%1, %2, %3, %4)").arg(TString::number(v.x), TString::number(v.y), TString::number(v.z), TString::number(v.w));
}
default: break;
}

return QString();
return TString();
}

protected:
Expand Down
Loading
Loading