Added VertexLum3D material, test PlaneGrid3D OK!
This commit is contained in:
parent
1a63fa8c76
commit
78946994bb
@ -1 +1 @@
|
||||
Subproject commit 660c371ed1b1f98d5f0d96c57964026c70bff8c0
|
||||
Subproject commit bc0b1d5a2ce66c3b9875df4dcbd1a7575c35782b
|
@ -15,6 +15,13 @@ using namespace hgl::graph;
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
constexpr const Vector4f GridColor[3]=
|
||||
{
|
||||
{1,0,0,1},
|
||||
{0,1,0,1},
|
||||
{0,0,1,1}
|
||||
};
|
||||
|
||||
class TestApp:public CameraAppFramework
|
||||
{
|
||||
Color4f color;
|
||||
@ -27,44 +34,39 @@ private:
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * ro_plane_grid[3]{};
|
||||
Primitive * ro_plane_grid =nullptr;
|
||||
MaterialInstance * material_instance[3]{};
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor3D",Prim::Lines);
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor3D(&cfg);
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexLuminance3D(&cfg);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci);
|
||||
if(!material_instance)return(false);
|
||||
material=db->CreateMaterial(mci);
|
||||
if(!material)return(false);
|
||||
|
||||
db->global_descriptor.Bind(material_instance->GetMaterial());
|
||||
db->global_descriptor.Bind(material);
|
||||
|
||||
for(uint i=0;i<3;i++)
|
||||
{
|
||||
material_instance[i]=db->CreateMaterialInstance(material);
|
||||
|
||||
material_instance[i]->WriteMIData(GridColor[i]);
|
||||
}
|
||||
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D,Prim::Lines);
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,material_instance,pipeline);
|
||||
|
||||
if(!ri)
|
||||
return(nullptr);
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
void CreateRenderObject()
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
@ -81,28 +83,31 @@ private:
|
||||
pgci.side_step.x=8;
|
||||
pgci.side_step.y=8;
|
||||
|
||||
pgci.color.Set(0.5,0,0,1);
|
||||
pgci.side_color.Set(1,0,0,1);
|
||||
pgci.lum=0.5;
|
||||
pgci.side_lum=1.0;
|
||||
|
||||
const VIL *vil=material_instance->GetVIL();
|
||||
ro_plane_grid=CreatePlaneGrid(db,material->GetDefaultVIL(),&pgci);
|
||||
|
||||
ro_plane_grid[0]=CreatePlaneGrid(db,vil,&pgci);
|
||||
return ro_plane_grid;
|
||||
}
|
||||
|
||||
Renderable *Add(MaterialInstance *mi,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(ro_plane_grid,mi,pipeline);
|
||||
|
||||
pgci.color.Set(0,0.5,0,1);
|
||||
pgci.side_color.Set(0,1,0,1);
|
||||
if(!ri)
|
||||
return(nullptr);
|
||||
|
||||
ro_plane_grid[1]=CreatePlaneGrid(db,vil,&pgci);
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
pgci.color.Set(0,0,0.5,1);
|
||||
pgci.side_color.Set(0,0,1,1);
|
||||
ro_plane_grid[2]=CreatePlaneGrid(db,vil,&pgci);
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(ro_plane_grid[0],Matrix4f(1.0f));
|
||||
Add(ro_plane_grid[1],rotate(HGL_RAD_90,0,1,0));
|
||||
Add(ro_plane_grid[2],rotate(HGL_RAD_90,1,0,0));
|
||||
Add(material_instance[0],Matrix4f(1.0f));
|
||||
Add(material_instance[1],rotate(HGL_RAD_90,0,1,0));
|
||||
Add(material_instance[2],rotate(HGL_RAD_90,1,0,0));
|
||||
|
||||
camera->pos=Vector3f(200,200,200);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
@ -131,7 +136,8 @@ public:
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
CreateRenderObject();
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
@ -68,8 +68,8 @@ namespace hgl
|
||||
|
||||
Vector2u side_step; //到边界的步数
|
||||
|
||||
Color4f color; //一般线条颜色
|
||||
Color4f side_color; //边界线条颜色
|
||||
float lum; //一般线条颜色
|
||||
float side_lum; //边界线条颜色
|
||||
};//struct PlaneGridCreateInfo
|
||||
|
||||
/**
|
||||
|
@ -33,6 +33,7 @@ public:
|
||||
};//struct Material3DCreateConfig:public MaterialCreateConfig
|
||||
|
||||
MaterialCreateInfo *CreateVertexColor3D(const Material3DCreateConfig *);
|
||||
MaterialCreateInfo *CreateVertexLuminance3D(const Material3DCreateConfig *);
|
||||
//MaterialCreateInfo *CreatePureColor2D(const Material2DCreateConfig *);
|
||||
//MaterialCreateInfo *CreatePureTexture2D(const Material2DCreateConfig *);
|
||||
//MaterialCreateInfo *CreateRectTexture2D(Material2DCreateConfig *);
|
||||
|
@ -186,23 +186,23 @@ namespace hgl
|
||||
to(pgci->coord[0],pgci->coord[3],pos));
|
||||
}
|
||||
|
||||
AutoDelete<VB4f> color=rc.AccessVAD<VB4f>(VAN::Color);
|
||||
if(color)
|
||||
AutoDelete<VB1f> lum=rc.AccessVAD<VB1f>(VAN::Luminance);
|
||||
if(lum)
|
||||
{
|
||||
for(uint row=0;row<=pgci->step.x;row++)
|
||||
{
|
||||
if((row%pgci->side_step.x)==0)
|
||||
color->RepeatWrite(pgci->side_color,2);
|
||||
lum->RepeatWrite(pgci->side_lum,2);
|
||||
else
|
||||
color->RepeatWrite(pgci->color,2);
|
||||
lum->RepeatWrite(pgci->lum,2);
|
||||
}
|
||||
|
||||
for(uint col=0;col<=pgci->step.y;col++)
|
||||
{
|
||||
if((col%pgci->side_step.y)==0)
|
||||
color->RepeatWrite(pgci->side_color,2);
|
||||
lum->RepeatWrite(pgci->side_lum,2);
|
||||
else
|
||||
color->RepeatWrite(pgci->color,2);
|
||||
lum->RepeatWrite(pgci->lum,2);
|
||||
}
|
||||
}
|
||||
|
||||
|
77
src/ShaderGen/3d/M_VertexLum3D.cpp
Normal file
77
src/ShaderGen/3d/M_VertexLum3D.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include"Std3DMaterial.h"
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
namespace
|
||||
{
|
||||
constexpr const char mi_codes[]="vec4 Color;"; //材质实例代码
|
||||
constexpr const uint32_t mi_bytes=sizeof(Vector4f); //材质实例数据大小
|
||||
|
||||
constexpr const char vs_main[]=R"(
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
Output.Color=Luminance*mi.Color;
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
})";
|
||||
|
||||
//一个shader中输出的所有数据,会被定义在一个名为Output的结构中。所以编写时要用Output.XXXX来使用。
|
||||
//而同时,这个结构在下一个Shader中以Input名称出现,使用时以Input.XXX的形式使用。
|
||||
|
||||
constexpr const char fs_main[]=R"(
|
||||
void main()
|
||||
{
|
||||
Color=Input.Color;
|
||||
})";// ^ ^
|
||||
// | |
|
||||
// | +--ps:这里的Input.Color就是上一个Shader中的Output.Color
|
||||
// +--ps:这里的Color就是最终的RT
|
||||
|
||||
class MaterialVertexLuminance3D:public Std3DMaterial
|
||||
{
|
||||
public:
|
||||
|
||||
using Std3DMaterial::Std3DMaterial;
|
||||
~MaterialVertexLuminance3D()=default;
|
||||
|
||||
bool CustomVertexShader(ShaderCreateInfoVertex *vsc) override
|
||||
{
|
||||
if(!Std3DMaterial::CustomVertexShader(vsc))
|
||||
return(false);
|
||||
|
||||
vsc->AddInput(VAT_FLOAT,VAN::Luminance);
|
||||
|
||||
vsc->AddOutput(VAT_VEC4,"Color");
|
||||
|
||||
vsc->SetMain(vs_main);
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool CustomFragmentShader(ShaderCreateInfoFragment *fsc) override
|
||||
{
|
||||
fsc->AddOutput(VAT_VEC4,"Color"); //Fragment shader的输出等于最终的RT了,所以这个名称其实随便起。
|
||||
|
||||
fsc->SetMain(fs_main);
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool EndCustomShader() override
|
||||
{
|
||||
mci->SetMaterialInstance( mi_codes, //材质实例glsl代码
|
||||
mi_bytes, //材质实例数据大小
|
||||
VK_SHADER_STAGE_VERTEX_BIT); //只在Vertex Shader中使用材质实例最终数据
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class MaterialVertexLuminance3D:public Std3DMaterial
|
||||
}//namespace
|
||||
|
||||
MaterialCreateInfo *CreateVertexLuminance3D(const Material3DCreateConfig *cfg)
|
||||
{
|
||||
MaterialVertexLuminance3D mvc3d(cfg);
|
||||
|
||||
return mvc3d.Create();
|
||||
}
|
||||
STD_MTL_NAMESPACE_END
|
@ -63,6 +63,7 @@ SET(STD_MTL_3D_SOURCE_FILES ${STD_MTL_3D_HEADER_PATH}/Material3DCreateConfig.h
|
||||
3d/Std3DMaterial.h
|
||||
3d/Std3DMaterial.cpp
|
||||
3d/M_VertexColor3D.cpp
|
||||
3d/M_VertexLum3D.cpp
|
||||
)
|
||||
|
||||
SET(STD_MTL_SOURCE ${STD_MTL_HEADER_PATH}/MaterialConfig.h
|
||||
|
Loading…
x
Reference in New Issue
Block a user