redefine the Material class.
This commit is contained in:
parent
5e64222c48
commit
27c6aefc7a
@ -67,22 +67,6 @@ namespace hgl
|
||||
g=-0.9689f*x+1.8758f*y+0.0416f*z;
|
||||
b= 0.0557f*x-0.2040f*y+1.0570f*z;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void RGB2YCbCr(T &Y,T &Cb,T &Cr,const T &r,const T &g,const T &b
|
||||
{
|
||||
Y = 0.299 * r + 0.587 * g + 0.114 * b;
|
||||
Cb = (b - Y) * 0.565;
|
||||
Cr = (r - Y) * 0.713;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void YCbCr2RGB(T &r,T &g,T &b,const T &Y,const T &Cb,const T &Cr)
|
||||
{
|
||||
r=Y+1.403*Cr;
|
||||
g=Y-0.344*Cb-0.714*Cr;
|
||||
b=Y+1.770*Cb;
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_COLOR_SPACE_INCLUDE
|
||||
|
@ -1,94 +1,97 @@
|
||||
#ifndef HGL_GRAPH_MATERIAL_INCLUDE
|
||||
#define HGL_GRAPH_MATERIAL_INCLUDE
|
||||
|
||||
#include<hgl/graph/TextureType.h>
|
||||
#include<hgl/type/Color4f.h>
|
||||
#include<hgl/type/Set.h>
|
||||
#include<hgl/graph/MaterialData.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
struct MaterialTextureData
|
||||
class Material
|
||||
{
|
||||
TextureType type=TextureType::None;
|
||||
};//
|
||||
|
||||
int32 tex_id=-1;
|
||||
|
||||
uint8 uvindex=0;
|
||||
float blend=0;
|
||||
uint8 op=0;
|
||||
uint8 wrap_mode[2]={0,0};
|
||||
};//struct MaterialTextureData
|
||||
|
||||
struct MaterialData
|
||||
enum class MaterialBlendMode
|
||||
{
|
||||
UTF8String name;
|
||||
Opaque=0,
|
||||
Mask,
|
||||
Alpha,
|
||||
Additive,
|
||||
Modulate,
|
||||
PreMultiAlpha, //预计算好一半的Alpha
|
||||
|
||||
uint8 tex_count;
|
||||
BEGIN_RANGE =Opaque,
|
||||
END_RANGE =PreMultiAlpha,
|
||||
RANGE_SIZE =END_RANGE-BEGIN_RANGE+1
|
||||
};//
|
||||
|
||||
MaterialTextureData *tex_list;
|
||||
enum class MaterialComponent
|
||||
{
|
||||
Color=0,
|
||||
Normal,
|
||||
Tangent,
|
||||
|
||||
Set<uint> uv_use;
|
||||
Metallic,
|
||||
Roughness,
|
||||
Emissive,
|
||||
Specular,
|
||||
|
||||
bool two_sided=false;
|
||||
uint shading_model=0;
|
||||
bool wireframe=false;
|
||||
Anisotropy,
|
||||
|
||||
uint blend_func;
|
||||
Opacity,
|
||||
|
||||
float opacity; ///<透明度
|
||||
SubsurfaceColor,
|
||||
AmbientOcclusion,
|
||||
Refraction,
|
||||
|
||||
uint transparency_factor;
|
||||
Rotation,
|
||||
IOR,
|
||||
|
||||
float bump_scaling;
|
||||
float shininess;
|
||||
float reflectivity; ///<反射率
|
||||
float shininess_strength;
|
||||
ShadingModel,
|
||||
|
||||
float refracti; ///<折射率
|
||||
BEGIN_RANGE =Opaque,
|
||||
END_RANGE =ShadingModel,
|
||||
RANGE_SIZE =END_RANGE-BEGIN_RANGE+1,
|
||||
};//
|
||||
|
||||
Color4f diffuse;
|
||||
Color4f ambient;
|
||||
Color4f specular;
|
||||
Color4f emission;
|
||||
Color4f transparent; ///<透明色
|
||||
Color4f reflective; ///<反射颜色
|
||||
enum class MaterialComponentBit
|
||||
{
|
||||
#define MC_BIT_DEFINE(name) name=1<<MaterialComponent::name
|
||||
MC_BIT_DEFINE(Color ),
|
||||
MC_BIT_DEFINE(Normal ),
|
||||
MC_BIT_DEFINE(Tangent ),
|
||||
|
||||
public:
|
||||
MC_BIT_DEFINE(Metallic ),
|
||||
MC_BIT_DEFINE(Roughness ),
|
||||
MC_BIT_DEFINE(Emissive ),
|
||||
MC_BIT_DEFINE(Specular ),
|
||||
|
||||
MaterialData()
|
||||
{
|
||||
tex_count=0;
|
||||
tex_list=nullptr;
|
||||
}
|
||||
MC_BIT_DEFINE(Anisotropy ),
|
||||
|
||||
void InitDefaultColor()
|
||||
{
|
||||
diffuse.Set(1,1,1,1);
|
||||
specular.Set(0,0,0,1);
|
||||
ambient.Set(0.2f,0.2f,0.2f,1.0f);
|
||||
emission.Set(0,0,0,1);
|
||||
MC_BIT_DEFINE(Opacity ),
|
||||
|
||||
shininess=0;
|
||||
MC_BIT_DEFINE(SubsurfaceColor ),
|
||||
MC_BIT_DEFINE(AmbientOcclusion ),
|
||||
MC_BIT_DEFINE(Refraction ),
|
||||
|
||||
opacity=1.0f;
|
||||
refracti=0;
|
||||
transparent.Set(0,0,0,1);
|
||||
reflective.Set(1,1,1,1);
|
||||
}
|
||||
MC_BIT_DEFINE(Rotation ),
|
||||
MC_BIT_DEFINE(IOR ),
|
||||
|
||||
void Init(const uint32 tc)
|
||||
{
|
||||
tex_count=tc;
|
||||
MC_BIT_DEFINE(ShadingModel )
|
||||
};//enum class MaterialComponentBit
|
||||
|
||||
tex_list=new MaterialTextureData[tc];
|
||||
}
|
||||
using MCB=MaterialComponentBit;
|
||||
|
||||
~MaterialData()
|
||||
{
|
||||
delete[] tex_list;
|
||||
}
|
||||
};//struct MaterialData
|
||||
using MaterialComponentConfig=uint32;
|
||||
|
||||
constexpr MaterialComponentConfig MC_PureColor =MCB::Color;
|
||||
constexpr MaterialComponentConfig MC_ColorNormal =MCB::Color|MCB::Normal;
|
||||
constexpr MaterialComponentConfig MC_PBR =MCB::Color|MCB::Normal|MCB::Metallic|MCB::Roughness;
|
||||
|
||||
class Material
|
||||
{
|
||||
MaterialBlendMode blend_mode;
|
||||
MaterialComponentConfig component_config;
|
||||
};//class Material
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_MATERIAL_INCLUDE
|
||||
#endif//HGL_GRAPH_MATERIAL_INCLUDE
|
||||
|
94
inc/hgl/graph/MaterialData.h
Normal file
94
inc/hgl/graph/MaterialData.h
Normal file
@ -0,0 +1,94 @@
|
||||
#ifndef HGL_GRAPH_MATERIAL_DATA_INCLUDE
|
||||
#define HGL_GRAPH_MATERIAL_DATA_INCLUDE
|
||||
|
||||
#include<hgl/graph/TextureType.h>
|
||||
#include<hgl/type/Color4f.h>
|
||||
#include<hgl/type/Set.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
struct MaterialTextureData
|
||||
{
|
||||
TextureType type=TextureType::None;
|
||||
|
||||
int32 tex_id=-1;
|
||||
|
||||
uint8 uvindex=0;
|
||||
float blend=0;
|
||||
uint8 op=0;
|
||||
uint8 wrap_mode[2]={0,0};
|
||||
};//struct MaterialTextureData
|
||||
|
||||
struct MaterialData
|
||||
{
|
||||
UTF8String name;
|
||||
|
||||
uint8 tex_count;
|
||||
|
||||
MaterialTextureData *tex_list;
|
||||
|
||||
Set<uint> uv_use;
|
||||
|
||||
bool two_sided=false;
|
||||
uint shading_model=0;
|
||||
bool wireframe=false;
|
||||
|
||||
uint blend_func;
|
||||
|
||||
float opacity; ///<透明度
|
||||
|
||||
uint transparency_factor;
|
||||
|
||||
float bump_scaling;
|
||||
float shininess;
|
||||
float reflectivity; ///<反射率
|
||||
float shininess_strength;
|
||||
|
||||
float refracti; ///<折射率
|
||||
|
||||
Color4f diffuse;
|
||||
Color4f ambient;
|
||||
Color4f specular;
|
||||
Color4f emission;
|
||||
Color4f transparent; ///<透明色
|
||||
Color4f reflective; ///<反射颜色
|
||||
|
||||
public:
|
||||
|
||||
MaterialData()
|
||||
{
|
||||
tex_count=0;
|
||||
tex_list=nullptr;
|
||||
}
|
||||
|
||||
void InitDefaultColor()
|
||||
{
|
||||
diffuse.Set(1,1,1,1);
|
||||
specular.Set(0,0,0,1);
|
||||
ambient.Set(0.2f,0.2f,0.2f,1.0f);
|
||||
emission.Set(0,0,0,1);
|
||||
|
||||
shininess=0;
|
||||
|
||||
opacity=1.0f;
|
||||
refracti=0;
|
||||
transparent.Set(0,0,0,1);
|
||||
reflective.Set(1,1,1,1);
|
||||
}
|
||||
|
||||
void Init(const uint32 tc)
|
||||
{
|
||||
tex_count=tc;
|
||||
|
||||
tex_list=new MaterialTextureData[tc];
|
||||
}
|
||||
|
||||
~MaterialData()
|
||||
{
|
||||
delete[] tex_list;
|
||||
}
|
||||
};//struct MaterialData
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_MATERIAL_DATA_INCLUDE
|
Loading…
x
Reference in New Issue
Block a user