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;
|
g=-0.9689f*x+1.8758f*y+0.0416f*z;
|
||||||
b= 0.0557f*x-0.2040f*y+1.0570f*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 graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
#endif//HGL_GRAPH_COLOR_SPACE_INCLUDE
|
#endif//HGL_GRAPH_COLOR_SPACE_INCLUDE
|
||||||
|
@ -1,94 +1,97 @@
|
|||||||
#ifndef HGL_GRAPH_MATERIAL_INCLUDE
|
#ifndef HGL_GRAPH_MATERIAL_INCLUDE
|
||||||
#define HGL_GRAPH_MATERIAL_INCLUDE
|
#define HGL_GRAPH_MATERIAL_INCLUDE
|
||||||
|
|
||||||
#include<hgl/graph/TextureType.h>
|
#include<hgl/graph/MaterialData.h>
|
||||||
#include<hgl/type/Color4f.h>
|
|
||||||
#include<hgl/type/Set.h>
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
namespace graph
|
namespace graph
|
||||||
{
|
{
|
||||||
struct MaterialTextureData
|
class Material
|
||||||
{
|
{
|
||||||
TextureType type=TextureType::None;
|
};//
|
||||||
|
|
||||||
int32 tex_id=-1;
|
enum class MaterialBlendMode
|
||||||
|
|
||||||
uint8 uvindex=0;
|
|
||||||
float blend=0;
|
|
||||||
uint8 op=0;
|
|
||||||
uint8 wrap_mode[2]={0,0};
|
|
||||||
};//struct MaterialTextureData
|
|
||||||
|
|
||||||
struct MaterialData
|
|
||||||
{
|
{
|
||||||
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;
|
Anisotropy,
|
||||||
uint shading_model=0;
|
|
||||||
bool wireframe=false;
|
|
||||||
|
|
||||||
uint blend_func;
|
Opacity,
|
||||||
|
|
||||||
float opacity; ///<透明度
|
SubsurfaceColor,
|
||||||
|
AmbientOcclusion,
|
||||||
|
Refraction,
|
||||||
|
|
||||||
uint transparency_factor;
|
Rotation,
|
||||||
|
IOR,
|
||||||
|
|
||||||
float bump_scaling;
|
ShadingModel,
|
||||||
float shininess;
|
|
||||||
float reflectivity; ///<反射率
|
|
||||||
float shininess_strength;
|
|
||||||
|
|
||||||
float refracti; ///<折射率
|
BEGIN_RANGE =Opaque,
|
||||||
|
END_RANGE =ShadingModel,
|
||||||
|
RANGE_SIZE =END_RANGE-BEGIN_RANGE+1,
|
||||||
|
};//
|
||||||
|
|
||||||
Color4f diffuse;
|
enum class MaterialComponentBit
|
||||||
Color4f ambient;
|
{
|
||||||
Color4f specular;
|
#define MC_BIT_DEFINE(name) name=1<<MaterialComponent::name
|
||||||
Color4f emission;
|
MC_BIT_DEFINE(Color ),
|
||||||
Color4f transparent; ///<透明色
|
MC_BIT_DEFINE(Normal ),
|
||||||
Color4f reflective; ///<反射颜色
|
MC_BIT_DEFINE(Tangent ),
|
||||||
|
|
||||||
public:
|
MC_BIT_DEFINE(Metallic ),
|
||||||
|
MC_BIT_DEFINE(Roughness ),
|
||||||
|
MC_BIT_DEFINE(Emissive ),
|
||||||
|
MC_BIT_DEFINE(Specular ),
|
||||||
|
|
||||||
MaterialData()
|
MC_BIT_DEFINE(Anisotropy ),
|
||||||
{
|
|
||||||
tex_count=0;
|
|
||||||
tex_list=nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitDefaultColor()
|
MC_BIT_DEFINE(Opacity ),
|
||||||
{
|
|
||||||
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;
|
MC_BIT_DEFINE(SubsurfaceColor ),
|
||||||
|
MC_BIT_DEFINE(AmbientOcclusion ),
|
||||||
|
MC_BIT_DEFINE(Refraction ),
|
||||||
|
|
||||||
opacity=1.0f;
|
MC_BIT_DEFINE(Rotation ),
|
||||||
refracti=0;
|
MC_BIT_DEFINE(IOR ),
|
||||||
transparent.Set(0,0,0,1);
|
|
||||||
reflective.Set(1,1,1,1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Init(const uint32 tc)
|
MC_BIT_DEFINE(ShadingModel )
|
||||||
{
|
};//enum class MaterialComponentBit
|
||||||
tex_count=tc;
|
|
||||||
|
|
||||||
tex_list=new MaterialTextureData[tc];
|
using MCB=MaterialComponentBit;
|
||||||
}
|
|
||||||
|
|
||||||
~MaterialData()
|
using MaterialComponentConfig=uint32;
|
||||||
{
|
|
||||||
delete[] tex_list;
|
constexpr MaterialComponentConfig MC_PureColor =MCB::Color;
|
||||||
}
|
constexpr MaterialComponentConfig MC_ColorNormal =MCB::Color|MCB::Normal;
|
||||||
};//struct MaterialData
|
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 graph
|
||||||
}//namespace hgl
|
}//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