fixed PlaneGrid3D example, it RUN OK!!!

This commit is contained in:
2023-09-28 17:44:47 +08:00
parent 3db94948c5
commit db766f33ac
6 changed files with 82 additions and 13 deletions

2
CMCore

Submodule CMCore updated: 416e96c169...09d9678e11

View File

@@ -6,6 +6,8 @@
#include<hgl/graph/VKRenderResource.h> #include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/RenderList.h> #include<hgl/graph/RenderList.h>
#include<hgl/graph/Camera.h> #include<hgl/graph/Camera.h>
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
#include<hgl/graph/mtl/3d/Material3DCreateConfig.h>
using namespace hgl; using namespace hgl;
using namespace hgl::graph; using namespace hgl::graph;
@@ -34,23 +36,29 @@ private:
bool InitMDP() bool InitMDP()
{ {
material=db->CreateMaterial(OS_TEXT("res/material/VertexColor3D")); mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor3D",Prim::Lines);
if(!material)return(false);
material_instance=db->CreateMaterialInstance(material); cfg.local_to_world=true;
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor3D(&cfg);
material_instance=db->CreateMaterialInstance(mci);
if(!material_instance)return(false); if(!material_instance)return(false);
db->global_descriptor.Bind(material_instance->GetMaterial());
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D,Prim::Lines); pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D,Prim::Lines);
if(!pipeline)
return(false);
return(true); return pipeline;
} }
Renderable *Add(Primitive *r,const Matrix4f &mat) Renderable *Add(Primitive *r,const Matrix4f &mat)
{ {
Renderable *ri=db->CreateRenderable(r,material_instance,pipeline); Renderable *ri=db->CreateRenderable(r,material_instance,pipeline);
if(!ri)
return(nullptr);
render_root.CreateSubNode(mat,ri); render_root.CreateSubNode(mat,ri);
return ri; return ri;
@@ -101,7 +109,7 @@ private:
camera_control->Refresh(); camera_control->Refresh();
render_root.RefreshMatrix(); render_root.RefreshMatrix();
render_list->Expend(camera->info,&render_root); render_list->Expend(&render_root);
return(true); return(true);
} }
@@ -133,9 +141,6 @@ public:
void BuildCommandBuffer(uint32 index) void BuildCommandBuffer(uint32 index)
{ {
render_root.RefreshMatrix();
render_list->Expend(GetCameraInfo(),&render_root);
VulkanApplicationFramework::BuildCommandBuffer(index,render_list); VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
} }

View File

@@ -66,7 +66,7 @@ namespace hgl
Vector3f coord[4]; Vector3f coord[4];
Vector2u step; Vector2u step;
Vector2u side_step; //到边界的步数 Vector2u side_step; //到边界的步数
Color4f color; //一般线条颜色 Color4f color; //一般线条颜色
Color4f side_color; //边界线条颜色 Color4f side_color; //边界线条颜色

View File

@@ -0,0 +1,63 @@
#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()
{
Color=Input.Color;
})";// ^ ^
// | |
// | +--ps:这里的Input.Color就是上一个Shader中的Output.Color
// +--ps:这里的Color就是最终的RT
class MaterialVertexColor3D:public Std3DMaterial
{
public:
using Std3DMaterial::Std3DMaterial;
~MaterialVertexColor3D()=default;
bool CustomVertexShader(ShaderCreateInfoVertex *vsc) override
{
if(!Std3DMaterial::CustomVertexShader(vsc))
return(false);
vsc->AddInput(VAT_VEC4,VAN::Color);
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);
}
};//class MaterialVertexColor3D:public Std3DMaterial
}//namespace
MaterialCreateInfo *CreateVertexColor3D(const Material3DCreateConfig *cfg)
{
MaterialVertexColor3D mvc3d(cfg);
return mvc3d.Create();
}
STD_MTL_NAMESPACE_END

View File

@@ -62,6 +62,7 @@ SET(STD_MTL_3D_HEADER_PATH ${STD_MTL_HEADER_PATH}/3d)
SET(STD_MTL_3D_SOURCE_FILES ${STD_MTL_3D_HEADER_PATH}/Material3DCreateConfig.h SET(STD_MTL_3D_SOURCE_FILES ${STD_MTL_3D_HEADER_PATH}/Material3DCreateConfig.h
3d/Std3DMaterial.h 3d/Std3DMaterial.h
3d/Std3DMaterial.cpp 3d/Std3DMaterial.cpp
3d/M_VertexColor3D.cpp
) )
SET(STD_MTL_SOURCE ${STD_MTL_HEADER_PATH}/MaterialConfig.h SET(STD_MTL_SOURCE ${STD_MTL_HEADER_PATH}/MaterialConfig.h