[WIP]preparing Billboard 2DWay sample
This commit is contained in:
parent
f1f0843bee
commit
23197e147c
@ -1 +1 @@
|
||||
Subproject commit c5b0f901b93929431c53cb112b09bc1e3df69665
|
||||
Subproject commit c93bbb8296944843f9abe778ab26a0ff432455fa
|
0
ShaderLibrary/Billboard/2DWay.vert
Normal file
0
ShaderLibrary/Billboard/2DWay.vert
Normal file
131
example/Basic/Billboard2D.cpp
Normal file
131
example/Basic/Billboard2D.cpp
Normal file
@ -0,0 +1,131 @@
|
||||
// Billboard2D
|
||||
// 用于实现在3D场景中显示固定象素尺寸的2D内容,比如显示在3D场景中的血条、头顶名字等。
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#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/mtl/Material3DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
private:
|
||||
|
||||
Material * material =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
MaterialInstance * material_instance[3]{};
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
cfg.position_format=VAT_VEC2;
|
||||
|
||||
material=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!material)return(false);
|
||||
|
||||
Color4f GridColor;
|
||||
COLOR ce=COLOR::BlenderAxisRed;
|
||||
|
||||
for(uint i=0;i<3;i++)
|
||||
{
|
||||
GridColor=GetColor4f(ce,1.0);
|
||||
|
||||
material_instance[i]=db->CreateMaterialInstance(material,nullptr,&GridColor);
|
||||
|
||||
ce=COLOR((int)ce+1);
|
||||
}
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.grid_size.Set(32,32);
|
||||
pgci.sub_count.Set(8,8);
|
||||
|
||||
pgci.lum=0.75;
|
||||
pgci.sub_lum=1.0;
|
||||
|
||||
PrimitiveCreater pc(device,material->GetDefaultVIL());
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid(&pc,&pgci);
|
||||
|
||||
return prim_plane_grid;
|
||||
}
|
||||
|
||||
Renderable *Add(MaterialInstance *mi,const Matrix4f &mat)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(prim_plane_grid,mi,pipeline);
|
||||
|
||||
if(!ri)
|
||||
return(nullptr);
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
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(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
// camera_control->SetReserveDirection(true,true); //反转x,y
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_plane_grid);
|
||||
}
|
||||
|
||||
bool Init(uint width,uint height) override
|
||||
{
|
||||
if(!SceneAppFramework::Init(width,height))
|
||||
return(false);
|
||||
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user