延迟渲染已可用,但合成shader未完成

This commit is contained in:
hyzboy 2019-07-17 16:51:42 +08:00
parent 7135b59134
commit 9cd6d3c76d
5 changed files with 91 additions and 18 deletions

View File

@ -96,7 +96,9 @@ private:
*ro_sphere, *ro_sphere,
*ro_torus, *ro_torus,
*ro_cylinder, *ro_cylinder,
*ro_cone; *ro_cone,
*ro_plane;
vulkan::Sampler * sampler=nullptr; vulkan::Sampler * sampler=nullptr;
@ -153,8 +155,8 @@ private:
bool InitGBuffer() bool InitGBuffer()
{ {
gbuffer.extent.width =512; gbuffer.extent.width =1024;
gbuffer.extent.height =512; gbuffer.extent.height =1024;
gbuffer.render_complete_semaphore =device->CreateSem(); gbuffer.render_complete_semaphore =device->CreateSem();
@ -263,7 +265,7 @@ private:
pipeline_creater->SetDepthTest(false); pipeline_creater->SetDepthTest(false);
pipeline_creater->SetDepthWrite(false); pipeline_creater->SetDepthWrite(false);
pipeline_creater->SetCullMode(VK_CULL_MODE_NONE); pipeline_creater->SetCullMode(VK_CULL_MODE_NONE);
pipeline_creater->Set(PRIM_TRIANGLES); pipeline_creater->Set(PRIM_TRIANGLE_FAN);
sp->pipeline_solid=pipeline_creater->Create(); sp->pipeline_solid=pipeline_creater->Create();
@ -277,14 +279,13 @@ private:
bool InitMaterial() bool InitMaterial()
{ {
if(!InitSubpass(&sp_gbuffer, OS_TEXT("res/shader/gbuffer_opaque.vert.spv"),OS_TEXT("res/shader/gbuffer_opaque.frag.spv")))return(false); if(!InitSubpass(&sp_gbuffer, OS_TEXT("res/shader/gbuffer_opaque.vert.spv"),OS_TEXT("res/shader/gbuffer_opaque.frag.spv")))return(false);
//if(!InitSubpass(&sp_composition,OS_TEXT("res/shader/ds_composition.vert.spv"),OS_TEXT("res/shader/ds_composition.frag.spv")))return(false); if(!InitSubpass(&sp_composition,OS_TEXT("res/shader/gbuffer_composition.vert.spv"),OS_TEXT("res/shader/gbuffer_composition.frag.spv")))return(false);
if(!InitGBufferPipeline(&sp_gbuffer))return(false); if(!InitGBufferPipeline(&sp_gbuffer))return(false);
//if(!InitCompositionPipeline(&sp_composition))return(false); if(!InitCompositionPipeline(&sp_composition))return(false);
texture.color =vulkan::LoadTGATexture(OS_TEXT("res/image/cardboardPlainStain.tga"),device); texture.color =vulkan::LoadTGATexture(OS_TEXT("res/image/cardboardPlainStain.tga"),device);
texture.normal =vulkan::LoadTGATexture(OS_TEXT("res/image/APOCWALL029_NRM.tga"),device); texture.normal =vulkan::LoadTGATexture(OS_TEXT("res/image/APOCWALL029_NRM.tga"),device);
//texture.normal =vulkan::LoadTGATexture(OS_TEXT("res/image/flat_normal.tga"),device);
//texture.specular=vulkan::LoadTGATexture(OS_TEXT("res/image/APOCWALL029_SPEC.tga"),device); //texture.specular=vulkan::LoadTGATexture(OS_TEXT("res/image/APOCWALL029_SPEC.tga"),device);
VkSamplerCreateInfo sampler_create_info; VkSamplerCreateInfo sampler_create_info;
@ -310,12 +311,17 @@ private:
sampler=device->CreateSampler(&sampler_create_info); sampler=device->CreateSampler(&sampler_create_info);
sp_gbuffer.desc_sets->BindSampler(sp_gbuffer.material->GetSampler("TextureColor"),texture.color,sampler);
sp_gbuffer.desc_sets->BindSampler(sp_gbuffer.material->GetSampler("TextureNormal"),texture.normal,sampler);
InitCameraUBO(sp_gbuffer.desc_sets,sp_gbuffer.material->GetUBO("world")); InitCameraUBO(sp_gbuffer.desc_sets,sp_gbuffer.material->GetUBO("world"));
sp_gbuffer.desc_sets->BindSampler(sp_gbuffer.material->GetSampler("TextureColor" ),texture.color, sampler);
sp_gbuffer.desc_sets->BindSampler(sp_gbuffer.material->GetSampler("TextureNormal" ),texture.normal, sampler);
sp_gbuffer.desc_sets->Update(); sp_gbuffer.desc_sets->Update();
sp_composition.desc_sets->BindSampler(sp_composition.material->GetSampler("GB_Position" ),gbuffer.position, sampler);
sp_composition.desc_sets->BindSampler(sp_composition.material->GetSampler("GB_Normal" ),gbuffer.normal, sampler);
sp_composition.desc_sets->BindSampler(sp_composition.material->GetSampler("GB_Color" ),gbuffer.color, sampler);
sp_composition.desc_sets->Update();
return(true); return(true);
} }
@ -383,6 +389,13 @@ private:
ro_cone=CreateRenderableCone(db,mtl,&cci); ro_cone=CreateRenderableCone(db,mtl,&cci);
} }
} }
bool InitCompositionRenderable()
{
ro_plane=CreateRenderableGBufferComposition(db,sp_composition.material);
return ro_plane;
}
bool InitScene(SubpassParam *sp) bool InitScene(SubpassParam *sp)
{ {
@ -438,6 +451,9 @@ public:
if(!InitGBufferCommandBuffer()) if(!InitGBufferCommandBuffer())
return(false); return(false);
if(!InitCompositionRenderable())
return(false);
return(true); return(true);
} }
@ -453,12 +469,11 @@ public:
} }
void BuildCommandBuffer(uint32_t index) override void BuildCommandBuffer(uint32_t index) override
{ {
render_root.RefreshMatrix(); VulkanApplicationFramework::BuildCommandBuffer( index,
render_list.Clear(); sp_composition.pipeline_solid,
render_root.ExpendToList(&render_list); sp_composition.desc_sets,
ro_plane);
VulkanApplicationFramework::BuildCommandBuffer(index,&render_list);
} }
};//class TestApp:public CameraAppFramework };//class TestApp:public CameraAppFramework

View File

@ -21,6 +21,11 @@ namespace hgl
vulkan::Renderable *CreateRenderableRectangle(SceneDB *db,vulkan::Material *mtl,const RectangleCreateInfo *rci); vulkan::Renderable *CreateRenderableRectangle(SceneDB *db,vulkan::Material *mtl,const RectangleCreateInfo *rci);
/**
*
*/
vulkan::Renderable *CreateRenderableGBufferComposition(SceneDB *db,vulkan::Material *mtl);
/** /**
* (/线) * (/线)
*/ */
@ -69,6 +74,13 @@ namespace hgl
struct PlaneCreateInfo struct PlaneCreateInfo
{ {
Vector2f tile; Vector2f tile;
public:
PlaneCreateInfo()
{
tile.Set(1,1);
}
};//struct PlaneCreateInfo };//struct PlaneCreateInfo
/** /**

View File

@ -1,9 +1,46 @@
#version 450 core #version 450 core
layout(binding = 0) uniform WorldMatrix
{
mat4 ortho;
mat4 projection;
mat4 modelview;
mat4 mvp;
vec4 view_pos;
} world;
layout(push_constant) uniform Consts {
mat4 local_to_world;
} pc;
layout(binding = 0) uniform sampler2D GB_Position;
layout(binding = 1) uniform sampler2D GB_Normal;
layout(binding = 2) uniform sampler2D GB_Color;
layout(location = 0) in vec2 FragmentPosition; layout(location = 0) in vec2 FragmentPosition;
layout(location = 0) out vec4 FragColor; layout(location = 0) out vec4 FragColor;
void main() void main()
{ {
FragColor=vec4(normalize(FragmentPosition),0.0,1.0); vec3 pos =texture(GB_Position, FragmentPosition).xyz;
vec3 normal =texture(GB_Normal, FragmentPosition).xyz;
vec3 color =texture(GB_Color, FragmentPosition).xyz;
vec3 light_pos=vec3(1,1,1);
vec3 light_halfVector=vec3(1,1,1);
float pf;
float nDotVP=max(0.0,dot(normal,normalize(light_pos)));
float nDotHV=max(0.0,dot(normal,normalize(light_halfVector)));
if(nDotVP==0.0)
{
pf=0.0;
}
else
{
pf=pow(nDotHV,
}
} }

View File

@ -8,5 +8,5 @@ void main()
{ {
gl_Position=vec4(Vertex,0.0,1.0); gl_Position=vec4(Vertex,0.0,1.0);
FragmentPosition=Vertex; FragmentPosition=(Vertex+1.0)/2.0;
} }

View File

@ -153,6 +153,15 @@ namespace hgl
return gc.Finish(); return gc.Finish();
} }
vulkan::Renderable *CreateRenderableGBufferComposition(SceneDB *db,vulkan::Material *mtl)
{
RectangleCreateInfo rci;
rci.scope.Set(-1,-1,2,2);
return CreateRenderableRectangle(db,mtl,&rci);
}
vulkan::Renderable *CreateRenderableRoundRectangle(SceneDB *db,vulkan::Material *mtl,const RoundRectangleCreateInfo *rci) vulkan::Renderable *CreateRenderableRoundRectangle(SceneDB *db,vulkan::Material *mtl,const RoundRectangleCreateInfo *rci)
{ {
GeometryCreater2D gc(db,mtl); GeometryCreater2D gc(db,mtl);