151 lines
6.2 KiB
C++
151 lines
6.2 KiB
C++
#pragma once
|
|
#include "MaterialMultiRootOctreeBuilder.h"
|
|
#include "../../scene/Octree/MultiRootBitsTree.h"
|
|
#include "../BitHelper.h"
|
|
|
|
template<>
|
|
void MaterialMultiRootOctreeBuilder<BitsMaterial<1>>::AddNode(const glm::uvec3& coordinate, const Color& color)
|
|
{
|
|
mCurPassTree->AddLeafNode(coordinate, BitsMaterial<1>(1));
|
|
for (unsigned8 c = 0; c < 3; c++)
|
|
for (unsigned8 i = 0; i < mBitsPerChannel; i++)
|
|
{
|
|
auto material = BitsMaterial<1>(color[c], i);
|
|
if (material.GetValue() != 0)
|
|
mCurPassTree->AddLeafNode(coordinate, mBitsPerChannel * c + i, material);
|
|
}
|
|
}
|
|
|
|
template<>
|
|
void MaterialMultiRootOctreeBuilder<BitsMaterial<2>>::AddNode(const glm::uvec3& coordinate, const Color& color)
|
|
{
|
|
unsigned N = 2;
|
|
mCurPassTree->AddLeafNode(coordinate, BitsMaterial<2>(1));
|
|
unsigned treesPerChannel = mBitsPerChannel / N + ((mBitsPerChannel % N) != 0 ? 1 : 0);
|
|
unsigned8 mask = BitHelper::GetLSMaskUntil<unsigned8>(8 - mBitsPerChannel);
|
|
for (unsigned8 c = 0; c < 3; c++)
|
|
{
|
|
unsigned8 maskedColor = color[c] & mask;
|
|
for (unsigned8 i = 0; i < treesPerChannel; i++)
|
|
{
|
|
auto material = BitsMaterial<2>(maskedColor, N * i);
|
|
if (material.GetValue() != 0)
|
|
mCurPassTree->AddLeafNode(coordinate, treesPerChannel * c + i, material);
|
|
}
|
|
}
|
|
}
|
|
|
|
template<>
|
|
void MaterialMultiRootOctreeBuilder<BitsMaterial<3>>::AddNode(const glm::uvec3& coordinate, const Color& color)
|
|
{
|
|
unsigned N = 3;
|
|
mCurPassTree->AddLeafNode(coordinate, BitsMaterial<3>(1));
|
|
unsigned treesPerChannel = mBitsPerChannel / N + ((mBitsPerChannel % N) != 0 ? 1 : 0);
|
|
unsigned8 mask = BitHelper::GetLSMaskUntil<unsigned8>(8 - mBitsPerChannel);
|
|
for (unsigned8 c = 0; c < 3; c++)
|
|
{
|
|
unsigned8 maskedColor = color[c] & mask;
|
|
for (unsigned8 i = 0; i < treesPerChannel; i++)
|
|
{
|
|
auto material = BitsMaterial<3>(maskedColor, N * i);
|
|
if (material.GetValue() != 0)
|
|
mCurPassTree->AddLeafNode(coordinate, treesPerChannel * c + i, material);
|
|
}
|
|
}
|
|
}
|
|
|
|
template<>
|
|
void MaterialMultiRootOctreeBuilder<BitsMaterial<4>>::AddNode(const glm::uvec3& coordinate, const Color& color)
|
|
{
|
|
unsigned N = 4;
|
|
mCurPassTree->AddLeafNode(coordinate, BitsMaterial<4>(1));
|
|
unsigned treesPerChannel = mBitsPerChannel / N + ((mBitsPerChannel % N) != 0 ? 1 : 0);
|
|
unsigned8 mask = BitHelper::GetLSMaskUntil<unsigned8>(8 - mBitsPerChannel);
|
|
for (unsigned8 c = 0; c < 3; c++)
|
|
{
|
|
unsigned8 maskedColor = color[c] & mask;
|
|
for (unsigned8 i = 0; i < treesPerChannel; i++)
|
|
{
|
|
auto material = BitsMaterial<4>(maskedColor, N * i);
|
|
if (material.GetValue() != 0)
|
|
mCurPassTree->AddLeafNode(coordinate, treesPerChannel * c + i, material);
|
|
}
|
|
}
|
|
}
|
|
|
|
template<>
|
|
void MaterialMultiRootOctreeBuilder<BitsMaterial<5>>::AddNode(const glm::uvec3& coordinate, const Color& color)
|
|
{
|
|
unsigned N = 5;
|
|
mCurPassTree->AddLeafNode(coordinate, BitsMaterial<5>(1));
|
|
unsigned treesPerChannel = mBitsPerChannel / N + ((mBitsPerChannel % N) != 0 ? 1 : 0);
|
|
unsigned8 mask = BitHelper::GetLSMaskUntil<unsigned8>(8 - mBitsPerChannel);
|
|
for (unsigned8 c = 0; c < 3; c++)
|
|
{
|
|
unsigned8 maskedColor = color[c] & mask;
|
|
for (unsigned8 i = 0; i < treesPerChannel; i++)
|
|
{
|
|
auto material = BitsMaterial<5>(maskedColor, N * i);
|
|
if (material.GetValue() != 0)
|
|
mCurPassTree->AddLeafNode(coordinate, treesPerChannel * c + i, material);
|
|
}
|
|
}
|
|
}
|
|
|
|
template<>
|
|
void MaterialMultiRootOctreeBuilder<BitsMaterial<6>>::AddNode(const glm::uvec3& coordinate, const Color& color)
|
|
{
|
|
unsigned N = 6;
|
|
mCurPassTree->AddLeafNode(coordinate, BitsMaterial<6>(1));
|
|
unsigned treesPerChannel = mBitsPerChannel / N + ((mBitsPerChannel % N) != 0 ? 1 : 0);
|
|
unsigned8 mask = BitHelper::GetLSMaskUntil<unsigned8>(8 - mBitsPerChannel);
|
|
for (unsigned8 c = 0; c < 3; c++)
|
|
{
|
|
unsigned8 maskedColor = color[c] & mask;
|
|
for (unsigned8 i = 0; i < treesPerChannel; i++)
|
|
{
|
|
auto material = BitsMaterial<6>(maskedColor, N * i);
|
|
if (material.GetValue() != 0)
|
|
mCurPassTree->AddLeafNode(coordinate, treesPerChannel * c + i, material);
|
|
}
|
|
}
|
|
}
|
|
|
|
template<>
|
|
void MaterialMultiRootOctreeBuilder<BitsMaterial<7>>::AddNode(const glm::uvec3& coordinate, const Color& color)
|
|
{
|
|
unsigned N = 7;
|
|
mCurPassTree->AddLeafNode(coordinate, BitsMaterial<7>(1));
|
|
unsigned treesPerChannel = mBitsPerChannel / N + ((mBitsPerChannel % N) != 0 ? 1 : 0);
|
|
unsigned8 mask = BitHelper::GetLSMaskUntil<unsigned8>(8 - mBitsPerChannel);
|
|
for (unsigned8 c = 0; c < 3; c++)
|
|
{
|
|
unsigned8 maskedColor = color[c] & mask;
|
|
for (unsigned8 i = 0; i < treesPerChannel; i++)
|
|
{
|
|
auto material = BitsMaterial<7>(maskedColor, N * i);
|
|
if (material.GetValue() != 0)
|
|
mCurPassTree->AddLeafNode(coordinate, treesPerChannel * c + i, material);
|
|
}
|
|
}
|
|
}
|
|
|
|
template<>
|
|
void MaterialMultiRootOctreeBuilder<BitsMaterial<8>>::AddNode(const glm::uvec3& coordinate, const Color& color)
|
|
{
|
|
mCurPassTree->AddLeafNode(coordinate, BitsMaterial<8>());
|
|
unsigned8 mask = BitHelper::GetLSMaskUntil<unsigned8>(8 - mBitsPerChannel);
|
|
|
|
mCurPassTree->AddLeafNode(coordinate, 0, BitsMaterial<8>(color.GetR() & mask));
|
|
mCurPassTree->AddLeafNode(coordinate, 1, BitsMaterial<8>(color.GetG() & mask));
|
|
mCurPassTree->AddLeafNode(coordinate, 2, BitsMaterial<8>(color.GetB() & mask));
|
|
}
|
|
|
|
template<> std::string MaterialMultiRootOctreeBuilder<BitsMaterial<1>>::GetTreeType() { return "m" + std::to_string(mBitsPerChannel) + "b1"; }
|
|
template<> std::string MaterialMultiRootOctreeBuilder<BitsMaterial<2>>::GetTreeType() { return "m" + std::to_string(mBitsPerChannel) + "b2"; }
|
|
template<> std::string MaterialMultiRootOctreeBuilder<BitsMaterial<3>>::GetTreeType() { return "m" + std::to_string(mBitsPerChannel) + "b3"; }
|
|
template<> std::string MaterialMultiRootOctreeBuilder<BitsMaterial<4>>::GetTreeType() { return "m" + std::to_string(mBitsPerChannel) + "b4"; }
|
|
template<> std::string MaterialMultiRootOctreeBuilder<BitsMaterial<5>>::GetTreeType() { return "m" + std::to_string(mBitsPerChannel) + "b5"; }
|
|
template<> std::string MaterialMultiRootOctreeBuilder<BitsMaterial<6>>::GetTreeType() { return "m" + std::to_string(mBitsPerChannel) + "b6"; }
|
|
template<> std::string MaterialMultiRootOctreeBuilder<BitsMaterial<7>>::GetTreeType() { return "m" + std::to_string(mBitsPerChannel) + "b7"; }
|
|
template<> std::string MaterialMultiRootOctreeBuilder<BitsMaterial<8>>::GetTreeType() { return "m" + std::to_string(mBitsPerChannel) + "b8"; } |