Skip to content

Commit 382d955

Browse files
Create aabb.hlsl
1 parent c606c06 commit 382d955

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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_SHAPES_AABB_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_SHAPES_AABB_INCLUDED_
6+
7+
#include <nbl/builtin/hlsl/format/decode.hlsl>
8+
9+
10+
namespace nbl
11+
{
12+
namespace hlsl
13+
{
14+
namespace shapes
15+
{
16+
17+
struct AABB_t
18+
{
19+
//
20+
void addPoint(const float3 pt)
21+
{
22+
minVx = min(pt, minVx);
23+
maxVx = max(pt, maxVx);
24+
}
25+
//
26+
float3 getExtent()
27+
{
28+
return maxVx - minVx;
29+
}
30+
31+
//
32+
float getVolume()
33+
{
34+
const float3 extent = AABB_t::getExtent();
35+
return extent.x * extent.y * extent.z;
36+
}
37+
38+
// returns the corner of the AABB which has the most positive dot product
39+
float3 getFarthestPointInFront(const float3 plane)
40+
{
41+
return lerp(maxVx, minVx, plane<float3(0.f,0.f,0.f));
42+
}
43+
44+
float3 minVx;
45+
float3 maxVx;
46+
};
47+
48+
struct nbl_glsl_shapes_CompressedAABB_t
49+
{
50+
//
51+
AABB_t decompress()
52+
{
53+
AABB_t retval;
54+
retval.minVx = decodeRGB18E7S3(minVx18E7S3);
55+
retval.maxVx = decodeRGB18E7S3(maxVx18E7S3);
56+
return retval;
57+
}
58+
59+
uint2 minVx18E7S3;
60+
uint2 maxVx18E7S3;
61+
};
62+
63+
64+
}
65+
}
66+
}
67+
68+
#endif

0 commit comments

Comments
 (0)