Skip to content

Commit 94a778f

Browse files
committed
restore regular triangle stuff, refactor usage
1 parent 04f1c76 commit 94a778f

File tree

4 files changed

+49
-25
lines changed

4 files changed

+49
-25
lines changed

include/nbl/builtin/hlsl/shapes/spherical_triangle.hlsl

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -102,29 +102,6 @@ struct SphericalTriangle
102102
vector3_type csc_sides;
103103
};
104104

105-
namespace util
106-
{
107-
// Use this convetion e_i = v_{i+2}-v_{i+1}. vertex index is modulo by 3.
108-
template <typename float_t>
109-
vector<float_t, 3> compInternalAngle(const vector<float_t, 3> e0, vector<float_t, 3> e1, const vector<float_t, 3> e2)
110-
{
111-
// Calculate this triangle's weight for each of its three m_vertices
112-
// start by calculating the lengths of its sides
113-
const float_t a = hlsl::dot(e0, e0);
114-
const float_t asqrt = hlsl::sqrt(a);
115-
const float_t b = hlsl::dot(e1, e1);
116-
const float_t bsqrt = hlsl::sqrt(b);
117-
const float_t c = hlsl::dot(e2, e2);
118-
const float_t csqrt = hlsl::sqrt(c);
119-
120-
const float_t angle0 = hlsl::acos((b + c - a) / (2.f * bsqrt * csqrt));
121-
const float_t angle1 = hlsl::acos((-b + c + a) / (2.f * asqrt * csqrt));
122-
const float_t angle2 = hlsl::numbers::pi<float_t> - (angle0 + angle1);
123-
// use them to find the angle at each vertex
124-
return vector<float_t, 3>(angle0, angle1, angle2);
125-
}
126-
}
127-
128105
}
129106
}
130107
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (C) 2018-2025 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
5+
#ifndef _NBL_BUILTIN_HLSL_SHAPES_TRIANGLE_INCLUDED_
6+
#define _NBL_BUILTIN_HLSL_SHAPES_TRIANGLE_INCLUDED_
7+
8+
#include <nbl/builtin/hlsl/cpp_compat.hlsl>
9+
#include <nbl/builtin/hlsl/tgmath.hlsl>
10+
#include <nbl/builtin/hlsl/numbers.hlsl>
11+
12+
namespace nbl
13+
{
14+
namespace hlsl
15+
{
16+
namespace shapes
17+
{
18+
19+
namespace util
20+
{
21+
// Use this convetion e_i = v_{i+2}-v_{i+1}. vertex index is modulo by 3.
22+
template <typename float_t>
23+
vector<float_t, 3> anglesFromTriangleEdge(const vector<float_t, 3> e0, vector<float_t, 3> e1, const vector<float_t, 3> e2)
24+
{
25+
// Calculate this triangle's weight for each of its three m_vertices
26+
// start by calculating the lengths of its sides
27+
const float_t a = hlsl::dot(e0, e0);
28+
const float_t asqrt = hlsl::sqrt(a);
29+
const float_t b = hlsl::dot(e1, e1);
30+
const float_t bsqrt = hlsl::sqrt(b);
31+
const float_t c = hlsl::dot(e2, e2);
32+
const float_t csqrt = hlsl::sqrt(c);
33+
34+
const float_t angle0 = hlsl::acos((b + c - a) / (2.f * bsqrt * csqrt));
35+
const float_t angle1 = hlsl::acos((-b + c + a) / (2.f * asqrt * csqrt));
36+
const float_t angle2 = hlsl::numbers::pi<float_t> - (angle0 + angle1);
37+
// use them to find the angle at each vertex
38+
return vector<float_t, 3>(angle0, angle1, angle2);
39+
}
40+
}
41+
42+
}
43+
}
44+
}
45+
46+
#endif

src/nbl/asset/utils/CSmoothNormalGenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "CSmoothNormalGenerator.h"
66

77
#include "nbl/core/declarations.h"
8-
#include "nbl/builtin/hlsl/shapes/spherical_triangle.hlsl"
8+
#include "nbl/builtin/hlsl/shapes/triangle.hlsl"
99

1010
#include <algorithm>
1111

@@ -58,7 +58,7 @@ CSmoothNormalGenerator::VertexHashMap CSmoothNormalGenerator::setupData(const as
5858
const auto faceNormal = normalize(cross(v1 - v0, v2 - v0));
5959

6060
//set data for m_vertices
61-
const auto angleWages = hlsl::shapes::util::compInternalAngle(v2 - v1, v0 - v2, v1 - v2);
61+
const auto angleWages = hlsl::shapes::util::anglesFromTriangleEdge(v2 - v1, v0 - v2, v1 - v2);
6262

6363
vertices.add({ i, 0, faceNormal * angleWages.x, v0});
6464
vertices.add({ i + 1, 0, faceNormal * angleWages.y,v1});

src/nbl/builtin/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/shapes/circle.hlsl")
253253
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/shapes/ellipse.hlsl")
254254
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/shapes/line.hlsl")
255255
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/shapes/beziers.hlsl")
256+
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/shapes/triangle.hlsl")
256257
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/shapes/spherical_triangle.hlsl")
257258
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/shapes/spherical_rectangle.hlsl")
258259
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/shapes/aabb.hlsl")

0 commit comments

Comments
 (0)