Skip to content

Commit 7259919

Browse files
committed
Merge branch 'cad_shaders_work' of github.com:Devsh-Graphics-Programming/Nabla into cad_shaders_work
2 parents 9fe2967 + 94f6152 commit 7259919

File tree

6 files changed

+48
-24
lines changed

6 files changed

+48
-24
lines changed

include/nbl/builtin/hlsl/equations/cubic.hlsl renamed to include/nbl/builtin/hlsl/math/equations/cubic.hlsl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
44

5-
#ifndef _NBL_BUILTIN_HLSL_EQUATIONS_CUBIC_INCLUDED_
6-
#define _NBL_BUILTIN_HLSL_EQUATIONS_CUBIC_INCLUDED_
5+
#ifndef _NBL_BUILTIN_HLSL_MATH_EQUATIONS_CUBIC_INCLUDED_
6+
#define _NBL_BUILTIN_HLSL_MATH_EQUATIONS_CUBIC_INCLUDED_
77

88
// TODO: Later include from correct hlsl header
99
#ifndef nbl_hlsl_FLT_EPSILON
@@ -23,6 +23,8 @@ namespace nbl
2323
{
2424
namespace hlsl
2525
{
26+
namespace math
27+
{
2628
namespace equations
2729
{
2830
//TODO: use numeric_limits<float_t>::PI
@@ -120,5 +122,6 @@ namespace equations
120122
}
121123
}
122124
}
125+
}
123126

124127
#endif

include/nbl/builtin/hlsl/equations/quadratic.hlsl renamed to include/nbl/builtin/hlsl/math/equations/quadratic.hlsl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
44

5-
#ifndef _NBL_BUILTIN_HLSL_EQUATIONS_QUADRATIC_INCLUDED_
6-
#define _NBL_BUILTIN_HLSL_EQUATIONS_QUADRATIC_INCLUDED_
5+
#ifndef _NBL_BUILTIN_HLSL_MATH_EQUATIONS_QUADRATIC_INCLUDED_
6+
#define _NBL_BUILTIN_HLSL_MATH_EQUATIONS_QUADRATIC_INCLUDED_
77

88
// TODO: Later include from correct hlsl header
99
#ifndef nbl_hlsl_FLT_EPSILON
@@ -29,6 +29,8 @@ namespace nbl
2929
{
3030
namespace hlsl
3131
{
32+
namespace math
33+
{
3234
namespace equations
3335
{
3436
template<typename float_t>
@@ -81,5 +83,6 @@ namespace equations
8183
}
8284
}
8385
}
86+
}
8487

8588
#endif

include/nbl/builtin/hlsl/equations/quartic.hlsl renamed to include/nbl/builtin/hlsl/math/equations/quartic.hlsl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
44

5-
#ifndef _NBL_BUILTIN_HLSL_EQUATIONS_QUARTIC_INCLUDED_
6-
#define _NBL_BUILTIN_HLSL_EQUATIONS_QUARTIC_INCLUDED_
5+
#ifndef _NBL_BUILTIN_HLSL_MATH_EQUATIONS_QUARTIC_INCLUDED_
6+
#define _NBL_BUILTIN_HLSL_MATH_EQUATIONS_QUARTIC_INCLUDED_
77

8-
#include <nbl/builtin/hlsl/equations/quadratic.hlsl>
9-
#include <nbl/builtin/hlsl/equations/cubic.hlsl>
8+
#include <nbl/builtin/hlsl/math/equations/quadratic.hlsl>
9+
#include <nbl/builtin/hlsl/math/equations/cubic.hlsl>
1010

1111
// TODO: Later include from correct hlsl header
1212
#ifndef nbl_hlsl_FLT_EPSILON
@@ -26,6 +26,8 @@ namespace nbl
2626
{
2727
namespace hlsl
2828
{
29+
namespace math
30+
{
2931
namespace equations
3032
{
3133
template<typename float_t>
@@ -77,15 +79,15 @@ namespace equations
7779
{
7880
/* no absolute term: y(y^3 + py + q) = 0 */
7981

80-
float3_t cubic = nbl::hlsl::equations::Cubic<float_t>::construct(1, 0, p, q).computeRoots();
82+
float3_t cubic = Cubic<float_t>::construct(1, 0, p, q).computeRoots();
8183
s[rootCount ++] = cubic[0];
8284
s[rootCount ++] = cubic[1];
8385
s[rootCount ++] = cubic[2];
8486
}
8587
else
8688
{
8789
/* solve the resolvent cubic ... */
88-
float3_t cubic = nbl::hlsl::equations::Cubic<float_t>::construct(1, -1.0 / 2 * p, -r, 1.0 / 2 * r * p - 1.0 / 8 * q * q).computeRoots();
90+
float3_t cubic = Cubic<float_t>::construct(1, -1.0 / 2 * p, -r, 1.0 / 2 * r * p - 1.0 / 8 * q * q).computeRoots();
8991
/* ... and take the one real solution ... */
9092
for (uint i = 0; i < 3; i ++)
9193
if (!isnan(cubic[i]))
@@ -113,8 +115,8 @@ namespace equations
113115
else
114116
return s; // (empty)
115117

116-
float2_t quadric1 = nbl::hlsl::equations::Quadratic<float_t>::construct(1, q < 0 ? -v : v, z - u).computeRoots();
117-
float2_t quadric2 = nbl::hlsl::equations::Quadratic<float_t>::construct(1, q < 0 ? v : -v, z + u).computeRoots();
118+
float2_t quadric1 = Quadratic<float_t>::construct(1, q < 0 ? -v : v, z - u).computeRoots();
119+
float2_t quadric2 = Quadratic<float_t>::construct(1, q < 0 ? v : -v, z + u).computeRoots();
118120

119121
for (uint i = 0; i < 2; i ++)
120122
if (!isinf(quadric1[i]) && !isnan(quadric1[i]))
@@ -140,5 +142,6 @@ namespace equations
140142
}
141143
}
142144
}
145+
}
143146

144147
#endif

include/nbl/builtin/hlsl/shapes/beziers.hlsl

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,21 +317,36 @@ namespace shapes
317317
return ret;
318318
}
319319

320-
static Quadratic constructFromBezier(NBL_CONST_REF_ARG(QuadraticBezier<float_t>) curve)
320+
static Quadratic constructFromBezier(float_t2 P0, float_t2 P1, float_t2 P2)
321321
{
322-
const float_t2 A = curve.P0 - 2.0 * curve.P1 + curve.P2;
323-
const float_t2 B = 2.0 * (curve.P1 - curve.P0);
324-
const float_t2 C = curve.P0;
325-
322+
const float_t2 A = P0 - 2.0 * P1 + P2;
323+
const float_t2 B = 2.0 * (P1 - P0);
324+
const float_t2 C = P0;
325+
326326
Quadratic ret = { A, B, C };
327327
return ret;
328328
}
329-
330-
float_t2 evaluate(float_t t)
329+
330+
static Quadratic constructFromBezier(NBL_CONST_REF_ARG(QuadraticBezier<float_t>) curve)
331+
{
332+
return constructFromBezier(curve.P0, curve.P1, curve.P2);
333+
}
334+
335+
float_t2 evaluate(float_t t) NBL_CONST_MEMBER_FUNC
331336
{
332337
return t * (A * t + B) + C;
333338
}
334-
339+
340+
float_t2 derivative(float_t t) NBL_CONST_MEMBER_FUNC
341+
{
342+
return float_t(2.0) * A * t + B;
343+
}
344+
345+
float_t2 secondDerivative(float_t t) NBL_CONST_MEMBER_FUNC
346+
{
347+
return float_t(2.0) * A;
348+
}
349+
335350
NBL_CONSTEXPR_STATIC_INLINE uint32_t MaxCandidates = 3u;
336351
using Candidates = vector<float_t, MaxCandidates>;
337352

src/nbl/builtin/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/shapes/ellipse.hlsl")
275275
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/shapes/line.hlsl")
276276
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/shapes/beziers.hlsl")
277277

278-
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/equations/quadratic.hlsl")
279-
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/equations/cubic.hlsl")
280-
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/equations/quartic.hlsl")
278+
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/math/equations/quadratic.hlsl")
279+
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/math/equations/cubic.hlsl")
280+
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/math/equations/quartic.hlsl")
281281

282282
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/algorithm.hlsl")
283283
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/scanning_append.hlsl")

0 commit comments

Comments
 (0)