From 6da3df75dfa58e46baebfa84ec38cf3b5b2a3f8f Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 18 Jul 2019 14:56:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=86=85=E7=BD=AE=E5=87=A0?= =?UTF-8?q?=E4=BD=95=E4=BD=93=E7=94=9F=E6=88=90=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3rdpty/dl_glslang.sh | 1 + 3rdpty/dl_mgl.sh | 2 + example/Vulkan/Deferred.cpp | 80 ++++++++++++++----------------- res/shader/gbuffer_opaque.frag | 4 +- src/SceneGraph/InlineGeometry.cpp | 39 ++++++++------- 5 files changed, 61 insertions(+), 65 deletions(-) create mode 100644 3rdpty/dl_glslang.sh diff --git a/3rdpty/dl_glslang.sh b/3rdpty/dl_glslang.sh new file mode 100644 index 00000000..c7c4ff69 --- /dev/null +++ b/3rdpty/dl_glslang.sh @@ -0,0 +1 @@ +git clone https://github.com/KhronosGroup/glslang.git \ No newline at end of file diff --git a/3rdpty/dl_mgl.sh b/3rdpty/dl_mgl.sh index f5327f76..ab387c49 100755 --- a/3rdpty/dl_mgl.sh +++ b/3rdpty/dl_mgl.sh @@ -1 +1,3 @@ git clone https://github.com/juj/MathGeoLib.git +cd MathGeoLib +git.exe reset --hard ae6dc5e9b1ec83429af3b3ba17a7d61a046d3400 -- \ No newline at end of file diff --git a/example/Vulkan/Deferred.cpp b/example/Vulkan/Deferred.cpp index be6075de..d83c2c14 100644 --- a/example/Vulkan/Deferred.cpp +++ b/example/Vulkan/Deferred.cpp @@ -84,21 +84,21 @@ private: { vulkan::Material * material; vulkan::DescriptorSets *desc_sets; - vulkan::Pipeline * pipeline_line; - vulkan::Pipeline * pipeline_solid; + vulkan::Pipeline * pipeline_fan; + vulkan::Pipeline * pipeline_triangles; };// SubpassParam sp_gbuffer; SubpassParam sp_composition; - vulkan::Renderable *ro_plane_grid, + vulkan::Renderable *ro_plane, *ro_cube, *ro_sphere, *ro_torus, *ro_cylinder, *ro_cone, - *ro_plane; + *ro_gbc_plane; vulkan::Sampler * sampler=nullptr; @@ -238,24 +238,28 @@ private: bool InitGBufferPipeline(SubpassParam *sp) { AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,sp->material,gbuffer.rt); - pipeline_creater->Set(PRIM_TRIANGLES); - sp->pipeline_solid=pipeline_creater->Create(); + { + pipeline_creater->Set(PRIM_TRIANGLES); + + sp->pipeline_triangles=pipeline_creater->Create(); - if(!sp->pipeline_solid) - return(false); + if(!sp->pipeline_triangles) + 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_fan) + return(false); - if(!sp->pipeline_line) - return(false); - - db->Add(sp->pipeline_line); + db->Add(sp->pipeline_fan); + } return(true); } @@ -267,12 +271,12 @@ private: pipeline_creater->SetCullMode(VK_CULL_MODE_NONE); 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); - db->Add(sp->pipeline_solid); + db->Add(sp->pipeline_triangles); return(true); } @@ -328,23 +332,9 @@ private: void CreateRenderObject(vulkan::Material *mtl) { { - struct PlaneGridCreateInfo pgci; + struct PlaneCreateInfo pci; - pgci.coord[0].Set(-100,-100,0); - 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); + ro_plane=CreateRenderablePlane(db,mtl,&pci); } { @@ -392,20 +382,20 @@ private: 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) { CreateRenderObject(sp->material); - render_root.Add(db->CreateRenderableInstance(sp->pipeline_line,sp->desc_sets,ro_plane_grid)); - render_root.Add(db->CreateRenderableInstance(sp->pipeline_solid,sp->desc_sets,ro_torus ),translate(0,0,25)); - render_root.Add(db->CreateRenderableInstance(sp->pipeline_solid,sp->desc_sets,ro_sphere ),scale(25,25,25)); - 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_solid,sp->desc_sets,ro_cylinder ),translate( 16, 16,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_fan,sp->desc_sets,ro_plane),scale(100,100,1)); + render_root.Add(db->CreateRenderableInstance(sp->pipeline_triangles,sp->desc_sets,ro_torus ),translate(0,0,0)); + render_root.Add(db->CreateRenderableInstance(sp->pipeline_triangles,sp->desc_sets,ro_sphere ),scale(20,20,20)); + 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_triangles,sp->desc_sets,ro_cylinder ),translate( 30, 30,10)*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.ExpendToList(&render_list); @@ -472,9 +462,9 @@ public: void BuildCommandBuffer(uint32_t index) override { VulkanApplicationFramework::BuildCommandBuffer( index, - sp_composition.pipeline_solid, + sp_composition.pipeline_triangles, sp_composition.desc_sets, - ro_plane); + ro_gbc_plane); } };//class TestApp:public CameraAppFramework diff --git a/res/shader/gbuffer_opaque.frag b/res/shader/gbuffer_opaque.frag index 7ee64be9..b90df622 100644 --- a/res/shader/gbuffer_opaque.frag +++ b/res/shader/gbuffer_opaque.frag @@ -23,7 +23,7 @@ void main() vec3 tnorm = (texture(TextureNormal,FragmentTexCoord).xyz*2.0-vec3(1.0))*TBN; outNormal=vec4(normalize(tnorm),1.0); - //outNormal=vec4(normalize(FragmentNormal),1.0); - +// outNormal=vec4(normalize(FragmentNormal),1.0); + outColor=texture(TextureColor,FragmentTexCoord); } diff --git a/src/SceneGraph/InlineGeometry.cpp b/src/SceneGraph/InlineGeometry.cpp index 55825a84..82ea7033 100644 --- a/src/SceneGraph/InlineGeometry.cpp +++ b/src/SceneGraph/InlineGeometry.cpp @@ -1,4 +1,7 @@ -#include +// 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 #include #include #include @@ -307,8 +310,8 @@ namespace hgl 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}; - float xy_tex_coord[] = { 0.0f, 0.0f, 1.0f,0.0f, 0.0f,1.0f, 1.0f, 1.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, 1.0f, 1.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); @@ -336,7 +339,7 @@ namespace hgl 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; tex_coord->BufferData(xy_tex_coord); @@ -426,12 +429,12 @@ namespace hgl for (uint j = 0; j < numberSlices; j++) { *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 + 1); ++tp; *tp= i * (numberSlices + 1) + j; ++tp; - *tp= i * (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++) { float x= sin(angleStep * (double) i) * sin(angleStep * (double) j); - float y= sin(angleStep * (double) i) * cos(angleStep * (double) j); - float z=-cos(angleStep * (double) i); + float y= cos(angleStep * (double) i); + float z= sin(angleStep * (double) i) * cos(angleStep * (double) j); *vp=x;++vp; *vp=y;++vp; @@ -1093,13 +1096,13 @@ namespace hgl *vp = 0.0f; ++vp; *vp = 0.0f; ++vp; - *vp = cci->halfExtend; ++vp; + *vp = -cci->halfExtend; ++vp; if(np) { - *np = 0.0f;++np; - *np = -1.0f;++np; - *np = 0.0f;++np; + *np = 0.0f;++np; + *np = 0.0f;++np; + *np =-1.0f;++np; } if(tp) @@ -1121,13 +1124,13 @@ namespace hgl *vp = cosf(currentAngle) * cci->radius;++vp; *vp = -sinf(currentAngle) * cci->radius;++vp; - *vp = cci->halfExtend; ++vp; + *vp = -cci->halfExtend; ++vp; if(np) { - *np = 0.0f;++np; - *np = -1.0f;++np; - *np = 0.0f;++np; + *np = 0.0f;++np; + *np = 0.0f;++np; + *np =-1.0f;++np; } if(tp) @@ -1154,13 +1157,13 @@ namespace hgl *vp = cosf(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) { *np = h / l * cosf(currentAngle); ++np; - *np = r / l; ++np; *np = h / l * -sinf(currentAngle); ++np; + *np = r / l; ++np; } if(tp)