#pragma once #include "BaseOctreeBuilder.h" #include "../../inc/glm/common.hpp" #include #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 struct MaterialAbbreviation { std::string operator()() const { return ""; } }; template<> struct MaterialAbbreviation { std::string operator()() const { return "c"; } }; template<> struct MaterialAbbreviation { std::string operator()() const { return "n"; } }; template<> struct MaterialAbbreviation { std::string operator()() const { return "cn"; } }; template<> struct MaterialAbbreviation { std::string operator()() const { return "co"; } }; template<> struct MaterialAbbreviation { std::string operator()() const { return "cnr"; } }; template struct MaterialName { std::string operator()() const { return "" } }; template<> struct MaterialName { std::string operator()() const { return "color"; } }; template<> struct MaterialName { std::string operator()() const { return "normal"; } }; template<> struct MaterialName { std::string operator()() const { return "color and normal"; } }; template<> struct MaterialName { std::string operator()() const { return "color and opacity"; } }; template<> struct MaterialName { std::string operator()() const { return "color, normal and value"; } }; template struct DefaultMaterials { std::vector operator()() const { return std::vector(); } }; template<> struct DefaultMaterials { std::vector operator()() const { return SmallNormal::GetAll(); } }; template 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::RequiresNormals() const { return false; } template<> bool BaseMaterialOctreeBuilder::RequiresReflectivity() const { return false; } template<> Color BaseMaterialOctreeBuilder::GetMaterial(const VoxelInfo& voxel) const { return Color(voxel.color); } // Hack to render the normals (debugging) //template<> BaseMaterialOctreeBuilder::BaseMaterialOctreeBuilder() { readColors = false; readNormals = true; } //template<> Color BaseMaterialOctreeBuilder::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::RequiresColors() const { return false; } template<> bool BaseMaterialOctreeBuilder::RequiresReflectivity() const { return false; } template<> SmallNormal BaseMaterialOctreeBuilder::GetMaterial(const VoxelInfo& voxel) const { return SmallNormal(voxel.normal); } template<> bool BaseMaterialOctreeBuilder::RequiresReflectivity() const { return false; } template<> ColorAndNormal BaseMaterialOctreeBuilder::GetMaterial(const VoxelInfo& voxel) const { return ColorAndNormal(voxel.color, voxel.normal); } template<> ColorAndNormalAndValue BaseMaterialOctreeBuilder::GetMaterial(const VoxelInfo& voxel) const { return ColorAndNormalAndValue(voxel.color, NormalAndValue(voxel.normal, (unsigned8)(voxel.reflectivity * 255.0f))); } template<> bool BaseMaterialOctreeBuilder::RequiresNormals() const { return false; } template<> ColorAndOpacity BaseMaterialOctreeBuilder::GetMaterial(const VoxelInfo& voxel) const { return ColorAndOpacity(voxel.color, (unsigned32)(glm::clamp(voxel.reflectivity, 0.f, 1.f) * 65535.f)); }