Skip to content

Commit

Permalink
Traktor: Implemented support for partial solve Discard node in shader…
Browse files Browse the repository at this point in the history
… traits.
  • Loading branch information
apistol78 committed Mar 5, 2024
1 parent b7dc899 commit 48e0b61
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
4 changes: 2 additions & 2 deletions code/Render/Editor/Shader/ShaderPipeline.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022-2023 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -138,7 +138,7 @@ std::wstring resolveShaderModule(editor::IPipelineCommon* pipelineCommon, const

}

T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.render.ShaderPipeline", 100, ShaderPipeline, editor::IPipeline)
T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.render.ShaderPipeline", 101, ShaderPipeline, editor::IPipeline)

ShaderPipeline::ShaderPipeline()
: m_optimize(4)
Expand Down
54 changes: 47 additions & 7 deletions code/Render/Editor/Shader/Traits/ConditionalNodeTraits.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -10,12 +10,10 @@
#include "Render/Editor/Shader/Nodes.h"
#include "Render/Editor/Shader/Traits/ConditionalNodeTraits.h"

namespace traktor
namespace traktor::render
{
namespace render
namespace
{
namespace
{

int32_t getInputPinIndex(const Node* node, const InputPin* inputPin)
{
Expand All @@ -29,7 +27,7 @@ int32_t getInputPinIndex(const Node* node, const InputPin* inputPin)
return -1;
}

}
}

T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.render.ConditionalNodeTraits", 0, ConditionalNodeTraits, INodeTraits)

Expand Down Expand Up @@ -296,6 +294,49 @@ bool ConditionalNodeTraits::evaluatePartial(
return true;
}
}
else if (const Discard* discard = dynamic_type_cast< const Discard* >(node))
{
if (inputConstants[0].isConst(0) && inputConstants[1].isConst(0))
{
bool result = false;
switch (discard->getOperator())
{
case Discard::CoLess:
result = inputConstants[0].x() < inputConstants[1].x();
break;

case Discard::CoLessEqual:
result = inputConstants[0].x() <= inputConstants[1].x();
break;

case Discard::CoEqual:
result = inputConstants[0].x() == inputConstants[1].x();
break;

case Discard::CoNotEqual:
result = inputConstants[0].x() != inputConstants[1].x();
break;

case Discard::CoGreater:
result = inputConstants[0].x() > inputConstants[1].x();
break;

case Discard::CoGreaterEqual:
result = inputConstants[0].x() >= inputConstants[1].x();
break;

default:
return false;
}

if (result)
foldOutputPin = inputOutputPins[2];
else
foldOutputPin = nullptr;

return true;
}
}
return false;
}

Expand All @@ -309,5 +350,4 @@ PinOrder ConditionalNodeTraits::evaluateOrder(
return pinOrderConstantOrNonLinear(inputPinOrders, node->getInputPinCount());
}

}
}

0 comments on commit 48e0b61

Please sign in to comment.