From 27c6aefc7a673f36fe6ab17d4d7786b4681aa8fe Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 8 Jan 2020 21:52:53 +0800 Subject: [PATCH] redefine the Material class. --- inc/hgl/graph/ColorSpace.h | 16 ----- inc/hgl/graph/Material.h | 131 ++++++++++++++++++----------------- inc/hgl/graph/MaterialData.h | 94 +++++++++++++++++++++++++ 3 files changed, 161 insertions(+), 80 deletions(-) create mode 100644 inc/hgl/graph/MaterialData.h diff --git a/inc/hgl/graph/ColorSpace.h b/inc/hgl/graph/ColorSpace.h index 43aea9e4..a5b7ea7c 100644 --- a/inc/hgl/graph/ColorSpace.h +++ b/inc/hgl/graph/ColorSpace.h @@ -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 - 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 - 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 diff --git a/inc/hgl/graph/Material.h b/inc/hgl/graph/Material.h index 4c15c191..adb18ada 100644 --- a/inc/hgl/graph/Material.h +++ b/inc/hgl/graph/Material.h @@ -1,94 +1,97 @@ #ifndef HGL_GRAPH_MATERIAL_INCLUDE #define HGL_GRAPH_MATERIAL_INCLUDE -#include -#include -#include +#include 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 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< +#include +#include +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 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