add new MaterialComponent

This commit is contained in:
hyzboy 2020-01-09 16:53:30 +08:00
parent 27c6aefc7a
commit 93d680926e
5 changed files with 213 additions and 145 deletions

View File

@ -1,97 +1,26 @@
#ifndef HGL_GRAPH_MATERIAL_INCLUDE
#define HGL_GRAPH_MATERIAL_INCLUDE
#include<hgl/graph/MaterialData.h>
namespace hgl
{
namespace graph
#include<hgl/graph/MaterialComponent.h>
BEGIN_MATERIAL_NAMESPACE
enum class BlendMode
{
class Material
{
};//
Opaque=0,
Mask,
Alpha,
Additive,
Modulate,
PreMultiAlpha, // 预计算好一半的Alpha
enum class MaterialBlendMode
{
Opaque=0,
Mask,
Alpha,
Additive,
Modulate,
PreMultiAlpha, //预计算好一半的Alpha
BEGIN_RANGE =Opaque,
END_RANGE =PreMultiAlpha,
RANGE_SIZE =END_RANGE-BEGIN_RANGE+1
};//
BEGIN_RANGE =Opaque,
END_RANGE =PreMultiAlpha,
RANGE_SIZE =END_RANGE-BEGIN_RANGE+1
};//
enum class MaterialComponent
{
Color=0,
Normal,
Tangent,
Metallic,
Roughness,
Emissive,
Specular,
Anisotropy,
Opacity,
SubsurfaceColor,
AmbientOcclusion,
Refraction,
Rotation,
IOR,
ShadingModel,
BEGIN_RANGE =Opaque,
END_RANGE =ShadingModel,
RANGE_SIZE =END_RANGE-BEGIN_RANGE+1,
};//
enum class MaterialComponentBit
{
#define MC_BIT_DEFINE(name) name=1<<MaterialComponent::name
MC_BIT_DEFINE(Color ),
MC_BIT_DEFINE(Normal ),
MC_BIT_DEFINE(Tangent ),
MC_BIT_DEFINE(Metallic ),
MC_BIT_DEFINE(Roughness ),
MC_BIT_DEFINE(Emissive ),
MC_BIT_DEFINE(Specular ),
MC_BIT_DEFINE(Anisotropy ),
MC_BIT_DEFINE(Opacity ),
MC_BIT_DEFINE(SubsurfaceColor ),
MC_BIT_DEFINE(AmbientOcclusion ),
MC_BIT_DEFINE(Refraction ),
MC_BIT_DEFINE(Rotation ),
MC_BIT_DEFINE(IOR ),
MC_BIT_DEFINE(ShadingModel )
};//enum class MaterialComponentBit
using MCB=MaterialComponentBit;
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
class Material
{
BlendMode blend_mode;
ComponentBitsConfig comp_cfg;
};//class Material
END_MATERIAL_NAMESPACE
#endif//HGL_GRAPH_MATERIAL_INCLUDE

View File

@ -0,0 +1,87 @@
#ifndef HGL_GRAPH_MATERIAL_COMPONENT_INCLUDE
#define HGL_GRAPH_MATERIAL_COMPONENT_INCLUDE
#include<hgl/type/DataType.h>
#define BEGIN_MATERIAL_NAMESPACE namespace hgl{namespace graph{namespace material{
#define END_MATERIAL_NAMESPACE }}}
BEGIN_MATERIAL_NAMESPACE
enum class Component
{
ShadingModel=0,
Color,
Opacity,
Normal,
Metallic,
Roughness,
Emissive,
Refraction,
AO,
SSS,
Height,
RIM,
ClearCoat,
Anisotropy,
BEGIN_RANGE =ShadingModel,
END_RANGE =Anisotropy,
RANGE_SIZE =END_RANGE-BEGIN_RANGE+1,
};//
enum class ComponentBit
{
#define MC_BIT_DEFINE(name) name=1<<(uint)Component::name
MC_BIT_DEFINE(ShadingModel ),
MC_BIT_DEFINE(Color ),
MC_BIT_DEFINE(Opacity ),
MC_BIT_DEFINE(Normal ),
MC_BIT_DEFINE(Metallic ),
MC_BIT_DEFINE(Roughness ),
MC_BIT_DEFINE(Emissive ),
MC_BIT_DEFINE(Refraction ),
MC_BIT_DEFINE(AO ),
MC_BIT_DEFINE(SSS ),
MC_BIT_DEFINE(Height ),
MC_BIT_DEFINE(RIM ),
MC_BIT_DEFINE(ClearCoat ),
MC_BIT_DEFINE(Anisotropy ),
#undef MC_BIT_DEFINE
};//enum class ComponentBit
enum class ComponentDataType
{
Bool=0,
Float,
Int,
Uint,
};//
using ComponentBitsConfig=uint32;
constexpr ComponentBitsConfig MCC_PureColor =uint32(ComponentBit::Color);
constexpr ComponentBitsConfig MCC_PureNormal =uint32(ComponentBit::Normal);
constexpr ComponentBitsConfig MCC_ColorNormal =uint32(ComponentBit::Color)|uint32(ComponentBit::Normal);
constexpr ComponentBitsConfig MCC_CNMR =uint32(ComponentBit::Color)|uint32(ComponentBit::Normal)|uint32(ComponentBit::Metallic)|uint32(ComponentBit::Roughness);
struct ComponentConfig
{
Component comp; ///<成份ID
ComponentDataType type; ///<数据类型
uint channels; ///<通道数
bool LinearColorspace; ///<是要求线性颜色空间
};
const ComponentConfig *GetConfig(const enum class Component c);
END_MATERIAL_NAMESPACE
#endif//HGL_GRAPH_MATERIAL_COMPONENT_INCLUDE

View File

@ -1,5 +1,18 @@
SET(SCENE_GRAPH_HEADER ${ROOT_INCLUDE_PATH}/hgl/graph/Coordinate.h
${ROOT_INCLUDE_PATH}/hgl/graph/AABox.h
SET(SG_MATERIAL_SOURCE ${ROOT_INCLUDE_PATH}/hgl/graph/MaterialComponent.h
${ROOT_INCLUDE_PATH}/hgl/graph/Material.h
MaterialComponent.cpp
Material.cpp)
SOURCE_GROUP("Material" FILES ${SG_MATERIAL_SOURCE})
SET(SG_VERTEX_SOURCE ${ROOT_INCLUDE_PATH}/hgl/graph/VertexBufferCreater.h
${ROOT_INCLUDE_PATH}/hgl/graph/VertexBuffer.h)
SOURCE_GROUP("VertexBuffer" FILES ${SG_VERTEX_SOURCE})
SET(SCENE_GRAPH_HEADER ${ROOT_INCLUDE_PATH}/hgl/graph/Coordinate.h
${ROOT_INCLUDE_PATH}/hgl/graph/AABox.h
${ROOT_INCLUDE_PATH}/hgl/graph/Camera.h
${ROOT_INCLUDE_PATH}/hgl/graph/Light.h
${ROOT_INCLUDE_PATH}/hgl/graph/SceneDB.h
@ -7,8 +20,6 @@
${ROOT_INCLUDE_PATH}/hgl/graph/SceneOrient.h
${ROOT_INCLUDE_PATH}/hgl/graph/RenderableInstance.h
${ROOT_INCLUDE_PATH}/hgl/graph/RenderList.h
${ROOT_INCLUDE_PATH}/hgl/graph/VertexBufferCreater.h
${ROOT_INCLUDE_PATH}/hgl/graph/VertexBuffer.h
${ROOT_INCLUDE_PATH}/hgl/graph/InlineGeometry.h
#${ROOT_INCLUDE_PATH}/hgl/graph/Mesh.h
#${ROOT_INCLUDE_PATH}/hgl/graph/Material.h
@ -16,14 +27,14 @@
)
SET(SCENE_GRAPH_SOURCE Coordinate.cpp
AABox.cpp
AABox.cpp
Camera.cpp
RenderList.cpp
SceneDB.cpp
SceneNode.cpp
SceneOrient.cpp
InlineGeometry.cpp
#InlinePipeline.cpp
#InlinePipeline.cpp
#Material.cpp
#Mesh.cpp
#SceneFile.cpp
@ -33,4 +44,7 @@ SOURCE_GROUP("Header Files" FILES ${SCENE_GRAPH_HEADER})
SOURCE_GROUP("Source Files" FILES ${SCENE_GRAPH_SOURCE})
add_cm_library(ULRE.SceneGraph "ULRE" ${SCENE_GRAPH_HEADER}
${SCENE_GRAPH_SOURCE})
${SCENE_GRAPH_SOURCE}
${SG_MATERIAL_SOURCE}
${SG_VERTEX_SOURCE})

View File

@ -1,68 +1,64 @@
#include<hgl/graph/Material.h>
#include<hgl/io/FileInputStream.h>
#include<hgl/io/DataInputStream.h>
#include<hgl/LogInfo.h>
#include<hgl/log/LogInfo.h>
namespace hgl
{
namespace graph
{
bool LoadMaterialFile(MaterialData &md,const OSString &filename)//,Texture **tex_list)
{
io::FileInputStream fis;
io::LEDataInputStream dis(&fis);
BEGIN_MATERIAL_NAMESPACE
//bool LoadMaterialFile(MaterialData &md,const OSString &filename)//,Texture **tex_list)
//{
// io::FileInputStream fis;
// io::LEDataInputStream dis(&fis);
if(!fis.Open(filename))
RETURN_FALSE;
// if(!fis.Open(filename))
// RETURN_FALSE;
uint8 flag[9];
// uint8 flag[9];
if(dis.ReadFully(flag,9)!=9)
RETURN_FALSE;
// if(dis.ReadFully(flag,9)!=9)
// RETURN_FALSE;
if(memcmp(flag,"Material\x1A",9))
RETURN_FALSE;
// if(memcmp(flag,"Material\x1A",9))
// RETURN_FALSE;
uint8 ver;
// uint8 ver;
if(!dis.ReadUint8(ver))RETURN_FALSE;
// if(!dis.ReadUint8(ver))RETURN_FALSE;
if(ver!=1)RETURN_FALSE;
// if(ver!=1)RETURN_FALSE;
if(dis.ReadFloat(md.diffuse,3)!=3)RETURN_FALSE;
if(dis.ReadFloat(md.specular,3)!=3)RETURN_FALSE;
if(dis.ReadFloat(md.ambient,3)!=3)RETURN_FALSE;
if(dis.ReadFloat(md.emission,3)!=3)RETURN_FALSE;
// if(dis.ReadFloat(md.diffuse,3)!=3)RETURN_FALSE;
// if(dis.ReadFloat(md.specular,3)!=3)RETURN_FALSE;
// if(dis.ReadFloat(md.ambient,3)!=3)RETURN_FALSE;
// if(dis.ReadFloat(md.emission,3)!=3)RETURN_FALSE;
if(!dis.ReadFloat(md.shininess))RETURN_FALSE;
if(!dis.ReadBool(md.wireframe))RETURN_FALSE;
if(!dis.ReadBool(md.two_sided))RETURN_FALSE;
// if(!dis.ReadFloat(md.shininess))RETURN_FALSE;
// if(!dis.ReadBool(md.wireframe))RETURN_FALSE;
// if(!dis.ReadBool(md.two_sided))RETURN_FALSE;
if(!dis.ReadUint8(md.tex_count))RETURN_FALSE;
// if(!dis.ReadUint8(md.tex_count))RETURN_FALSE;
md.Init(md.tex_count);
// md.Init(md.tex_count);
for(uint8 i=0;i<md.tex_count;i++)
{
MaterialTextureData *mtd=&(md.tex_list[i]);
// for(uint8 i=0;i<md.tex_count;i++)
// {
// MaterialTextureData *mtd=&(md.tex_list[i]);
uint8 tt;
if(!dis.ReadUint8(tt))RETURN_FALSE;
mtd->type=(TextureType)tt;
// uint8 tt;
// if(!dis.ReadUint8(tt))RETURN_FALSE;
// mtd->type=(TextureType)tt;
if(!dis.ReadInt32(mtd->tex_id))RETURN_FALSE;
if(!dis.ReadUint8(mtd->uvindex))RETURN_FALSE;
if(!dis.ReadFloat(mtd->blend))RETURN_FALSE;
if(!dis.ReadUint8(mtd->op))RETURN_FALSE;
// if(!dis.ReadInt32(mtd->tex_id))RETURN_FALSE;
// if(!dis.ReadUint8(mtd->uvindex))RETURN_FALSE;
// if(!dis.ReadFloat(mtd->blend))RETURN_FALSE;
// if(!dis.ReadUint8(mtd->op))RETURN_FALSE;
uint8 wm[2];
if(!dis.ReadUint8(wm,2))RETURN_FALSE;
hgl_typecpy(mtd->wrap_mode,wm,2);
// uint8 wm[2];
// if(!dis.ReadUint8(wm,2))RETURN_FALSE;
// hgl_typecpy(mtd->wrap_mode,wm,2);
//mtl.SetTexture(mtd->type,tex_list[mtd->tex_id]);
}
// //mtl.SetTexture(mtd->type,tex_list[mtd->tex_id]);
// }
return(true);
}
}//namespace graph
}//namespace hgl
// return(true);
//}
END_MATERIAL_NAMESPACE

View File

@ -0,0 +1,42 @@
#include<hgl/graph/MaterialComponent.h>
BEGIN_MATERIAL_NAMESPACE
namespace
{
constexpr ComponentConfig material_component_config_list[]=
{
#define MCC_DEFINE(name,dt,c,lc) {Component::name,ComponentDataType::dt,c,lc}
MCC_DEFINE(ShadingModel, Uint, 1, false ),
MCC_DEFINE(Color, Float, 3, true ),
MCC_DEFINE(Opacity, Float, 1, false ),
MCC_DEFINE(Normal, Float, 3, false ),
MCC_DEFINE(Metallic, Float, 1, false ),
MCC_DEFINE(Roughness, Float, 1, false ),
MCC_DEFINE(Emissive, Float, 3, true ),
MCC_DEFINE(Refraction, Float, 1, false ),
MCC_DEFINE(AO, Float, 1, false ),
MCC_DEFINE(SSS, Float, 1, false ),
MCC_DEFINE(Height, Float, 1, false ),
MCC_DEFINE(RIM, Float, 1, false ),
MCC_DEFINE(ClearCoat, Float, 1, false ),
MCC_DEFINE(Anisotropy, Float, 1, false )
#undef MCC_DEFINE
};
};//namespace
const ComponentConfig *GetConfig(const enum class Component c)
{
if(c<=Component::BEGIN_RANGE
||c>=Component::END_RANGE)return(nullptr);
return material_component_config_list+(uint)c;
}
END_MATERIAL_NAMESPACE