From c7d842ba602f50e58424f18e57d87d14d87b5df3 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bruyère Date: Tue, 28 Sep 2021 20:50:44 +0000 Subject: optional tesselation, default is off --- shaders/GBuffPbrInstanced.vert | 25 +++++++----------------- shaders/GBuffPbrInstancedTesselation.vert | 30 +++++++++++++++++++++++++++++ src/VkChess.cs | 13 ++++++++++++- src/deferredPbrRendererBase.cs | 32 ++++++++++++------------------- ui/debug.crow | 6 +++--- ui/winOptions.crow | 6 +++++- ui/winSSR.crow | 8 ++++---- 7 files changed, 73 insertions(+), 47 deletions(-) create mode 100644 shaders/GBuffPbrInstancedTesselation.vert diff --git a/shaders/GBuffPbrInstanced.vert b/shaders/GBuffPbrInstanced.vert index 12d2bd9..f0821a3 100644 --- a/shaders/GBuffPbrInstanced.vert +++ b/shaders/GBuffPbrInstanced.vert @@ -14,31 +14,20 @@ layout (set = 0, binding = 0) uniform UBO { mat4 view; } ubo; -layout (location = 0) out vec3 outNormal; -layout (location = 1) out vec2 outUV0; -layout (location = 2) out vec2 outUV1; -layout (location = 3) out vec4 outColor; - -/*out gl_PerVertex -{ - vec4 gl_Position; -};*/ +layout (location = 0) out vec3 outWorldPos; +layout (location = 1) out vec3 outNormal; +layout (location = 2) out vec2 outUV0; +layout (location = 3) out vec2 outUV1; +layout (location = 4) out vec4 outColor; void main() { - /*vec4 locPos = ubo.model * inModel * vec4(inPos, 1.0); + vec4 locPos = ubo.model * inModel * vec4(inPos, 1.0); outNormal = normalize(transpose(inverse(mat3(ubo.model * inModel))) * inNormal); outColor = inColor; outWorldPos = locPos.xyz; outUV0 = inUV0; outUV1 = inUV1; - gl_Position = ubo.projection * ubo.view * vec4(outWorldPos, 1.0);*/ - - outNormal = normalize(transpose(inverse(mat3(ubo.model * inModel))) * inNormal); - outUV0 = inUV0; - outUV1 = inUV1; - outColor = inColor; - - gl_Position = ubo.model * inModel * vec4(inPos, 1.0); + gl_Position = ubo.projection * ubo.view * vec4(outWorldPos, 1.0); } diff --git a/shaders/GBuffPbrInstancedTesselation.vert b/shaders/GBuffPbrInstancedTesselation.vert new file mode 100644 index 0000000..4afb5c2 --- /dev/null +++ b/shaders/GBuffPbrInstancedTesselation.vert @@ -0,0 +1,30 @@ +#version 450 + +layout (location = 0) in vec3 inPos; +layout (location = 1) in vec3 inNormal; +layout (location = 2) in vec2 inUV0; +layout (location = 3) in vec2 inUV1; +//instanced +layout (location = 4) in vec4 inColor; +layout (location = 5) in mat4 inModel; + +layout (set = 0, binding = 0) uniform UBO { + mat4 projection; + mat4 model; + mat4 view; +} ubo; + +layout (location = 0) out vec3 outNormal; +layout (location = 1) out vec2 outUV0; +layout (location = 2) out vec2 outUV1; +layout (location = 3) out vec4 outColor; + +void main() +{ + outNormal = normalize(transpose(inverse(mat3(ubo.model * inModel))) * inNormal); + outUV0 = inUV0; + outUV1 = inUV1; + outColor = inColor; + + gl_Position = ubo.model * inModel * vec4(inPos, 1.0); +} diff --git a/src/VkChess.cs b/src/VkChess.cs index 0aeab0f..de8f19f 100644 --- a/src/VkChess.cs +++ b/src/VkChess.cs @@ -107,7 +107,9 @@ namespace vkChess #if PIPELINE_STATS enabled_features.pipelineStatisticsQuery = available_features.pipelineStatisticsQuery; #endif - enabled_features.tessellationShader = available_features.tessellationShader; + if (!available_features.tessellationShader) + EnableTesselation = false; + enabled_features.tessellationShader = EnableTesselation; } #if PIPELINE_STATS @@ -840,6 +842,15 @@ namespace vkChess NotifyValueChanged ("SampleCount", value); } } + public bool EnableTesselation { + get => Configuration.Global.Get ("EnableTesselation", false); + set { + if (value == EnableTesselation) + return; + Configuration.Global.Set ("EnableTesselation", value); + NotifyValueChanged ("EnableTesselation", value); + } + } public bool EnableReflections { get => Configuration.Global.Get ("EnableReflections", false); set { diff --git a/src/deferredPbrRendererBase.cs b/src/deferredPbrRendererBase.cs index 9e18607..9bfa612 100644 --- a/src/deferredPbrRendererBase.cs +++ b/src/deferredPbrRendererBase.cs @@ -57,16 +57,6 @@ namespace vkChess public Matrices matrices = new Matrices { scaleIBLAmbient = 0.5f }; - //public Light[] lights = { - // new Light { - // position = new Vector4(3.5f,12.5f,2,0f), - // color = new Vector4(1,0.8f,0.8f,1) - // }, - // new Light { - // position = new Vector4(-3.5f,12.5f,2,0f), - // color = new Vector4(0.8f,0.8f,1,1) - // } - //}; public Light [] lights = { new Light { position = new Vector4(5.5f,12.5f,2,0f), @@ -77,9 +67,6 @@ namespace vkChess color = new Vector4(1,1,1,1) }*/ }; - - //public DescriptorSetWrites UiImageUpdate => new DescriptorSetWrites (dsMain, descLayoutMain.Bindings [8]); - const float lightMoveSpeed = 0.1f; FrameBuffers frameBuffers; @@ -111,10 +98,11 @@ namespace vkChess const int SP_DEPTH_PREPASS = 1; const int SP_MODELS = 2; const int SP_COMPOSE = 3; - //const int SP_TONE_MAPPING = 4; public Model.Scene mainScene; + bool enableTesselation => Crow.Configuration.Global.Get ("EnableTesselation", false); + public DeferredPbrRendererBase (Device dev, SwapChain swapChain, PresentQueue presentQueue, string cubemapPath, float nearPlane, float farPlane) { this.dev = dev; this.swapChain = swapChain; @@ -266,13 +254,17 @@ namespace vkChess new SpecializationConstant (0, nearPlane), new SpecializationConstant (1, farPlane), new SpecializationConstant (2, MAX_MATERIAL_COUNT))) { - cfg.inputAssemblyState.topology = VkPrimitiveTopology.PatchList; - - cfg.AddShader (dev, VkShaderStageFlags.TessellationControl, "#vkChess.net.pntriangles.tesc.spv"); - cfg.AddShader (dev, VkShaderStageFlags.TessellationEvaluation, "#vkChess.net.pntriangles.tese.spv"); - cfg.AddShader (dev, VkShaderStageFlags.Vertex, "#vkChess.net.GBuffPbrInstanced.vert.spv"); - cfg.TessellationPatchControlPoints = 3; + if (enableTesselation) { + cfg.inputAssemblyState.topology = VkPrimitiveTopology.PatchList; + cfg.AddShader (dev, VkShaderStageFlags.TessellationControl, "#vkChess.net.pntriangles.tesc.spv"); + cfg.AddShader (dev, VkShaderStageFlags.TessellationEvaluation, "#vkChess.net.pntriangles.tese.spv"); + cfg.AddShader (dev, VkShaderStageFlags.Vertex, "#vkChess.net.GBuffPbrInstancedTesselation.vert.spv"); + cfg.TessellationPatchControlPoints = 3; + } else { + cfg.inputAssemblyState.topology = VkPrimitiveTopology.TriangleList; + cfg.AddShader (dev, VkShaderStageFlags.Vertex, "#vkChess.net.GBuffPbrInstanced.vert.spv"); + } cfg.SubpassIndex = SP_DEPTH_PREPASS; diff --git a/ui/debug.crow b/ui/debug.crow index 44669a8..bc2aaa4 100644 --- a/ui/debug.crow +++ b/ui/debug.crow @@ -14,10 +14,10 @@ - - + diff --git a/ui/winOptions.crow b/ui/winOptions.crow index 0f7a96e..528ca5e 100644 --- a/ui/winOptions.crow +++ b/ui/winOptions.crow @@ -74,7 +74,11 @@