2024-06-16 23:49:23 +08:00
|
|
|
|
// Billboard
|
2024-06-13 13:56:48 +08:00
|
|
|
|
|
2025-05-22 01:11:30 +08:00
|
|
|
|
#include<hgl/WorkManager.h>
|
2024-06-13 13:56:48 +08:00
|
|
|
|
#include<hgl/filesystem/FileSystem.h>
|
|
|
|
|
#include<hgl/graph/InlineGeometry.h>
|
|
|
|
|
#include<hgl/graph/VKRenderResource.h>
|
|
|
|
|
#include<hgl/graph/RenderList.h>
|
|
|
|
|
#include<hgl/graph/Camera.h>
|
|
|
|
|
#include<hgl/graph/Ray.h>
|
|
|
|
|
#include<hgl/graph/VKVertexAttribBuffer.h>
|
|
|
|
|
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
|
|
|
|
#include<hgl/graph/VertexDataManager.h>
|
2024-07-24 23:15:16 +08:00
|
|
|
|
#include<hgl/graph/VKVertexInputConfig.h>
|
2025-05-22 01:11:30 +08:00
|
|
|
|
#include<hgl/graph/module/TextureManager.h>
|
2025-06-07 05:49:07 +08:00
|
|
|
|
#include<hgl/graph/FirstPersonCameraControl.h>
|
2025-06-15 17:53:15 +08:00
|
|
|
|
#include<hgl/component/MeshComponent.h>
|
2024-06-13 13:56:48 +08:00
|
|
|
|
|
|
|
|
|
using namespace hgl;
|
|
|
|
|
using namespace hgl::graph;
|
|
|
|
|
|
2024-06-16 22:58:45 +08:00
|
|
|
|
static float position_data[3]=
|
2024-06-13 13:56:48 +08:00
|
|
|
|
{
|
2024-06-16 22:58:45 +08:00
|
|
|
|
0,0,0
|
2024-06-13 13:56:48 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static float lumiance_data[2]={1,1};
|
|
|
|
|
|
|
|
|
|
static Color4f white_color(1,1,1,1);
|
|
|
|
|
static Color4f yellow_color(1,1,0,1);
|
|
|
|
|
|
2025-05-22 01:11:30 +08:00
|
|
|
|
class TestApp:public WorkObject
|
2024-06-13 13:56:48 +08:00
|
|
|
|
{
|
|
|
|
|
Color4f color;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
Material * mtl_plane_grid =nullptr;
|
|
|
|
|
MaterialInstance * mi_plane_grid =nullptr;
|
|
|
|
|
Pipeline * pipeline_plane_grid =nullptr;
|
|
|
|
|
Primitive * prim_plane_grid =nullptr;
|
|
|
|
|
|
|
|
|
|
MaterialInstance * mi_billboard =nullptr;
|
|
|
|
|
Pipeline * pipeline_billboard =nullptr;
|
2025-05-18 23:42:39 +08:00
|
|
|
|
Mesh * ro_billboard =nullptr;
|
2024-06-16 22:58:45 +08:00
|
|
|
|
|
|
|
|
|
Texture2D * texture =nullptr;
|
|
|
|
|
Sampler * sampler =nullptr;
|
2024-06-13 13:56:48 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
bool InitPlaneGridMP()
|
|
|
|
|
{
|
2025-05-18 23:42:39 +08:00
|
|
|
|
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
|
2024-06-13 13:56:48 +08:00
|
|
|
|
|
|
|
|
|
cfg.local_to_world=true;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
cfg.position_format=VAT_VEC2;
|
|
|
|
|
|
|
|
|
|
mtl_plane_grid=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
|
|
|
|
if(!mtl_plane_grid)return(false);
|
2024-07-24 23:15:16 +08:00
|
|
|
|
|
|
|
|
|
VILConfig vil_config;
|
|
|
|
|
|
|
|
|
|
vil_config.Add(VAN::Luminance,VF_V1UN8);
|
2024-06-13 13:56:48 +08:00
|
|
|
|
|
2024-07-24 23:15:16 +08:00
|
|
|
|
mi_plane_grid=db->CreateMaterialInstance(mtl_plane_grid,&vil_config,&white_color);
|
2024-06-13 13:56:48 +08:00
|
|
|
|
if(!mi_plane_grid)return(false);
|
|
|
|
|
|
2025-06-12 00:00:14 +08:00
|
|
|
|
pipeline_plane_grid=CreatePipeline(mi_plane_grid,InlinePipeline::Solid3D);
|
2024-06-13 13:56:48 +08:00
|
|
|
|
if(!pipeline_plane_grid)return(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InitBillboardMP()
|
|
|
|
|
{
|
2025-05-18 23:42:39 +08:00
|
|
|
|
mtl::BillboardMaterialCreateConfig cfg(PrimitiveType::Billboard);
|
2024-06-13 13:56:48 +08:00
|
|
|
|
|
|
|
|
|
{
|
2024-06-18 13:08:59 +08:00
|
|
|
|
cfg.fixed_size=true;
|
2024-06-16 23:49:23 +08:00
|
|
|
|
|
2025-05-18 23:42:39 +08:00
|
|
|
|
mi_billboard=CreateMaterialInstance(mtl::inline_material::Billboard2D,&cfg);
|
2024-06-13 13:56:48 +08:00
|
|
|
|
if(!mi_billboard)return(false);
|
|
|
|
|
|
2025-06-12 00:00:14 +08:00
|
|
|
|
pipeline_billboard=CreatePipeline(mi_billboard,InlinePipeline::Solid3D);
|
2024-06-13 13:56:48 +08:00
|
|
|
|
if(!pipeline_billboard)return(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(true);
|
2024-06-16 22:58:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InitTexture()
|
|
|
|
|
{
|
2025-05-22 01:11:30 +08:00
|
|
|
|
TextureManager *tex_manager=GetTextureManager();
|
|
|
|
|
|
|
|
|
|
texture=tex_manager->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"),true);
|
2024-06-16 22:58:45 +08:00
|
|
|
|
if(!texture)return(false);
|
|
|
|
|
|
|
|
|
|
sampler=db->CreateSampler();
|
|
|
|
|
|
|
|
|
|
if(!mi_billboard->GetMaterial()->BindImageSampler( DescriptorSetType::PerMaterial, ///<描述符合集
|
|
|
|
|
mtl::SamplerName::BaseColor, ///<采样器名称
|
|
|
|
|
texture, ///<纹理
|
|
|
|
|
sampler)) ///<采样器
|
|
|
|
|
return(false);
|
|
|
|
|
|
2024-06-18 13:08:59 +08:00
|
|
|
|
Vector2u texture_size(texture->GetWidth(),texture->GetHeight());
|
|
|
|
|
|
|
|
|
|
mi_billboard->WriteMIData(texture_size);
|
|
|
|
|
|
2024-06-16 22:58:45 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
2025-05-22 01:11:30 +08:00
|
|
|
|
|
2024-06-13 13:56:48 +08:00
|
|
|
|
bool CreateRenderObject()
|
|
|
|
|
{
|
|
|
|
|
using namespace inline_geometry;
|
2025-05-22 01:11:30 +08:00
|
|
|
|
|
2024-06-13 13:56:48 +08:00
|
|
|
|
{
|
2025-06-10 23:46:19 +08:00
|
|
|
|
auto pc=GetPrimitiveCreater(mi_plane_grid);
|
2024-06-13 13:56:48 +08:00
|
|
|
|
|
|
|
|
|
struct PlaneGridCreateInfo pgci;
|
|
|
|
|
|
2024-06-24 22:30:34 +08:00
|
|
|
|
pgci.grid_size.Set(500,500);
|
|
|
|
|
pgci.sub_count.Set(5,5);
|
2024-06-13 13:56:48 +08:00
|
|
|
|
|
2024-07-24 23:15:16 +08:00
|
|
|
|
pgci.lum=128;
|
|
|
|
|
pgci.sub_lum=192;
|
2024-06-13 13:56:48 +08:00
|
|
|
|
|
2025-06-10 23:46:19 +08:00
|
|
|
|
prim_plane_grid=CreatePlaneGrid2D(pc,&pgci);
|
2024-06-13 13:56:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-16 22:58:45 +08:00
|
|
|
|
{
|
2025-06-10 23:46:19 +08:00
|
|
|
|
auto pc=GetPrimitiveCreater(mi_billboard);
|
2024-06-16 22:58:45 +08:00
|
|
|
|
|
2025-06-10 23:46:19 +08:00
|
|
|
|
pc->Init("Billboard",1);
|
2024-06-16 22:58:45 +08:00
|
|
|
|
|
2025-06-10 23:46:19 +08:00
|
|
|
|
if(!pc->WriteVAB(VAN::Position,VF_V3F,position_data))
|
2024-06-16 22:58:45 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2025-06-10 23:46:19 +08:00
|
|
|
|
ro_billboard=db->CreateMesh(pc,mi_billboard,pipeline_billboard);
|
2025-05-22 01:11:30 +08:00
|
|
|
|
|
2024-06-16 22:58:45 +08:00
|
|
|
|
if(!ro_billboard)
|
|
|
|
|
return(false);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-13 13:56:48 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool InitScene()
|
|
|
|
|
{
|
2025-06-07 05:49:07 +08:00
|
|
|
|
SceneNode *scene_root=GetSceneRoot(); //取得缺省场景根节点
|
|
|
|
|
|
2025-06-15 17:53:15 +08:00
|
|
|
|
CreateComponent<MeshComponent>(scene_root,db->CreateMesh(prim_plane_grid,mi_plane_grid,pipeline_plane_grid));
|
|
|
|
|
CreateComponent<MeshComponent>(scene_root,ro_billboard);
|
2024-06-16 22:58:45 +08:00
|
|
|
|
|
2025-06-07 05:49:07 +08:00
|
|
|
|
CameraControl *camera_control=GetCameraControl();
|
|
|
|
|
|
2025-06-10 23:36:46 +08:00
|
|
|
|
camera_control->SetPosition(Vector3f(32,32,32));
|
|
|
|
|
camera_control->SetTarget(Vector3f(0,0,0));
|
2024-06-13 13:56:48 +08:00
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
2025-05-22 01:11:30 +08:00
|
|
|
|
using WorkObject::WorkObject;
|
|
|
|
|
|
2024-06-13 13:56:48 +08:00
|
|
|
|
~TestApp()
|
|
|
|
|
{
|
|
|
|
|
SAFE_CLEAR(prim_plane_grid);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-10 23:36:46 +08:00
|
|
|
|
bool Init() override
|
|
|
|
|
{
|
2024-06-13 13:56:48 +08:00
|
|
|
|
if(!InitPlaneGridMP())
|
|
|
|
|
return(false);
|
|
|
|
|
|
2024-06-16 22:58:45 +08:00
|
|
|
|
if(!InitBillboardMP())
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
if(!InitTexture())
|
|
|
|
|
return(false);
|
|
|
|
|
|
2024-06-13 13:56:48 +08:00
|
|
|
|
if(!CreateRenderObject())
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
if(!InitScene())
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
2025-05-22 01:11:30 +08:00
|
|
|
|
};//class TestApp:public WorkObject
|
2024-06-13 13:56:48 +08:00
|
|
|
|
|
2025-05-22 01:11:30 +08:00
|
|
|
|
int os_main(int,os_char **)
|
2024-06-13 13:56:48 +08:00
|
|
|
|
{
|
2025-06-10 01:34:13 +08:00
|
|
|
|
return RunFramework<TestApp>(OS_TEXT("Billboard"),1280,720);
|
2024-06-13 13:56:48 +08:00
|
|
|
|
}
|