Update ShaderNode
This commit is contained in:
@@ -7,14 +7,14 @@
|
||||
#include <ShaderNode/DataTypes/FloatData.hpp>
|
||||
#include <ShaderNode/DataTypes/VecData.hpp>
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
class BinOp : public ShaderNode
|
||||
{
|
||||
public:
|
||||
BinOp(ShaderGraph& graph);
|
||||
~BinOp() = default;
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
|
||||
virtual QString GetOperationString() const = 0;
|
||||
|
||||
@@ -45,40 +45,40 @@ class BinOp : public ShaderNode
|
||||
|
||||
|
||||
template<typename DataType>
|
||||
class BinAdd : public BinOp<DataType, Nz::ShaderNodes::BinaryType::Add>
|
||||
class BinAdd : public BinOp<DataType, Nz::ShaderAst::BinaryType::Add>
|
||||
{
|
||||
public:
|
||||
using BinOp<DataType, Nz::ShaderNodes::BinaryType::Add>::BinOp;
|
||||
using BinOp<DataType, Nz::ShaderAst::BinaryType::Add>::BinOp;
|
||||
|
||||
void ApplyOp(const Nz::Vector4f* left, const Nz::Vector4f* right, Nz::Vector4f* output, std::size_t pixelCount) override;
|
||||
QString GetOperationString() const final;
|
||||
};
|
||||
|
||||
template<typename DataType>
|
||||
class BinMul : public BinOp<DataType, Nz::ShaderNodes::BinaryType::Multiply>
|
||||
class BinMul : public BinOp<DataType, Nz::ShaderAst::BinaryType::Multiply>
|
||||
{
|
||||
public:
|
||||
using BinOp<DataType, Nz::ShaderNodes::BinaryType::Multiply>::BinOp;
|
||||
using BinOp<DataType, Nz::ShaderAst::BinaryType::Multiply>::BinOp;
|
||||
|
||||
void ApplyOp(const Nz::Vector4f* left, const Nz::Vector4f* right, Nz::Vector4f* output, std::size_t pixelCount) override;
|
||||
QString GetOperationString() const final;
|
||||
};
|
||||
|
||||
template<typename DataType>
|
||||
class BinSub : public BinOp<DataType, Nz::ShaderNodes::BinaryType::Subtract>
|
||||
class BinSub : public BinOp<DataType, Nz::ShaderAst::BinaryType::Subtract>
|
||||
{
|
||||
public:
|
||||
using BinOp<DataType, Nz::ShaderNodes::BinaryType::Subtract>::BinOp;
|
||||
using BinOp<DataType, Nz::ShaderAst::BinaryType::Subtract>::BinOp;
|
||||
|
||||
void ApplyOp(const Nz::Vector4f* left, const Nz::Vector4f* right, Nz::Vector4f* output, std::size_t pixelCount) override;
|
||||
QString GetOperationString() const final;
|
||||
};
|
||||
|
||||
template<typename DataType>
|
||||
class BinDiv : public BinOp<DataType, Nz::ShaderNodes::BinaryType::Divide>
|
||||
class BinDiv : public BinOp<DataType, Nz::ShaderAst::BinaryType::Divide>
|
||||
{
|
||||
public:
|
||||
using BinOp<DataType, Nz::ShaderNodes::BinaryType::Divide>::BinOp;
|
||||
using BinOp<DataType, Nz::ShaderAst::BinaryType::Divide>::BinOp;
|
||||
|
||||
void ApplyOp(const Nz::Vector4f* left, const Nz::Vector4f* right, Nz::Vector4f* output, std::size_t pixelCount) override;
|
||||
QString GetOperationString() const final;
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
#include <ShaderNode/DataModels/BinOp.hpp>
|
||||
#include <Nazara/Shader/ShaderBuilder.hpp>
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
BinOp<DataType, Op>::BinOp(ShaderGraph& graph) :
|
||||
ShaderNode(graph)
|
||||
{
|
||||
UpdateOutput();
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
Nz::ShaderNodes::NodePtr BinOp<DataType, Op>::BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
Nz::ShaderAst::NodePtr BinOp<DataType, Op>::BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
assert(count == 2);
|
||||
assert(outputIndex == 0);
|
||||
|
||||
using BuilderType = typename Nz::ShaderBuilder::template BinOpBuilder<Op>;
|
||||
constexpr BuilderType builder;
|
||||
return builder(expressions[0], expressions[1]);
|
||||
return Nz::ShaderBuilder::Binary(Op, std::move(expressions[0]), std::move(expressions[1]));
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
QtNodes::NodeDataType BinOp<DataType, Op>::dataType(QtNodes::PortType /*portType*/, QtNodes::PortIndex portIndex) const
|
||||
{
|
||||
assert(portIndex == 0 || portIndex == 1);
|
||||
@@ -27,7 +25,7 @@ QtNodes::NodeDataType BinOp<DataType, Op>::dataType(QtNodes::PortType /*portType
|
||||
return DataType::Type();
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
unsigned int BinOp<DataType, Op>::nPorts(QtNodes::PortType portType) const
|
||||
{
|
||||
switch (portType)
|
||||
@@ -41,14 +39,14 @@ unsigned int BinOp<DataType, Op>::nPorts(QtNodes::PortType portType) const
|
||||
throw std::runtime_error("invalid port type");
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
std::shared_ptr<QtNodes::NodeData> BinOp<DataType, Op>::outData(QtNodes::PortIndex port)
|
||||
{
|
||||
assert(port == 0);
|
||||
return m_output;
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
QString BinOp<DataType, Op>::portCaption(QtNodes::PortType portType, QtNodes::PortIndex portIndex) const
|
||||
{
|
||||
switch (portType)
|
||||
@@ -81,14 +79,14 @@ QString BinOp<DataType, Op>::portCaption(QtNodes::PortType portType, QtNodes::Po
|
||||
return QString{};
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
bool BinOp<DataType, Op>::portCaptionVisible(QtNodes::PortType portType, QtNodes::PortIndex portIndex) const
|
||||
{
|
||||
assert(portIndex == 0 || portIndex == 1);
|
||||
return portType == QtNodes::PortType::In || portType == QtNodes::PortType::Out;
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
void BinOp<DataType, Op>::setInData(std::shared_ptr<QtNodes::NodeData> value, int index)
|
||||
{
|
||||
assert(index == 0 || index == 1);
|
||||
@@ -105,7 +103,7 @@ void BinOp<DataType, Op>::setInData(std::shared_ptr<QtNodes::NodeData> value, in
|
||||
UpdateOutput();
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
QtNodes::NodeValidationState BinOp<DataType, Op>::validationState() const
|
||||
{
|
||||
if (!m_lhs || !m_rhs)
|
||||
@@ -120,7 +118,7 @@ QtNodes::NodeValidationState BinOp<DataType, Op>::validationState() const
|
||||
return QtNodes::NodeValidationState::Valid;
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
QString BinOp<DataType, Op>::validationMessage() const
|
||||
{
|
||||
if (!m_lhs || !m_rhs)
|
||||
@@ -135,7 +133,7 @@ QString BinOp<DataType, Op>::validationMessage() const
|
||||
return QString();
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
bool BinOp<DataType, Op>::ComputePreview(QPixmap& pixmap)
|
||||
{
|
||||
if (!m_lhs || !m_rhs)
|
||||
@@ -145,7 +143,7 @@ bool BinOp<DataType, Op>::ComputePreview(QPixmap& pixmap)
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
void BinOp<DataType, Op>::UpdateOutput()
|
||||
{
|
||||
if (validationState() != QtNodes::NodeValidationState::Valid)
|
||||
|
||||
@@ -89,7 +89,7 @@ void BoolValue::BuildNodeEdition(QFormLayout* layout)
|
||||
layout->addRow(tr("Value"), checkbox);
|
||||
}
|
||||
|
||||
Nz::ShaderNodes::NodePtr BoolValue::BuildNode(Nz::ShaderNodes::ExpressionPtr* /*expressions*/, std::size_t count, std::size_t outputIndex) const
|
||||
Nz::ShaderAst::NodePtr BoolValue::BuildNode(Nz::ShaderAst::ExpressionPtr* /*expressions*/, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
assert(count == 0);
|
||||
assert(outputIndex == 0);
|
||||
|
||||
@@ -17,7 +17,7 @@ class BoolValue : public ShaderNode
|
||||
BoolValue(ShaderGraph& graph);
|
||||
~BoolValue() = default;
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
void BuildNodeEdition(QFormLayout* layout) override;
|
||||
|
||||
QString caption() const override;
|
||||
|
||||
@@ -49,7 +49,7 @@ ShaderNode(graph)
|
||||
UpdatePreview();
|
||||
}
|
||||
|
||||
Nz::ShaderNodes::NodePtr BufferField::BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
Nz::ShaderAst::NodePtr BufferField::BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
assert(count == 0);
|
||||
assert(outputIndex == 0);
|
||||
@@ -62,23 +62,13 @@ Nz::ShaderNodes::NodePtr BufferField::BuildNode(Nz::ShaderNodes::ExpressionPtr*
|
||||
const auto& bufferEntry = graph.GetBuffer(*m_currentBufferIndex);
|
||||
const auto& structEntry = graph.GetStruct(bufferEntry.structIndex);
|
||||
|
||||
Nz::ShaderNodes::VariablePtr varPtr;
|
||||
switch (bufferEntry.type)
|
||||
{
|
||||
case BufferType::UniformBufferObject:
|
||||
varPtr = Nz::ShaderBuilder::Uniform(bufferEntry.name, structEntry.name);
|
||||
break;
|
||||
}
|
||||
|
||||
assert(varPtr);
|
||||
|
||||
assert(m_currentFieldIndex);
|
||||
const CurrentField& currentField = *m_currentFieldIndex;
|
||||
|
||||
Nz::ShaderNodes::ExpressionPtr sourceExpr = Nz::ShaderBuilder::Identifier(varPtr);
|
||||
Nz::ShaderAst::ExpressionPtr sourceExpr = Nz::ShaderBuilder::Identifier(bufferEntry.name);
|
||||
|
||||
std::vector<std::size_t> memberIndices;
|
||||
memberIndices.reserve(currentField.nestedFields.size() + 1);
|
||||
std::vector<std::string> memberIdentifiers;
|
||||
memberIdentifiers.reserve(currentField.nestedFields.size() + 1);
|
||||
|
||||
const ShaderGraph::StructEntry* sourceStruct = &structEntry;
|
||||
for (std::size_t nestedIndex : currentField.nestedFields)
|
||||
@@ -90,16 +80,17 @@ Nz::ShaderNodes::NodePtr BufferField::BuildNode(Nz::ShaderNodes::ExpressionPtr*
|
||||
std::size_t nestedStructIndex = std::get<std::size_t>(memberEntry.type);
|
||||
sourceStruct = &graph.GetStruct(nestedStructIndex);
|
||||
|
||||
memberIndices.push_back(nestedIndex);
|
||||
memberIdentifiers.push_back(memberEntry.name);
|
||||
}
|
||||
|
||||
memberIndices.push_back(currentField.finalFieldIndex);
|
||||
|
||||
assert(currentField.finalFieldIndex < sourceStruct->members.size());
|
||||
const auto& memberEntry = sourceStruct->members[currentField.finalFieldIndex];
|
||||
assert(std::holds_alternative<PrimitiveType>(memberEntry.type));
|
||||
|
||||
return Nz::ShaderBuilder::AccessMember(std::move(sourceExpr), std::move(memberIndices), graph.ToShaderExpressionType(std::get<PrimitiveType>(memberEntry.type)));
|
||||
memberIdentifiers.push_back(memberEntry.name);
|
||||
|
||||
using namespace Nz;
|
||||
return ShaderBuilder::AccessMember(std::move(sourceExpr), std::move(memberIdentifiers));
|
||||
}
|
||||
|
||||
unsigned int BufferField::nPorts(QtNodes::PortType portType) const
|
||||
|
||||
@@ -15,7 +15,7 @@ class BufferField : public ShaderNode
|
||||
BufferField(ShaderGraph& graph);
|
||||
~BufferField() = default;
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
void BuildNodeEdition(QFormLayout* layout) override;
|
||||
|
||||
QString caption() const override { return "BufferField"; }
|
||||
|
||||
@@ -17,7 +17,7 @@ class CastVec : public ShaderNode
|
||||
CastVec(ShaderGraph& graph);
|
||||
~CastVec() = default;
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const;
|
||||
void BuildNodeEdition(QFormLayout* layout) override;
|
||||
|
||||
QString caption() const override;
|
||||
|
||||
@@ -18,7 +18,7 @@ ShaderNode(graph)
|
||||
}
|
||||
|
||||
template<std::size_t ToComponentCount>
|
||||
Nz::ShaderNodes::NodePtr CastVec<ToComponentCount>::BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
Nz::ShaderAst::NodePtr CastVec<ToComponentCount>::BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
assert(m_input);
|
||||
assert(count == 1);
|
||||
@@ -30,29 +30,27 @@ Nz::ShaderNodes::NodePtr CastVec<ToComponentCount>::BuildNode(Nz::ShaderNodes::E
|
||||
{
|
||||
std::size_t overflowComponentCount = ToComponentCount - fromComponentCount;
|
||||
|
||||
std::array<Nz::ShaderNodes::ExpressionPtr, 4> expr;
|
||||
expr[0] = expressions[0];
|
||||
std::vector<Nz::ShaderAst::ExpressionPtr> params;
|
||||
params.emplace_back(std::move(params[0]));
|
||||
for (std::size_t i = 0; i < overflowComponentCount; ++i)
|
||||
expr[i + 1] = Nz::ShaderBuilder::Constant(m_overflowComponents[i]);
|
||||
params.emplace_back(Nz::ShaderBuilder::Constant(m_overflowComponents[i]));
|
||||
|
||||
constexpr auto ExpressionType = VecExpressionType<ToComponentCount>;
|
||||
|
||||
return Nz::ShaderBuilder::Cast<ExpressionType>(expr.data(), 1 + overflowComponentCount);
|
||||
return Nz::ShaderBuilder::Cast(Nz::ShaderAst::VectorType{ ToComponentCount, Nz::ShaderAst::PrimitiveType::Float32 }, std::move(params));
|
||||
}
|
||||
else if (ToComponentCount < fromComponentCount)
|
||||
{
|
||||
std::array<Nz::ShaderNodes::SwizzleComponent, ToComponentCount> swizzleComponents;
|
||||
std::array<Nz::ShaderAst::SwizzleComponent, ToComponentCount> swizzleComponents;
|
||||
for (std::size_t i = 0; i < ToComponentCount; ++i)
|
||||
swizzleComponents[i] = static_cast<Nz::ShaderNodes::SwizzleComponent>(static_cast<std::size_t>(Nz::ShaderNodes::SwizzleComponent::First) + i);
|
||||
swizzleComponents[i] = static_cast<Nz::ShaderAst::SwizzleComponent>(static_cast<std::size_t>(Nz::ShaderAst::SwizzleComponent::First) + i);
|
||||
|
||||
return std::apply([&](auto... components)
|
||||
{
|
||||
std::initializer_list<Nz::ShaderNodes::SwizzleComponent> componentList{ components... };
|
||||
return Nz::ShaderBuilder::Swizzle(expressions[0], componentList);
|
||||
}, swizzleComponents);
|
||||
{
|
||||
std::initializer_list<Nz::ShaderAst::SwizzleComponent> componentList{ components... };
|
||||
return Nz::ShaderBuilder::Swizzle(std::move(expressions[0]), componentList);
|
||||
}, swizzleComponents);
|
||||
}
|
||||
else
|
||||
return expressions[0]; //< no-op
|
||||
return std::move(expressions[0]); //< no-op
|
||||
}
|
||||
|
||||
template<std::size_t ToComponentCount>
|
||||
@@ -110,6 +108,7 @@ QtNodes::NodeDataType CastVec<ToComponentCount>::dataType(QtNodes::PortType port
|
||||
{
|
||||
case QtNodes::PortType::In: return VecData::Type();
|
||||
case QtNodes::PortType::Out: return VecData::Type();
|
||||
default: break;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
#include <ShaderNode/DataTypes/FloatData.hpp>
|
||||
#include <ShaderNode/DataTypes/VecData.hpp>
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
class CompOp : public ShaderNode
|
||||
{
|
||||
public:
|
||||
CompOp(ShaderGraph& graph);
|
||||
~CompOp() = default;
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
|
||||
virtual QString GetOperationString() const = 0;
|
||||
|
||||
@@ -46,60 +46,60 @@ class CompOp : public ShaderNode
|
||||
|
||||
|
||||
template<typename DataType>
|
||||
class CompEq : public CompOp<DataType, Nz::ShaderNodes::BinaryType::CompEq>
|
||||
class CompEq : public CompOp<DataType, Nz::ShaderAst::BinaryType::CompEq>
|
||||
{
|
||||
public:
|
||||
using CompOp<DataType, Nz::ShaderNodes::BinaryType::CompEq>::CompOp;
|
||||
using CompOp<DataType, Nz::ShaderAst::BinaryType::CompEq>::CompOp;
|
||||
|
||||
void ApplyOp(const Nz::Vector4f* left, const Nz::Vector4f* right, Nz::Vector4f* output, std::size_t pixelCount) override;
|
||||
QString GetOperationString() const final;
|
||||
};
|
||||
|
||||
template<typename DataType>
|
||||
class CompGe : public CompOp<DataType, Nz::ShaderNodes::BinaryType::CompGe>
|
||||
class CompGe : public CompOp<DataType, Nz::ShaderAst::BinaryType::CompGe>
|
||||
{
|
||||
public:
|
||||
using CompOp<DataType, Nz::ShaderNodes::BinaryType::CompGe>::CompOp;
|
||||
using CompOp<DataType, Nz::ShaderAst::BinaryType::CompGe>::CompOp;
|
||||
|
||||
void ApplyOp(const Nz::Vector4f* left, const Nz::Vector4f* right, Nz::Vector4f* output, std::size_t pixelCount) override;
|
||||
QString GetOperationString() const final;
|
||||
};
|
||||
|
||||
template<typename DataType>
|
||||
class CompGt : public CompOp<DataType, Nz::ShaderNodes::BinaryType::CompGt>
|
||||
class CompGt : public CompOp<DataType, Nz::ShaderAst::BinaryType::CompGt>
|
||||
{
|
||||
public:
|
||||
using CompOp<DataType, Nz::ShaderNodes::BinaryType::CompGt>::CompOp;
|
||||
using CompOp<DataType, Nz::ShaderAst::BinaryType::CompGt>::CompOp;
|
||||
|
||||
void ApplyOp(const Nz::Vector4f* left, const Nz::Vector4f* right, Nz::Vector4f* output, std::size_t pixelCount) override;
|
||||
QString GetOperationString() const final;
|
||||
};
|
||||
|
||||
template<typename DataType>
|
||||
class CompLe : public CompOp<DataType, Nz::ShaderNodes::BinaryType::CompLe>
|
||||
class CompLe : public CompOp<DataType, Nz::ShaderAst::BinaryType::CompLe>
|
||||
{
|
||||
public:
|
||||
using CompOp<DataType, Nz::ShaderNodes::BinaryType::CompLe>::CompOp;
|
||||
using CompOp<DataType, Nz::ShaderAst::BinaryType::CompLe>::CompOp;
|
||||
|
||||
void ApplyOp(const Nz::Vector4f* left, const Nz::Vector4f* right, Nz::Vector4f* output, std::size_t pixelCount) override;
|
||||
QString GetOperationString() const final;
|
||||
};
|
||||
|
||||
template<typename DataType>
|
||||
class CompLt : public CompOp<DataType, Nz::ShaderNodes::BinaryType::CompLt>
|
||||
class CompLt : public CompOp<DataType, Nz::ShaderAst::BinaryType::CompLt>
|
||||
{
|
||||
public:
|
||||
using CompOp<DataType, Nz::ShaderNodes::BinaryType::CompLt>::CompOp;
|
||||
using CompOp<DataType, Nz::ShaderAst::BinaryType::CompLt>::CompOp;
|
||||
|
||||
void ApplyOp(const Nz::Vector4f* left, const Nz::Vector4f* right, Nz::Vector4f* output, std::size_t pixelCount) override;
|
||||
QString GetOperationString() const final;
|
||||
};
|
||||
|
||||
template<typename DataType>
|
||||
class CompNe : public CompOp<DataType, Nz::ShaderNodes::BinaryType::CompNe>
|
||||
class CompNe : public CompOp<DataType, Nz::ShaderAst::BinaryType::CompNe>
|
||||
{
|
||||
public:
|
||||
using CompOp<DataType, Nz::ShaderNodes::BinaryType::CompNe>::CompOp;
|
||||
using CompOp<DataType, Nz::ShaderAst::BinaryType::CompNe>::CompOp;
|
||||
|
||||
void ApplyOp(const Nz::Vector4f* left, const Nz::Vector4f* right, Nz::Vector4f* output, std::size_t pixelCount) override;
|
||||
QString GetOperationString() const final;
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
#include <ShaderNode/DataModels/CompOp.hpp>
|
||||
#include <Nazara/Shader/ShaderBuilder.hpp>
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
CompOp<DataType, Op>::CompOp(ShaderGraph& graph) :
|
||||
ShaderNode(graph)
|
||||
{
|
||||
UpdateOutput();
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
Nz::ShaderNodes::NodePtr CompOp<DataType, Op>::BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
Nz::ShaderAst::NodePtr CompOp<DataType, Op>::BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
assert(count == 2);
|
||||
assert(outputIndex == 0);
|
||||
|
||||
using BuilderType = typename Nz::ShaderBuilder::template BinOpBuilder<Op>;
|
||||
constexpr BuilderType builder;
|
||||
return builder(expressions[0], expressions[1]);
|
||||
return Nz::ShaderBuilder::Binary(Op, std::move(expressions[0]), std::move(expressions[1]));
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
QtNodes::NodeDataType CompOp<DataType, Op>::dataType(QtNodes::PortType portType, QtNodes::PortIndex portIndex) const
|
||||
{
|
||||
switch (portType)
|
||||
@@ -43,7 +41,7 @@ QtNodes::NodeDataType CompOp<DataType, Op>::dataType(QtNodes::PortType portType,
|
||||
throw std::runtime_error("invalid port type");
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
unsigned int CompOp<DataType, Op>::nPorts(QtNodes::PortType portType) const
|
||||
{
|
||||
switch (portType)
|
||||
@@ -57,14 +55,14 @@ unsigned int CompOp<DataType, Op>::nPorts(QtNodes::PortType portType) const
|
||||
throw std::runtime_error("invalid port type");
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
std::shared_ptr<QtNodes::NodeData> CompOp<DataType, Op>::outData(QtNodes::PortIndex port)
|
||||
{
|
||||
assert(port == 0);
|
||||
return m_output;
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
QString CompOp<DataType, Op>::portCaption(QtNodes::PortType portType, QtNodes::PortIndex portIndex) const
|
||||
{
|
||||
switch (portType)
|
||||
@@ -97,14 +95,14 @@ QString CompOp<DataType, Op>::portCaption(QtNodes::PortType portType, QtNodes::P
|
||||
return QString{};
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
bool CompOp<DataType, Op>::portCaptionVisible(QtNodes::PortType portType, QtNodes::PortIndex portIndex) const
|
||||
{
|
||||
assert(portIndex == 0 || portIndex == 1);
|
||||
return portType == QtNodes::PortType::In || portType == QtNodes::PortType::Out;
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
void CompOp<DataType, Op>::setInData(std::shared_ptr<QtNodes::NodeData> value, int index)
|
||||
{
|
||||
assert(index == 0 || index == 1);
|
||||
@@ -121,7 +119,7 @@ void CompOp<DataType, Op>::setInData(std::shared_ptr<QtNodes::NodeData> value, i
|
||||
UpdateOutput();
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
QtNodes::NodeValidationState CompOp<DataType, Op>::validationState() const
|
||||
{
|
||||
if (!m_lhs || !m_rhs)
|
||||
@@ -136,7 +134,7 @@ QtNodes::NodeValidationState CompOp<DataType, Op>::validationState() const
|
||||
return QtNodes::NodeValidationState::Valid;
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
QString CompOp<DataType, Op>::validationMessage() const
|
||||
{
|
||||
if (!m_lhs || !m_rhs)
|
||||
@@ -151,7 +149,7 @@ QString CompOp<DataType, Op>::validationMessage() const
|
||||
return QString();
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
bool CompOp<DataType, Op>::ComputePreview(QPixmap& pixmap)
|
||||
{
|
||||
if (!m_lhs || !m_rhs)
|
||||
@@ -161,7 +159,7 @@ bool CompOp<DataType, Op>::ComputePreview(QPixmap& pixmap)
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename DataType, Nz::ShaderNodes::BinaryType Op>
|
||||
template<typename DataType, Nz::ShaderAst::BinaryType Op>
|
||||
void CompOp<DataType, Op>::UpdateOutput()
|
||||
{
|
||||
if (validationState() != QtNodes::NodeValidationState::Valid)
|
||||
|
||||
@@ -35,7 +35,7 @@ ShaderNode(graph)
|
||||
UpdatePreview();
|
||||
}
|
||||
|
||||
Nz::ShaderNodes::NodePtr ConditionalExpression::BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
Nz::ShaderAst::NodePtr ConditionalExpression::BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
assert(count == 2);
|
||||
assert(outputIndex == 0);
|
||||
@@ -46,7 +46,7 @@ Nz::ShaderNodes::NodePtr ConditionalExpression::BuildNode(Nz::ShaderNodes::Expre
|
||||
const ShaderGraph& graph = GetGraph();
|
||||
|
||||
const auto& conditionEntry = graph.GetCondition(*m_currentConditionIndex);
|
||||
return Nz::ShaderBuilder::ConditionalExpression(conditionEntry.name, expressions[0], expressions[1]);
|
||||
return Nz::ShaderBuilder::ConditionalExpression(conditionEntry.name, std::move(expressions[0]), std::move(expressions[1]));
|
||||
}
|
||||
|
||||
QString ConditionalExpression::caption() const
|
||||
|
||||
@@ -15,7 +15,7 @@ class ConditionalExpression : public ShaderNode
|
||||
ConditionalExpression(ShaderGraph& graph);
|
||||
~ConditionalExpression() = default;
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
void BuildNodeEdition(QFormLayout* layout) override;
|
||||
|
||||
QString caption() const override;
|
||||
|
||||
@@ -16,14 +16,15 @@ ShaderNode(graph)
|
||||
DisableCustomVariableName();
|
||||
}
|
||||
|
||||
Nz::ShaderNodes::NodePtr Discard::BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
Nz::ShaderAst::NodePtr Discard::BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
using namespace Nz::ShaderBuilder;
|
||||
|
||||
assert(count == 1);
|
||||
assert(outputIndex == 0);
|
||||
|
||||
return Branch(Equal(expressions[0], Constant(true)), Nz::ShaderBuilder::Discard(), nullptr);
|
||||
using namespace Nz;
|
||||
|
||||
auto condition = ShaderBuilder::Binary(ShaderAst::BinaryType::CompEq, std::move(expressions[0]), ShaderBuilder::Constant(true));
|
||||
return ShaderBuilder::Branch(std::move(condition), ShaderBuilder::Discard());
|
||||
}
|
||||
|
||||
int Discard::GetOutputOrder() const
|
||||
|
||||
@@ -14,7 +14,7 @@ class Discard : public ShaderNode
|
||||
public:
|
||||
Discard(ShaderGraph& graph);
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
int GetOutputOrder() const;
|
||||
|
||||
QString caption() const override { return "Discard"; }
|
||||
|
||||
@@ -89,7 +89,7 @@ void FloatValue::BuildNodeEdition(QFormLayout* layout)
|
||||
layout->addRow(tr("Value"), spinbox);
|
||||
}
|
||||
|
||||
Nz::ShaderNodes::NodePtr FloatValue::BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
Nz::ShaderAst::NodePtr FloatValue::BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
assert(count == 0);
|
||||
assert(outputIndex == 0);
|
||||
|
||||
@@ -17,7 +17,7 @@ class FloatValue : public ShaderNode
|
||||
FloatValue(ShaderGraph& graph);
|
||||
~FloatValue() = default;
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
void BuildNodeEdition(QFormLayout* layout) override;
|
||||
|
||||
QString caption() const override;
|
||||
|
||||
@@ -109,7 +109,7 @@ void InputValue::BuildNodeEdition(QFormLayout* layout)
|
||||
layout->addRow(tr("Input"), inputSelection);
|
||||
}
|
||||
|
||||
Nz::ShaderNodes::NodePtr InputValue::BuildNode(Nz::ShaderNodes::ExpressionPtr* /*expressions*/, std::size_t count, std::size_t outputIndex) const
|
||||
Nz::ShaderAst::NodePtr InputValue::BuildNode(Nz::ShaderAst::ExpressionPtr* /*expressions*/, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
assert(count == 0);
|
||||
assert(outputIndex == 0);
|
||||
@@ -118,7 +118,7 @@ Nz::ShaderNodes::NodePtr InputValue::BuildNode(Nz::ShaderNodes::ExpressionPtr* /
|
||||
throw std::runtime_error("no input");
|
||||
|
||||
const auto& inputEntry = GetGraph().GetInput(*m_currentInputIndex);
|
||||
return Nz::ShaderBuilder::Identifier(Nz::ShaderBuilder::Input(inputEntry.name, ShaderGraph::ToShaderExpressionType(inputEntry.type)));
|
||||
return Nz::ShaderBuilder::AccessMember(Nz::ShaderBuilder::Identifier("input"), { inputEntry.name });
|
||||
}
|
||||
|
||||
auto InputValue::dataType(QtNodes::PortType portType, QtNodes::PortIndex portIndex) const -> QtNodes::NodeDataType
|
||||
|
||||
@@ -19,7 +19,7 @@ class InputValue : public ShaderNode
|
||||
|
||||
void BuildNodeEdition(QFormLayout* layout) override;
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
|
||||
QString caption() const override { return "Input"; }
|
||||
QString name() const override { return "Input"; }
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
#include <ShaderNode/DataModels/ShaderNode.hpp>
|
||||
#include <ShaderNode/DataTypes/Matrix4Data.hpp>
|
||||
|
||||
template<Nz::ShaderNodes::BinaryType Op>
|
||||
template<Nz::ShaderAst::BinaryType Op>
|
||||
class Mat4BinOp : public ShaderNode
|
||||
{
|
||||
public:
|
||||
Mat4BinOp(ShaderGraph& graph);
|
||||
~Mat4BinOp() = default;
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const;
|
||||
|
||||
unsigned int nPorts(QtNodes::PortType portType) const override;
|
||||
|
||||
@@ -35,28 +35,28 @@ class Mat4BinOp : public ShaderNode
|
||||
std::shared_ptr<Matrix4Data> m_output;
|
||||
};
|
||||
|
||||
class Mat4Add : public Mat4BinOp<Nz::ShaderNodes::BinaryType::Add>
|
||||
class Mat4Add : public Mat4BinOp<Nz::ShaderAst::BinaryType::Add>
|
||||
{
|
||||
public:
|
||||
using Mat4BinOp<Nz::ShaderNodes::BinaryType::Add>::Mat4BinOp;
|
||||
using Mat4BinOp<Nz::ShaderAst::BinaryType::Add>::Mat4BinOp;
|
||||
|
||||
QString caption() const override;
|
||||
QString name() const override;
|
||||
};
|
||||
|
||||
class Mat4Mul : public Mat4BinOp<Nz::ShaderNodes::BinaryType::Multiply>
|
||||
class Mat4Mul : public Mat4BinOp<Nz::ShaderAst::BinaryType::Multiply>
|
||||
{
|
||||
public:
|
||||
using Mat4BinOp<Nz::ShaderNodes::BinaryType::Multiply>::Mat4BinOp;
|
||||
using Mat4BinOp<Nz::ShaderAst::BinaryType::Multiply>::Mat4BinOp;
|
||||
|
||||
QString caption() const override;
|
||||
QString name() const override;
|
||||
};
|
||||
|
||||
class Mat4Sub : public Mat4BinOp<Nz::ShaderNodes::BinaryType::Subtract>
|
||||
class Mat4Sub : public Mat4BinOp<Nz::ShaderAst::BinaryType::Subtract>
|
||||
{
|
||||
public:
|
||||
using Mat4BinOp<Nz::ShaderNodes::BinaryType::Subtract>::Mat4BinOp;
|
||||
using Mat4BinOp<Nz::ShaderAst::BinaryType::Subtract>::Mat4BinOp;
|
||||
|
||||
QString caption() const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
#include <ShaderNode/DataModels/Mat4BinOp.hpp>
|
||||
#include <Nazara/Shader/ShaderBuilder.hpp>
|
||||
|
||||
template<Nz::ShaderNodes::BinaryType Op>
|
||||
template<Nz::ShaderAst::BinaryType Op>
|
||||
Mat4BinOp<Op>::Mat4BinOp(ShaderGraph& graph) :
|
||||
ShaderNode(graph)
|
||||
{
|
||||
UpdateOutput();
|
||||
}
|
||||
|
||||
template<Nz::ShaderNodes::BinaryType Op>
|
||||
Nz::ShaderNodes::NodePtr Mat4BinOp<Op>::BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
template<Nz::ShaderAst::BinaryType Op>
|
||||
Nz::ShaderAst::NodePtr Mat4BinOp<Op>::BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
assert(count == 2);
|
||||
assert(outputIndex == 0);
|
||||
|
||||
using BuilderType = typename Nz::ShaderBuilder::template BinOpBuilder<Op>;
|
||||
constexpr BuilderType builder;
|
||||
return builder(expressions[0], expressions[1]);
|
||||
return Nz::ShaderBuilder::Binary(Op, std::move(expressions[0]), std::move(expressions[1]));
|
||||
}
|
||||
|
||||
template<Nz::ShaderNodes::BinaryType Op>
|
||||
template<Nz::ShaderAst::BinaryType Op>
|
||||
QtNodes::NodeDataType Mat4BinOp<Op>::dataType(QtNodes::PortType /*portType*/, QtNodes::PortIndex portIndex) const
|
||||
{
|
||||
assert(portIndex == 0 || portIndex == 1);
|
||||
@@ -27,7 +25,7 @@ QtNodes::NodeDataType Mat4BinOp<Op>::dataType(QtNodes::PortType /*portType*/, Qt
|
||||
return Matrix4Data::Type();
|
||||
}
|
||||
|
||||
template<Nz::ShaderNodes::BinaryType Op>
|
||||
template<Nz::ShaderAst::BinaryType Op>
|
||||
unsigned int Mat4BinOp<Op>::nPorts(QtNodes::PortType portType) const
|
||||
{
|
||||
switch (portType)
|
||||
@@ -41,14 +39,14 @@ unsigned int Mat4BinOp<Op>::nPorts(QtNodes::PortType portType) const
|
||||
throw std::runtime_error("invalid port type");
|
||||
}
|
||||
|
||||
template<Nz::ShaderNodes::BinaryType Op>
|
||||
template<Nz::ShaderAst::BinaryType Op>
|
||||
std::shared_ptr<QtNodes::NodeData> Mat4BinOp<Op>::outData(QtNodes::PortIndex port)
|
||||
{
|
||||
assert(port == 0);
|
||||
return m_output;
|
||||
}
|
||||
|
||||
template<Nz::ShaderNodes::BinaryType Op>
|
||||
template<Nz::ShaderAst::BinaryType Op>
|
||||
void Mat4BinOp<Op>::setInData(std::shared_ptr<QtNodes::NodeData> value, int index)
|
||||
{
|
||||
assert(index == 0 || index == 1);
|
||||
@@ -68,7 +66,7 @@ void Mat4BinOp<Op>::setInData(std::shared_ptr<QtNodes::NodeData> value, int inde
|
||||
UpdateOutput();
|
||||
}
|
||||
|
||||
template<Nz::ShaderNodes::BinaryType Op>
|
||||
template<Nz::ShaderAst::BinaryType Op>
|
||||
QtNodes::NodeValidationState Mat4BinOp<Op>::validationState() const
|
||||
{
|
||||
if (!m_lhs || !m_rhs)
|
||||
@@ -77,7 +75,7 @@ QtNodes::NodeValidationState Mat4BinOp<Op>::validationState() const
|
||||
return QtNodes::NodeValidationState::Valid;
|
||||
}
|
||||
|
||||
template<Nz::ShaderNodes::BinaryType Op>
|
||||
template<Nz::ShaderAst::BinaryType Op>
|
||||
QString Mat4BinOp<Op>::validationMessage() const
|
||||
{
|
||||
if (!m_lhs || !m_rhs)
|
||||
@@ -86,7 +84,7 @@ QString Mat4BinOp<Op>::validationMessage() const
|
||||
return QString();
|
||||
}
|
||||
|
||||
template<Nz::ShaderNodes::BinaryType Op>
|
||||
template<Nz::ShaderAst::BinaryType Op>
|
||||
bool Mat4BinOp<Op>::ComputePreview(QPixmap& pixmap)
|
||||
{
|
||||
if (!m_lhs || !m_rhs)
|
||||
@@ -98,7 +96,7 @@ bool Mat4BinOp<Op>::ComputePreview(QPixmap& pixmap)
|
||||
//return true;
|
||||
}
|
||||
|
||||
template<Nz::ShaderNodes::BinaryType Op>
|
||||
template<Nz::ShaderAst::BinaryType Op>
|
||||
void Mat4BinOp<Op>::UpdateOutput()
|
||||
{
|
||||
if (validationState() != QtNodes::NodeValidationState::Valid)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <ShaderNode/DataModels/Mat4VecMul.hpp>
|
||||
#include <Nazara/Shader/ShaderBuilder.hpp>
|
||||
#include <Nazara/Shader/ShaderNodes.hpp>
|
||||
|
||||
Mat4VecMul::Mat4VecMul(ShaderGraph& graph) :
|
||||
@@ -7,13 +8,12 @@ ShaderNode(graph)
|
||||
UpdateOutput();
|
||||
}
|
||||
|
||||
Nz::ShaderNodes::NodePtr Mat4VecMul::BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
Nz::ShaderAst::NodePtr Mat4VecMul::BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
assert(count == 2);
|
||||
assert(outputIndex == 0);
|
||||
|
||||
using namespace Nz::ShaderNodes;
|
||||
return BinaryOp::Build(BinaryType::Multiply, expressions[0], expressions[1]);
|
||||
return Nz::ShaderBuilder::Binary(Nz::ShaderAst::BinaryType::Multiply, std::move(expressions[0]), std::move(expressions[1]));
|
||||
}
|
||||
|
||||
QString Mat4VecMul::caption() const
|
||||
|
||||
@@ -13,7 +13,7 @@ class Mat4VecMul : public ShaderNode
|
||||
Mat4VecMul(ShaderGraph& graph);
|
||||
~Mat4VecMul() = default;
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
|
||||
QString caption() const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -54,11 +54,8 @@ void OutputValue::BuildNodeEdition(QFormLayout* layout)
|
||||
layout->addRow(tr("Output"), outputSelection);
|
||||
}
|
||||
|
||||
Nz::ShaderNodes::NodePtr OutputValue::BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
Nz::ShaderAst::NodePtr OutputValue::BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
using namespace Nz::ShaderBuilder;
|
||||
using namespace Nz::ShaderNodes;
|
||||
|
||||
assert(count == 1);
|
||||
assert(outputIndex == 0);
|
||||
|
||||
@@ -66,9 +63,10 @@ Nz::ShaderNodes::NodePtr OutputValue::BuildNode(Nz::ShaderNodes::ExpressionPtr*
|
||||
throw std::runtime_error("no output");
|
||||
|
||||
const auto& outputEntry = GetGraph().GetOutput(*m_currentOutputIndex);
|
||||
auto output = Nz::ShaderBuilder::Identifier(Nz::ShaderBuilder::Output(outputEntry.name, ShaderGraph::ToShaderExpressionType(outputEntry.type)));
|
||||
auto output = Nz::ShaderBuilder::AccessMember(Nz::ShaderBuilder::Identifier("output"), { outputEntry.name });
|
||||
|
||||
return Nz::ShaderBuilder::Assign(std::move(output), *expressions);
|
||||
using namespace Nz;
|
||||
return Nz::ShaderBuilder::Assign(ShaderAst::AssignType::Simple, std::move(output), std::move(expressions[0]));
|
||||
}
|
||||
|
||||
std::shared_ptr<QtNodes::NodeData> OutputValue::outData(QtNodes::PortIndex /*port*/)
|
||||
|
||||
@@ -16,7 +16,7 @@ class OutputValue : public ShaderNode
|
||||
|
||||
void BuildNodeEdition(QFormLayout* layout) override;
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
|
||||
QString caption() const override { return "Output"; }
|
||||
QString name() const override { return "Output"; }
|
||||
|
||||
@@ -14,16 +14,15 @@ ShaderNode(graph)
|
||||
DisableCustomVariableName();
|
||||
}
|
||||
|
||||
Nz::ShaderNodes::NodePtr PositionOutputValue::BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
Nz::ShaderAst::NodePtr PositionOutputValue::BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
using namespace Nz::ShaderBuilder;
|
||||
using namespace Nz::ShaderNodes;
|
||||
using namespace Nz;
|
||||
|
||||
assert(count == 1);
|
||||
assert(outputIndex == 0);
|
||||
|
||||
auto output = Nz::ShaderBuilder::Identifier(Nz::ShaderBuilder::Builtin(BuiltinEntry::VertexPosition));
|
||||
return Nz::ShaderBuilder::Assign(std::move(output), *expressions);
|
||||
auto output = Nz::ShaderBuilder::AccessMember(Nz::ShaderBuilder::Identifier("OutputData"), { "position" });
|
||||
return ShaderBuilder::Assign(ShaderAst::AssignType::Simple, std::move(output), std::move(expressions[0]));
|
||||
}
|
||||
|
||||
QtNodes::NodeDataType PositionOutputValue::dataType(QtNodes::PortType portType, QtNodes::PortIndex portIndex) const
|
||||
|
||||
@@ -14,7 +14,7 @@ class PositionOutputValue : public ShaderNode
|
||||
public:
|
||||
PositionOutputValue(ShaderGraph& graph);
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
|
||||
QString caption() const override { return "PositionOutputValue"; }
|
||||
QString name() const override { return "PositionOutputValue"; }
|
||||
|
||||
@@ -71,14 +71,18 @@ bool SampleTexture::ComputePreview(QPixmap& pixmap)
|
||||
return true;
|
||||
}
|
||||
|
||||
Nz::ShaderNodes::NodePtr SampleTexture::BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
Nz::ShaderAst::NodePtr SampleTexture::BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
assert(m_texture);
|
||||
assert(m_uv);
|
||||
assert(count == 2);
|
||||
assert(outputIndex == 0);
|
||||
|
||||
return Nz::ShaderBuilder::Sample2D(expressions[0], expressions[1]);
|
||||
std::vector<Nz::ShaderAst::ExpressionPtr> params;
|
||||
params.push_back(std::move(expressions[0]));
|
||||
params.push_back(std::move(expressions[1]));
|
||||
|
||||
return Nz::ShaderBuilder::Intrinsic(Nz::ShaderAst::IntrinsicType::SampleTexture, std::move(params));
|
||||
}
|
||||
|
||||
auto SampleTexture::dataType(QtNodes::PortType portType, QtNodes::PortIndex portIndex) const -> QtNodes::NodeDataType
|
||||
|
||||
@@ -17,7 +17,7 @@ class SampleTexture : public ShaderNode
|
||||
SampleTexture(ShaderGraph& graph);
|
||||
~SampleTexture() = default;
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
|
||||
QString caption() const override { return "Sample texture"; }
|
||||
QString name() const override { return "SampleTexture"; }
|
||||
|
||||
@@ -18,7 +18,7 @@ class ShaderNode : public QtNodes::NodeDataModel
|
||||
public:
|
||||
ShaderNode(ShaderGraph& graph);
|
||||
|
||||
virtual Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const = 0;
|
||||
virtual Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const = 0;
|
||||
virtual void BuildNodeEdition(QFormLayout* layout);
|
||||
|
||||
inline void DisablePreview();
|
||||
|
||||
@@ -110,7 +110,7 @@ void TextureValue::BuildNodeEdition(QFormLayout* layout)
|
||||
layout->addRow(tr("Texture"), textureSelection);
|
||||
}
|
||||
|
||||
Nz::ShaderNodes::NodePtr TextureValue::BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
Nz::ShaderAst::NodePtr TextureValue::BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
if (!m_currentTextureIndex)
|
||||
throw std::runtime_error("invalid texture input");
|
||||
@@ -119,19 +119,7 @@ Nz::ShaderNodes::NodePtr TextureValue::BuildNode(Nz::ShaderNodes::ExpressionPtr*
|
||||
assert(outputIndex == 0);
|
||||
|
||||
const auto& textureEntry = GetGraph().GetTexture(*m_currentTextureIndex);
|
||||
|
||||
Nz::ShaderNodes::BasicType expression = [&]
|
||||
{
|
||||
switch (textureEntry.type)
|
||||
{
|
||||
case TextureType::Sampler2D: return Nz::ShaderNodes::BasicType::Sampler2D;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
throw std::runtime_error("Unhandled texture type");
|
||||
}();
|
||||
|
||||
return Nz::ShaderBuilder::Identifier(Nz::ShaderBuilder::Uniform(textureEntry.name, expression));
|
||||
return Nz::ShaderBuilder::Identifier(textureEntry.name);
|
||||
}
|
||||
|
||||
auto TextureValue::dataType(QtNodes::PortType portType, QtNodes::PortIndex portIndex) const -> QtNodes::NodeDataType
|
||||
|
||||
@@ -18,7 +18,7 @@ class TextureValue : public ShaderNode
|
||||
|
||||
void BuildNodeEdition(QFormLayout* layout) override;
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
|
||||
QString caption() const override { return "Texture"; }
|
||||
QString name() const override { return "Texture"; }
|
||||
|
||||
@@ -17,7 +17,7 @@ class VecComposition : public ShaderNode
|
||||
VecComposition(ShaderGraph& graph);
|
||||
~VecComposition() = default;
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
|
||||
QString caption() const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -14,17 +14,16 @@ ShaderNode(graph)
|
||||
}
|
||||
|
||||
template<std::size_t ComponentCount>
|
||||
Nz::ShaderNodes::NodePtr VecComposition<ComponentCount>::BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
Nz::ShaderAst::NodePtr VecComposition<ComponentCount>::BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
assert(count == ComponentCount);
|
||||
assert(outputIndex == 0);
|
||||
|
||||
std::array<Nz::ShaderNodes::ExpressionPtr, ComponentCount> expr;
|
||||
std::vector<Nz::ShaderAst::ExpressionPtr> params;
|
||||
for (std::size_t i = 0; i < count; ++i)
|
||||
expr[i] = expressions[i];
|
||||
params.emplace_back(std::move(expressions[i]));
|
||||
|
||||
constexpr auto ExpressionType = VecExpressionType<ComponentCount>;
|
||||
return Nz::ShaderBuilder::Cast<ExpressionType>(expr.data(), expr.size());
|
||||
return Nz::ShaderBuilder::Cast(Nz::ShaderAst::VectorType{ ComponentCount, Nz::ShaderAst::PrimitiveType::Float32 }, std::move(params));
|
||||
}
|
||||
|
||||
template<std::size_t ComponentCount>
|
||||
|
||||
@@ -16,15 +16,15 @@ ShaderNode(graph)
|
||||
DisableCustomVariableName();
|
||||
}
|
||||
|
||||
Nz::ShaderNodes::NodePtr VecDecomposition::BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
Nz::ShaderAst::NodePtr VecDecomposition::BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
assert(count == 1);
|
||||
assert(outputIndex < m_outputs.size());
|
||||
|
||||
using namespace Nz::ShaderBuilder;
|
||||
using namespace Nz::ShaderNodes;
|
||||
using namespace Nz;
|
||||
|
||||
return Nz::ShaderBuilder::Swizzle(expressions[0], static_cast<SwizzleComponent>(Nz::UnderlyingCast(SwizzleComponent::First) + outputIndex));
|
||||
ShaderAst::SwizzleComponent swizzleComponent = static_cast<ShaderAst::SwizzleComponent>(Nz::UnderlyingCast(ShaderAst::SwizzleComponent::First) + outputIndex);
|
||||
return ShaderBuilder::Swizzle(std::move(expressions[0]), { swizzleComponent });
|
||||
}
|
||||
|
||||
QString VecDecomposition::caption() const
|
||||
|
||||
@@ -18,7 +18,7 @@ class VecDecomposition : public ShaderNode
|
||||
VecDecomposition(ShaderGraph& graph);
|
||||
~VecDecomposition() = default;
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
|
||||
QString caption() const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <ShaderNode/DataModels/VecDot.hpp>
|
||||
#include <Nazara/Shader/ShaderBuilder.hpp>
|
||||
#include <Nazara/Shader/ShaderNodes.hpp>
|
||||
|
||||
VecDot::VecDot(ShaderGraph& graph) :
|
||||
@@ -8,13 +9,16 @@ ShaderNode(graph)
|
||||
UpdateOutput();
|
||||
}
|
||||
|
||||
Nz::ShaderNodes::NodePtr VecDot::BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
Nz::ShaderAst::NodePtr VecDot::BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
assert(count == 2);
|
||||
assert(outputIndex == 0);
|
||||
|
||||
using namespace Nz::ShaderNodes;
|
||||
return IntrinsicCall::Build(IntrinsicType::DotProduct, { expressions[0], expressions[1] });
|
||||
std::vector<Nz::ShaderAst::ExpressionPtr> params;
|
||||
params.push_back(std::move(expressions[0]));
|
||||
params.push_back(std::move(expressions[1]));
|
||||
|
||||
return Nz::ShaderBuilder::Intrinsic(Nz::ShaderAst::IntrinsicType::DotProduct, std::move(params));
|
||||
}
|
||||
|
||||
QString VecDot::caption() const
|
||||
|
||||
@@ -13,7 +13,7 @@ class VecDot : public ShaderNode
|
||||
VecDot(ShaderGraph& graph);
|
||||
~VecDot() = default;
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
|
||||
QString caption() const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <ShaderNode/DataModels/VecFloatMul.hpp>
|
||||
#include <Nazara/Shader/ShaderBuilder.hpp>
|
||||
#include <Nazara/Shader/ShaderNodes.hpp>
|
||||
|
||||
VecFloatMul::VecFloatMul(ShaderGraph& graph) :
|
||||
@@ -7,13 +8,12 @@ ShaderNode(graph)
|
||||
UpdateOutput();
|
||||
}
|
||||
|
||||
Nz::ShaderNodes::NodePtr VecFloatMul::BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
Nz::ShaderAst::NodePtr VecFloatMul::BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
assert(count == 2);
|
||||
assert(outputIndex == 0);
|
||||
|
||||
using namespace Nz::ShaderNodes;
|
||||
return BinaryOp::Build(BinaryType::Multiply, expressions[0], expressions[1]);
|
||||
return Nz::ShaderBuilder::Binary(Nz::ShaderAst::BinaryType::Multiply, std::move(expressions[0]), std::move(expressions[1]));
|
||||
}
|
||||
|
||||
QString VecFloatMul::caption() const
|
||||
|
||||
@@ -13,7 +13,7 @@ class VecFloatMul : public ShaderNode
|
||||
VecFloatMul(ShaderGraph& graph);
|
||||
~VecFloatMul() = default;
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
|
||||
QString caption() const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -18,7 +18,7 @@ class VecValue : public ShaderNode
|
||||
VecValue(ShaderGraph& graph);
|
||||
~VecValue() = default;
|
||||
|
||||
Nz::ShaderNodes::NodePtr BuildNode(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
Nz::ShaderAst::NodePtr BuildNode(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count, std::size_t outputIndex) const override;
|
||||
void BuildNodeEdition(QFormLayout* layout) override;
|
||||
|
||||
QString caption() const override;
|
||||
|
||||
@@ -127,7 +127,7 @@ void VecValue<ComponentCount>::BuildNodeEdition(QFormLayout* layout)
|
||||
}
|
||||
|
||||
template<std::size_t ComponentCount>
|
||||
Nz::ShaderNodes::NodePtr VecValue<ComponentCount>::BuildNode(Nz::ShaderNodes::ExpressionPtr* /*expressions*/, std::size_t count, std::size_t outputIndex) const
|
||||
Nz::ShaderAst::NodePtr VecValue<ComponentCount>::BuildNode(Nz::ShaderAst::ExpressionPtr* /*expressions*/, std::size_t count, std::size_t outputIndex) const
|
||||
{
|
||||
assert(count == 0);
|
||||
assert(outputIndex == 0);
|
||||
|
||||
Reference in New Issue
Block a user