Skip to content

Commit 0879ce7

Browse files
committed
fix + optimize aabb vertex calc, includes
1 parent aae42fa commit 0879ce7

File tree

3 files changed

+13
-31
lines changed

3 files changed

+13
-31
lines changed

include/nbl/ext/DebugDraw/builtin/hlsl/aabb_instances.vertex.hlsl

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#pragma shader_stage(vertex)
22

3-
#include "nbl/builtin/hlsl/math/linalg/fast_affine.hlsl"
4-
#include "nbl/builtin/hlsl/glsl_compat/core.hlsl"
5-
#include "nbl/builtin/hlsl/bda/__ptr.hlsl"
63
#include "nbl/ext/DebugDraw/builtin/hlsl/common.hlsl"
74

85
using namespace nbl::hlsl;
@@ -13,19 +10,8 @@ using namespace nbl::ext::debug_draw;
1310
[shader("vertex")]
1411
PSInput main()
1512
{
16-
const float32_t3 unitAABBVertices[8] = {
17-
float32_t3(0.0, 0.0, 0.0),
18-
float32_t3(1.0, 0.0, 0.0),
19-
float32_t3(0.0, 0.0, 1.0),
20-
float32_t3(1.0, 0.0, 1.0),
21-
float32_t3(0.0, 1.0, 0.0),
22-
float32_t3(1.0, 1.0, 0.0),
23-
float32_t3(0.0, 1.0, 1.0),
24-
float32_t3(1.0, 1.0, 1.0)
25-
};
26-
2713
PSInput output;
28-
float32_t3 vertex = unitAABBVertices[glsl::gl_VertexIndex()];
14+
const float32_t3 vertex = getUnitAABBVertex();
2915
InstanceData instance = vk::BufferPointer<InstanceData>(pc.pInstanceBuffer + sizeof(InstanceData) * glsl::gl_InstanceIndex()).Get();
3016

3117
output.position = math::linalg::promoted_mul(instance.transform, vertex);

include/nbl/ext/DebugDraw/builtin/hlsl/common.hlsl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
#define _NBL_DEBUG_DRAW_EXT_COMMON_HLSL
33

44
#include "nbl/builtin/hlsl/cpp_compat.hlsl"
5+
#ifdef __HLSL_VERSION
6+
#include "nbl/builtin/hlsl/math/linalg/fast_affine.hlsl"
7+
#include "nbl/builtin/hlsl/glsl_compat/core.hlsl"
8+
#include "nbl/builtin/hlsl/bda/__ptr.hlsl"
9+
#endif
510

611
namespace nbl
712
{
@@ -30,8 +35,13 @@ struct SPushConstants
3035
struct PSInput
3136
{
3237
float32_t4 position : SV_Position;
33-
float32_t4 color : TEXCOORD0;
38+
nointerpolation float32_t4 color : TEXCOORD0;
3439
};
40+
41+
float32_t3 getUnitAABBVertex()
42+
{
43+
return (hlsl::promote<uint32_t3>(hlsl::glsl::gl_VertexIndex()) >> uint32_t3(0,2,1)) & 0x1u;
44+
}
3545
#endif
3646

3747
}

include/nbl/ext/DebugDraw/builtin/hlsl/single.vertex.hlsl

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#pragma shader_stage(vertex)
22

3-
#include "nbl/builtin/hlsl/math/linalg/fast_affine.hlsl"
4-
#include "nbl/builtin/hlsl/glsl_compat/core.hlsl"
5-
#include "nbl/builtin/hlsl/bda/__ptr.hlsl"
63
#include "nbl/ext/DebugDraw/builtin/hlsl/common.hlsl"
74

85
using namespace nbl::hlsl;
@@ -13,19 +10,8 @@ using namespace nbl::ext::debug_draw;
1310
[shader("vertex")]
1411
PSInput main()
1512
{
16-
const float32_t3 unitAABBVertices[8] = {
17-
float32_t3(0.0, 0.0, 0.0),
18-
float32_t3(1.0, 0.0, 0.0),
19-
float32_t3(0.0, 0.0, 1.0),
20-
float32_t3(1.0, 0.0, 1.0),
21-
float32_t3(0.0, 1.0, 0.0),
22-
float32_t3(1.0, 1.0, 0.0),
23-
float32_t3(0.0, 1.0, 1.0),
24-
float32_t3(1.0, 1.0, 1.0)
25-
};
26-
2713
PSInput output;
28-
float32_t3 vertex = unitAABBVertices[glsl::gl_VertexIndex()];
14+
float32_t3 vertex = getUnitAABBVertex();
2915

3016
output.position = math::linalg::promoted_mul(pc.instance.transform, vertex);
3117
output.color = pc.instance.color;

0 commit comments

Comments
 (0)