ShaderAst: Big refactor + add binding/location support
This commit is contained in:
@@ -19,7 +19,7 @@ class CastVec : public ShaderNode
|
||||
|
||||
void BuildNodeEdition(QFormLayout* layout) override;
|
||||
|
||||
Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const override;
|
||||
Nz::ShaderNodes::ExpressionPtr GetExpression(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count) const override;
|
||||
|
||||
QString caption() const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -49,7 +49,7 @@ void CastVec<ToComponentCount>::BuildNodeEdition(QFormLayout* layout)
|
||||
}
|
||||
|
||||
template<std::size_t ToComponentCount>
|
||||
Nz::ShaderAst::ExpressionPtr CastVec<ToComponentCount>::GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const
|
||||
Nz::ShaderNodes::ExpressionPtr CastVec<ToComponentCount>::GetExpression(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count) const
|
||||
{
|
||||
assert(m_input);
|
||||
assert(count == 1);
|
||||
@@ -60,7 +60,7 @@ Nz::ShaderAst::ExpressionPtr CastVec<ToComponentCount>::GetExpression(Nz::Shader
|
||||
{
|
||||
std::size_t overflowComponentCount = ToComponentCount - fromComponentCount;
|
||||
|
||||
std::array<Nz::ShaderAst::ExpressionPtr, 4> expr;
|
||||
std::array<Nz::ShaderNodes::ExpressionPtr, 4> expr;
|
||||
expr[0] = expressions[0];
|
||||
for (std::size_t i = 0; i < overflowComponentCount; ++i)
|
||||
expr[i + 1] = Nz::ShaderBuilder::Constant(m_overflowComponents[i]);
|
||||
@@ -71,13 +71,13 @@ Nz::ShaderAst::ExpressionPtr CastVec<ToComponentCount>::GetExpression(Nz::Shader
|
||||
}
|
||||
else if (ToComponentCount < fromComponentCount)
|
||||
{
|
||||
std::array<Nz::ShaderAst::SwizzleComponent, ToComponentCount> swizzleComponents;
|
||||
std::array<Nz::ShaderNodes::SwizzleComponent, ToComponentCount> swizzleComponents;
|
||||
for (std::size_t i = 0; i < ToComponentCount; ++i)
|
||||
swizzleComponents[i] = static_cast<Nz::ShaderAst::SwizzleComponent>(static_cast<std::size_t>(Nz::ShaderAst::SwizzleComponent::First) + i);
|
||||
swizzleComponents[i] = static_cast<Nz::ShaderNodes::SwizzleComponent>(static_cast<std::size_t>(Nz::ShaderNodes::SwizzleComponent::First) + i);
|
||||
|
||||
return std::apply([&](auto... components)
|
||||
{
|
||||
std::initializer_list<Nz::ShaderAst::SwizzleComponent> componentList{ components... };
|
||||
std::initializer_list<Nz::ShaderNodes::SwizzleComponent> componentList{ components... };
|
||||
return Nz::ShaderBuilder::Swizzle(expressions[0], componentList);
|
||||
}, swizzleComponents);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ void FloatValue::BuildNodeEdition(QFormLayout* layout)
|
||||
layout->addRow(tr("Value"), spinbox);
|
||||
}
|
||||
|
||||
Nz::ShaderAst::ExpressionPtr FloatValue::GetExpression(Nz::ShaderAst::ExpressionPtr* /*expressions*/, std::size_t count) const
|
||||
Nz::ShaderNodes::ExpressionPtr FloatValue::GetExpression(Nz::ShaderNodes::ExpressionPtr* /*expressions*/, std::size_t count) const
|
||||
{
|
||||
assert(count == 0);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class FloatValue : public ShaderNode
|
||||
|
||||
void BuildNodeEdition(QFormLayout* layout) override;
|
||||
|
||||
Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const override;
|
||||
Nz::ShaderNodes::ExpressionPtr GetExpression(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count) const override;
|
||||
|
||||
private:
|
||||
bool ComputePreview(QPixmap& pixmap) override;
|
||||
|
||||
@@ -107,7 +107,7 @@ void InputValue::BuildNodeEdition(QFormLayout* layout)
|
||||
layout->addRow(tr("Input"), inputSelection);
|
||||
}
|
||||
|
||||
Nz::ShaderAst::ExpressionPtr InputValue::GetExpression(Nz::ShaderAst::ExpressionPtr* /*expressions*/, std::size_t count) const
|
||||
Nz::ShaderNodes::ExpressionPtr InputValue::GetExpression(Nz::ShaderNodes::ExpressionPtr* /*expressions*/, std::size_t count) const
|
||||
{
|
||||
assert(count == 0);
|
||||
|
||||
@@ -116,22 +116,22 @@ Nz::ShaderAst::ExpressionPtr InputValue::GetExpression(Nz::ShaderAst::Expression
|
||||
|
||||
const auto& inputEntry = GetGraph().GetInput(*m_currentInputIndex);
|
||||
|
||||
Nz::ShaderAst::ExpressionType expression = [&]
|
||||
Nz::ShaderNodes::ExpressionType expression = [&]
|
||||
{
|
||||
switch (inputEntry.type)
|
||||
{
|
||||
case InOutType::Bool: return Nz::ShaderAst::ExpressionType::Boolean;
|
||||
case InOutType::Float1: return Nz::ShaderAst::ExpressionType::Float1;
|
||||
case InOutType::Float2: return Nz::ShaderAst::ExpressionType::Float2;
|
||||
case InOutType::Float3: return Nz::ShaderAst::ExpressionType::Float3;
|
||||
case InOutType::Float4: return Nz::ShaderAst::ExpressionType::Float4;
|
||||
case InOutType::Bool: return Nz::ShaderNodes::ExpressionType::Boolean;
|
||||
case InOutType::Float1: return Nz::ShaderNodes::ExpressionType::Float1;
|
||||
case InOutType::Float2: return Nz::ShaderNodes::ExpressionType::Float2;
|
||||
case InOutType::Float3: return Nz::ShaderNodes::ExpressionType::Float3;
|
||||
case InOutType::Float4: return Nz::ShaderNodes::ExpressionType::Float4;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
throw std::runtime_error("Unhandled input type");
|
||||
}();
|
||||
|
||||
return Nz::ShaderBuilder::Input(inputEntry.name, expression);
|
||||
return Nz::ShaderBuilder::Identifier(Nz::ShaderBuilder::Input(inputEntry.name, expression));
|
||||
}
|
||||
|
||||
auto InputValue::dataType(QtNodes::PortType portType, QtNodes::PortIndex portIndex) const -> QtNodes::NodeDataType
|
||||
@@ -145,7 +145,7 @@ auto InputValue::dataType(QtNodes::PortType portType, QtNodes::PortIndex portInd
|
||||
const auto& inputEntry = GetGraph().GetInput(*m_currentInputIndex);
|
||||
switch (inputEntry.type)
|
||||
{
|
||||
//case InputType::Bool: return Nz::ShaderAst::ExpressionType::Boolean;
|
||||
//case InputType::Bool: return Nz::ShaderNodes::ExpressionType::Boolean;
|
||||
case InOutType::Float1:
|
||||
return FloatData::Type();
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class InputValue : public ShaderNode
|
||||
|
||||
void BuildNodeEdition(QFormLayout* layout) override;
|
||||
|
||||
Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* /*expressions*/, std::size_t count) const override;
|
||||
Nz::ShaderNodes::ExpressionPtr GetExpression(Nz::ShaderNodes::ExpressionPtr* /*expressions*/, std::size_t count) const override;
|
||||
|
||||
QString caption() const override { return "Input"; }
|
||||
QString name() const override { return "Input"; }
|
||||
|
||||
@@ -51,10 +51,10 @@ void OutputValue::BuildNodeEdition(QFormLayout* layout)
|
||||
layout->addRow(tr("Output"), outputSelection);
|
||||
}
|
||||
|
||||
Nz::ShaderAst::ExpressionPtr OutputValue::GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const
|
||||
Nz::ShaderNodes::ExpressionPtr OutputValue::GetExpression(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count) const
|
||||
{
|
||||
using namespace Nz::ShaderAst;
|
||||
using namespace Nz::ShaderBuilder;
|
||||
using namespace Nz::ShaderNodes;
|
||||
|
||||
assert(count == 1);
|
||||
|
||||
@@ -63,22 +63,22 @@ Nz::ShaderAst::ExpressionPtr OutputValue::GetExpression(Nz::ShaderAst::Expressio
|
||||
|
||||
const auto& outputEntry = GetGraph().GetOutput(*m_currentOutputIndex);
|
||||
|
||||
Nz::ShaderAst::ExpressionType expression = [&]
|
||||
Nz::ShaderNodes::ExpressionType expression = [&]
|
||||
{
|
||||
switch (outputEntry.type)
|
||||
{
|
||||
case InOutType::Bool: return Nz::ShaderAst::ExpressionType::Boolean;
|
||||
case InOutType::Float1: return Nz::ShaderAst::ExpressionType::Float1;
|
||||
case InOutType::Float2: return Nz::ShaderAst::ExpressionType::Float2;
|
||||
case InOutType::Float3: return Nz::ShaderAst::ExpressionType::Float3;
|
||||
case InOutType::Float4: return Nz::ShaderAst::ExpressionType::Float4;
|
||||
case InOutType::Bool: return Nz::ShaderNodes::ExpressionType::Boolean;
|
||||
case InOutType::Float1: return Nz::ShaderNodes::ExpressionType::Float1;
|
||||
case InOutType::Float2: return Nz::ShaderNodes::ExpressionType::Float2;
|
||||
case InOutType::Float3: return Nz::ShaderNodes::ExpressionType::Float3;
|
||||
case InOutType::Float4: return Nz::ShaderNodes::ExpressionType::Float4;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
throw std::runtime_error("Unhandled output type");
|
||||
}();
|
||||
|
||||
auto output = Nz::ShaderBuilder::Output(outputEntry.name, expression);
|
||||
auto output = Nz::ShaderBuilder::Identifier(Nz::ShaderBuilder::Output(outputEntry.name, expression));
|
||||
|
||||
return Nz::ShaderBuilder::Assign(std::move(output), *expressions);
|
||||
}
|
||||
@@ -94,8 +94,8 @@ QtNodes::NodeDataType OutputValue::dataType(QtNodes::PortType portType, QtNodes:
|
||||
const auto& outputEntry = GetGraph().GetOutput(*m_currentOutputIndex);
|
||||
switch (outputEntry.type)
|
||||
{
|
||||
//case InOutType::Bool: return Nz::ShaderAst::ExpressionType::Boolean;
|
||||
//case InOutType::Float1: return Nz::ShaderAst::ExpressionType::Float1;
|
||||
//case InOutType::Bool: return Nz::ShaderNodes::ExpressionType::Boolean;
|
||||
//case InOutType::Float1: return Nz::ShaderNodes::ExpressionType::Float1;
|
||||
case InOutType::Float2:
|
||||
case InOutType::Float3:
|
||||
case InOutType::Float4:
|
||||
|
||||
@@ -16,7 +16,7 @@ class OutputValue : public ShaderNode
|
||||
|
||||
void BuildNodeEdition(QFormLayout* layout) override;
|
||||
|
||||
Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const override;
|
||||
Nz::ShaderNodes::ExpressionPtr GetExpression(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count) const override;
|
||||
|
||||
QString caption() const override { return "Output"; }
|
||||
QString name() const override { return "Output"; }
|
||||
|
||||
@@ -91,7 +91,7 @@ bool SampleTexture::ComputePreview(QPixmap& pixmap)
|
||||
return true;
|
||||
}
|
||||
|
||||
Nz::ShaderAst::ExpressionPtr SampleTexture::GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const
|
||||
Nz::ShaderNodes::ExpressionPtr SampleTexture::GetExpression(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count) const
|
||||
{
|
||||
assert(m_texture);
|
||||
assert(m_uv);
|
||||
|
||||
@@ -17,7 +17,7 @@ class SampleTexture : public ShaderNode
|
||||
SampleTexture(ShaderGraph& graph);
|
||||
~SampleTexture() = default;
|
||||
|
||||
Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* /*expressions*/, std::size_t count) const override;
|
||||
Nz::ShaderNodes::ExpressionPtr GetExpression(Nz::ShaderNodes::ExpressionPtr* /*expressions*/, std::size_t count) const override;
|
||||
|
||||
QString caption() const override { return "Sample texture"; }
|
||||
QString name() const override { return "SampleTexture"; }
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define NAZARA_SHADERNODES_SHADERNODE_HPP
|
||||
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Renderer/ShaderAst.hpp>
|
||||
#include <Nazara/Renderer/ShaderNodes.hpp>
|
||||
#include <nodes/NodeDataModel>
|
||||
#include <QtGui/QPixmap>
|
||||
#include <optional>
|
||||
@@ -23,7 +23,7 @@ class ShaderNode : public QtNodes::NodeDataModel
|
||||
inline void DisablePreview();
|
||||
void EnablePreview(bool enable = true);
|
||||
|
||||
virtual Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const = 0;
|
||||
virtual Nz::ShaderNodes::ExpressionPtr GetExpression(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count) const = 0;
|
||||
inline ShaderGraph& GetGraph();
|
||||
inline const ShaderGraph& GetGraph() const;
|
||||
inline const std::string& GetVariableName() const;
|
||||
|
||||
@@ -106,7 +106,7 @@ void TextureValue::BuildNodeEdition(QFormLayout* layout)
|
||||
layout->addRow(tr("Texture"), textureSelection);
|
||||
}
|
||||
|
||||
Nz::ShaderAst::ExpressionPtr TextureValue::GetExpression(Nz::ShaderAst::ExpressionPtr* /*expressions*/, std::size_t count) const
|
||||
Nz::ShaderNodes::ExpressionPtr TextureValue::GetExpression(Nz::ShaderNodes::ExpressionPtr* /*expressions*/, std::size_t count) const
|
||||
{
|
||||
if (!m_currentTextureIndex)
|
||||
throw std::runtime_error("invalid texture input");
|
||||
@@ -115,18 +115,18 @@ Nz::ShaderAst::ExpressionPtr TextureValue::GetExpression(Nz::ShaderAst::Expressi
|
||||
|
||||
const auto& textureEntry = GetGraph().GetTexture(*m_currentTextureIndex);
|
||||
|
||||
Nz::ShaderAst::ExpressionType expression = [&]
|
||||
Nz::ShaderNodes::ExpressionType expression = [&]
|
||||
{
|
||||
switch (textureEntry.type)
|
||||
{
|
||||
case TextureType::Sampler2D: return Nz::ShaderAst::ExpressionType::Sampler2D;
|
||||
case TextureType::Sampler2D: return Nz::ShaderNodes::ExpressionType::Sampler2D;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
throw std::runtime_error("Unhandled texture type");
|
||||
}();
|
||||
|
||||
return Nz::ShaderBuilder::Uniform(textureEntry.name, expression);
|
||||
return Nz::ShaderBuilder::Identifier(Nz::ShaderBuilder::Uniform(textureEntry.name, expression));
|
||||
}
|
||||
|
||||
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::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* /*expressions*/, std::size_t count) const override;
|
||||
Nz::ShaderNodes::ExpressionPtr GetExpression(Nz::ShaderNodes::ExpressionPtr* /*expressions*/, std::size_t count) const override;
|
||||
|
||||
QString caption() const override { return "Texture"; }
|
||||
QString name() const override { return "Texture"; }
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
#include <ShaderNode/DataModels/ShaderNode.hpp>
|
||||
#include <ShaderNode/DataTypes/VecData.hpp>
|
||||
|
||||
template<Nz::ShaderAst::BinaryType BinOp>
|
||||
template<Nz::ShaderNodes::BinaryType BinOp>
|
||||
class VecBinOp : public ShaderNode
|
||||
{
|
||||
public:
|
||||
VecBinOp(ShaderGraph& graph);
|
||||
~VecBinOp() = default;
|
||||
|
||||
Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const override;
|
||||
Nz::ShaderNodes::ExpressionPtr GetExpression(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count) const override;
|
||||
|
||||
unsigned int nPorts(QtNodes::PortType portType) const override;
|
||||
|
||||
@@ -37,10 +37,10 @@ class VecBinOp : public ShaderNode
|
||||
std::shared_ptr<VecData> m_output;
|
||||
};
|
||||
|
||||
class VecAdd : public VecBinOp<Nz::ShaderAst::BinaryType::Add>
|
||||
class VecAdd : public VecBinOp<Nz::ShaderNodes::BinaryType::Add>
|
||||
{
|
||||
public:
|
||||
using VecBinOp<Nz::ShaderAst::BinaryType::Add>::VecBinOp;
|
||||
using VecBinOp<Nz::ShaderNodes::BinaryType::Add>::VecBinOp;
|
||||
|
||||
QString caption() const override;
|
||||
QString name() const override;
|
||||
@@ -48,10 +48,10 @@ class VecAdd : public VecBinOp<Nz::ShaderAst::BinaryType::Add>
|
||||
void ApplyOp(const std::uint8_t* left, const std::uint8_t* right, std::uint8_t* output, std::size_t pixelCount) override;
|
||||
};
|
||||
|
||||
class VecMul : public VecBinOp<Nz::ShaderAst::BinaryType::Multiply>
|
||||
class VecMul : public VecBinOp<Nz::ShaderNodes::BinaryType::Multiply>
|
||||
{
|
||||
public:
|
||||
using VecBinOp<Nz::ShaderAst::BinaryType::Multiply>::VecBinOp;
|
||||
using VecBinOp<Nz::ShaderNodes::BinaryType::Multiply>::VecBinOp;
|
||||
|
||||
QString caption() const override;
|
||||
QString name() const override;
|
||||
@@ -59,10 +59,10 @@ class VecMul : public VecBinOp<Nz::ShaderAst::BinaryType::Multiply>
|
||||
void ApplyOp(const std::uint8_t* left, const std::uint8_t* right, std::uint8_t* output, std::size_t pixelCount) override;
|
||||
};
|
||||
|
||||
class VecSub : public VecBinOp<Nz::ShaderAst::BinaryType::Substract>
|
||||
class VecSub : public VecBinOp<Nz::ShaderNodes::BinaryType::Substract>
|
||||
{
|
||||
public:
|
||||
using VecBinOp<Nz::ShaderAst::BinaryType::Substract>::VecBinOp;
|
||||
using VecBinOp<Nz::ShaderNodes::BinaryType::Substract>::VecBinOp;
|
||||
|
||||
QString caption() const override;
|
||||
QString name() const override;
|
||||
@@ -70,10 +70,10 @@ class VecSub : public VecBinOp<Nz::ShaderAst::BinaryType::Substract>
|
||||
void ApplyOp(const std::uint8_t* left, const std::uint8_t* right, std::uint8_t* output, std::size_t pixelCount) override;
|
||||
};
|
||||
|
||||
class VecDiv : public VecBinOp<Nz::ShaderAst::BinaryType::Divide>
|
||||
class VecDiv : public VecBinOp<Nz::ShaderNodes::BinaryType::Divide>
|
||||
{
|
||||
public:
|
||||
using VecBinOp<Nz::ShaderAst::BinaryType::Divide>::VecBinOp;
|
||||
using VecBinOp<Nz::ShaderNodes::BinaryType::Divide>::VecBinOp;
|
||||
|
||||
QString caption() const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#include <ShaderNode/DataModels/VecBinOp.hpp>
|
||||
#include <Nazara/Renderer/ShaderBuilder.hpp>
|
||||
|
||||
template<Nz::ShaderAst::BinaryType BinOp>
|
||||
template<Nz::ShaderNodes::BinaryType BinOp>
|
||||
VecBinOp<BinOp>::VecBinOp(ShaderGraph& graph) :
|
||||
ShaderNode(graph)
|
||||
{
|
||||
UpdateOutput();
|
||||
}
|
||||
|
||||
template<Nz::ShaderAst::BinaryType BinOp>
|
||||
Nz::ShaderAst::ExpressionPtr VecBinOp<BinOp>::GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const
|
||||
template<Nz::ShaderNodes::BinaryType BinOp>
|
||||
Nz::ShaderNodes::ExpressionPtr VecBinOp<BinOp>::GetExpression(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count) const
|
||||
{
|
||||
assert(count == 2);
|
||||
using BuilderType = typename Nz::ShaderBuilder::template BinOpBuilder<BinOp>;
|
||||
@@ -17,7 +17,7 @@ Nz::ShaderAst::ExpressionPtr VecBinOp<BinOp>::GetExpression(Nz::ShaderAst::Expre
|
||||
return builder(expressions[0], expressions[1]);
|
||||
}
|
||||
|
||||
template<Nz::ShaderAst::BinaryType BinOp>
|
||||
template<Nz::ShaderNodes::BinaryType BinOp>
|
||||
QtNodes::NodeDataType VecBinOp<BinOp>::dataType(QtNodes::PortType /*portType*/, QtNodes::PortIndex portIndex) const
|
||||
{
|
||||
assert(portIndex == 0 || portIndex == 1);
|
||||
@@ -25,7 +25,7 @@ QtNodes::NodeDataType VecBinOp<BinOp>::dataType(QtNodes::PortType /*portType*/,
|
||||
return VecData::Type();
|
||||
}
|
||||
|
||||
template<Nz::ShaderAst::BinaryType BinOp>
|
||||
template<Nz::ShaderNodes::BinaryType BinOp>
|
||||
unsigned int VecBinOp<BinOp>::nPorts(QtNodes::PortType portType) const
|
||||
{
|
||||
switch (portType)
|
||||
@@ -37,14 +37,14 @@ unsigned int VecBinOp<BinOp>::nPorts(QtNodes::PortType portType) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<Nz::ShaderAst::BinaryType BinOp>
|
||||
template<Nz::ShaderNodes::BinaryType BinOp>
|
||||
std::shared_ptr<QtNodes::NodeData> VecBinOp<BinOp>::outData(QtNodes::PortIndex port)
|
||||
{
|
||||
assert(port == 0);
|
||||
return m_output;
|
||||
}
|
||||
|
||||
template<Nz::ShaderAst::BinaryType BinOp>
|
||||
template<Nz::ShaderNodes::BinaryType BinOp>
|
||||
void VecBinOp<BinOp>::setInData(std::shared_ptr<QtNodes::NodeData> value, int index)
|
||||
{
|
||||
assert(index == 0 || index == 1);
|
||||
@@ -65,7 +65,7 @@ void VecBinOp<BinOp>::setInData(std::shared_ptr<QtNodes::NodeData> value, int in
|
||||
UpdateOutput();
|
||||
}
|
||||
|
||||
template<Nz::ShaderAst::BinaryType BinOp>
|
||||
template<Nz::ShaderNodes::BinaryType BinOp>
|
||||
QtNodes::NodeValidationState VecBinOp<BinOp>::validationState() const
|
||||
{
|
||||
if (!m_lhs || !m_rhs)
|
||||
@@ -77,7 +77,7 @@ QtNodes::NodeValidationState VecBinOp<BinOp>::validationState() const
|
||||
return QtNodes::NodeValidationState::Valid;
|
||||
}
|
||||
|
||||
template<Nz::ShaderAst::BinaryType BinOp>
|
||||
template<Nz::ShaderNodes::BinaryType BinOp>
|
||||
QString VecBinOp<BinOp>::validationMessage() const
|
||||
{
|
||||
if (!m_lhs || !m_rhs)
|
||||
@@ -89,7 +89,7 @@ QString VecBinOp<BinOp>::validationMessage() const
|
||||
return QString();
|
||||
}
|
||||
|
||||
template<Nz::ShaderAst::BinaryType BinOp>
|
||||
template<Nz::ShaderNodes::BinaryType BinOp>
|
||||
bool VecBinOp<BinOp>::ComputePreview(QPixmap& pixmap)
|
||||
{
|
||||
if (!m_lhs || !m_rhs)
|
||||
@@ -99,7 +99,7 @@ bool VecBinOp<BinOp>::ComputePreview(QPixmap& pixmap)
|
||||
return true;
|
||||
}
|
||||
|
||||
template<Nz::ShaderAst::BinaryType BinOp>
|
||||
template<Nz::ShaderNodes::BinaryType BinOp>
|
||||
void VecBinOp<BinOp>::UpdateOutput()
|
||||
{
|
||||
if (validationState() != QtNodes::NodeValidationState::Valid)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <ShaderNode/DataModels/VecDot.hpp>
|
||||
#include <Nazara/Renderer/ShaderAst.hpp>
|
||||
#include <Nazara/Renderer/ShaderNodes.hpp>
|
||||
|
||||
VecDot::VecDot(ShaderGraph& graph) :
|
||||
ShaderNode(graph)
|
||||
@@ -8,11 +8,11 @@ ShaderNode(graph)
|
||||
UpdateOutput();
|
||||
}
|
||||
|
||||
Nz::ShaderAst::ExpressionPtr VecDot::GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const
|
||||
Nz::ShaderNodes::ExpressionPtr VecDot::GetExpression(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count) const
|
||||
{
|
||||
assert(count == 2);
|
||||
using namespace Nz::ShaderAst;
|
||||
return BinaryFunc::Build(BinaryIntrinsic::DotProduct, expressions[0], expressions[1]);
|
||||
using namespace Nz::ShaderNodes;
|
||||
return IntrinsicCall::Build(IntrinsicType::DotProduct, { expressions[0], expressions[1] });
|
||||
}
|
||||
|
||||
QString VecDot::caption() const
|
||||
|
||||
@@ -13,7 +13,7 @@ class VecDot : public ShaderNode
|
||||
VecDot(ShaderGraph& graph);
|
||||
~VecDot() = default;
|
||||
|
||||
Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const override;
|
||||
Nz::ShaderNodes::ExpressionPtr GetExpression(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count) const override;
|
||||
|
||||
QString caption() const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <ShaderNode/DataModels/VecFloatMul.hpp>
|
||||
#include <Nazara/Renderer/ShaderAst.hpp>
|
||||
#include <Nazara/Renderer/ShaderNodes.hpp>
|
||||
|
||||
VecFloatMul::VecFloatMul(ShaderGraph& graph) :
|
||||
ShaderNode(graph)
|
||||
@@ -7,10 +7,10 @@ ShaderNode(graph)
|
||||
UpdateOutput();
|
||||
}
|
||||
|
||||
Nz::ShaderAst::ExpressionPtr VecFloatMul::GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const
|
||||
Nz::ShaderNodes::ExpressionPtr VecFloatMul::GetExpression(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count) const
|
||||
{
|
||||
assert(count == 2);
|
||||
using namespace Nz::ShaderAst;
|
||||
using namespace Nz::ShaderNodes;
|
||||
return BinaryOp::Build(BinaryType::Multiply, expressions[0], expressions[1]);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class VecFloatMul : public ShaderNode
|
||||
VecFloatMul(ShaderGraph& graph);
|
||||
~VecFloatMul() = default;
|
||||
|
||||
Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const override;
|
||||
Nz::ShaderNodes::ExpressionPtr GetExpression(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count) const override;
|
||||
|
||||
QString caption() const override;
|
||||
QString name() const override;
|
||||
|
||||
@@ -29,7 +29,7 @@ class VecValue : public ShaderNode
|
||||
|
||||
void BuildNodeEdition(QFormLayout* layout) override;
|
||||
|
||||
Nz::ShaderAst::ExpressionPtr GetExpression(Nz::ShaderAst::ExpressionPtr* expressions, std::size_t count) const override;
|
||||
Nz::ShaderNodes::ExpressionPtr GetExpression(Nz::ShaderNodes::ExpressionPtr* expressions, std::size_t count) const override;
|
||||
|
||||
private:
|
||||
bool ComputePreview(QPixmap& pixmap) override;
|
||||
|
||||
@@ -94,7 +94,7 @@ void VecValue<ComponentCount>::BuildNodeEdition(QFormLayout* layout)
|
||||
}
|
||||
|
||||
template<std::size_t ComponentCount>
|
||||
Nz::ShaderAst::ExpressionPtr VecValue<ComponentCount>::GetExpression(Nz::ShaderAst::ExpressionPtr* /*expressions*/, std::size_t count) const
|
||||
Nz::ShaderNodes::ExpressionPtr VecValue<ComponentCount>::GetExpression(Nz::ShaderNodes::ExpressionPtr* /*expressions*/, std::size_t count) const
|
||||
{
|
||||
assert(count == 0);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#ifndef NAZARA_SHADERNODES_TEXTUREDATA_HPP
|
||||
#define NAZARA_SHADERNODES_TEXTUREDATA_HPP
|
||||
|
||||
#include <Nazara/Renderer/ShaderAst.hpp>
|
||||
#include <Nazara/Renderer/ShaderNodes.hpp>
|
||||
#include <nodes/NodeData>
|
||||
#include <QtGui/QImage>
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
#include <cassert>
|
||||
#include <stdexcept>
|
||||
|
||||
Nz::ShaderAst::ExpressionType VecData::GetExpressionType() const
|
||||
Nz::ShaderNodes::ExpressionType VecData::GetExpressionType() const
|
||||
{
|
||||
switch (componentCount)
|
||||
{
|
||||
case 2: return Nz::ShaderAst::ExpressionType::Float2;
|
||||
case 3: return Nz::ShaderAst::ExpressionType::Float3;
|
||||
case 4: return Nz::ShaderAst::ExpressionType::Float4;
|
||||
case 2: return Nz::ShaderNodes::ExpressionType::Float2;
|
||||
case 3: return Nz::ShaderNodes::ExpressionType::Float3;
|
||||
case 4: return Nz::ShaderNodes::ExpressionType::Float4;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#ifndef NAZARA_SHADERNODES_VECDATA_HPP
|
||||
#define NAZARA_SHADERNODES_VECDATA_HPP
|
||||
|
||||
#include <Nazara/Renderer/ShaderAst.hpp>
|
||||
#include <Nazara/Renderer/ShaderNodes.hpp>
|
||||
#include <nodes/NodeData>
|
||||
#include <QtGui/QImage>
|
||||
|
||||
@@ -13,7 +13,7 @@ struct VecData : public QtNodes::NodeData
|
||||
|
||||
inline QtNodes::NodeDataType type() const override;
|
||||
|
||||
Nz::ShaderAst::ExpressionType GetExpressionType() const;
|
||||
Nz::ShaderNodes::ExpressionType GetExpressionType() const;
|
||||
|
||||
static inline QtNodes::NodeDataType Type();
|
||||
|
||||
@@ -27,28 +27,28 @@ struct VecExpressionTypeHelper;
|
||||
template<>
|
||||
struct VecExpressionTypeHelper<1>
|
||||
{
|
||||
static constexpr Nz::ShaderAst::ExpressionType ExpressionType = Nz::ShaderAst::ExpressionType::Float1;
|
||||
static constexpr Nz::ShaderNodes::ExpressionType ExpressionType = Nz::ShaderNodes::ExpressionType::Float1;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct VecExpressionTypeHelper<2>
|
||||
{
|
||||
static constexpr Nz::ShaderAst::ExpressionType ExpressionType = Nz::ShaderAst::ExpressionType::Float2;
|
||||
static constexpr Nz::ShaderNodes::ExpressionType ExpressionType = Nz::ShaderNodes::ExpressionType::Float2;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct VecExpressionTypeHelper<3>
|
||||
{
|
||||
static constexpr Nz::ShaderAst::ExpressionType ExpressionType = Nz::ShaderAst::ExpressionType::Float3;
|
||||
static constexpr Nz::ShaderNodes::ExpressionType ExpressionType = Nz::ShaderNodes::ExpressionType::Float3;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct VecExpressionTypeHelper<4>
|
||||
{
|
||||
static constexpr Nz::ShaderAst::ExpressionType ExpressionType = Nz::ShaderAst::ExpressionType::Float4;
|
||||
static constexpr Nz::ShaderNodes::ExpressionType ExpressionType = Nz::ShaderNodes::ExpressionType::Float4;
|
||||
};
|
||||
|
||||
template<std::size_t N> constexpr Nz::ShaderAst::ExpressionType VecExpressionType = VecExpressionTypeHelper<N>::template ExpressionType;
|
||||
template<std::size_t N> constexpr Nz::ShaderNodes::ExpressionType VecExpressionType = VecExpressionTypeHelper<N>::template ExpressionType;
|
||||
|
||||
|
||||
struct VecTypeDummy {};
|
||||
|
||||
@@ -46,9 +46,9 @@ m_flowScene(BuildRegistry())
|
||||
});
|
||||
|
||||
// Test
|
||||
AddInput("UV", InOutType::Float2, InputRole::TexCoord, 0);
|
||||
AddOutput("RenderTarget0", InOutType::Float4);
|
||||
AddTexture("Potato", TextureType::Sampler2D);
|
||||
AddInput("UV", InOutType::Float2, InputRole::TexCoord, 0, 0);
|
||||
AddOutput("RenderTarget0", InOutType::Float4, 0);
|
||||
AddTexture("Potato", TextureType::Sampler2D, 1);
|
||||
|
||||
UpdateTexturePreview(0, QImage(R"(C:\Users\Lynix\Pictures\potatavril.png)"));
|
||||
|
||||
@@ -79,10 +79,11 @@ ShaderGraph::~ShaderGraph()
|
||||
m_flowScene.clearScene();
|
||||
}
|
||||
|
||||
std::size_t ShaderGraph::AddInput(std::string name, InOutType type, InputRole role, std::size_t roleIndex)
|
||||
std::size_t ShaderGraph::AddInput(std::string name, InOutType type, InputRole role, std::size_t roleIndex, std::size_t locationIndex)
|
||||
{
|
||||
std::size_t index = m_inputs.size();
|
||||
auto& inputEntry = m_inputs.emplace_back();
|
||||
inputEntry.locationIndex = locationIndex;
|
||||
inputEntry.name = std::move(name);
|
||||
inputEntry.role = role;
|
||||
inputEntry.roleIndex = roleIndex;
|
||||
@@ -93,10 +94,11 @@ std::size_t ShaderGraph::AddInput(std::string name, InOutType type, InputRole ro
|
||||
return index;
|
||||
}
|
||||
|
||||
std::size_t ShaderGraph::AddOutput(std::string name, InOutType type)
|
||||
std::size_t ShaderGraph::AddOutput(std::string name, InOutType type, std::size_t locationIndex)
|
||||
{
|
||||
std::size_t index = m_outputs.size();
|
||||
auto& outputEntry = m_outputs.emplace_back();
|
||||
outputEntry.locationIndex = locationIndex;
|
||||
outputEntry.name = std::move(name);
|
||||
outputEntry.type = type;
|
||||
|
||||
@@ -105,10 +107,11 @@ std::size_t ShaderGraph::AddOutput(std::string name, InOutType type)
|
||||
return index;
|
||||
}
|
||||
|
||||
std::size_t ShaderGraph::AddTexture(std::string name, TextureType type)
|
||||
std::size_t ShaderGraph::AddTexture(std::string name, TextureType type, std::size_t bindingIndex)
|
||||
{
|
||||
std::size_t index = m_textures.size();
|
||||
auto& textureEntry = m_textures.emplace_back();
|
||||
textureEntry.bindingIndex = bindingIndex;
|
||||
textureEntry.name = std::move(name);
|
||||
textureEntry.type = type;
|
||||
|
||||
@@ -141,6 +144,7 @@ void ShaderGraph::Load(const QJsonObject& data)
|
||||
QJsonObject inputDoc = inputDocRef.toObject();
|
||||
|
||||
InputEntry& input = m_inputs.emplace_back();
|
||||
input.locationIndex = static_cast<std::size_t>(inputDoc["locationIndex"].toInt(0));
|
||||
input.name = inputDoc["name"].toString().toStdString();
|
||||
input.role = DecodeEnum<InputRole>(inputDoc["role"].toString().toStdString()).value();
|
||||
input.roleIndex = static_cast<std::size_t>(inputDoc["roleIndex"].toInt(0));
|
||||
@@ -155,6 +159,7 @@ void ShaderGraph::Load(const QJsonObject& data)
|
||||
QJsonObject outputDoc = outputDocRef.toObject();
|
||||
|
||||
OutputEntry& output = m_outputs.emplace_back();
|
||||
output.locationIndex = static_cast<std::size_t>(outputDoc["locationIndex"].toInt(0));
|
||||
output.name = outputDoc["name"].toString().toStdString();
|
||||
output.type = DecodeEnum<InOutType>(outputDoc["type"].toString().toStdString()).value();
|
||||
}
|
||||
@@ -167,6 +172,7 @@ void ShaderGraph::Load(const QJsonObject& data)
|
||||
QJsonObject textureDoc = textureDocRef.toObject();
|
||||
|
||||
TextureEntry& texture = m_textures.emplace_back();
|
||||
texture.bindingIndex = static_cast<std::size_t>(textureDoc["bindingIndex"].toInt(0));
|
||||
texture.name = textureDoc["name"].toString().toStdString();
|
||||
texture.type = DecodeEnum<TextureType>(textureDoc["type"].toString().toStdString()).value();
|
||||
}
|
||||
@@ -189,6 +195,7 @@ QJsonObject ShaderGraph::Save()
|
||||
for (const auto& input : m_inputs)
|
||||
{
|
||||
QJsonObject inputDoc;
|
||||
inputDoc["locationIndex"] = int(input.locationIndex);
|
||||
inputDoc["name"] = QString::fromStdString(input.name);
|
||||
inputDoc["role"] = QString(EnumToString(input.role));
|
||||
inputDoc["roleIndex"] = int(input.roleIndex);
|
||||
@@ -204,6 +211,7 @@ QJsonObject ShaderGraph::Save()
|
||||
for (const auto& output : m_outputs)
|
||||
{
|
||||
QJsonObject outputDoc;
|
||||
outputDoc["locationIndex"] = int(output.locationIndex);
|
||||
outputDoc["name"] = QString::fromStdString(output.name);
|
||||
outputDoc["type"] = QString(EnumToString(output.type));
|
||||
|
||||
@@ -217,6 +225,7 @@ QJsonObject ShaderGraph::Save()
|
||||
for (const auto& texture : m_textures)
|
||||
{
|
||||
QJsonObject textureDoc;
|
||||
textureDoc["bindingIndex"] = int(texture.bindingIndex);
|
||||
textureDoc["name"] = QString::fromStdString(texture.name);
|
||||
textureDoc["type"] = QString(EnumToString(texture.type));
|
||||
|
||||
@@ -247,9 +256,9 @@ QJsonObject ShaderGraph::Save()
|
||||
return sceneJson;
|
||||
}
|
||||
|
||||
Nz::ShaderAst::StatementPtr ShaderGraph::ToAst()
|
||||
Nz::ShaderNodes::StatementPtr ShaderGraph::ToAst()
|
||||
{
|
||||
std::vector<Nz::ShaderAst::StatementPtr> statements;
|
||||
std::vector<Nz::ShaderNodes::StatementPtr> statements;
|
||||
QHash<QUuid, unsigned int> usageCount;
|
||||
|
||||
std::function<void(QtNodes::Node*)> DetectVariables;
|
||||
@@ -278,13 +287,13 @@ Nz::ShaderAst::StatementPtr ShaderGraph::ToAst()
|
||||
DetectVariables(node);
|
||||
});
|
||||
|
||||
QHash<QUuid, Nz::ShaderAst::ExpressionPtr> variableExpressions;
|
||||
QHash<QUuid, Nz::ShaderNodes::ExpressionPtr> variableExpressions;
|
||||
|
||||
unsigned int varCount = 0;
|
||||
std::unordered_set<std::string> usedVariableNames;
|
||||
|
||||
std::function<Nz::ShaderAst::ExpressionPtr(QtNodes::Node*)> HandleNode;
|
||||
HandleNode = [&](QtNodes::Node* node) -> Nz::ShaderAst::ExpressionPtr
|
||||
std::function<Nz::ShaderNodes::ExpressionPtr(QtNodes::Node*)> HandleNode;
|
||||
HandleNode = [&](QtNodes::Node* node) -> Nz::ShaderNodes::ExpressionPtr
|
||||
{
|
||||
ShaderNode* shaderNode = static_cast<ShaderNode*>(node->nodeDataModel());
|
||||
if (shaderNode->validationState() != QtNodes::NodeValidationState::Valid)
|
||||
@@ -298,7 +307,7 @@ Nz::ShaderAst::StatementPtr ShaderGraph::ToAst()
|
||||
assert(it != usageCount.end());
|
||||
|
||||
std::size_t inputCount = shaderNode->nPorts(QtNodes::PortType::In);
|
||||
Nz::StackArray<Nz::ShaderAst::ExpressionPtr> expressions = NazaraStackArray(Nz::ShaderAst::ExpressionPtr, inputCount);
|
||||
Nz::StackArray<Nz::ShaderNodes::ExpressionPtr> expressions = NazaraStackArray(Nz::ShaderNodes::ExpressionPtr, inputCount);
|
||||
std::size_t i = 0;
|
||||
|
||||
for (const auto& connectionSet : node->nodeState().getEntries(QtNodes::PortType::In))
|
||||
@@ -316,8 +325,8 @@ Nz::ShaderAst::StatementPtr ShaderGraph::ToAst()
|
||||
const std::string& variableName = shaderNode->GetVariableName();
|
||||
if (*it > 1 || !variableName.empty())
|
||||
{
|
||||
Nz::ShaderAst::ExpressionPtr varExpression;
|
||||
if (expression->GetExpressionCategory() == Nz::ShaderAst::ExpressionCategory::RValue)
|
||||
Nz::ShaderNodes::ExpressionPtr varExpression;
|
||||
if (expression->GetExpressionCategory() == Nz::ShaderNodes::ExpressionCategory::RValue)
|
||||
{
|
||||
std::string name;
|
||||
if (variableName.empty())
|
||||
@@ -330,10 +339,10 @@ Nz::ShaderAst::StatementPtr ShaderGraph::ToAst()
|
||||
|
||||
usedVariableNames.insert(name);
|
||||
|
||||
auto variable = Nz::ShaderBuilder::Variable(std::move(name), expression->GetExpressionType());
|
||||
auto variable = Nz::ShaderBuilder::Local(std::move(name), expression->GetExpressionType());
|
||||
statements.emplace_back(Nz::ShaderBuilder::DeclareVariable(variable, expression));
|
||||
|
||||
varExpression = variable;
|
||||
varExpression = Nz::ShaderBuilder::Identifier(variable);
|
||||
}
|
||||
else
|
||||
varExpression = expression;
|
||||
@@ -354,13 +363,14 @@ Nz::ShaderAst::StatementPtr ShaderGraph::ToAst()
|
||||
}
|
||||
});
|
||||
|
||||
return Nz::ShaderAst::StatementBlock::Build(std::move(statements));
|
||||
return Nz::ShaderNodes::StatementBlock::Build(std::move(statements));
|
||||
}
|
||||
|
||||
void ShaderGraph::UpdateInput(std::size_t inputIndex, std::string name, InOutType type, InputRole role, std::size_t roleIndex)
|
||||
void ShaderGraph::UpdateInput(std::size_t inputIndex, std::string name, InOutType type, InputRole role, std::size_t roleIndex, std::size_t locationIndex)
|
||||
{
|
||||
assert(inputIndex < m_inputs.size());
|
||||
auto& inputEntry = m_inputs[inputIndex];
|
||||
inputEntry.locationIndex = locationIndex;
|
||||
inputEntry.name = std::move(name);
|
||||
inputEntry.role = role;
|
||||
inputEntry.roleIndex = roleIndex;
|
||||
@@ -369,10 +379,11 @@ void ShaderGraph::UpdateInput(std::size_t inputIndex, std::string name, InOutTyp
|
||||
OnInputUpdate(this, inputIndex);
|
||||
}
|
||||
|
||||
void ShaderGraph::UpdateOutput(std::size_t outputIndex, std::string name, InOutType type)
|
||||
void ShaderGraph::UpdateOutput(std::size_t outputIndex, std::string name, InOutType type, std::size_t locationIndex)
|
||||
{
|
||||
assert(outputIndex < m_outputs.size());
|
||||
auto& outputEntry = m_outputs[outputIndex];
|
||||
outputEntry.locationIndex = locationIndex;
|
||||
outputEntry.name = std::move(name);
|
||||
outputEntry.type = type;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define NAZARA_SHADERNODES_SHADERGRAPH_HPP
|
||||
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Renderer/ShaderAst.hpp>
|
||||
#include <Nazara/Renderer/ShaderNodes.hpp>
|
||||
#include <nodes/FlowScene>
|
||||
#include <ShaderNode/Enums.hpp>
|
||||
#include <ShaderNode/Previews/PreviewModel.hpp>
|
||||
@@ -23,9 +23,9 @@ class ShaderGraph
|
||||
ShaderGraph();
|
||||
~ShaderGraph();
|
||||
|
||||
std::size_t AddInput(std::string name, InOutType type, InputRole role, std::size_t roleIndex);
|
||||
std::size_t AddOutput(std::string name, InOutType type);
|
||||
std::size_t AddTexture(std::string name, TextureType type);
|
||||
std::size_t AddInput(std::string name, InOutType type, InputRole role, std::size_t roleIndex, std::size_t locationIndex);
|
||||
std::size_t AddOutput(std::string name, InOutType type, std::size_t locationIndex);
|
||||
std::size_t AddTexture(std::string name, TextureType type, std::size_t bindingIndex);
|
||||
|
||||
void Clear();
|
||||
|
||||
@@ -44,14 +44,15 @@ class ShaderGraph
|
||||
void Load(const QJsonObject& data);
|
||||
QJsonObject Save();
|
||||
|
||||
Nz::ShaderAst::StatementPtr ToAst();
|
||||
Nz::ShaderNodes::StatementPtr ToAst();
|
||||
|
||||
void UpdateInput(std::size_t inputIndex, std::string name, InOutType type, InputRole role, std::size_t roleIndex);
|
||||
void UpdateOutput(std::size_t outputIndex, std::string name, InOutType type);
|
||||
void UpdateInput(std::size_t inputIndex, std::string name, InOutType type, InputRole role, std::size_t roleIndex, std::size_t locationIndex);
|
||||
void UpdateOutput(std::size_t outputIndex, std::string name, InOutType type, std::size_t locationIndex);
|
||||
void UpdateTexturePreview(std::size_t texture, QImage preview);
|
||||
|
||||
struct InputEntry
|
||||
{
|
||||
std::size_t locationIndex;
|
||||
std::size_t roleIndex;
|
||||
std::string name;
|
||||
InputRole role;
|
||||
@@ -60,12 +61,14 @@ class ShaderGraph
|
||||
|
||||
struct OutputEntry
|
||||
{
|
||||
std::size_t locationIndex;
|
||||
std::string name;
|
||||
InOutType type;
|
||||
};
|
||||
|
||||
struct TextureEntry
|
||||
{
|
||||
std::size_t bindingIndex;
|
||||
std::string name;
|
||||
TextureType type;
|
||||
QImage preview;
|
||||
|
||||
@@ -23,6 +23,8 @@ QDialog(parent)
|
||||
for (std::size_t i = 0; i < InputRoleCount; ++i)
|
||||
m_roleList->addItem(EnumToString(static_cast<InputRole>(i)));
|
||||
|
||||
m_locationIndex = new QSpinBox;
|
||||
|
||||
m_roleIndex = new QSpinBox;
|
||||
|
||||
QFormLayout* formLayout = new QFormLayout;
|
||||
@@ -30,6 +32,7 @@ QDialog(parent)
|
||||
formLayout->addRow(tr("Type"), m_typeList);
|
||||
formLayout->addRow(tr("Role"), m_roleList);
|
||||
formLayout->addRow(tr("Role index"), m_roleIndex);
|
||||
formLayout->addRow(tr("Input index"), m_locationIndex);
|
||||
|
||||
QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &InputEditDialog::OnAccept);
|
||||
@@ -46,6 +49,7 @@ InputEditDialog::InputEditDialog(const InputInfo& input, QWidget* parent) :
|
||||
InputEditDialog(parent)
|
||||
{
|
||||
m_inputName->setText(QString::fromStdString(input.name));
|
||||
m_locationIndex->setValue(int(input.locationIndex));
|
||||
m_roleIndex->setValue(int(input.roleIndex));
|
||||
m_roleList->setCurrentText(EnumToString(input.role));
|
||||
m_typeList->setCurrentText(EnumToString(input.type));
|
||||
@@ -54,6 +58,7 @@ InputEditDialog(parent)
|
||||
InputInfo InputEditDialog::GetInputInfo() const
|
||||
{
|
||||
InputInfo inputInfo;
|
||||
inputInfo.locationIndex = static_cast<std::size_t>(m_locationIndex->value());
|
||||
inputInfo.name = m_inputName->text().toStdString();
|
||||
inputInfo.role = static_cast<InputRole>(m_roleList->currentIndex());
|
||||
inputInfo.roleIndex = static_cast<std::size_t>(m_roleIndex->value());
|
||||
|
||||
@@ -12,6 +12,7 @@ class QSpinBox;
|
||||
|
||||
struct InputInfo
|
||||
{
|
||||
std::size_t locationIndex;
|
||||
std::size_t roleIndex;
|
||||
std::string name;
|
||||
InputRole role;
|
||||
@@ -33,6 +34,7 @@ class InputEditDialog : public QDialog
|
||||
QComboBox* m_roleList;
|
||||
QComboBox* m_typeList;
|
||||
QLineEdit* m_inputName;
|
||||
QSpinBox* m_locationIndex;
|
||||
QSpinBox* m_roleIndex;
|
||||
};
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ void InputEditor::OnAddInput()
|
||||
connect(dialog, &QDialog::accepted, [this, dialog]
|
||||
{
|
||||
InputInfo inputInfo = dialog->GetInputInfo();
|
||||
m_shaderGraph.AddInput(std::move(inputInfo.name), inputInfo.type, inputInfo.role, inputInfo.roleIndex);
|
||||
m_shaderGraph.AddInput(std::move(inputInfo.name), inputInfo.type, inputInfo.role, inputInfo.roleIndex, inputInfo.locationIndex);
|
||||
});
|
||||
|
||||
dialog->open();
|
||||
@@ -60,7 +60,7 @@ void InputEditor::OnEditInput(int inputIndex)
|
||||
connect(dialog, &QDialog::accepted, [this, dialog, inputIndex]
|
||||
{
|
||||
InputInfo inputInfo = dialog->GetInputInfo();
|
||||
m_shaderGraph.UpdateInput(inputIndex, std::move(inputInfo.name), inputInfo.type, inputInfo.role, inputInfo.roleIndex);
|
||||
m_shaderGraph.UpdateInput(inputIndex, std::move(inputInfo.name), inputInfo.type, inputInfo.role, inputInfo.roleIndex, inputInfo.locationIndex);
|
||||
});
|
||||
|
||||
dialog->open();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <ShaderNode/Widgets/MainWindow.hpp>
|
||||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Renderer/GlslWriter.hpp>
|
||||
#include <Nazara/Renderer/ShaderSerializer.hpp>
|
||||
#include <ShaderNode/ShaderGraph.hpp>
|
||||
#include <ShaderNode/Widgets/InputEditor.hpp>
|
||||
#include <ShaderNode/Widgets/OutputEditor.hpp>
|
||||
@@ -84,8 +86,6 @@ void MainWindow::BuildMenu()
|
||||
|
||||
QMenu* shader = menu->addMenu(tr("&Shader"));
|
||||
{
|
||||
QtNodes::FlowScene* scene = &m_shaderGraph.GetScene();
|
||||
|
||||
QAction* loadShader = shader->addAction(tr("Load..."));
|
||||
QObject::connect(loadShader, &QAction::triggered, this, &MainWindow::OnLoad);
|
||||
QAction* saveShader = shader->addAction(tr("Save..."));
|
||||
@@ -101,8 +101,52 @@ void MainWindow::OnCompileToGLSL()
|
||||
{
|
||||
try
|
||||
{
|
||||
Nz::ShaderNodes::StatementPtr shaderAst = m_shaderGraph.ToAst();
|
||||
|
||||
Nz::File file("shader.shader", Nz::OpenMode_WriteOnly);
|
||||
file.Write(Nz::ShaderNodes::Serialize(shaderAst));
|
||||
|
||||
//TODO: Put in another function
|
||||
auto GetExpressionFromInOut = [&] (InOutType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case InOutType::Bool: return Nz::ShaderNodes::ExpressionType::Boolean;
|
||||
case InOutType::Float1: return Nz::ShaderNodes::ExpressionType::Float1;
|
||||
case InOutType::Float2: return Nz::ShaderNodes::ExpressionType::Float2;
|
||||
case InOutType::Float3: return Nz::ShaderNodes::ExpressionType::Float3;
|
||||
case InOutType::Float4: return Nz::ShaderNodes::ExpressionType::Float4;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
throw std::runtime_error("Unhandled input type");
|
||||
};
|
||||
|
||||
auto GetExpressionFromTexture = [&](TextureType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case TextureType::Sampler2D: return Nz::ShaderNodes::ExpressionType::Sampler2D;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
throw std::runtime_error("Unhandled texture type");
|
||||
};
|
||||
|
||||
Nz::ShaderAst shader;
|
||||
for (const auto& input : m_shaderGraph.GetInputs())
|
||||
shader.AddInput(input.name, GetExpressionFromInOut(input.type), input.locationIndex);
|
||||
|
||||
for (const auto& output : m_shaderGraph.GetOutputs())
|
||||
shader.AddOutput(output.name, GetExpressionFromInOut(output.type), output.locationIndex);
|
||||
|
||||
for (const auto& uniform : m_shaderGraph.GetTextures())
|
||||
shader.AddUniform(uniform.name, GetExpressionFromTexture(uniform.type), uniform.bindingIndex);
|
||||
|
||||
shader.AddFunction("main", shaderAst);
|
||||
|
||||
Nz::GlslWriter writer;
|
||||
Nz::String glsl = writer.Generate(m_shaderGraph.ToAst());
|
||||
Nz::String glsl = writer.Generate(shader);
|
||||
|
||||
std::cout << glsl << std::endl;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QtWidgets/QFormLayout>
|
||||
#include <QtWidgets/QLineEdit>
|
||||
#include <QtWidgets/QMessageBox>
|
||||
#include <QtWidgets/QSpinBox>
|
||||
#include <QtWidgets/QVBoxLayout>
|
||||
|
||||
OutputEditDialog::OutputEditDialog(QWidget* parent) :
|
||||
@@ -18,9 +19,12 @@ QDialog(parent)
|
||||
for (std::size_t i = 0; i < InOutTypeCount; ++i)
|
||||
m_typeList->addItem(EnumToString(static_cast<InOutType>(i)));
|
||||
|
||||
m_locationIndex = new QSpinBox;
|
||||
|
||||
QFormLayout* formLayout = new QFormLayout;
|
||||
formLayout->addRow(tr("Name"), m_outputName);
|
||||
formLayout->addRow(tr("Type"), m_typeList);
|
||||
formLayout->addRow(tr("Output index"), m_locationIndex);
|
||||
|
||||
QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &OutputEditDialog::OnAccept);
|
||||
@@ -33,16 +37,18 @@ QDialog(parent)
|
||||
setLayout(verticalLayout);
|
||||
}
|
||||
|
||||
OutputEditDialog::OutputEditDialog(const OutputInfo& input, QWidget* parent) :
|
||||
OutputEditDialog::OutputEditDialog(const OutputInfo& output, QWidget* parent) :
|
||||
OutputEditDialog(parent)
|
||||
{
|
||||
m_outputName->setText(QString::fromStdString(input.name));
|
||||
m_typeList->setCurrentText(EnumToString(input.type));
|
||||
m_locationIndex->setValue(int(output.locationIndex));
|
||||
m_outputName->setText(QString::fromStdString(output.name));
|
||||
m_typeList->setCurrentText(EnumToString(output.type));
|
||||
}
|
||||
|
||||
OutputInfo OutputEditDialog::GetOutputInfo() const
|
||||
{
|
||||
OutputInfo inputInfo;
|
||||
inputInfo.locationIndex = static_cast<std::size_t>(m_locationIndex->value());
|
||||
inputInfo.name = m_outputName->text().toStdString();
|
||||
inputInfo.type = static_cast<InOutType>(m_typeList->currentIndex());
|
||||
|
||||
|
||||
@@ -8,9 +8,11 @@
|
||||
|
||||
class QComboBox;
|
||||
class QLineEdit;
|
||||
class QSpinBox;
|
||||
|
||||
struct OutputInfo
|
||||
{
|
||||
std::size_t locationIndex;
|
||||
std::string name;
|
||||
InOutType type;
|
||||
};
|
||||
@@ -19,7 +21,7 @@ class OutputEditDialog : public QDialog
|
||||
{
|
||||
public:
|
||||
OutputEditDialog(QWidget* parent = nullptr);
|
||||
OutputEditDialog(const OutputInfo& input, QWidget* parent = nullptr);
|
||||
OutputEditDialog(const OutputInfo& output, QWidget* parent = nullptr);
|
||||
~OutputEditDialog() = default;
|
||||
|
||||
OutputInfo GetOutputInfo() const;
|
||||
@@ -29,6 +31,7 @@ class OutputEditDialog : public QDialog
|
||||
|
||||
QComboBox* m_typeList;
|
||||
QLineEdit* m_outputName;
|
||||
QSpinBox* m_locationIndex;
|
||||
};
|
||||
|
||||
#include <ShaderNode/Widgets/OutputEditDialog.inl>
|
||||
|
||||
@@ -38,8 +38,8 @@ void OutputEditor::OnAddOutput()
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
connect(dialog, &QDialog::accepted, [this, dialog]
|
||||
{
|
||||
OutputInfo inputInfo = dialog->GetOutputInfo();
|
||||
m_shaderGraph.AddOutput(std::move(inputInfo.name), inputInfo.type);
|
||||
OutputInfo outputInfo = dialog->GetOutputInfo();
|
||||
m_shaderGraph.AddOutput(std::move(outputInfo.name), outputInfo.type, outputInfo.locationIndex);
|
||||
});
|
||||
|
||||
dialog->open();
|
||||
@@ -57,8 +57,8 @@ void OutputEditor::OnEditOutput(int inputIndex)
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
connect(dialog, &QDialog::accepted, [this, dialog, inputIndex]
|
||||
{
|
||||
OutputInfo inputInfo = dialog->GetOutputInfo();
|
||||
m_shaderGraph.UpdateOutput(inputIndex, std::move(inputInfo.name), inputInfo.type);
|
||||
OutputInfo outputInfo = dialog->GetOutputInfo();
|
||||
m_shaderGraph.UpdateOutput(inputIndex, std::move(outputInfo.name), outputInfo.type, outputInfo.locationIndex);
|
||||
});
|
||||
|
||||
dialog->open();
|
||||
|
||||
Reference in New Issue
Block a user