File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
include/nbl/builtin/hlsl/barycentric Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright (C) 2018-2022 - 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
+ #ifndef _NBL_BUILTIN_HLSL_BARYCENTRIC_UTILS_INCLUDED_
5
+ #define _NBL_BUILTIN_HLSL_BARYCENTRIC_UTILS_INCLUDED_
6
+
7
+ namespace nbl
8
+ {
9
+ namespace hlsl
10
+ {
11
+ namespace barycentric
12
+ {
13
+
14
+ float2 reconstructBarycentrics (in float3 positionRelativeToV0, in float2x3 edges)
15
+ {
16
+ const float e0_2 = dot (edges[0 ], edges[0 ]);
17
+ const float e0e1 = dot (edges[0 ], edges[1 ]);
18
+ const float e1_2 = dot (edges[1 ], edges[1 ]);
19
+
20
+ const float qe0 = dot (positionRelativeToV0, edges[0 ]);
21
+ const float qe1 = dot (positionRelativeToV0, edges[1 ]);
22
+ const float2 protoBary = float2 (qe0 * e1_2 - qe1 * e0e1, qe1 * e0_2 - qe0 * e0e1);
23
+
24
+ const float rcp_dep = 1.f / (e0_2 * e1_2 - e0e1 * e0e1);
25
+ return protoBary * rcp_dep;
26
+ }
27
+ float2 reconstructBarycentrics (in float3 pointPosition, in float3x3 vertexPositions)
28
+ {
29
+ return reconstructBarycentrics (pointPosition - vertexPositions[2 ], float2x3 (vertexPositions[0 ] - vertexPositions[2 ], vertexPositions[1 ] - vertexPositions[2 ]));
30
+ }
31
+
32
+ float3 expand (in float2 compactBarycentrics)
33
+ {
34
+ return float3 (compactBarycentrics.xy,1.f -compactBarycentrics.x-compactBarycentrics.y);
35
+ }
36
+
37
+ }
38
+ }
39
+ }
40
+
41
+ #endif
You can’t perform that action at this time.
0 commit comments