[WIP] Gizmo
This commit is contained in:
parent
09e9e71d59
commit
fafe6c077b
@ -1,4 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include<hgl/graph/VK.h>
|
#include<hgl/graph/VK.h>
|
||||||
|
|
||||||
@ -6,10 +6,19 @@ VK_NAMESPACE_BEGIN
|
|||||||
|
|
||||||
class Gizmo
|
class Gizmo
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
Material * material;
|
Material * material;
|
||||||
MaterialInstance * mi;
|
MaterialInstance * mtl_inst;
|
||||||
Pipeline * pipeline;
|
Pipeline * pipeline;
|
||||||
Primitive * primitive;
|
VertexDataManager * vdm;
|
||||||
|
|
||||||
|
Primitive * prim_cylinder; ///<圆柱
|
||||||
|
Primitive * prim_cone; ///<圆锥
|
||||||
|
Primitive * prim_sphere; ///<球体
|
||||||
|
Primitive * prim_cube; ///<立方体
|
||||||
|
Primitive * prim_plane; ///<平面
|
||||||
|
|
||||||
|
|
||||||
};//class Gizmo
|
};//class Gizmo
|
||||||
|
|
||||||
|
@ -1,228 +1,23 @@
|
|||||||
// Gizmo 3D Move
|
/*
|
||||||
|
Gizmo move
|
||||||
|
|
||||||
#include"VulkanAppFramework.h"
|
ref: Blender 4
|
||||||
#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/VKVertexAttribBuffer.h>
|
|
||||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
|
||||||
|
|
||||||
using namespace hgl;
|
|
||||||
using namespace hgl::graph;
|
|
||||||
|
|
||||||
static Color4f white_color(1,1,1,1);
|
0 9-10
|
||||||
static Color4f yellow_color(1,1,0,1);
|
*----------------->>>>
|
||||||
|
|
|
||||||
|
|
|
||||||
|
| 5+
|
||||||
|
| +6
|
||||||
|
|
|
||||||
|
|
|
||||||
|
v
|
||||||
|
|
||||||
class TestApp:public SceneAppFramework
|
假设轴尺寸为10
|
||||||
{
|
箭头长度为2,直径为2
|
||||||
Color4f color;
|
双轴调节正方形,长宽为1,位置为5,5
|
||||||
|
|
||||||
DeviceBuffer *ubo_color=nullptr;
|
中心球半径为1
|
||||||
|
*/
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
Material * mtl_vtx_lum =nullptr;
|
|
||||||
MaterialInstance * mi_plane_grid =nullptr;
|
|
||||||
Pipeline * pipeline_vtx_lum =nullptr;
|
|
||||||
Primitive * prim_plane_grid =nullptr;
|
|
||||||
|
|
||||||
Material * mtl_vtx_color =nullptr;
|
|
||||||
MaterialInstance * mi_line =nullptr;
|
|
||||||
Pipeline * pipeline_vtx_color =nullptr;
|
|
||||||
Primitive * prim_line =nullptr;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
bool InitMaterialAndPipeline()
|
|
||||||
{
|
|
||||||
{
|
|
||||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
|
||||||
|
|
||||||
cfg.local_to_world=true;
|
|
||||||
|
|
||||||
mtl_vtx_lum=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
|
||||||
if(!mtl_vtx_lum)return(false);
|
|
||||||
|
|
||||||
mi_plane_grid=db->CreateMaterialInstance(mtl_vtx_lum,nullptr,&white_color);
|
|
||||||
if(!mi_plane_grid)return(false);
|
|
||||||
|
|
||||||
pipeline_vtx_lum=CreatePipeline(mtl_vtx_lum,InlinePipeline::Solid3D,Prim::Lines);
|
|
||||||
|
|
||||||
if(!pipeline_vtx_lum)
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor3D",Prim::Lines);
|
|
||||||
|
|
||||||
cfg.local_to_world=true;
|
|
||||||
|
|
||||||
mtl_vtx_color=db->LoadMaterial("Std3D/VertexColor3D",&cfg);
|
|
||||||
if(!mtl_vtx_color)return(false);
|
|
||||||
|
|
||||||
mi_line=db->CreateMaterialInstance(mtl_vtx_color);
|
|
||||||
if(!mi_line)return(false);
|
|
||||||
|
|
||||||
{
|
|
||||||
const PipelineData *ipd=GetPipelineData(InlinePipeline::Solid3D);
|
|
||||||
|
|
||||||
if(!ipd)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
PipelineData *pd=new PipelineData(ipd);
|
|
||||||
|
|
||||||
pd->SetLineWidth(2);
|
|
||||||
|
|
||||||
pipeline_vtx_color=CreatePipeline(mtl_vtx_color,pd,Prim::Lines);
|
|
||||||
|
|
||||||
delete pd;
|
|
||||||
|
|
||||||
if(!pipeline_vtx_color)
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
|
||||||
{
|
|
||||||
Renderable *ri=db->CreateRenderable(r,mi,p);
|
|
||||||
|
|
||||||
if(!ri)
|
|
||||||
{
|
|
||||||
LOG_ERROR(OS_TEXT("Create Renderable failed."));
|
|
||||||
return(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
render_root.CreateSubNode(ri);
|
|
||||||
|
|
||||||
return ri;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 写入一个坐标轴的线条数据.
|
|
||||||
*
|
|
||||||
* \param pos 要写入数据的指针
|
|
||||||
* \param max_line 主线条方向
|
|
||||||
* \param oa1 其它轴1方向
|
|
||||||
* \param oa2 其它轴2方向
|
|
||||||
*/
|
|
||||||
void WriteAxisPosition(Vector3f *pos,const Vector3f &max_line,const Vector3f &oa1,const Vector3f &oa2)
|
|
||||||
{
|
|
||||||
constexpr const float AXIS_LENGTH =4;
|
|
||||||
constexpr const float AXIS_MIN_STEP =1;
|
|
||||||
constexpr const float AXIS_ARROW_SIZE=0.25;
|
|
||||||
|
|
||||||
const Vector3f end_pos =max_line*AXIS_LENGTH; ///<最终点位置
|
|
||||||
const Vector3f cross_pos=max_line*AXIS_MIN_STEP; ///<坐标轴尾部交叉线位置
|
|
||||||
const Vector3f arrow_pos=max_line*(AXIS_LENGTH-AXIS_MIN_STEP); ///<箭头末端在主线上的位置
|
|
||||||
|
|
||||||
//主线
|
|
||||||
pos[0]=Vector3f(0, 0, 0);
|
|
||||||
pos[1]=end_pos;
|
|
||||||
|
|
||||||
//四根箭头线
|
|
||||||
pos[2]=end_pos;
|
|
||||||
pos[3]=arrow_pos-oa1*AXIS_ARROW_SIZE;
|
|
||||||
|
|
||||||
pos[4]=end_pos;
|
|
||||||
pos[5]=arrow_pos+oa1*AXIS_ARROW_SIZE;
|
|
||||||
|
|
||||||
pos[6]=end_pos;
|
|
||||||
pos[7]=arrow_pos-oa2*AXIS_ARROW_SIZE;
|
|
||||||
|
|
||||||
pos[8]=end_pos;
|
|
||||||
pos[9]=arrow_pos+oa2*AXIS_ARROW_SIZE;
|
|
||||||
|
|
||||||
//侧边连接其它轴线
|
|
||||||
pos[10]=cross_pos;
|
|
||||||
pos[11]=cross_pos+oa1*AXIS_MIN_STEP;
|
|
||||||
pos[12]=cross_pos;
|
|
||||||
pos[13]=cross_pos+oa2*AXIS_MIN_STEP;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CreateRenderObject()
|
|
||||||
{
|
|
||||||
using namespace inline_geometry;
|
|
||||||
|
|
||||||
{
|
|
||||||
struct PlaneGridCreateInfo pgci;
|
|
||||||
|
|
||||||
pgci.grid_size.Set(32,32);
|
|
||||||
|
|
||||||
pgci.sub_count.Set(8,8);
|
|
||||||
|
|
||||||
pgci.lum=0.5;
|
|
||||||
pgci.sub_lum=0.75;
|
|
||||||
|
|
||||||
prim_plane_grid=CreatePlaneGrid(db,mtl_vtx_lum->GetDefaultVIL(),&pgci);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
constexpr const uint AXIS_MAX_LINES =7;
|
|
||||||
constexpr const uint AXIS_MAX_VERTICES =AXIS_MAX_LINES*2*3;
|
|
||||||
|
|
||||||
prim_line=db->CreatePrimitive("Line",AXIS_MAX_VERTICES);
|
|
||||||
if(!prim_line)return(false);
|
|
||||||
|
|
||||||
Vector3f position_data[3][AXIS_MAX_LINES*2];
|
|
||||||
|
|
||||||
WriteAxisPosition(position_data[0],Vector3f(1,0,0),Vector3f(0,1,0),Vector3f(0,0,1));
|
|
||||||
WriteAxisPosition(position_data[1],Vector3f(0,1,0),Vector3f(1,0,0),Vector3f(0,0,1));
|
|
||||||
WriteAxisPosition(position_data[2],Vector3f(0,0,1),Vector3f(1,0,0),Vector3f(0,1,0));
|
|
||||||
|
|
||||||
Color4f color_data[3][AXIS_MAX_LINES*2];
|
|
||||||
|
|
||||||
for(Color4f &c:color_data[0])c=Color4f(1,0,0,1);
|
|
||||||
for(Color4f &c:color_data[1])c=Color4f(0,1,0,1);
|
|
||||||
for(Color4f &c:color_data[2])c=Color4f(0,0,1,1);
|
|
||||||
|
|
||||||
if(!prim_line->Set(VAN::Position, db->CreateVAB(VF_V3F,AXIS_MAX_VERTICES,position_data)))return(false);
|
|
||||||
if(!prim_line->Set(VAN::Color, db->CreateVAB(VF_V4F,AXIS_MAX_VERTICES,color_data )))return(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool InitScene()
|
|
||||||
{
|
|
||||||
Add(prim_plane_grid,mi_plane_grid,pipeline_vtx_lum);
|
|
||||||
Add(prim_line,mi_line,pipeline_vtx_color);
|
|
||||||
|
|
||||||
camera->pos=Vector3f(32,32,32);
|
|
||||||
camera_control->SetTarget(Vector3f(0,0,0));
|
|
||||||
camera_control->Refresh();
|
|
||||||
|
|
||||||
render_root.RefreshMatrix();
|
|
||||||
render_list->Expend(&render_root);
|
|
||||||
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
bool Init(uint w,uint h) override
|
|
||||||
{
|
|
||||||
if(!SceneAppFramework::Init(w,h))
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
if(!InitMaterialAndPipeline())
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
@ -5,6 +5,57 @@
|
|||||||
#include<hgl/graph/VertexAttrib.h>
|
#include<hgl/graph/VertexAttrib.h>
|
||||||
|
|
||||||
STD_MTL_NAMESPACE_BEGIN
|
STD_MTL_NAMESPACE_BEGIN
|
||||||
|
enum class LightingModel:uint8
|
||||||
|
{
|
||||||
|
Unlit,
|
||||||
|
|
||||||
|
Gizmo, ///<Gizmo专用(Blinnphong的特定版本,写死太阳光方向和各种颜色)
|
||||||
|
|
||||||
|
Blinnphong, ///<Blinnphong光照模型
|
||||||
|
|
||||||
|
FakePBR, ///<假PBR(使用Blinnphong+HalfLambert模拟)
|
||||||
|
MicroPBR, ///<微型PBR(只有BaseColor/Normal/Metallic/Roughness四个基础数据的PBR)
|
||||||
|
|
||||||
|
WebPBR, ///<Khronos为WebGL提供的PBR
|
||||||
|
FilamentPBR, ///<Filament引擎所使用的PBR
|
||||||
|
AMDPBR, ///<AMD Caulrdon框架所使用的PBR
|
||||||
|
|
||||||
|
BlenderPBR, ///<Blender所使用的PBR
|
||||||
|
|
||||||
|
ENUM_CLASS_RANGE(Unlit,BlenderPBR)
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr const char *LightingModelName[]=
|
||||||
|
{
|
||||||
|
"Unlit",
|
||||||
|
|
||||||
|
"Gizmo",
|
||||||
|
|
||||||
|
"Blinnphong",
|
||||||
|
|
||||||
|
"FakePBR",
|
||||||
|
"MicroPBR",
|
||||||
|
|
||||||
|
"WebPBR",
|
||||||
|
"FilamentPBR",
|
||||||
|
"AMDPBR",
|
||||||
|
|
||||||
|
"BlenderPBR"
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 天光来源
|
||||||
|
*/
|
||||||
|
enum class SkyLightSource:uint8
|
||||||
|
{
|
||||||
|
PureColor, ///<纯色
|
||||||
|
OneLineCode, ///<一行代码
|
||||||
|
Cubemap, ///<立方体贴图
|
||||||
|
IBL, ///<IBL立方体贴图
|
||||||
|
|
||||||
|
ENUM_CLASS_RANGE(PureColor,IBL)
|
||||||
|
};
|
||||||
|
|
||||||
struct Material3DCreateConfig:public MaterialCreateConfig
|
struct Material3DCreateConfig:public MaterialCreateConfig
|
||||||
{
|
{
|
||||||
bool camera; ///<包含摄像机矩阵信息
|
bool camera; ///<包含摄像机矩阵信息
|
||||||
|
63
src/ShaderGen/3d/M_BlinnPhongPureColor.cpp
Normal file
63
src/ShaderGen/3d/M_BlinnPhongPureColor.cpp
Normal 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()
|
||||||
|
{
|
||||||
|
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
|
@ -74,6 +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
|
||||||
)
|
)
|
||||||
|
|
||||||
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