finished BillboardFixedSize. next step is use ShaderVariable
This commit is contained in:
parent
3927b3c788
commit
90a4f1d49f
@ -28,8 +28,6 @@ class TestApp:public SceneAppFramework
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
DeviceBuffer *ubo_color=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
Material * mtl_plane_grid =nullptr;
|
||||
@ -73,7 +71,7 @@ private:
|
||||
mtl::BillboardMaterialCreateConfig cfg(device->GetDeviceAttribute(),"Billboard2D",Prim::Billboard);
|
||||
|
||||
{
|
||||
cfg.fixed_size=false;
|
||||
cfg.fixed_size=true;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateBillboard2D(&cfg);
|
||||
|
||||
@ -100,6 +98,10 @@ private:
|
||||
sampler)) ///<采样器
|
||||
return(false);
|
||||
|
||||
Vector2u texture_size(texture->GetWidth(),texture->GetHeight());
|
||||
|
||||
mi_billboard->WriteMIData(texture_size);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
@ -4,9 +4,16 @@
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
namespace
|
||||
{
|
||||
constexpr const char mi_codes[]="uvec2 BillboardSize;"; //材质实例代码
|
||||
constexpr const uint32_t mi_bytes=sizeof(Vector2u); //材质实例数据大小
|
||||
|
||||
constexpr const char vs_main[]=R"(
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
Output.BillboardSize=mi.BillboardSize/viewport.canvas_resolution;
|
||||
|
||||
gl_Position=GetPosition3D();
|
||||
gl_Position/=gl_Position.w;
|
||||
})";
|
||||
@ -25,7 +32,7 @@ void main()
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
gl_Position=gl_in[0].gl_Position;
|
||||
gl_Position.xy+=BillboardVertex[i];
|
||||
gl_Position.xy+=BillboardVertex[i]*Input[0].BillboardSize;
|
||||
|
||||
Output.TexCoord=BillboardVertex[i]+vec2(0.5);
|
||||
|
||||
@ -52,6 +59,8 @@ void main()
|
||||
if(!Std3DMaterial::CustomVertexShader(vsc))
|
||||
return(false);
|
||||
|
||||
vsc->AddOutput(VAT_VEC2,"BillboardSize");
|
||||
|
||||
vsc->SetMain(vs_main);
|
||||
return(true);
|
||||
}
|
||||
@ -75,6 +84,15 @@ void main()
|
||||
fsc->SetMain(fs_main);
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool EndCustomShader() override
|
||||
{
|
||||
mci->SetMaterialInstance( mi_codes, //材质实例glsl代码
|
||||
mi_bytes, //材质实例数据大小
|
||||
VK_SHADER_STAGE_VERTEX_BIT); //只在Vertex Shader中使用材质实例最终数据
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class MaterialBillboard2DFixedSize:public Std3DMaterial
|
||||
}//namespace
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user