Last active
September 13, 2023 16:40
-
-
Save pollend/bf50735c3dc57287245290469ec35d88 to your computer and use it in GitHub Desktop.
NUMaterial.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "math/Uuid.h" | |
#include <cstdint> | |
#include <engine/RTTI.h> | |
#include <folly/small_vector.h> | |
#include <optional> | |
namespace hpl::material { | |
template<class TBase> | |
class NUMaterial { | |
public: | |
template<class I> | |
class MaterialInfo { | |
protected: | |
I m_info; | |
MaterialInfo<I>(NUMaterial* material) { | |
material->m_vlid_infos.push_back(I::ID); | |
} | |
}; | |
enum MaterialID: uint8_t { | |
Unknown = 0, | |
SolidDiffuse, | |
Translucent, | |
Water, | |
Decal, | |
MaterialIDCount | |
}; | |
inline NUMaterial(MaterialID id): m_id(id) {} | |
template<class I> | |
std::optional<I&> Info() { | |
auto& value = std::find(m_vlid_infos, [](auto& id) {id == I::ID;}); | |
if(value != m_vlid_infos.end()) { | |
return std::nullopt; | |
} | |
return static_cast<MaterialInfo<I>>( | |
static_cast<TBase>(this) | |
).m_info; | |
} | |
private: | |
MaterialID m_id; | |
folly::small_vector<hpl::Uuid, 32> m_vlid_infos; | |
}; | |
// always has refraction if enabled | |
struct WaterInfo { | |
static constexpr const hpl::Uuid ID = hpl::detail::From("2d446a3e-b68d-4f4d-a80f-30a242ad7935"); | |
bool m_hasReflection; | |
float m_refractionScale; | |
float m_frenselBias; | |
float m_frenselPow; | |
float m_reflectionFadeStart; | |
float mfReflectionFadeEnd; | |
float mfWaveSpeed; | |
float mfWaveAmplitude; | |
float mfWaveFreq; | |
}; | |
class WaterMaterial: | |
public NUMaterial<WaterMaterial>, | |
public NUMaterial<WaterMaterial>::MaterialInfo<WaterInfo> { | |
WaterMaterial(): | |
NUMaterial(NUMaterial::MaterialID::Water), | |
NUMaterial::MaterialInfo<WaterInfo>(this) { | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment