From 79957d0ed2c6183bf371edfc3e056fde6adb79b0 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 17 Jul 2019 17:37:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=BB=B6=E8=BF=9F=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E8=B0=83=E8=AF=95SHADER=EF=BC=8C=E4=BD=86=E5=87=A0?= =?UTF-8?q?=E4=BD=95=E5=A4=9A=E8=BE=B9=E5=BD=A2=E7=94=9F=E6=88=90=E6=9C=89?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/Vulkan/Deferred.cpp | 5 ++-- inc/hgl/graph/VertexBuffer.h | 12 ++++----- res/shader/gbuffer_composition.frag | 2 ++ res/shader/gbuffer_debug.frag | 40 +++++++++++++++++++++++++++++ res/shader/gbuffer_debug.vert | 31 ++++++++++++++++++++++ res/shader/shader_compile.sh | 5 +++- src/SceneGraph/InlineGeometry.cpp | 2 +- 7 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 res/shader/gbuffer_debug.frag create mode 100644 res/shader/gbuffer_debug.vert diff --git a/example/Vulkan/Deferred.cpp b/example/Vulkan/Deferred.cpp index edbe4871..087c6d08 100644 --- a/example/Vulkan/Deferred.cpp +++ b/example/Vulkan/Deferred.cpp @@ -279,7 +279,7 @@ private: 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_composition,OS_TEXT("res/shader/gbuffer_composition.vert.spv"),OS_TEXT("res/shader/gbuffer_composition.frag.spv")))return(false); + if(!InitSubpass(&sp_composition,OS_TEXT("res/shader/gbuffer_debug.vert.spv"),OS_TEXT("res/shader/gbuffer_debug.frag.spv")))return(false); if(!InitGBufferPipeline(&sp_gbuffer))return(false); if(!InitCompositionPipeline(&sp_composition))return(false); @@ -458,7 +458,7 @@ public: } virtual void SubmitDraw(int index) override - { + { gbuffer.rt->Submit(*gbuffer_cmd,present_complete_semaphore,gbuffer.render_complete_semaphore); VkCommandBuffer cb=*cmd_buf[index]; @@ -466,6 +466,7 @@ public: sc_render_target->Submit(cb,gbuffer.render_complete_semaphore,render_complete_semaphore); sc_render_target->PresentBackbuffer(render_complete_semaphore); sc_render_target->Wait(); + gbuffer.rt->Wait(); } void BuildCommandBuffer(uint32_t index) override diff --git a/inc/hgl/graph/VertexBuffer.h b/inc/hgl/graph/VertexBuffer.h index 7a29f24c..e04ea19a 100644 --- a/inc/hgl/graph/VertexBuffer.h +++ b/inc/hgl/graph/VertexBuffer.h @@ -442,18 +442,18 @@ namespace hgl LOG_HINT(OS_TEXT("VertexBuffer2::WriteRectFan(RectScope2 *) out")); return(false); } - + *this->access++=scope.GetLeft(); - *this->access++=scope.GetTop(); + *this->access++=scope.GetBottom(); + + *this->access++=scope.GetRight(); + *this->access++=scope.GetBottom(); *this->access++=scope.GetRight(); *this->access++=scope.GetTop(); - *this->access++=scope.GetRight(); - *this->access++=scope.GetBottom(); - *this->access++=scope.GetLeft(); - *this->access++=scope.GetBottom(); + *this->access++=scope.GetTop(); return(true); } diff --git a/res/shader/gbuffer_composition.frag b/res/shader/gbuffer_composition.frag index 4c5ea8a2..caa0b04e 100644 --- a/res/shader/gbuffer_composition.frag +++ b/res/shader/gbuffer_composition.frag @@ -30,6 +30,8 @@ void main() 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))); diff --git a/res/shader/gbuffer_debug.frag b/res/shader/gbuffer_debug.frag new file mode 100644 index 00000000..03cab91c --- /dev/null +++ b/res/shader/gbuffer_debug.frag @@ -0,0 +1,40 @@ +#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 = 1) flat in uint FragmentTexID; +layout(location = 2) in vec2 FragmentTexCoord; + +layout(location = 0) out vec4 FragColor; + +void main() +{ + FragColor=vec4(normalize(FragmentTexCoord),0.0,1.0); +/* vec3 components[3]; + + components[0]=texture(GB_Position, FragmentTexCoord).xyz; + components[1]=texture(GB_Normal, FragmentTexCoord).xyz; + components[2]=texture(GB_Color, FragmentTexCoord).xyz; + + if(FragmentTexID<3) + FragColor=vec4(components[FragmentTexID],1.0); + else + FragColor=vec4(0.0,0.0,0.0,1.0);*/ +} + diff --git a/res/shader/gbuffer_debug.vert b/res/shader/gbuffer_debug.vert new file mode 100644 index 00000000..dbdff199 --- /dev/null +++ b/res/shader/gbuffer_debug.vert @@ -0,0 +1,31 @@ +#version 450 core + +layout(location = 0) in vec2 Vertex; + +layout(location = 0) out vec2 FragmentPosition; + +layout(location = 1) out uint FragmentTexID; +layout(location = 2) out vec2 FragmentTexCoord; + +void main() +{ + gl_Position=vec4(Vertex,0.0,1.0); + + FragmentPosition=Vertex; + FragmentTexCoord=(Vertex+1.0)/2.0; + + if(Vertex.x<0) + { + if(Vertex.y<0) + FragmentTexID=0; + else + FragmentTexID=1; + } + else + { + if(Vertex.y<0) + FragmentTexID=2; + else + FragmentTexID=3; + } +} diff --git a/res/shader/shader_compile.sh b/res/shader/shader_compile.sh index dcc41d62..62d9f32f 100755 --- a/res/shader/shader_compile.sh +++ b/res/shader/shader_compile.sh @@ -19,4 +19,7 @@ glslangValidator -V -o gbuffer_opaque.vert.spv gbuffer_opaque.vert glslangValidator -V -o gbuffer_opaque.frag.spv gbuffer_opaque.frag glslangValidator -V -o gbuffer_composition.vert.spv gbuffer_composition.vert -glslangValidator -V -o gbuffer_composition.frag.spv gbuffer_composition.frag \ No newline at end of file +glslangValidator -V -o gbuffer_composition.frag.spv gbuffer_composition.frag + +glslangValidator -V -o gbuffer_debug.vert.spv gbuffer_debug.vert +glslangValidator -V -o gbuffer_debug.frag.spv gbuffer_debug.frag diff --git a/src/SceneGraph/InlineGeometry.cpp b/src/SceneGraph/InlineGeometry.cpp index cb124c9c..22d3aa6a 100644 --- a/src/SceneGraph/InlineGeometry.cpp +++ b/src/SceneGraph/InlineGeometry.cpp @@ -148,7 +148,7 @@ namespace hgl VB2f *vertex=gc.GetVertex(); - vertex->WriteRectFan(rci->scope); + vertex->WriteRectTriangleStrip(rci->scope); return gc.Finish(); }