added M_Gizmo3D.cpp inline material.
This commit is contained in:
parent
fafe6c077b
commit
0137ef6e0c
@ -9,7 +9,7 @@ enum class LightingModel:uint8
|
|||||||
{
|
{
|
||||||
Unlit,
|
Unlit,
|
||||||
|
|
||||||
Gizmo, ///<Gizmo专用(Blinnphong的特定版本,写死太阳光方向和各种颜色)
|
Gizmo, ///<Gizmo专用(Blinnphong的特定版本,内置假的太阳光方向、高光系数等,使其不需要外部UBO传入)
|
||||||
|
|
||||||
Blinnphong, ///<Blinnphong光照模型
|
Blinnphong, ///<Blinnphong光照模型
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ constexpr const char *LightingModelName[]=
|
|||||||
enum class SkyLightSource:uint8
|
enum class SkyLightSource:uint8
|
||||||
{
|
{
|
||||||
PureColor, ///<纯色
|
PureColor, ///<纯色
|
||||||
OneLineCode, ///<一行代码
|
Simplest, ///<极简(一行代码)
|
||||||
Cubemap, ///<立方体贴图
|
Cubemap, ///<立方体贴图
|
||||||
IBL, ///<IBL立方体贴图
|
IBL, ///<IBL立方体贴图
|
||||||
|
|
||||||
@ -105,6 +105,8 @@ public:
|
|||||||
MaterialCreateInfo *CreateVertexColor3D(const Material3DCreateConfig *);
|
MaterialCreateInfo *CreateVertexColor3D(const Material3DCreateConfig *);
|
||||||
MaterialCreateInfo *CreateVertexLuminance3D(const Material3DCreateConfig *);
|
MaterialCreateInfo *CreateVertexLuminance3D(const Material3DCreateConfig *);
|
||||||
|
|
||||||
|
MaterialCreateInfo *CreateMaterialGizmo3D(const Material3DCreateConfig *cfg);
|
||||||
|
|
||||||
struct BillboardMaterialCreateConfig:public Material3DCreateConfig
|
struct BillboardMaterialCreateConfig:public Material3DCreateConfig
|
||||||
{
|
{
|
||||||
bool fixed_size; ///<固定大小(指像素尺寸)
|
bool fixed_size; ///<固定大小(指像素尺寸)
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
#include"Std3DMaterial.h"
|
|
||||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
|
||||||
|
|
||||||
STD_MTL_NAMESPACE_BEGIN
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
constexpr const char vs_main[]=R"(
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
Output.Color=Color;
|
|
||||||
|
|
||||||
gl_Position=GetPosition3D();
|
|
||||||
})";
|
|
||||||
|
|
||||||
//一个shader中输出的所有数据,会被定义在一个名为Output的结构中。所以编写时要用Output.XXXX来使用。
|
|
||||||
//而同时,这个结构在下一个Shader中以Input名称出现,使用时以Input.XXX的形式使用。
|
|
||||||
|
|
||||||
constexpr const char fs_main[]=R"(
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
FragColor=Input.Color;
|
|
||||||
})";// ^ ^
|
|
||||||
// | |
|
|
||||||
// | +--ps:这里的Input.Color就是上一个Shader中的Output.Color
|
|
||||||
// +--ps:这里的Color就是最终的RT
|
|
||||||
|
|
||||||
class MaterialBlinnPhongPureColor3D:public Std3DMaterial
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
using Std3DMaterial::Std3DMaterial;
|
|
||||||
~MaterialBlinnPhongPureColor3D()=default;
|
|
||||||
|
|
||||||
bool CustomVertexShader(ShaderCreateInfoVertex *vsc) override
|
|
||||||
{
|
|
||||||
if(!Std3DMaterial::CustomVertexShader(vsc))
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
vsc->AddInput(VAT_VEC4,VAN::Color);
|
|
||||||
|
|
||||||
vsc->AddOutput(SVT_VEC4,"Color");
|
|
||||||
|
|
||||||
vsc->SetMain(vs_main);
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CustomFragmentShader(ShaderCreateInfoFragment *fsc) override
|
|
||||||
{
|
|
||||||
fsc->AddOutput(VAT_VEC4,"FragColor"); //Fragment shader的输出等于最终的RT了,所以这个名称其实随便起。
|
|
||||||
|
|
||||||
fsc->SetMain(fs_main);
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
};//class MaterialBlinnPhongPureColor3D:public Std3DMaterial
|
|
||||||
}//namespace
|
|
||||||
|
|
||||||
MaterialCreateInfo *CreateMaterialBlinnPhongPureColor3D(const Material3DCreateConfig *cfg)
|
|
||||||
{
|
|
||||||
MaterialBlinnPhongPureColor3D mbppc3d(cfg);
|
|
||||||
|
|
||||||
return mbppc3d.Create();
|
|
||||||
}
|
|
||||||
STD_MTL_NAMESPACE_END
|
|
91
src/ShaderGen/3d/M_Gizmo3D.cpp
Normal file
91
src/ShaderGen/3d/M_Gizmo3D.cpp
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
#include"Std3DMaterial.h"
|
||||||
|
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||||
|
|
||||||
|
STD_MTL_NAMESPACE_BEGIN
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
// Gizmo3D材质其实就是纯色的blinnphong材质,但不需要外部传入太阳光方向、高光系数等数据。
|
||||||
|
// 其全部在Shader中直接包含,它是专门为Gizmo 3D控件所准备的一种材质。
|
||||||
|
|
||||||
|
constexpr const char mi_codes[]="vec4 Color;"; //材质实例代码
|
||||||
|
constexpr const uint32_t mi_bytes=sizeof(Vector4f); //材质实例数据大小
|
||||||
|
|
||||||
|
constexpr const char vs_main[]=R"(
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
HandoverMI();
|
||||||
|
|
||||||
|
Output.Normal =GetNormal();
|
||||||
|
Output.Position =GetPosition3D();
|
||||||
|
|
||||||
|
gl_Position =Output.Position;
|
||||||
|
})";
|
||||||
|
|
||||||
|
//一个shader中输出的所有数据,会被定义在一个名为Output的结构中。所以编写时要用Output.XXXX来使用。
|
||||||
|
//而同时,这个结构在下一个Shader中以Input名称出现,使用时以Input.XXX的形式使用。
|
||||||
|
|
||||||
|
constexpr const char fs_main[]=R"(
|
||||||
|
|
||||||
|
const vec3 SUN_DIRECTION=vec3(0.655386,0.491539,0.573462); //normalized(8,6,7)
|
||||||
|
const vec3 SUN_COLOR=vec3(1.0,1.0,1.0);
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
MaterialInstance mi=GetMI();
|
||||||
|
|
||||||
|
//点乘法线和光照
|
||||||
|
float intensity=0.5*max(dot(Input.Normal,SUN_DIRECTION),0.0)+0.5;
|
||||||
|
|
||||||
|
//直接光颜色
|
||||||
|
vec3 direct_color=intensity*SUN_COLOR*mi.Color.rgb;
|
||||||
|
|
||||||
|
vec3 SpecularColor=vec3(0);
|
||||||
|
|
||||||
|
if(intensity>0.0)
|
||||||
|
{
|
||||||
|
vec3 half_vector=normalize(SUN_DIRECTION+normalize(Input.Position.xyz+camera.pos));
|
||||||
|
|
||||||
|
float specular=max(dot(half_vector,Input.Normal),0.0);
|
||||||
|
|
||||||
|
spec_color=specular*pow(specular,64)*SUN_COLOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
FragColor=vec4(direct_color+spec_color,1.0);
|
||||||
|
})";
|
||||||
|
|
||||||
|
class MaterialGizmo3D:public Std3DMaterial
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
using Std3DMaterial::Std3DMaterial;
|
||||||
|
~MaterialGizmo3D()=default;
|
||||||
|
|
||||||
|
bool CustomVertexShader(ShaderCreateInfoVertex *vsc) override
|
||||||
|
{
|
||||||
|
if(!Std3DMaterial::CustomVertexShader(vsc))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
vsc->AddOutput(SVT_VEC4,"Position");
|
||||||
|
vsc->AddOutput(SVT_VEC3,"Normal");
|
||||||
|
|
||||||
|
vsc->SetMain(vs_main);
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CustomFragmentShader(ShaderCreateInfoFragment *fsc) override
|
||||||
|
{
|
||||||
|
fsc->AddOutput(VAT_VEC4,"FragColor"); //Fragment shader的输出等于最终的RT了,所以这个名称其实随便起。
|
||||||
|
|
||||||
|
fsc->SetMain(fs_main);
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
};//class MaterialGizmo3D:public Std3DMaterial
|
||||||
|
}//namespace
|
||||||
|
|
||||||
|
MaterialCreateInfo *CreateMaterialGizmo3D(const Material3DCreateConfig *cfg)
|
||||||
|
{
|
||||||
|
MaterialGizmo3D mg3d(cfg);
|
||||||
|
|
||||||
|
return mg3d.Create();
|
||||||
|
}
|
||||||
|
STD_MTL_NAMESPACE_END
|
@ -74,7 +74,7 @@ SET(STD_MTL_3D_SOURCE_FILES ${STD_MTL_HEADER_PATH}/Material3DCreateConfig.h
|
|||||||
3d/M_BillboardDynamicSize.cpp
|
3d/M_BillboardDynamicSize.cpp
|
||||||
3d/M_BillboardFixedSize.cpp
|
3d/M_BillboardFixedSize.cpp
|
||||||
3d/M_Billboard.cpp
|
3d/M_Billboard.cpp
|
||||||
3d/M_BlinnPhongPureColor.cpp
|
3d/M_Gizmo3D.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(STD_MTL_SOURCE ${STD_MTL_HEADER_PATH}/MaterialConfig.h
|
SET(STD_MTL_SOURCE ${STD_MTL_HEADER_PATH}/MaterialConfig.h
|
||||||
|
Loading…
x
Reference in New Issue
Block a user