修正内置几何体生成的数据

This commit is contained in:
hyzboy 2019-07-18 14:56:10 +08:00
parent 39db360b4a
commit 6da3df75df
5 changed files with 61 additions and 65 deletions

1
3rdpty/dl_glslang.sh Normal file
View File

@ -0,0 +1 @@
git clone https://github.com/KhronosGroup/glslang.git

View File

@ -1 +1,3 @@
git clone https://github.com/juj/MathGeoLib.git git clone https://github.com/juj/MathGeoLib.git
cd MathGeoLib
git.exe reset --hard ae6dc5e9b1ec83429af3b3ba17a7d61a046d3400 --

View File

@ -84,21 +84,21 @@ private:
{ {
vulkan::Material * material; vulkan::Material * material;
vulkan::DescriptorSets *desc_sets; vulkan::DescriptorSets *desc_sets;
vulkan::Pipeline * pipeline_line; vulkan::Pipeline * pipeline_fan;
vulkan::Pipeline * pipeline_solid; vulkan::Pipeline * pipeline_triangles;
};// };//
SubpassParam sp_gbuffer; SubpassParam sp_gbuffer;
SubpassParam sp_composition; SubpassParam sp_composition;
vulkan::Renderable *ro_plane_grid, vulkan::Renderable *ro_plane,
*ro_cube, *ro_cube,
*ro_sphere, *ro_sphere,
*ro_torus, *ro_torus,
*ro_cylinder, *ro_cylinder,
*ro_cone, *ro_cone,
*ro_plane; *ro_gbc_plane;
vulkan::Sampler * sampler=nullptr; vulkan::Sampler * sampler=nullptr;
@ -238,24 +238,28 @@ private:
bool InitGBufferPipeline(SubpassParam *sp) bool InitGBufferPipeline(SubpassParam *sp)
{ {
AutoDelete<vulkan::PipelineCreater> pipeline_creater=new vulkan::PipelineCreater(device,sp->material,gbuffer.rt); AutoDelete<vulkan::PipelineCreater> pipeline_creater=new vulkan::PipelineCreater(device,sp->material,gbuffer.rt);
{
pipeline_creater->Set(PRIM_TRIANGLES); pipeline_creater->Set(PRIM_TRIANGLES);
sp->pipeline_solid=pipeline_creater->Create(); sp->pipeline_triangles=pipeline_creater->Create();
if(!sp->pipeline_solid) if(!sp->pipeline_triangles)
return(false); return(false);
db->Add(sp->pipeline_solid); db->Add(sp->pipeline_triangles);
}
pipeline_creater->CloseCullFace(); {
pipeline_creater->Set(PRIM_LINES); pipeline_creater->Set(PRIM_TRIANGLE_FAN);
sp->pipeline_line=pipeline_creater->Create(); sp->pipeline_fan=pipeline_creater->Create();
if(!sp->pipeline_line) if(!sp->pipeline_fan)
return(false); return(false);
db->Add(sp->pipeline_line); db->Add(sp->pipeline_fan);
}
return(true); return(true);
} }
@ -267,12 +271,12 @@ private:
pipeline_creater->SetCullMode(VK_CULL_MODE_NONE); pipeline_creater->SetCullMode(VK_CULL_MODE_NONE);
pipeline_creater->Set(PRIM_TRIANGLE_FAN); pipeline_creater->Set(PRIM_TRIANGLE_FAN);
sp->pipeline_solid=pipeline_creater->Create(); sp->pipeline_triangles=pipeline_creater->Create();
if(!sp->pipeline_solid) if(!sp->pipeline_triangles)
return(false); return(false);
db->Add(sp->pipeline_solid); db->Add(sp->pipeline_triangles);
return(true); return(true);
} }
@ -328,23 +332,9 @@ private:
void CreateRenderObject(vulkan::Material *mtl) void CreateRenderObject(vulkan::Material *mtl)
{ {
{ {
struct PlaneGridCreateInfo pgci; struct PlaneCreateInfo pci;
pgci.coord[0].Set(-100,-100,0); ro_plane=CreateRenderablePlane(db,mtl,&pci);
pgci.coord[1].Set( 100,-100,0);
pgci.coord[2].Set( 100, 100,0);
pgci.coord[3].Set(-100, 100,0);
pgci.step.u=20;
pgci.step.v=20;
pgci.side_step.u=10;
pgci.side_step.v=10;
pgci.color.Set(0.75,0,0,1);
pgci.side_color.Set(1,0,0,1);
ro_plane_grid=CreateRenderablePlaneGrid(db,mtl,&pgci);
} }
{ {
@ -392,20 +382,20 @@ private:
bool InitCompositionRenderable() bool InitCompositionRenderable()
{ {
ro_plane=CreateRenderableGBufferComposition(db,sp_composition.material); ro_gbc_plane=CreateRenderableGBufferComposition(db,sp_composition.material);
return ro_plane; return ro_gbc_plane;
} }
bool InitScene(SubpassParam *sp) bool InitScene(SubpassParam *sp)
{ {
CreateRenderObject(sp->material); CreateRenderObject(sp->material);
render_root.Add(db->CreateRenderableInstance(sp->pipeline_line,sp->desc_sets,ro_plane_grid)); render_root.Add(db->CreateRenderableInstance(sp->pipeline_fan,sp->desc_sets,ro_plane),scale(100,100,1));
render_root.Add(db->CreateRenderableInstance(sp->pipeline_solid,sp->desc_sets,ro_torus ),translate(0,0,25)); render_root.Add(db->CreateRenderableInstance(sp->pipeline_triangles,sp->desc_sets,ro_torus ),translate(0,0,0));
render_root.Add(db->CreateRenderableInstance(sp->pipeline_solid,sp->desc_sets,ro_sphere ),scale(25,25,25)); render_root.Add(db->CreateRenderableInstance(sp->pipeline_triangles,sp->desc_sets,ro_sphere ),scale(20,20,20));
render_root.Add(db->CreateRenderableInstance(sp->pipeline_solid,sp->desc_sets,ro_cube ),translate(-16, 0,15)*scale(10,10,10)); render_root.Add(db->CreateRenderableInstance(sp->pipeline_triangles,sp->desc_sets,ro_cube ),translate(-30, 0,10)*scale(10,10,10));
render_root.Add(db->CreateRenderableInstance(sp->pipeline_solid,sp->desc_sets,ro_cylinder ),translate( 16, 16,10)*scale(1,1,2)); render_root.Add(db->CreateRenderableInstance(sp->pipeline_triangles,sp->desc_sets,ro_cylinder ),translate( 30, 30,10)*scale(1,1,2));
render_root.Add(db->CreateRenderableInstance(sp->pipeline_solid,sp->desc_sets,ro_cone ),translate( 0,-16, 0)*scale(1,1,2)); render_root.Add(db->CreateRenderableInstance(sp->pipeline_triangles,sp->desc_sets,ro_cone ),translate( 0,-30, 0)*scale(1,1,2));
render_root.RefreshMatrix(); render_root.RefreshMatrix();
render_root.ExpendToList(&render_list); render_root.ExpendToList(&render_list);
@ -472,9 +462,9 @@ public:
void BuildCommandBuffer(uint32_t index) override void BuildCommandBuffer(uint32_t index) override
{ {
VulkanApplicationFramework::BuildCommandBuffer( index, VulkanApplicationFramework::BuildCommandBuffer( index,
sp_composition.pipeline_solid, sp_composition.pipeline_triangles,
sp_composition.desc_sets, sp_composition.desc_sets,
ro_plane); ro_gbc_plane);
} }
};//class TestApp:public CameraAppFramework };//class TestApp:public CameraAppFramework

View File

@ -1,4 +1,7 @@
#include<hgl/graph/InlineGeometry.h> // sphere、cylinear、cone、tours code from McNopper,website: https://github.com/McNopper/GLUS
// GL to VK: swap Y/Z of position/normal/tangent/index
#include<hgl/graph/InlineGeometry.h>
#include<hgl/graph/VertexBuffer.h> #include<hgl/graph/VertexBuffer.h>
#include<hgl/graph/vulkan/VKDevice.h> #include<hgl/graph/vulkan/VKDevice.h>
#include<hgl/graph/vulkan/VKShaderModule.h> #include<hgl/graph/vulkan/VKShaderModule.h>
@ -307,8 +310,8 @@ namespace hgl
vulkan::Renderable *CreateRenderablePlane(SceneDB *db,vulkan::Material *mtl,const PlaneCreateInfo *pci) vulkan::Renderable *CreateRenderablePlane(SceneDB *db,vulkan::Material *mtl,const PlaneCreateInfo *pci)
{ {
const float xy_vertices [] = { -0.5f,-0.5f,0.0f, +0.5f,-0.5f,0.0f, -0.5f,+0.5f,0.0f, +0.5f,+0.5f,0.0f}; const float xy_vertices [] = { -0.5f,-0.5f,0.0f, +0.5f,-0.5f,0.0f, +0.5f,+0.5f,0.0f, -0.5f,+0.5f,0.0f };
float xy_tex_coord[] = { 0.0f, 0.0f, 1.0f,0.0f, 0.0f,1.0f, 1.0f, 1.0f}; float xy_tex_coord[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f };
const Vector3f xy_normal(0.0f,0.0f,1.0f); const Vector3f xy_normal(0.0f,0.0f,1.0f);
const Vector3f xy_tangent(1.0f,0.0f,0.0f); const Vector3f xy_tangent(1.0f,0.0f,0.0f);
@ -336,7 +339,7 @@ namespace hgl
if(tex_coord) if(tex_coord)
{ {
xy_tex_coord[2]=xy_tex_coord[6]=pci->tile.x; xy_tex_coord[2]=xy_tex_coord[4]=pci->tile.x;
xy_tex_coord[5]=xy_tex_coord[7]=pci->tile.y; xy_tex_coord[5]=xy_tex_coord[7]=pci->tile.y;
tex_coord->BufferData(xy_tex_coord); tex_coord->BufferData(xy_tex_coord);
@ -426,12 +429,12 @@ namespace hgl
for (uint j = 0; j < numberSlices; j++) for (uint j = 0; j < numberSlices; j++)
{ {
*tp= i * (numberSlices + 1) + j; ++tp; *tp= i * (numberSlices + 1) + j; ++tp;
*tp=(i + 1) * (numberSlices + 1) + (j + 1); ++tp;
*tp=(i + 1) * (numberSlices + 1) + j; ++tp; *tp=(i + 1) * (numberSlices + 1) + j; ++tp;
*tp=(i + 1) * (numberSlices + 1) + (j + 1); ++tp;
*tp= i * (numberSlices + 1) + j; ++tp; *tp= i * (numberSlices + 1) + j; ++tp;
*tp= i * (numberSlices + 1) + (j + 1); ++tp;
*tp=(i + 1) * (numberSlices + 1) + (j + 1); ++tp; *tp=(i + 1) * (numberSlices + 1) + (j + 1); ++tp;
*tp= i * (numberSlices + 1) + (j + 1); ++tp;
} }
} }
} }
@ -543,8 +546,8 @@ namespace hgl
for (uint j = 0; j < numberSlices + 1; j++) for (uint j = 0; j < numberSlices + 1; j++)
{ {
float x= sin(angleStep * (double) i) * sin(angleStep * (double) j); float x= sin(angleStep * (double) i) * sin(angleStep * (double) j);
float y= sin(angleStep * (double) i) * cos(angleStep * (double) j); float y= cos(angleStep * (double) i);
float z=-cos(angleStep * (double) i); float z= sin(angleStep * (double) i) * cos(angleStep * (double) j);
*vp=x;++vp; *vp=x;++vp;
*vp=y;++vp; *vp=y;++vp;
@ -1093,13 +1096,13 @@ namespace hgl
*vp = 0.0f; ++vp; *vp = 0.0f; ++vp;
*vp = 0.0f; ++vp; *vp = 0.0f; ++vp;
*vp = cci->halfExtend; ++vp; *vp = -cci->halfExtend; ++vp;
if(np) if(np)
{ {
*np = 0.0f;++np; *np = 0.0f;++np;
*np = -1.0f;++np;
*np = 0.0f;++np; *np = 0.0f;++np;
*np =-1.0f;++np;
} }
if(tp) if(tp)
@ -1121,13 +1124,13 @@ namespace hgl
*vp = cosf(currentAngle) * cci->radius;++vp; *vp = cosf(currentAngle) * cci->radius;++vp;
*vp = -sinf(currentAngle) * cci->radius;++vp; *vp = -sinf(currentAngle) * cci->radius;++vp;
*vp = cci->halfExtend; ++vp; *vp = -cci->halfExtend; ++vp;
if(np) if(np)
{ {
*np = 0.0f;++np; *np = 0.0f;++np;
*np = -1.0f;++np;
*np = 0.0f;++np; *np = 0.0f;++np;
*np =-1.0f;++np;
} }
if(tp) if(tp)
@ -1154,13 +1157,13 @@ namespace hgl
*vp = cosf(currentAngle) * cci->radius * (1.0f - level); ++vp; *vp = cosf(currentAngle) * cci->radius * (1.0f - level); ++vp;
*vp = -sinf(currentAngle) * cci->radius * (1.0f - level); ++vp; *vp = -sinf(currentAngle) * cci->radius * (1.0f - level); ++vp;
*vp = cci->halfExtend + 2.0f * cci->halfExtend * level; ++vp; *vp = -cci->halfExtend + 2.0f * cci->halfExtend * level; ++vp;
if(np) if(np)
{ {
*np = h / l * cosf(currentAngle); ++np; *np = h / l * cosf(currentAngle); ++np;
*np = r / l; ++np;
*np = h / l * -sinf(currentAngle); ++np; *np = h / l * -sinf(currentAngle); ++np;
*np = r / l; ++np;
} }
if(tp) if(tp)