Skip to content

Commit 7424828

Browse files
author
kevyuu
committed
Fix triangle.hlsl
1 parent 0feb4e9 commit 7424828

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

include/nbl/asset/utils/CVertexHashGrid.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class CVertexHashGrid
182182
hash,
183183
[](const VertexData& vertex, uint32_t hash)
184184
{
185-
return vertex.hash < hash;
185+
return vertex.getHash() < hash;
186186
});
187187

188188
auto end = std::upper_bound(
@@ -191,7 +191,7 @@ class CVertexHashGrid
191191
hash,
192192
[](uint32_t hash, const VertexData& vertex)
193193
{
194-
return hash < vertex.hash;
194+
return hash < vertex.getHash();
195195
});
196196

197197
const auto beginIx = begin - m_vertices.begin();

include/nbl/builtin/hlsl/shapes/triangle.hlsl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#define _NBL_BUILTIN_HLSL_SHAPES_TRIANGLE_INCLUDED_
77

88
#include <nbl/builtin/hlsl/cpp_compat.hlsl>
9+
#include <nbl/builtin/hlsl/tgmath.hlsl>
10+
#include <nbl/builtin/hlsl/numbers.hlsl>
911

1012
namespace nbl
1113
{
@@ -17,22 +19,22 @@ namespace shapes
1719
namespace util
1820
{
1921
template <typename float_t>
20-
vector<float_t, 3> GetAngleWeight(const vector<float_t, 3>& e1, const vector<float_t, 3>& e2, const vector<float_t, 3>& e3)
22+
vector<float_t, 3> compInternalAngle(NBL_CONST_REF_ARG(vector<float_t, 3>) e1, NBL_CONST_REF_ARG(vector<float_t, 3>) e2, NBL_CONST_REF_ARG(vector<float_t, 3>) e3)
2123
{
2224
// Calculate this triangle's weight for each of its three m_vertices
2325
// start by calculating the lengths of its sides
24-
const float_t a = dot(e1, e1);
25-
const float_t asqrt = sqrt(a);
26-
const float_t b = dot(e2, e2);
27-
const float_t bsqrt = sqrt(b);
28-
const float_t c = dot(e3, e3);
29-
const float_t csqrt = sqrt(c);
26+
const float_t a = hlsl::dot(e1, e1);
27+
const float_t asqrt = hlsl::sqrt(a);
28+
const float_t b = hlsl::dot(e2, e2);
29+
const float_t bsqrt = hlsl::sqrt(b);
30+
const float_t c = hlsl::dot(e3, e3);
31+
const float_t csqrt = hlsl::sqrt(c);
3032

33+
const float_t angle1 = hlsl::acos((b + c - a) / (2.f * bsqrt * csqrt));
34+
const float_t angle2 = hlsl::acos((-b + c + a) / (2.f * asqrt * csqrt));
35+
const float_t angle3 = hlsl::numbers::pi<float_t> - (angle1 + angle2);
3136
// use them to find the angle at each vertex
32-
return vector<float_t, 3>(
33-
acosf((b + c - a) / (2.f * bsqrt * csqrt)),
34-
acosf((-b + c + a) / (2.f * asqrt * csqrt)),
35-
acosf((b - c + a) / (2.f * bsqrt * asqrt)));
37+
return vector<float_t, 3>(angle1, angle2, angle3);
3638
}
3739
}
3840

src/nbl/asset/utils/CSmoothNormalGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ CSmoothNormalGenerator::VertexHashMap CSmoothNormalGenerator::setupData(const as
5555
const auto faceNormal = normalize(cross(v2 - v1, v3 - v1));
5656

5757
//set data for m_vertices
58-
const auto angleWages = hlsl::shapes::util::GetAngleWeight(v2 - v3, v1 - v3, v1 - v2);
58+
const auto angleWages = hlsl::shapes::util::compInternalAngle(v2 - v3, v1 - v3, v1 - v2);
5959

6060
vertices.add({ i, 0, faceNormal * angleWages.x, v1});
6161
vertices.add({ i + 1, 0, faceNormal * angleWages.y,v2});

0 commit comments

Comments
 (0)