Skip to content

Commit 65bbad8

Browse files
committed
Adds ternary op for complex numbers
1 parent dcc537e commit 65bbad8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

include/nbl/builtin/hlsl/complex.hlsl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,19 @@ complex_t<Scalar> rotateRight(NBL_CONST_REF_ARG(complex_t<Scalar>) value)
379379
return retVal;
380380
}
381381

382+
// Annoyed at having to write a lot of boilerplate to do a select
383+
// Essentially returns what you'd expect from doing `condition ? a : b`
384+
template<typename Scalar>
385+
complex_t<Scalar> ternaryOperator(bool condition, NBL_CONST_REF_ARG(complex_t<Scalar>) a, NBL_CONST_REF_ARG(complex_t<Scalar>) b)
386+
{
387+
const vector<Scalar, 2> aVector = vector<Scalar, 2>(a.real(), a.imag());
388+
const vector<Scalar, 2> bVector = vector<Scalar, 2>(b.real(), b.imag());
389+
const vector<Scalar, 2> resultVector = condition ? aVector : bVector;
390+
const complex_t<Scalar> result = { resultVector.x, resultVector.y };
391+
return result;
392+
}
393+
394+
382395
}
383396
}
384397

0 commit comments

Comments
 (0)