diff --git a/example/Vulkan/Deferred.cpp b/example/Vulkan/Deferred.cpp index 0a43ed41..d68701d9 100644 --- a/example/Vulkan/Deferred.cpp +++ b/example/Vulkan/Deferred.cpp @@ -1,4 +1,4 @@ -// 9.延迟渲染 +// 9.延迟渲染 // 简单的延迟渲染测试,仅一个太阳光 #include"VulkanAppFramework.h" @@ -224,6 +224,7 @@ private: AutoDelete pipeline_creater=new vulkan::PipelineCreater(device,sp->material,gbuffer.renderpass,gbuffer.extent); pipeline_creater->SetDepthTest(true); pipeline_creater->SetDepthWrite(true); + pipeline_creater->SetDepthCompareOp(VK_COMPARE_OP_ALWAYS); //pipeline_creater->SetCullMode(VK_CULL_MODE_BACK_BIT); pipeline_creater->SetCullMode(VK_CULL_MODE_NONE); pipeline_creater->Set(PRIM_TRIANGLES); diff --git a/res/shader/gbuffer_opaque.frag b/res/shader/gbuffer_opaque.frag index f3ae5a13..f90ea19a 100644 --- a/res/shader/gbuffer_opaque.frag +++ b/res/shader/gbuffer_opaque.frag @@ -14,7 +14,7 @@ layout (location = 2) out vec4 outColor; void main() { - outPosition=vec4(FragmentPosition,1.0); + outPosition=vec4(normalize(FragmentPosition*2.0-vec3(1.0)),1.0); /* vec3 N = normalize(FragmentNormal); N.y=-N.y; @@ -25,6 +25,6 @@ void main() //outNormal=vec4(tnorm,1.0); - outNormal=vec4(FragmentNormal,1.0); + outNormal=vec4(normalize(FragmentNormal*2.0-vec3(1.0)),1.0); outColor=texture(TextureColor,FragmentTexCoord); } diff --git a/res/shader/gbuffer_opaque.vert b/res/shader/gbuffer_opaque.vert index 84782de7..8c99fa31 100644 --- a/res/shader/gbuffer_opaque.vert +++ b/res/shader/gbuffer_opaque.vert @@ -29,7 +29,7 @@ void main() gl_Position=pos*world.mvp; - FragmentPosition=pos.xyz; + FragmentPosition=(pos*world.modelview).xyz; FragmentTexCoord=TexCoord; // mat3 n=inverse(mat3(pc.local_to_world)); @@ -38,6 +38,6 @@ void main() // FragmentNormal=normalize(Normal)*n; // FragmentTangent=normalize(Tangent)*n; - FragmentNormal=normalize((Normal+vec3(1.0))/2.0); + FragmentNormal=Normal; FragmentTangent=Tangent; } diff --git a/src/RenderDevice/Vulkan/VKDeviceCreater.cpp b/src/RenderDevice/Vulkan/VKDeviceCreater.cpp index 74abc069..10702f9f 100644 --- a/src/RenderDevice/Vulkan/VKDeviceCreater.cpp +++ b/src/RenderDevice/Vulkan/VKDeviceCreater.cpp @@ -195,7 +195,7 @@ namespace bool CreateDepthBuffer(DeviceAttribute *rsa) { - const VkFormat depth_format=rsa->physical_device->GetDepthFormat(); + const VkFormat depth_format=rsa->physical_device->GetDepthFormat(false); const VkFormatProperties props=rsa->physical_device->GetFormatProperties(depth_format); diff --git a/src/RenderDevice/Vulkan/VKImageView.cpp b/src/RenderDevice/Vulkan/VKImageView.cpp index 815ebf7b..a0ccf482 100644 --- a/src/RenderDevice/Vulkan/VKImageView.cpp +++ b/src/RenderDevice/Vulkan/VKImageView.cpp @@ -23,7 +23,10 @@ ImageView *CreateImageView(VkDevice device,VkImageViewType type,VkFormat format, iv_createinfo.subresourceRange.layerCount=1; if(aspectMask&VK_IMAGE_ASPECT_DEPTH_BIT) - { + { + if(format>=VK_FORMAT_D16_UNORM_S8_UINT) + iv_createinfo.subresourceRange.aspectMask|=VK_IMAGE_ASPECT_STENCIL_BIT; + iv_createinfo.components.r=VK_COMPONENT_SWIZZLE_IDENTITY; iv_createinfo.components.g=VK_COMPONENT_SWIZZLE_IDENTITY; iv_createinfo.components.b=VK_COMPONENT_SWIZZLE_IDENTITY;