87 lines
5.1 KiB
C++
87 lines
5.1 KiB
C++
#pragma once
|
|
#include "BaseOctreeBuilder.h"
|
|
#include "../../inc/glm/common.hpp"
|
|
#include <unordered_set>
|
|
#include "../../core/Hashers.h"
|
|
#include "../../scene/Material/Color.h"
|
|
#include "../../scene/Material/SmallNormal.h"
|
|
#include "../../scene/Material/ColorAndNormal.h"
|
|
#include "../../scene/Material/ColorAndNormalAndValue.h"
|
|
#include "../../scene/Material/ColorAndOpacity.h"
|
|
#include "../Voxelizer/VoxelInfo.h"
|
|
|
|
template<typename T> struct MaterialAbbreviation { std::string operator()() const { return ""; } };
|
|
template<> struct MaterialAbbreviation<Color> { std::string operator()() const { return "c"; } };
|
|
template<> struct MaterialAbbreviation<SmallNormal> { std::string operator()() const { return "n"; } };
|
|
template<> struct MaterialAbbreviation<ColorAndNormal> { std::string operator()() const { return "cn"; } };
|
|
template<> struct MaterialAbbreviation<ColorAndOpacity> { std::string operator()() const { return "co"; } };
|
|
template<> struct MaterialAbbreviation<ColorAndNormalAndValue> { std::string operator()() const { return "cnr"; } };
|
|
|
|
template <typename T> struct MaterialName { std::string operator()() const { return "" } };
|
|
template<> struct MaterialName<Color> { std::string operator()() const { return "color"; } };
|
|
template<> struct MaterialName<SmallNormal> { std::string operator()() const { return "normal"; } };
|
|
template<> struct MaterialName<ColorAndNormal> { std::string operator()() const { return "color and normal"; } };
|
|
template<> struct MaterialName<ColorAndOpacity> { std::string operator()() const { return "color and opacity"; } };
|
|
template<> struct MaterialName<ColorAndNormalAndValue> { std::string operator()() const { return "color, normal and value"; } };
|
|
|
|
template<typename T> struct DefaultMaterials { std::vector<T> operator()() const { return std::vector<T>(); } };
|
|
template<> struct DefaultMaterials<SmallNormal> { std::vector<SmallNormal> operator()() const { return SmallNormal::GetAll(); } };
|
|
|
|
template<typename T>
|
|
class BaseMaterialOctreeBuilder : public BaseOctreeBuilder
|
|
{
|
|
public:
|
|
BaseMaterialOctreeBuilder() : BaseOctreeBuilder() {}
|
|
~BaseMaterialOctreeBuilder() override {}
|
|
protected:
|
|
T GetMaterial(const VoxelInfo& voxel) const { printf("Error: Material not implemented!"); }
|
|
bool RequiresColors() const override { return true; }
|
|
bool RequiresNormals() const override { return true; }
|
|
bool RequiresReflectivity() const override { return true; }
|
|
|
|
virtual void PreProcessNode(const glm::uvec3& coordinate, const T& material) {}
|
|
void PreProcessNode(const VoxelInfo& voxel) override { PreProcessNode(voxel.position, GetMaterial(voxel)); }
|
|
virtual void PreProcessMissingNode(const glm::uvec3& coordinate, const T& material) {}
|
|
void PreProcessMissingNode(const VoxelInfo& voxel) override { PreProcessMissingNode(voxel.position, GetMaterial(voxel)); }
|
|
|
|
// Should add a node to the current pass tree at the given coordinate and color
|
|
virtual void AddNode(const glm::uvec3& coordinate, const T& color) = 0;
|
|
void AddNode(const VoxelInfo& voxel) override { AddNode(voxel.position, GetMaterial(voxel)); }
|
|
virtual void AddMissingNode(const glm::uvec3& coordinate, const T& color) { printf("Warning: Missing nodes not caught!"); }
|
|
void AddMissingNode(const VoxelInfo& voxel) override { AddMissingNode(voxel.position, GetMaterial(voxel)); }
|
|
private:
|
|
};
|
|
|
|
template<> bool BaseMaterialOctreeBuilder<Color>::RequiresNormals() const { return false; }
|
|
template<> bool BaseMaterialOctreeBuilder<Color>::RequiresReflectivity() const { return false; }
|
|
template<> Color BaseMaterialOctreeBuilder<Color>::GetMaterial(const VoxelInfo& voxel) const { return Color(voxel.color); }
|
|
|
|
// Hack to render the normals (debugging)
|
|
//template<> BaseMaterialOctreeBuilder<Color>::BaseMaterialOctreeBuilder() { readColors = false; readNormals = true; }
|
|
//template<> Color BaseMaterialOctreeBuilder<Color>::GetMaterial(const VoxelInfo& voxel)
|
|
//{
|
|
// glm::vec3 scaledNormal = SmallNormal(voxel.normal).Get();
|
|
// scaledNormal = scaledNormal * 128.0f + 128.f;
|
|
// return Color(glm::u8vec3(scaledNormal));
|
|
//
|
|
//}
|
|
|
|
template<> bool BaseMaterialOctreeBuilder<SmallNormal>::RequiresColors() const { return false; }
|
|
template<> bool BaseMaterialOctreeBuilder<SmallNormal>::RequiresReflectivity() const { return false; }
|
|
template<> SmallNormal BaseMaterialOctreeBuilder<SmallNormal>::GetMaterial(const VoxelInfo& voxel) const { return SmallNormal(voxel.normal); }
|
|
|
|
template<> bool BaseMaterialOctreeBuilder<ColorAndNormal>::RequiresReflectivity() const { return false; }
|
|
template<> ColorAndNormal BaseMaterialOctreeBuilder<ColorAndNormal>::GetMaterial(const VoxelInfo& voxel) const {
|
|
return ColorAndNormal(voxel.color, voxel.normal);
|
|
}
|
|
|
|
template<> ColorAndNormalAndValue BaseMaterialOctreeBuilder<ColorAndNormalAndValue>::GetMaterial(const VoxelInfo& voxel) const
|
|
{
|
|
return ColorAndNormalAndValue(voxel.color, NormalAndValue(voxel.normal, (unsigned8)(voxel.reflectivity * 255.0f)));
|
|
}
|
|
|
|
template<> bool BaseMaterialOctreeBuilder<ColorAndOpacity>::RequiresNormals() const { return false; }
|
|
template<> ColorAndOpacity BaseMaterialOctreeBuilder<ColorAndOpacity>::GetMaterial(const VoxelInfo& voxel) const
|
|
{
|
|
return ColorAndOpacity(voxel.color, (unsigned32)(glm::clamp(voxel.reflectivity, 0.f, 1.f) * 65535.f));
|
|
} |