ShaderNode: Add VecDiv
This commit is contained in:
parent
725ecc7606
commit
5790b502f7
|
|
@ -71,3 +71,35 @@ void VecSub::ApplyOp(const std::uint8_t* left, const std::uint8_t* right, std::u
|
||||||
output[i] = static_cast<std::uint8_t>(sub);
|
output[i] = static_cast<std::uint8_t>(sub);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString VecDiv::caption() const
|
||||||
|
{
|
||||||
|
static QString caption = "Vector divide";
|
||||||
|
return caption;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString VecDiv::name() const
|
||||||
|
{
|
||||||
|
static QString name = "vec_div";
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VecDiv::ApplyOp(const std::uint8_t* left, const std::uint8_t* right, std::uint8_t* output, std::size_t pixelCount)
|
||||||
|
{
|
||||||
|
for (std::size_t i = 0; i < pixelCount; ++i)
|
||||||
|
{
|
||||||
|
unsigned int lValue = left[i];
|
||||||
|
unsigned int rValue = right[i];
|
||||||
|
|
||||||
|
unsigned res;
|
||||||
|
if (rValue != 0)
|
||||||
|
res = lValue / rValue;
|
||||||
|
else if (lValue != 0)
|
||||||
|
res = 0xFF; //< positive / 0 = +inf, which we clamp to 0xFF
|
||||||
|
else
|
||||||
|
res = 0; //< 0 / 0 = NaN, which we set to zero
|
||||||
|
|
||||||
|
output[i] = static_cast<std::uint8_t>(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,17 @@ 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;
|
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>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using VecBinOp<Nz::ShaderAst::BinaryType::Divide>::VecBinOp;
|
||||||
|
|
||||||
|
QString caption() const override;
|
||||||
|
QString name() const override;
|
||||||
|
|
||||||
|
void ApplyOp(const std::uint8_t* left, const std::uint8_t* right, std::uint8_t* output, std::size_t pixelCount) override;
|
||||||
|
};
|
||||||
|
|
||||||
#include <ShaderNode/DataModels/VecBinOp.inl>
|
#include <ShaderNode/DataModels/VecBinOp.inl>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -268,6 +268,7 @@ std::shared_ptr<QtNodes::DataModelRegistry> ShaderGraph::BuildRegistry()
|
||||||
RegisterShaderNode<SampleTexture>(*this, registry, "Texture");
|
RegisterShaderNode<SampleTexture>(*this, registry, "Texture");
|
||||||
RegisterShaderNode<TextureValue>(*this, registry, "Texture");
|
RegisterShaderNode<TextureValue>(*this, registry, "Texture");
|
||||||
RegisterShaderNode<VecAdd>(*this, registry, "Vector operations");
|
RegisterShaderNode<VecAdd>(*this, registry, "Vector operations");
|
||||||
|
RegisterShaderNode<VecDiv>(*this, registry, "Vector operations");
|
||||||
RegisterShaderNode<VecMul>(*this, registry, "Vector operations");
|
RegisterShaderNode<VecMul>(*this, registry, "Vector operations");
|
||||||
RegisterShaderNode<VecSub>(*this, registry, "Vector operations");
|
RegisterShaderNode<VecSub>(*this, registry, "Vector operations");
|
||||||
RegisterShaderNode<Vec2Value>(*this, registry, "Constants");
|
RegisterShaderNode<Vec2Value>(*this, registry, "Constants");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue