Skip to content

Commit b832bad

Browse files
committed
Restored CQuantNormalCache.h
1 parent 2806020 commit b832bad

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-2021 - 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_ASSET_C_QUANT_NORMAL_CACHE_H_INCLUDED
6+
#define __NBL_ASSET_C_QUANT_NORMAL_CACHE_H_INCLUDED
7+
8+
9+
#include "nbl/asset/utils/CDirQuantCacheBase.h"
10+
11+
12+
namespace nbl
13+
{
14+
namespace asset
15+
{
16+
17+
namespace impl
18+
{
19+
20+
struct VectorUV
21+
{
22+
inline VectorUV(const core::vectorSIMDf& absNormal)
23+
{
24+
const float rcpManhattanNorm = 1.f / (absNormal.x + absNormal.y + absNormal.z);
25+
u = absNormal.x * rcpManhattanNorm;
26+
v = absNormal.z * rcpManhattanNorm;
27+
}
28+
29+
inline bool operator==(const VectorUV& other) const
30+
{
31+
return (u == other.u && v == other.v);
32+
}
33+
34+
float u;
35+
float v;
36+
};
37+
38+
struct QuantNormalHash
39+
{
40+
inline size_t operator()(const VectorUV& vec) const noexcept
41+
{
42+
static constexpr size_t primeNumber1 = 18446744073709551557ull;
43+
static constexpr size_t primeNumber2 = 4611686018427388273ull;
44+
45+
return ((static_cast<size_t>(static_cast<double>(vec.u)*(std::numeric_limits<size_t>::max)()) * primeNumber1) ^
46+
(static_cast<size_t>(static_cast<double>(vec.v)*(std::numeric_limits<size_t>::max)()) * primeNumber2));
47+
}
48+
};
49+
50+
}
51+
52+
53+
class CQuantNormalCache : public CDirQuantCacheBase<impl::VectorUV,impl::QuantNormalHash,EF_A2B10G10R10_SNORM_PACK32,EF_R8G8B8_SNORM,EF_R16G16B16_SNORM>
54+
{
55+
using Base = CDirQuantCacheBase<impl::VectorUV,impl::QuantNormalHash,EF_A2B10G10R10_SNORM_PACK32,EF_R8G8B8_SNORM,EF_R16G16B16_SNORM>;
56+
57+
public:
58+
template<E_FORMAT CacheFormat>
59+
value_type_t<CacheFormat> quantize(core::vectorSIMDf normal)
60+
{
61+
normal.makeSafe3D();
62+
return Base::quantize<3u,CacheFormat>(normal);
63+
}
64+
};
65+
66+
}
67+
}
68+
#endif

0 commit comments

Comments
 (0)