ShaderEditor: Fixes
This commit is contained in:
parent
2258a4f87f
commit
90abb52e4e
|
|
@ -38,6 +38,9 @@ class CastVec : public ShaderNode
|
||||||
bool ComputePreview(QPixmap& pixmap) override;
|
bool ComputePreview(QPixmap& pixmap) override;
|
||||||
void UpdateOutput();
|
void UpdateOutput();
|
||||||
|
|
||||||
|
void restore(const QJsonObject& data) override;
|
||||||
|
QJsonObject save() const override;
|
||||||
|
|
||||||
std::shared_ptr<VecData> m_input;
|
std::shared_ptr<VecData> m_input;
|
||||||
std::shared_ptr<VecData> m_output;
|
std::shared_ptr<VecData> m_output;
|
||||||
VecType<ToComponentCount> m_overflowComponents;
|
VecType<ToComponentCount> m_overflowComponents;
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ void CastVec<ToComponentCount>::BuildNodeEdition(QFormLayout* layout)
|
||||||
{
|
{
|
||||||
QDoubleSpinBox* spinbox = new QDoubleSpinBox;
|
QDoubleSpinBox* spinbox = new QDoubleSpinBox;
|
||||||
spinbox->setDecimals(6);
|
spinbox->setDecimals(6);
|
||||||
|
spinbox->setRange(std::numeric_limits<float>::lowest(), std::numeric_limits<float>::max());
|
||||||
spinbox->setValue(m_overflowComponents[i]);
|
spinbox->setValue(m_overflowComponents[i]);
|
||||||
|
|
||||||
connect(spinbox, qOverload<double>(&QDoubleSpinBox::valueChanged), [=](double)
|
connect(spinbox, qOverload<double>(&QDoubleSpinBox::valueChanged), [=](double)
|
||||||
|
|
@ -66,7 +67,7 @@ Nz::ShaderAst::ExpressionPtr CastVec<ToComponentCount>::GetExpression(Nz::Shader
|
||||||
|
|
||||||
constexpr auto ExpressionType = VecExpressionType<ToComponentCount>;
|
constexpr auto ExpressionType = VecExpressionType<ToComponentCount>;
|
||||||
|
|
||||||
return Nz::ShaderBuilder::Cast<ExpressionType>(expr.data(), overflowComponentCount);
|
return Nz::ShaderBuilder::Cast<ExpressionType>(expr.data(), 1 + overflowComponentCount);
|
||||||
}
|
}
|
||||||
else if (ToComponentCount < fromComponentCount)
|
else if (ToComponentCount < fromComponentCount)
|
||||||
{
|
{
|
||||||
|
|
@ -232,3 +233,29 @@ void CastVec<ToComponentCount>::UpdateOutput()
|
||||||
|
|
||||||
UpdatePreview();
|
UpdatePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<std::size_t ToComponentCount>
|
||||||
|
void CastVec<ToComponentCount>::restore(const QJsonObject& data)
|
||||||
|
{
|
||||||
|
QJsonArray vecValues = data["value"].toArray();
|
||||||
|
std::size_t commonValues = std::min(static_cast<std::size_t>(vecValues.size()), ToComponentCount);
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < commonValues; ++i)
|
||||||
|
m_overflowComponents[i] = float(vecValues[int(i)].toDouble(m_overflowComponents[i]));
|
||||||
|
|
||||||
|
ShaderNode::restore(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::size_t ToComponentCount>
|
||||||
|
QJsonObject CastVec<ToComponentCount>::save() const
|
||||||
|
{
|
||||||
|
QJsonObject data = ShaderNode::save();
|
||||||
|
|
||||||
|
QJsonArray vecValues;
|
||||||
|
for (std::size_t i = 0; i < ToComponentCount; ++i)
|
||||||
|
vecValues.push_back(m_overflowComponents[i]);
|
||||||
|
|
||||||
|
data["value"] = vecValues;
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ void FloatValue::BuildNodeEdition(QFormLayout* layout)
|
||||||
|
|
||||||
QDoubleSpinBox* spinbox = new QDoubleSpinBox;
|
QDoubleSpinBox* spinbox = new QDoubleSpinBox;
|
||||||
spinbox->setDecimals(6);
|
spinbox->setDecimals(6);
|
||||||
|
spinbox->setRange(std::numeric_limits<float>::lowest(), std::numeric_limits<float>::max());
|
||||||
spinbox->setValue(m_value);
|
spinbox->setValue(m_value);
|
||||||
|
|
||||||
connect(spinbox, qOverload<double>(&QDoubleSpinBox::valueChanged), [=](double)
|
connect(spinbox, qOverload<double>(&QDoubleSpinBox::valueChanged), [=](double)
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,8 @@ ShaderNode(graph)
|
||||||
|
|
||||||
if (graph.GetInputCount() > 0)
|
if (graph.GetInputCount() > 0)
|
||||||
{
|
{
|
||||||
auto& firstInput = graph.GetInput(0);
|
|
||||||
m_currentInputIndex = 0;
|
m_currentInputIndex = 0;
|
||||||
m_currentInputText = firstInput.name;
|
UpdateInputText();
|
||||||
}
|
}
|
||||||
|
|
||||||
DisableCustomVariableName();
|
DisableCustomVariableName();
|
||||||
|
|
@ -70,11 +69,27 @@ void InputValue::OnInputListUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InputValue::UpdateInputText()
|
||||||
|
{
|
||||||
|
if (m_currentInputIndex)
|
||||||
|
{
|
||||||
|
auto& input = GetGraph().GetInput(*m_currentInputIndex);
|
||||||
|
m_currentInputText = input.name;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_currentInputText.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void InputValue::BuildNodeEdition(QFormLayout* layout)
|
void InputValue::BuildNodeEdition(QFormLayout* layout)
|
||||||
{
|
{
|
||||||
ShaderNode::BuildNodeEdition(layout);
|
ShaderNode::BuildNodeEdition(layout);
|
||||||
|
|
||||||
QComboBox* inputSelection = new QComboBox;
|
QComboBox* inputSelection = new QComboBox;
|
||||||
|
for (const auto& inputEntry : GetGraph().GetInputs())
|
||||||
|
inputSelection->addItem(QString::fromStdString(inputEntry.name));
|
||||||
|
|
||||||
|
if (m_currentInputIndex)
|
||||||
|
inputSelection->setCurrentIndex(int(*m_currentInputIndex));
|
||||||
|
|
||||||
connect(inputSelection, qOverload<int>(&QComboBox::currentIndexChanged), [&](int index)
|
connect(inputSelection, qOverload<int>(&QComboBox::currentIndexChanged), [&](int index)
|
||||||
{
|
{
|
||||||
|
|
@ -83,11 +98,11 @@ void InputValue::BuildNodeEdition(QFormLayout* layout)
|
||||||
else
|
else
|
||||||
m_currentInputIndex.reset();
|
m_currentInputIndex.reset();
|
||||||
|
|
||||||
|
UpdateInputText();
|
||||||
UpdatePreview();
|
UpdatePreview();
|
||||||
});
|
|
||||||
|
|
||||||
for (const auto& inputEntry : GetGraph().GetInputs())
|
Q_EMIT dataUpdated(0);
|
||||||
inputSelection->addItem(QString::fromStdString(inputEntry.name));
|
});
|
||||||
|
|
||||||
layout->addRow(tr("Input"), inputSelection);
|
layout->addRow(tr("Input"), inputSelection);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ class InputValue : public ShaderNode
|
||||||
private:
|
private:
|
||||||
bool ComputePreview(QPixmap& pixmap) override;
|
bool ComputePreview(QPixmap& pixmap) override;
|
||||||
void OnInputListUpdate();
|
void OnInputListUpdate();
|
||||||
|
void UpdateInputText();
|
||||||
|
|
||||||
void restore(const QJsonObject& data) override;
|
void restore(const QJsonObject& data) override;
|
||||||
QJsonObject save() const override;
|
QJsonObject save() const override;
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,8 @@ ShaderNode(graph)
|
||||||
|
|
||||||
if (graph.GetOutputCount() > 0)
|
if (graph.GetOutputCount() > 0)
|
||||||
{
|
{
|
||||||
auto& firstOutput = graph.GetOutput(0);
|
|
||||||
m_currentOutputIndex = 0;
|
m_currentOutputIndex = 0;
|
||||||
m_currentOutputText = firstOutput.name;
|
UpdateOutputText();
|
||||||
}
|
}
|
||||||
|
|
||||||
EnablePreview();
|
EnablePreview();
|
||||||
|
|
@ -32,7 +31,12 @@ void OutputValue::BuildNodeEdition(QFormLayout* layout)
|
||||||
ShaderNode::BuildNodeEdition(layout);
|
ShaderNode::BuildNodeEdition(layout);
|
||||||
|
|
||||||
QComboBox* outputSelection = new QComboBox;
|
QComboBox* outputSelection = new QComboBox;
|
||||||
|
for (const auto& outputEntry : GetGraph().GetOutputs())
|
||||||
|
outputSelection->addItem(QString::fromStdString(outputEntry.name));
|
||||||
|
|
||||||
|
if (m_currentOutputIndex)
|
||||||
|
outputSelection->setCurrentIndex(int(*m_currentOutputIndex));
|
||||||
|
|
||||||
connect(outputSelection, qOverload<int>(&QComboBox::currentIndexChanged), [&](int index)
|
connect(outputSelection, qOverload<int>(&QComboBox::currentIndexChanged), [&](int index)
|
||||||
{
|
{
|
||||||
if (index >= 0)
|
if (index >= 0)
|
||||||
|
|
@ -40,12 +44,10 @@ void OutputValue::BuildNodeEdition(QFormLayout* layout)
|
||||||
else
|
else
|
||||||
m_currentOutputIndex.reset();
|
m_currentOutputIndex.reset();
|
||||||
|
|
||||||
|
UpdateOutputText();
|
||||||
UpdatePreview();
|
UpdatePreview();
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const auto& outputEntry : GetGraph().GetOutputs())
|
|
||||||
outputSelection->addItem(QString::fromStdString(outputEntry.name));
|
|
||||||
|
|
||||||
layout->addRow(tr("Output"), outputSelection);
|
layout->addRow(tr("Output"), outputSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -189,9 +191,20 @@ void OutputValue::OnOutputListUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OutputValue::UpdateOutputText()
|
||||||
|
{
|
||||||
|
if (m_currentOutputIndex)
|
||||||
|
{
|
||||||
|
auto& output = GetGraph().GetOutput(*m_currentOutputIndex);
|
||||||
|
m_currentOutputText = output.name;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_currentOutputText.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void OutputValue::restore(const QJsonObject& data)
|
void OutputValue::restore(const QJsonObject& data)
|
||||||
{
|
{
|
||||||
m_currentOutputText = data["input"].toString().toStdString();
|
m_currentOutputText = data["output"].toString().toStdString();
|
||||||
OnOutputListUpdate();
|
OnOutputListUpdate();
|
||||||
|
|
||||||
ShaderNode::restore(data);
|
ShaderNode::restore(data);
|
||||||
|
|
@ -200,7 +213,7 @@ void OutputValue::restore(const QJsonObject& data)
|
||||||
QJsonObject OutputValue::save() const
|
QJsonObject OutputValue::save() const
|
||||||
{
|
{
|
||||||
QJsonObject data = ShaderNode::save();
|
QJsonObject data = ShaderNode::save();
|
||||||
data["input"] = QString::fromStdString(m_currentOutputText);
|
data["output"] = QString::fromStdString(m_currentOutputText);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ class OutputValue : public ShaderNode
|
||||||
private:
|
private:
|
||||||
bool ComputePreview(QPixmap& pixmap) override;
|
bool ComputePreview(QPixmap& pixmap) override;
|
||||||
void OnOutputListUpdate();
|
void OnOutputListUpdate();
|
||||||
|
void UpdateOutputText();
|
||||||
|
|
||||||
void restore(const QJsonObject& data) override;
|
void restore(const QJsonObject& data) override;
|
||||||
QJsonObject save() const override;
|
QJsonObject save() const override;
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,8 @@ ShaderNode(graph)
|
||||||
|
|
||||||
if (graph.GetTextureCount() > 0)
|
if (graph.GetTextureCount() > 0)
|
||||||
{
|
{
|
||||||
auto& firstInput = graph.GetTexture(0);
|
|
||||||
m_currentTextureIndex = 0;
|
m_currentTextureIndex = 0;
|
||||||
m_currentTextureText = firstInput.name;
|
UpdateOutputTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
DisableCustomVariableName();
|
DisableCustomVariableName();
|
||||||
|
|
@ -57,6 +56,17 @@ void TextureValue::OnTextureListUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextureValue::UpdateOutputTexture()
|
||||||
|
{
|
||||||
|
if (m_currentTextureIndex)
|
||||||
|
{
|
||||||
|
auto& texture = GetGraph().GetTexture(*m_currentTextureIndex);
|
||||||
|
m_currentTextureText = texture.name;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_currentTextureText.clear();
|
||||||
|
}
|
||||||
|
|
||||||
bool TextureValue::ComputePreview(QPixmap& pixmap)
|
bool TextureValue::ComputePreview(QPixmap& pixmap)
|
||||||
{
|
{
|
||||||
if (!m_currentTextureIndex)
|
if (!m_currentTextureIndex)
|
||||||
|
|
@ -74,6 +84,12 @@ void TextureValue::BuildNodeEdition(QFormLayout* layout)
|
||||||
ShaderNode::BuildNodeEdition(layout);
|
ShaderNode::BuildNodeEdition(layout);
|
||||||
|
|
||||||
QComboBox* textureSelection = new QComboBox;
|
QComboBox* textureSelection = new QComboBox;
|
||||||
|
for (const auto& textureEntry : GetGraph().GetTextures())
|
||||||
|
textureSelection->addItem(QString::fromStdString(textureEntry.name));
|
||||||
|
|
||||||
|
if (m_currentTextureIndex)
|
||||||
|
textureSelection->setCurrentIndex(int(*m_currentTextureIndex));
|
||||||
|
|
||||||
connect(textureSelection, qOverload<int>(&QComboBox::currentIndexChanged), [&](int index)
|
connect(textureSelection, qOverload<int>(&QComboBox::currentIndexChanged), [&](int index)
|
||||||
{
|
{
|
||||||
if (index >= 0)
|
if (index >= 0)
|
||||||
|
|
@ -81,14 +97,12 @@ void TextureValue::BuildNodeEdition(QFormLayout* layout)
|
||||||
else
|
else
|
||||||
m_currentTextureIndex.reset();
|
m_currentTextureIndex.reset();
|
||||||
|
|
||||||
|
UpdateOutputTexture();
|
||||||
UpdatePreview();
|
UpdatePreview();
|
||||||
|
|
||||||
Q_EMIT dataUpdated(0);
|
Q_EMIT dataUpdated(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const auto& textureEntry : GetGraph().GetTextures())
|
|
||||||
textureSelection->addItem(QString::fromStdString(textureEntry.name));
|
|
||||||
|
|
||||||
layout->addRow(tr("Texture"), textureSelection);
|
layout->addRow(tr("Texture"), textureSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,7 +134,7 @@ auto TextureValue::dataType(QtNodes::PortType portType, QtNodes::PortIndex portI
|
||||||
assert(portType == QtNodes::PortType::Out);
|
assert(portType == QtNodes::PortType::Out);
|
||||||
assert(portIndex == 0);
|
assert(portIndex == 0);
|
||||||
|
|
||||||
return VecData::Type();
|
return Texture2Data::Type();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<QtNodes::NodeData> TextureValue::outData(QtNodes::PortIndex port)
|
std::shared_ptr<QtNodes::NodeData> TextureValue::outData(QtNodes::PortIndex port)
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ class TextureValue : public ShaderNode
|
||||||
protected:
|
protected:
|
||||||
bool ComputePreview(QPixmap& pixmap) override;
|
bool ComputePreview(QPixmap& pixmap) override;
|
||||||
void OnTextureListUpdate();
|
void OnTextureListUpdate();
|
||||||
|
void UpdateOutputTexture();
|
||||||
|
|
||||||
void restore(const QJsonObject& data) override;
|
void restore(const QJsonObject& data) override;
|
||||||
QJsonObject save() const override;
|
QJsonObject save() const override;
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@ void VecValue<ComponentCount>::BuildNodeEdition(QFormLayout* layout)
|
||||||
{
|
{
|
||||||
QDoubleSpinBox* spinbox = new QDoubleSpinBox;
|
QDoubleSpinBox* spinbox = new QDoubleSpinBox;
|
||||||
spinbox->setDecimals(6);
|
spinbox->setDecimals(6);
|
||||||
|
spinbox->setRange(std::numeric_limits<float>::lowest(), std::numeric_limits<float>::max());
|
||||||
spinbox->setValue(m_value[i]);
|
spinbox->setValue(m_value[i]);
|
||||||
|
|
||||||
connect(spinbox, qOverload<double>(&QDoubleSpinBox::valueChanged), [=](double)
|
connect(spinbox, qOverload<double>(&QDoubleSpinBox::valueChanged), [=](double)
|
||||||
|
|
@ -122,8 +123,10 @@ template<std::size_t ComponentCount>
|
||||||
void VecValue<ComponentCount>::restore(const QJsonObject& data)
|
void VecValue<ComponentCount>::restore(const QJsonObject& data)
|
||||||
{
|
{
|
||||||
QJsonArray vecValues = data["value"].toArray();
|
QJsonArray vecValues = data["value"].toArray();
|
||||||
for (std::size_t i = 0; i < ComponentCount; ++i)
|
std::size_t commonValues = std::min(static_cast<std::size_t>(vecValues.size()), ComponentCount);
|
||||||
m_value[i] = vecValues[int(i)].toInt(m_value[i]);
|
|
||||||
|
for (std::size_t i = 0; i < commonValues; ++i)
|
||||||
|
m_value[i] = float(vecValues[int(i)].toDouble(m_value[i]));
|
||||||
|
|
||||||
ShaderNode::restore(data);
|
ShaderNode::restore(data);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,12 @@
|
||||||
|
|
||||||
QImage QuadPreview::GetImage(InputRole role, std::size_t roleIndex) const
|
QImage QuadPreview::GetImage(InputRole role, std::size_t roleIndex) const
|
||||||
{
|
{
|
||||||
assert(role == InputRole::TexCoord);
|
if (role != InputRole::TexCoord)
|
||||||
assert(roleIndex == 0);
|
{
|
||||||
|
QImage dummy(1, 1, QImage::Format_RGBA8888);
|
||||||
|
dummy.fill(QColor::fromRgb(0, 0, 0, 0));
|
||||||
|
return dummy;
|
||||||
|
}
|
||||||
|
|
||||||
QImage uv(128, 128, QImage::Format_RGBA8888);
|
QImage uv(128, 128, QImage::Format_RGBA8888);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue