diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2019-04-25 16:46:46 +0200 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2019-04-25 16:46:46 +0200 |
| commit | 53a2d61a35e3fee03db78090c050867ad21f7c06 (patch) | |
| tree | 67f9bbcd564387f816c53674c265c09ddd18fd6a | |
| parent | dfe818f27f0e5ae939b0a57062da53d80a4f5de7 (diff) | |
add debug view for cubes
| -rw-r--r-- | samples/deferred/EnvironmentPipeline.cs | 5 | ||||
| -rw-r--r-- | samples/deferred/main.cs | 86 | ||||
| -rw-r--r-- | samples/deferred/shaders/compose.frag | 15 | ||||
| -rw-r--r-- | samples/deferred/shaders/emissive.frag | 25 | ||||
| -rw-r--r-- | samples/deferred/shaders/show_gbuff.frag | 31 | ||||
| -rw-r--r-- | samples/pbrSashaWillem/PbrPipeline.cs | 1 | ||||
| -rw-r--r-- | samples/pbrSashaWillem/main.cs | 2 |
7 files changed, 132 insertions, 33 deletions
diff --git a/samples/deferred/EnvironmentPipeline.cs b/samples/deferred/EnvironmentPipeline.cs index 2d9fc17..063f5e2 100644 --- a/samples/deferred/EnvironmentPipeline.cs +++ b/samples/deferred/EnvironmentPipeline.cs @@ -15,7 +15,7 @@ namespace CVKL { public Image prefilterCube { get; set; } public Image debugImg; - public int debugMip = -1; + public int debugMip = 0; public int debugFace = 0; public EnvironmentCube (DescriptorSet dsSkybox, PipelineLayout plLayout, Queue staggingQ, RenderPass renderPass) @@ -288,6 +288,7 @@ namespace CVKL { 1, region.Pin ()); region.Unpin (); + /* //debug img if (target == CBTarget.PREFILTEREDENV && m == debugMip && f == debugFace) { debugImg?.Dispose (); @@ -306,7 +307,7 @@ namespace CVKL { debugImg.SetLayout (cmd, VkImageAspectFlags.Color, VkImageLayout.TransferDstOptimal, VkImageLayout.ShaderReadOnlyOptimal); region.Unpin (); - } + }*/ imgFbOffscreen.SetLayout (cmd, VkImageAspectFlags.Color, VkImageLayout.TransferSrcOptimal, VkImageLayout.ColorAttachmentOptimal); diff --git a/samples/deferred/main.cs b/samples/deferred/main.cs index b82eee1..929026c 100644 --- a/samples/deferred/main.cs +++ b/samples/deferred/main.cs @@ -18,7 +18,8 @@ namespace deferred { features.samplerAnisotropy = true; features.sampleRateShading = true; } - VkSampleCountFlags samples = VkSampleCountFlags.SampleCount8; + VkSampleCountFlags samples = VkSampleCountFlags.SampleCount4; + VkFormat hdrFormat = VkFormat.R32g32b32a32Sfloat; enum DebugView { none, @@ -29,7 +30,9 @@ namespace deferred { emissive, metallic, roughness, - depth + depth, + prefill, + irradiance } DebugView currentDebugView = DebugView.none; @@ -38,7 +41,7 @@ namespace deferred { public Matrix4x4 model; public Matrix4x4 view; public Vector4 camPos; - public Vector4 lightDir; + public Vector4 lightPos; public float exposure; public float gamma; public float prefilteredCubeMipLevels; @@ -48,22 +51,14 @@ namespace deferred { } public Matrices matrices = new Matrices { - lightDir = Vector4.Normalize (new Vector4 (0.7f, 0.6f, 0.2f, 0.0f)), + lightPos = Vector4.Normalize (new Vector4 (0.7f, 0.6f, 0.2f, 0.0f)), gamma = 1.2f, - exposure = 2.5f, - scaleIBLAmbient = 1f, + exposure = 2.0f, + scaleIBLAmbient = 1.0f, debugViewInputs = 0, debugViewEquation = 0 }; - Program () { - camera.SetPosition (0, 0, 5); - - init (); - - camera.Model = Matrix4x4.CreateScale (1f / Math.Max (Math.Max (modelAABB.max.X, modelAABB.max.Y), modelAABB.max.Z)); - } - Framebuffer[] frameBuffers; Image gbColorRough, gbEmitMetal, gbN_AO, gbPos, hdrImg; @@ -88,17 +83,24 @@ namespace deferred { const int SP_COMPOSE = 2; const int SP_TONE_MAPPING = 3; + Program () { + init (); + camera.SetPosition (0, 0, 3); + camera.Model = Matrix4x4.CreateScale (1f / Math.Max (Math.Max (modelAABB.max.X, modelAABB.max.Y), modelAABB.max.Z)); + //camera.Model = Matrix4x4.CreateScale (0.02f); + } + void init () { renderPass = new RenderPass (dev, samples); renderPass.AddAttachment (swapChain.ColorFormat, VkImageLayout.PresentSrcKHR, VkSampleCountFlags.SampleCount1);//swapchain image renderPass.AddAttachment (dev.GetSuitableDepthFormat(), VkImageLayout.DepthStencilAttachmentOptimal, samples); - renderPass.AddAttachment (VkFormat.R8g8b8a8Unorm, VkImageLayout.ColorAttachmentOptimal, samples);//GBuff0 and final color before resolve - renderPass.AddAttachment (VkFormat.R8g8b8a8Unorm, VkImageLayout.ColorAttachmentOptimal, samples);//GBuff1 - renderPass.AddAttachment (VkFormat.R16g16b16a16Sfloat, VkImageLayout.ColorAttachmentOptimal, samples);//GBuff2 - renderPass.AddAttachment (VkFormat.R16g16b16a16Sfloat, VkImageLayout.ColorAttachmentOptimal, samples);//GBuff3 - renderPass.AddAttachment (VkFormat.R16g16b16a16Sfloat, VkImageLayout.ColorAttachmentOptimal, samples);//hdr color + renderPass.AddAttachment (swapChain.ColorFormat, VkImageLayout.ColorAttachmentOptimal, samples);//GBuff0 (color + roughness) and final color before resolve + renderPass.AddAttachment (VkFormat.R8g8b8a8Unorm, VkImageLayout.ColorAttachmentOptimal, samples);//GBuff1 (emit + metal) + renderPass.AddAttachment (VkFormat.R16g16b16a16Sfloat, VkImageLayout.ColorAttachmentOptimal, samples);//GBuff2 (normals + AO) + renderPass.AddAttachment (VkFormat.R16g16b16a16Sfloat, VkImageLayout.ColorAttachmentOptimal, samples);//GBuff3 (Pos + depth) + renderPass.AddAttachment (hdrFormat, VkImageLayout.ColorAttachmentOptimal, samples);//hdr color renderPass.ClearValues.Add (new VkClearValue { color = new VkClearColorValue (0.0f, 0.0f, 0.0f) }); renderPass.ClearValues.Add (new VkClearValue { depthStencil = new VkClearDepthStencilValue (1.0f, 0) }); @@ -126,7 +128,7 @@ namespace deferred { new VkAttachmentReference (4, VkImageLayout.ShaderReadOnlyOptimal), new VkAttachmentReference (5, VkImageLayout.ShaderReadOnlyOptimal)); //tone mapping - subpass[SP_TONE_MAPPING].AddColorReference ((samples == VkSampleCountFlags.SampleCount1) ? 0u : 4u, VkImageLayout.ColorAttachmentOptimal); + subpass[SP_TONE_MAPPING].AddColorReference ((samples == VkSampleCountFlags.SampleCount1) ? 0u : 2u, VkImageLayout.ColorAttachmentOptimal); subpass[SP_TONE_MAPPING].AddInputReference (new VkAttachmentReference (6, VkImageLayout.ShaderReadOnlyOptimal)); if (samples != VkSampleCountFlags.SampleCount1) subpass[SP_TONE_MAPPING].AddResolveReference (0, VkImageLayout.ColorAttachmentOptimal); @@ -252,6 +254,8 @@ namespace deferred { "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/Lantern/glTF/Lantern.gltf", "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/SciFiHelmet/glTF/SciFiHelmet.gltf", "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/Sponza/glTF/Sponza.gltf", + "/mnt/devel/vkChess/data/chess.gltf", + "/home/jp/gltf/camaro/scene.gltf" }; model = new PbrModel (presentQueue, modelPathes[0], @@ -310,7 +314,9 @@ namespace deferred { composePipeline.Bind (cmd); else { debugPipeline.Bind (cmd); - cmd.PushConstant (debugPipeline.Layout, VkShaderStageFlags.Fragment, (int)currentDebugView - 1, (uint)Marshal.SizeOf<Matrix4x4> ()); + uint debugValue = (uint)currentDebugView - 1; + debugValue += (uint)((envCube.debugFace << 8) + (envCube.debugMip << 16)); + cmd.PushConstant (debugPipeline.Layout, VkShaderStageFlags.Fragment, debugValue, (uint)Marshal.SizeOf<Matrix4x4> ()); } cmd.Draw (3, 1, 0, 0); @@ -326,7 +332,8 @@ namespace deferred { public override void UpdateView () { camera.AspectRatio = (float)swapChain.Width / swapChain.Height; - matrices.lightDir = lightPos; + matrices.lightPos = lightPos; + matrices.projection = camera.Projection; matrices.view = camera.View; matrices.model = camera.Model; @@ -347,8 +354,6 @@ namespace deferred { #endregion - - void createGBuff () { gbColorRough?.Dispose (); gbEmitMetal?.Dispose (); @@ -356,11 +361,11 @@ namespace deferred { gbPos?.Dispose (); hdrImg?.Dispose (); - gbColorRough = new Image (dev, VkFormat.R8g8b8a8Unorm, VkImageUsageFlags.InputAttachment | VkImageUsageFlags.ColorAttachment, VkMemoryPropertyFlags.DeviceLocal, swapChain.Width, swapChain.Height, VkImageType.Image2D, samples); + gbColorRough = new Image (dev, swapChain.ColorFormat, VkImageUsageFlags.InputAttachment | VkImageUsageFlags.ColorAttachment, VkMemoryPropertyFlags.DeviceLocal, swapChain.Width, swapChain.Height, VkImageType.Image2D, samples); gbEmitMetal = new Image (dev, VkFormat.R8g8b8a8Unorm, VkImageUsageFlags.InputAttachment | VkImageUsageFlags.ColorAttachment, VkMemoryPropertyFlags.DeviceLocal, swapChain.Width, swapChain.Height, VkImageType.Image2D, samples); gbN_AO = new Image (dev, VkFormat.R16g16b16a16Sfloat, VkImageUsageFlags.InputAttachment | VkImageUsageFlags.ColorAttachment, VkMemoryPropertyFlags.DeviceLocal, swapChain.Width, swapChain.Height, VkImageType.Image2D, samples); gbPos = new Image (dev, VkFormat.R16g16b16a16Sfloat, VkImageUsageFlags.InputAttachment | VkImageUsageFlags.ColorAttachment, VkMemoryPropertyFlags.DeviceLocal, swapChain.Width, swapChain.Height, VkImageType.Image2D, samples); - hdrImg = new Image (dev, VkFormat.R16g16b16a16Sfloat, VkImageUsageFlags.InputAttachment | VkImageUsageFlags.ColorAttachment, VkMemoryPropertyFlags.DeviceLocal, swapChain.Width, swapChain.Height, VkImageType.Image2D, samples); + hdrImg = new Image (dev, hdrFormat, VkImageUsageFlags.InputAttachment | VkImageUsageFlags.ColorAttachment, VkMemoryPropertyFlags.DeviceLocal, swapChain.Width, swapChain.Height, VkImageType.Image2D, samples); gbColorRough.CreateView (); gbColorRough.CreateSampler (); @@ -422,6 +427,30 @@ namespace deferred { #region Mouse and keyboard protected override void onKeyDown (Key key, int scanCode, Modifier modifiers) { switch (key) { + case Key.F: + if (modifiers.HasFlag (Modifier.Shift)) { + envCube.debugFace--; + if (envCube.debugFace < 0) + envCube.debugFace = 5; + } else { + envCube.debugFace++; + if (envCube.debugFace > 5) + envCube.debugFace = 0; + } + rebuildBuffers = true; + break; + case Key.M: + if (modifiers.HasFlag (Modifier.Shift)) { + envCube.debugMip--; + if (envCube.debugMip < 0) + envCube.debugMip = (int)envCube.prefilterCube.CreateInfo.mipLevels - 1; + } else { + envCube.debugMip++; + if (envCube.debugMip > envCube.prefilterCube.CreateInfo.mipLevels) + envCube.debugMip = 0; + } + rebuildBuffers = true; + break; case Key.Keypad0: case Key.Keypad1: case Key.Keypad2: @@ -431,9 +460,14 @@ namespace deferred { case Key.Keypad6: case Key.Keypad7: case Key.Keypad8: + case Key.Keypad9: currentDebugView = (DebugView)(int)key-320; rebuildBuffers = true; break; + case Key.KeypadDivide: + currentDebugView = DebugView.irradiance; + rebuildBuffers = true; + break; case Key.Up: if (modifiers.HasFlag (Modifier.Shift)) lightPos -= Vector4.UnitZ; diff --git a/samples/deferred/shaders/compose.frag b/samples/deferred/shaders/compose.frag index 7b19797..8dbf013 100644 --- a/samples/deferred/shaders/compose.frag +++ b/samples/deferred/shaders/compose.frag @@ -7,7 +7,7 @@ layout (set = 0, binding = 0) uniform UBO { mat4 model; mat4 view; vec4 camPos; - vec4 lightDir; + vec4 lightPos; float exposure; float gamma; float prefilteredCubeMipLevels; @@ -18,6 +18,17 @@ layout (set = 0, binding = 0) uniform UBO { #endif } ubo; +#define MAX_LIGHT 4 + +struct Light { + vec4 position; + vec4 color; +}; + +layout (set = 0, binding = 5) uniform UBOLights { + Light lights[MAX_LIGHT]; +}; + const float M_PI = 3.141592653589793; const float c_MinRoughness = 0.04; @@ -161,7 +172,7 @@ void main() vec3 n = subpassLoad(samplerN_AO, gl_SampleID).rgb; vec3 v = subpassLoad(samplerPos, gl_SampleID).rgb; // Vector from surface point to camera - vec3 l = normalize(ubo.lightDir.xyz); // Vector from surface point to light + vec3 l = normalize(ubo.lightPos.xyz); // Vector from surface point to light vec3 h = normalize(l+v); // Half vector between both l and v vec3 reflection = -normalize(reflect(v, n)); reflection.y *= -1.0f; diff --git a/samples/deferred/shaders/emissive.frag b/samples/deferred/shaders/emissive.frag new file mode 100644 index 0000000..2efe331 --- /dev/null +++ b/samples/deferred/shaders/emissive.frag @@ -0,0 +1,25 @@ +#version 450 +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (input_attachment_index = 0, set = 2, binding = 0) uniform subpassInputMS samplerColorRough; +layout (input_attachment_index = 1, set = 2, binding = 1) uniform subpassInputMS samplerEmitMetal; +layout (input_attachment_index = 2, set = 2, binding = 2) uniform subpassInputMS samplerN_AO; +layout (input_attachment_index = 3, set = 2, binding = 3) uniform subpassInputMS samplerPos; + +layout (location = 0) in vec2 inUV; + +layout (location = 0) out vec4 outColor; + +const float offset[5] = float[](0.0, 1.0, 2.0, 3.0, 4.0); +const float weight[5] = float[](0.2270270270, 0.1945945946, 0.1216216216, + 0.0540540541, 0.0162162162); + +void main() +{ + if (subpassLoad(samplerPos, gl_SampleID).a == 1.0f) + discard; + vec3 emissive = subpassLoad (samplerEmitMetal, gl_SampleID).rgb; + + outColor = vec4(emissive, 1); +}
\ No newline at end of file diff --git a/samples/deferred/shaders/show_gbuff.frag b/samples/deferred/shaders/show_gbuff.frag index 1ae3f8e..9195fed 100644 --- a/samples/deferred/shaders/show_gbuff.frag +++ b/samples/deferred/shaders/show_gbuff.frag @@ -27,10 +27,31 @@ const uint emissive = 4; const uint metallic = 5; const uint roughness = 6; const uint depth = 7; - +const uint prefill = 8; +const uint irradiance = 9; + +vec4 sampleCubeMap (samplerCube sc, uint face, uint lod) { + vec2 uv = 2.0 * inUV - vec2(1.0); + switch (face) { + case 0: + return vec4 (textureLod (sc, vec3(1, uv.t, uv.s), lod).rgb, 1); + case 1: + return vec4 (textureLod (sc, vec3(-1, uv.t, uv.s), lod).rgb, 1); + case 2: + return vec4 (textureLod (sc, vec3(uv.s, 1, -uv.t), lod).rgb, 1); + case 3: + return vec4 (textureLod (sc, vec3(uv.s, -1, uv.t), lod).rgb, 1); + case 4: + return vec4 (textureLod (sc, vec3(uv, 1), lod).rgb, 1); + case 5: + return vec4 (textureLod (sc, vec3(-uv.s, uv.t, -1), lod).rgb, 1); + } +} + void main() { - switch (imgIdx) { + uint imgNum = bitfieldExtract (imgIdx, 0, 8); + switch (imgNum) { case color: outColor = vec4(subpassLoad(samplerColorRough, gl_SampleID).rgb, 1); break; @@ -55,5 +76,11 @@ void main() case depth: outColor = vec4(subpassLoad(samplerPos, gl_SampleID).aaa, 1); break; + default: + if (imgNum == prefill) + outColor = sampleCubeMap (prefilteredMap, bitfieldExtract (imgIdx, 8, 8), bitfieldExtract (imgIdx, 16, 8)); + else if (imgNum == irradiance) + outColor = sampleCubeMap (samplerIrradiance, bitfieldExtract (imgIdx, 8, 8), bitfieldExtract (imgIdx, 16, 8)); + break; } }
\ No newline at end of file diff --git a/samples/pbrSashaWillem/PbrPipeline.cs b/samples/pbrSashaWillem/PbrPipeline.cs index 11a959a..b7df5a1 100644 --- a/samples/pbrSashaWillem/PbrPipeline.cs +++ b/samples/pbrSashaWillem/PbrPipeline.cs @@ -104,6 +104,7 @@ namespace CVKL { "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/Lantern/glTF/Lantern.gltf", "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/SciFiHelmet/glTF/SciFiHelmet.gltf", "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/Sponza/glTF/Sponza.gltf", + "/mnt/devel/vkChess/data/chess.gltf" }; diff --git a/samples/pbrSashaWillem/main.cs b/samples/pbrSashaWillem/main.cs index 0eb9895..98fb5dc 100644 --- a/samples/pbrSashaWillem/main.cs +++ b/samples/pbrSashaWillem/main.cs @@ -202,7 +202,7 @@ namespace pbrSachaWillem { modelAABB = pbrPipeline.model.DefaultScene.AABB; - camera.Model = Matrix4x4.CreateScale (1f/ Math.Max (Math.Max (modelAABB.max.X, modelAABB.max.Y), modelAABB.max.Z)); + //camera.Model = Matrix4x4.CreateScale (1f/ Math.Max (Math.Max (modelAABB.max.X, modelAABB.max.Y), modelAABB.max.Z)); #if PIPELINE_STATS statPool = new PipelineStatisticsQueryPool (dev, |