added GetPosition3DCamera/GetPosition3DL2WCamera and to support UBO Camera
This commit is contained in:
parent
dbea7764fb
commit
45f50b3bc0
@ -472,6 +472,10 @@ public:
|
||||
|
||||
virtual void InitCamera(int w,int h)
|
||||
{
|
||||
camera=new Camera;
|
||||
|
||||
camera->pos=Vector3f(10,10,10);
|
||||
|
||||
camera_control=new FirstPersonCameraControl(&vp_info,camera);
|
||||
|
||||
camera_control->Refresh(); //更新矩阵计算
|
||||
@ -482,13 +486,11 @@ public:
|
||||
win->Join(ckc);
|
||||
win->Join(cmc);
|
||||
|
||||
camera=new Camera;
|
||||
|
||||
camera->pos=Vector3f(10,10,10);
|
||||
|
||||
RefreshCameraInfo(&camera_control->GetCameraInfo(),&vp_info,camera);
|
||||
|
||||
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&camera_control->GetCameraInfo());
|
||||
|
||||
db->global_descriptor.AddUBO(mtl::SBS_CameraInfo.name,ubo_camera_info);
|
||||
}
|
||||
|
||||
void Resize(int w,int h)override
|
||||
@ -510,11 +512,6 @@ public:
|
||||
return ubo_camera_info;
|
||||
}
|
||||
|
||||
bool BindCameraUBO(Material *mtl)
|
||||
{
|
||||
return mtl->BindUBO(DescriptorSetType::Global,"g_camera",ubo_camera_info);
|
||||
}
|
||||
|
||||
virtual void BuildCommandBuffer(uint32_t index)=0;
|
||||
|
||||
virtual void Draw()override
|
||||
|
@ -7,6 +7,8 @@
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
struct Material3DCreateConfig:public MaterialCreateConfig
|
||||
{
|
||||
bool camera; ///<包含摄像机矩阵信息
|
||||
|
||||
bool local_to_world; ///<包含LocalToWorld矩阵
|
||||
|
||||
VAT position_format; ///<position格式
|
||||
@ -21,6 +23,7 @@ public:
|
||||
rt_output.depth=true; //不输出深度
|
||||
rt_output.stencil=false; //不输出stencil
|
||||
|
||||
camera=true;
|
||||
local_to_world=false;
|
||||
|
||||
position_format=VAT_VEC3;
|
||||
|
@ -17,15 +17,24 @@ bool Std3DMaterial::CustomVertexShader(ShaderCreateInfoVertex *vsc)
|
||||
{
|
||||
vsc->AddInput(cfg->position_format,VAN::Position);
|
||||
|
||||
if(cfg->camera)
|
||||
{
|
||||
mci->AddStruct(SBS_CameraInfo);
|
||||
|
||||
mci->AddUBO(VK_SHADER_STAGE_ALL_GRAPHICS,
|
||||
DescriptorSetType::Global,
|
||||
SBS_CameraInfo);
|
||||
}
|
||||
|
||||
if(cfg->local_to_world)
|
||||
{
|
||||
mci->SetLocalToWorld(VK_SHADER_STAGE_ALL_GRAPHICS);
|
||||
|
||||
vsc->AddAssign();
|
||||
vsc->AddFunction(func::GetPosition3DL2W);
|
||||
vsc->AddFunction(cfg->camera?func::GetPosition3DL2WCamera:func::GetPosition3DL2W);
|
||||
}
|
||||
else
|
||||
vsc->AddFunction(func::GetPosition3D);
|
||||
vsc->AddFunction(cfg->camera?func::GetPosition3DCamera:func::GetPosition3D);
|
||||
|
||||
mci->AddUBO(VK_SHADER_STAGE_VERTEX_BIT,
|
||||
DescriptorSetType::Global,
|
||||
|
@ -66,5 +66,19 @@ vec4 GetPosition3D()
|
||||
return GetLocalToWorld()*vec4(Position,1);
|
||||
}
|
||||
)";
|
||||
|
||||
constexpr const char *GetPosition3DCamera=R"(
|
||||
vec4 GetPosition3D()
|
||||
{
|
||||
return camera.vp*vec4(Position,1);
|
||||
}
|
||||
)";
|
||||
|
||||
constexpr const char *GetPosition3DL2WCamera=R"(
|
||||
vec4 GetPosition3D()
|
||||
{
|
||||
return camera.vp*GetLocalToWorld()*vec4(Position,1);
|
||||
}
|
||||
)";
|
||||
}//namespace func
|
||||
STD_MTL_NAMESPACE_END
|
||||
|
Loading…
x
Reference in New Issue
Block a user