From 2d2e2ff4038db052d0186645f5afe4ec9daf2505 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bruyère Date: Wed, 24 Apr 2019 04:17:16 +0200 Subject: use boolean for tex0 and tex1 availability tests --- samples/Model/Camera2.cs | 102 ------ samples/Model/Model.csproj | 71 ---- samples/Model/data/chess.gltf | 3 - samples/Model/main.cs | 242 ------------- samples/Model/packages.config | 10 - samples/Model/shaders/pbrtest.frag | 193 ----------- samples/Model/shaders/pbrtest.vert | 48 --- samples/Pbr/main.cs | 311 ----------------- samples/Pbr/packages.config | 10 - samples/Pbr/pbr.csproj | 70 ---- samples/Pbr/shaders/filtercube.vert | 19 -- samples/Pbr/shaders/genbrdflut.frag | 90 ----- samples/Pbr/shaders/genbrdflut.vert | 9 - samples/Pbr/shaders/irradiancecube.frag | 37 -- samples/Pbr/shaders/pbr.vert | 58 ---- samples/Pbr/shaders/pbr_khr.frag | 415 ----------------------- samples/Pbr/shaders/pbrtest.frag | 193 ----------- samples/Pbr/shaders/pbrtest.vert | 49 --- samples/Pbr/shaders/prefilterenvmap.frag | 105 ------ samples/Pbr/shaders/skybox.frag | 15 - samples/Pbr/shaders/skybox.vert | 30 -- samples/Pbr/shaders/skybox_sw.frag | 55 --- samples/Pbr/shaders/skybox_sw.vert | 28 -- samples/Pbr/shaders/ui.frag | 13 - samples/Pbr/shaders/ui.vert | 25 -- samples/Textured/Textured.csproj | 4 +- samples/Textured/packages.config | 2 +- samples/TexturedCube/TexturedCube.csproj | 8 +- samples/Triangle/Triangle.csproj | 2 +- samples/VkvgCrowTest/PbrPipeline.cs | 2 +- samples/deferred/PbrPipeline.cs | 2 +- samples/deferred/deferred.csproj | 4 +- samples/deferred/main.cs | 2 +- samples/deferred/mainShadow.cs | 2 +- samples/deferred/mainWithDebugDrawer.cs | 2 +- samples/deferred/modelWithVkvgStats.cs | 2 +- samples/deferred/packages.config | 2 +- samples/pbrSashaWillem/EnvironmentPipeline.cs | 1 + samples/pbrSashaWillem/PbrModel.cs | 40 +-- samples/pbrSashaWillem/PbrPipeline.cs | 2 +- samples/pbrSashaWillem/main.cs | 2 +- samples/pbrSashaWillem/shaders/pbr_khr.frag | 132 +++---- samples/vkvg_overlay/Camera2.cs | 102 ------ samples/vkvg_overlay/main.cs | 384 --------------------- samples/vkvg_overlay/packages.config | 11 - samples/vkvg_overlay/shaders/FullScreenQuad.vert | 10 - samples/vkvg_overlay/shaders/model.frag | 110 ------ samples/vkvg_overlay/shaders/model.vert | 44 --- samples/vkvg_overlay/shaders/pbrtest.frag | 193 ----------- samples/vkvg_overlay/shaders/pbrtest.vert | 48 --- samples/vkvg_overlay/shaders/simpletexture.frag | 15 - samples/vkvg_overlay/vkvg_overlay.csproj | 73 ---- samples/vkvg_tests/packages.config | 2 +- samples/vkvg_tests/vkvg_tests.csproj | 4 +- 54 files changed, 104 insertions(+), 3304 deletions(-) delete mode 100644 samples/Model/Camera2.cs delete mode 100644 samples/Model/Model.csproj delete mode 100644 samples/Model/data/chess.gltf delete mode 100644 samples/Model/main.cs delete mode 100644 samples/Model/packages.config delete mode 100644 samples/Model/shaders/pbrtest.frag delete mode 100644 samples/Model/shaders/pbrtest.vert delete mode 100644 samples/Pbr/main.cs delete mode 100644 samples/Pbr/packages.config delete mode 100644 samples/Pbr/pbr.csproj delete mode 100644 samples/Pbr/shaders/filtercube.vert delete mode 100644 samples/Pbr/shaders/genbrdflut.frag delete mode 100644 samples/Pbr/shaders/genbrdflut.vert delete mode 100644 samples/Pbr/shaders/irradiancecube.frag delete mode 100644 samples/Pbr/shaders/pbr.vert delete mode 100644 samples/Pbr/shaders/pbr_khr.frag delete mode 100644 samples/Pbr/shaders/pbrtest.frag delete mode 100644 samples/Pbr/shaders/pbrtest.vert delete mode 100644 samples/Pbr/shaders/prefilterenvmap.frag delete mode 100644 samples/Pbr/shaders/skybox.frag delete mode 100644 samples/Pbr/shaders/skybox.vert delete mode 100644 samples/Pbr/shaders/skybox_sw.frag delete mode 100644 samples/Pbr/shaders/skybox_sw.vert delete mode 100644 samples/Pbr/shaders/ui.frag delete mode 100644 samples/Pbr/shaders/ui.vert delete mode 100644 samples/vkvg_overlay/Camera2.cs delete mode 100644 samples/vkvg_overlay/main.cs delete mode 100644 samples/vkvg_overlay/packages.config delete mode 100644 samples/vkvg_overlay/shaders/FullScreenQuad.vert delete mode 100644 samples/vkvg_overlay/shaders/model.frag delete mode 100644 samples/vkvg_overlay/shaders/model.vert delete mode 100644 samples/vkvg_overlay/shaders/pbrtest.frag delete mode 100644 samples/vkvg_overlay/shaders/pbrtest.vert delete mode 100644 samples/vkvg_overlay/shaders/simpletexture.frag delete mode 100644 samples/vkvg_overlay/vkvg_overlay.csproj (limited to 'samples') diff --git a/samples/Model/Camera2.cs b/samples/Model/Camera2.cs deleted file mode 100644 index 657564b..0000000 --- a/samples/Model/Camera2.cs +++ /dev/null @@ -1,102 +0,0 @@ -using System; -using System.Numerics; -using System.Runtime.InteropServices; - -using Vulkan; -using static CVKL.Camera; - -namespace CVKL { - public class Camera2 { - - float fov, aspectRatio, zNear = 0.1f, zFar = 256f; - float moveSpeed = 1, rotSpeed = 0.01f, zoomSpeed = 0.01f; - Vector3 rotation = new Vector3 (-1.5f, 2.7f, 0f); - Vector3 position = new Vector3 (0, 0, -2); - float zoom = 1.0f; - - public CamType Type; - - public float AspectRatio { - get { return aspectRatio; } - set { - aspectRatio = value; - Update (); - } - } - public float FieldOfView { - get { return fov; } - set { - fov = value; - Update (); - } - } - public Matrix4x4 Perspective { - get { return Matrix4x4.CreatePerspectiveFieldOfView (fov, aspectRatio, zNear, zFar); } - } - - public Camera2 (float fieldOfView, float aspectRatio) { - fov = fieldOfView; - this.aspectRatio = aspectRatio; - Update (); - } - - public void Rotate (float x, float y, float z = 0) { - rotation.Y += rotSpeed * x; - rotation.X += rotSpeed * y; - Update (); - } - public void Move (float x, float y, float z = 0) { - position.X += moveSpeed * x; - position.Y += moveSpeed * y; - position.Z += moveSpeed * z; - Update (); - } - public void Zoom (float factor) { - zoom += zoomSpeed * factor; - Update (); - } - - public Matrix4x4 Projection { get; private set;} - public Matrix4x4 View { get; private set;} - public Matrix4x4 Model { get; private set;} - - public Matrix4x4 SkyboxView { - get { - return - Matrix4x4.CreateFromAxisAngle (Vector3.UnitZ, rotation.Z) * - Matrix4x4.CreateFromAxisAngle (Vector3.UnitY, rotation.Y) * - Matrix4x4.CreateFromAxisAngle (Vector3.UnitX, rotation.X); - } - } - - //public void Update () { - // Projection = Matrix4x4.CreatePerspectiveFieldOfView (fov, aspectRatio, zNear, zFar); - // Matrix4x4 rot = - // Matrix4x4.CreateFromAxisAngle (Vector3.UnitX, rotation.X) * - // Matrix4x4.CreateFromAxisAngle (Vector3.UnitY, rotation.Y) * - // Matrix4x4.CreateFromAxisAngle (Vector3.UnitZ, rotation.Z); - // if (Type == CamType.LookAt) { - // View = Matrix4x4.CreateFromAxisAngle (Vector3.UnitX, rotation.X) * - // Matrix4x4.CreateFromAxisAngle (Vector3.UnitY, rotation.Y) * - // Matrix4x4.CreateFromAxisAngle (Vector3.UnitZ, rotation.Z) * - // Matrix4x4.CreateTranslation (position); - // } else { - // View = Matrix4x4.CreateTranslation (position) * - // Matrix4x4.CreateFromAxisAngle (Vector3.UnitZ, rotation.Z) * - // Matrix4x4.CreateFromAxisAngle (Vector3.UnitY, rotation.Y) * - // Matrix4x4.CreateFromAxisAngle (Vector3.UnitX, rotation.X); - // } - // Model = Matrix4x4.Identity; - //} - public void Update () { - Projection = Matrix4x4.CreatePerspectiveFieldOfView (fov, aspectRatio, zNear, zFar); - //matrices.view = Matrix4x4.CreateLookAt (new Vector3 (0, 0, -1), new Vector3 (0, 0, 0), Vector3.UnitY);//Matrix4x4.CreateTranslation (0, 0, -2.5f); - View = Matrix4x4.CreateTranslation (0, 0, -2.5f * zoom); - Model = - Matrix4x4.CreateFromAxisAngle (Vector3.UnitX, rotation.X) * - Matrix4x4.CreateFromAxisAngle (Vector3.UnitY, rotation.Y) * - Matrix4x4.CreateFromAxisAngle (Vector3.UnitZ, rotation.Z); - } - - } -} diff --git a/samples/Model/Model.csproj b/samples/Model/Model.csproj deleted file mode 100644 index 51a1861..0000000 --- a/samples/Model/Model.csproj +++ /dev/null @@ -1,71 +0,0 @@ - - - - {1F05E74F-AEE8-481C-8FDF-89D81CBB30BE} - Exe - Model - Model - v4.7.1 - $(SolutionDir)build\$(Configuration)\samples\Model - $(SolutionDir)build\obj\$(Configuration) - - - true - full - false - DEBUG;_DEBUG_MARKER - prompt - 4 - true - - - true - prompt - 4 - true - - - - - data\%(RecursiveDir)%(Filename)%(Extension) - - - - - - - - ..\..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll - - - - ..\..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll - - - ..\..\packages\glTF2Loader.1.1.3-alpha\lib\net35\glTFLoader.dll - - - ..\..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll - - - ..\..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll - - - ..\..\packages\System.Memory.4.5.2\lib\netstandard2.0\System.Memory.dll - - - ..\..\packages\Vulkan.0.1.2.6\lib\netstandard2.0\VK.dll - - - - - - - - {32B7E80D-BEA7-4811-B82D-CC2533069F0A} - CVKL - - - - - diff --git a/samples/Model/data/chess.gltf b/samples/Model/data/chess.gltf deleted file mode 100644 index f3d147c..0000000 --- a/samples/Model/data/chess.gltf +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:9f1d052e228693bc3dcf8f1459ecdb16e5b3eda401cf85ba4446e8ef308fffb7 -size 10075408 diff --git a/samples/Model/main.cs b/samples/Model/main.cs deleted file mode 100644 index 3223b16..0000000 --- a/samples/Model/main.cs +++ /dev/null @@ -1,242 +0,0 @@ -using System; -using System.Numerics; -using System.Runtime.InteropServices; -using Glfw; -using CVKL; -using VK; -using static CVKL.Camera; -using Buffer = CVKL.Buffer; - -namespace ModelSample { - class Program : VkWindow { - static void Main (string[] args) { - using (Program vke = new Program ()) { - vke.Run (); - } - } - - public struct Matrices { - public Matrix4x4 projection; - public Matrix4x4 view; - public Matrix4x4 model; - public Vector4 lightPos; - public float gamma; - public float exposure; - } - - public Matrices matrices = new Matrices { - lightPos = new Vector4 (0.0f, 0.0f, -2.0f, 1.0f), - gamma = 1.0f, - exposure = 2.0f, - }; - - HostBuffer uboMats; - - DescriptorPool descriptorPool; - DescriptorSetLayout descLayoutMatrix; - DescriptorSetLayout descLayoutTextures; - DescriptorSet dsMats; - - GraphicPipeline pipeline; - Framebuffer[] frameBuffers; - - Model model; - - Camera2 Camera = new Camera2 (Utils.DegreesToRadians (60f), 1f); - - Program () : base () { - init (); - - model = new Model (presentQueue, "../data/models/DamagedHelmet/glTF/DamagedHelmet.gltf"); - model.WriteMaterialsDescriptorSets (descLayoutTextures, - VK.AttachmentType.Color, - VK.AttachmentType.Normal, - VK.AttachmentType.AmbientOcclusion, - VK.AttachmentType.MetalRoughness, - VK.AttachmentType.Emissive); - } - - void init (VkSampleCountFlags samples = VkSampleCountFlags.SampleCount4) { - descriptorPool = new DescriptorPool (dev, 2, - new VkDescriptorPoolSize (VkDescriptorType.UniformBuffer) - ); - - descLayoutMatrix = new DescriptorSetLayout (dev, - new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Vertex|VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer)); - - descLayoutTextures = new DescriptorSetLayout (dev, - new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), - new VkDescriptorSetLayoutBinding (1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), - new VkDescriptorSetLayoutBinding (2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), - new VkDescriptorSetLayoutBinding (3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), - new VkDescriptorSetLayoutBinding (4, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) - ); - - dsMats = descriptorPool.Allocate (descLayoutMatrix); - - GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, samples); - - cfg.Layout = new PipelineLayout (dev, descLayoutMatrix, descLayoutTextures); - cfg.Layout.AddPushConstants ( - new VkPushConstantRange (VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf ()), - new VkPushConstantRange (VkShaderStageFlags.Fragment, (uint)Marshal.SizeOf (), 64) - ); - cfg.RenderPass = new RenderPass (dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat (), samples); - - cfg.AddVertexBinding (0); - cfg.SetVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat); - - cfg.AddShader (VkShaderStageFlags.Vertex, "shaders/pbrtest.vert.spv"); - cfg.AddShader (VkShaderStageFlags.Fragment, "shaders/pbrtest.frag.spv"); - - pipeline = new GraphicPipeline (cfg); - - uboMats = new HostBuffer (dev, VkBufferUsageFlags.UniformBuffer, (ulong)Marshal.SizeOf()); - uboMats.Map ();//permanent map - - DescriptorSetWrites uboUpdate = new DescriptorSetWrites (dsMats, descLayoutMatrix.Bindings[0]); - uboUpdate.Write (dev, uboMats.Descriptor); - } - - void buildCommandBuffers () { - for (int i = 0; i < swapChain.ImageCount; ++i) { - cmds[i]?.Free (); - cmds[i] = cmdPool.AllocateCommandBuffer (); - cmds[i].Start (); - - recordDraw (cmds[i], frameBuffers[i]); - - cmds[i].End (); - } - } - void recordDraw (CommandBuffer cmd, Framebuffer fb) { - pipeline.RenderPass.Begin (cmd, fb); - - cmd.SetViewport (fb.Width, fb.Height); - cmd.SetScissor (fb.Width, fb.Height); - - cmd.BindDescriptorSet (pipeline.Layout, dsMats); - pipeline.Bind (cmd); - model.Bind (cmd); - model.DrawAll (cmd, pipeline.Layout); - - pipeline.RenderPass.End (cmd); - } - - void updateMatrices () { - - Camera.AspectRatio = (float)swapChain.Width / swapChain.Height; - - matrices.projection = Camera.Projection; - matrices.view = Camera.View; - matrices.model = Camera.Model; - uboMats.Update (matrices, (uint)Marshal.SizeOf ()); - } - - public override void UpdateView () { - updateMatrices (); - updateViewRequested = false; - } - - protected override void onMouseMove (double xPos, double yPos) { - double diffX = lastMouseX - xPos; - double diffY = lastMouseY - yPos; - if (MouseButton[0]) { - Camera.Rotate ((float)-diffX,(float)-diffY); - } else if (MouseButton[1]) { - Camera.Zoom ((float)diffY); - } - - updateViewRequested = true; - } - - protected override void onKeyDown (Key key, int scanCode, Modifier modifiers) { - switch (key) { - case Key.Up: - Camera.Rotate (0, 0, 1); - break; - case Key.Down: - Camera.Move (0, 0, -1); - break; - case Key.Left: - Camera.Move (1, 0, 0); - break; - case Key.Right: - Camera.Move (-1, 0, 0); - break; - case Key.PageUp: - Camera.Move (0, 1, 0); - break; - case Key.PageDown: - Camera.Move (0, -1, 0); - break; - case Key.F1: - if (modifiers.HasFlag (Modifier.Shift)) - matrices.exposure -= 0.3f; - else - matrices.exposure += 0.3f; - break; - case Key.F2: - if (modifiers.HasFlag (Modifier.Shift)) - matrices.gamma -= 0.1f; - else - matrices.gamma += 0.1f; - break; - case Key.F3: - if (Camera.Type == CamType.FirstPerson) - Camera.Type = CamType.LookAt; - else - Camera.Type = CamType.FirstPerson; - break; - default: - base.onKeyDown (key, scanCode, modifiers); - return; - } - updateViewRequested = true; - } - - protected override void OnResize () { - - updateMatrices (); - - if (frameBuffers!=null) - for (int i = 0; i < swapChain.ImageCount; ++i) - frameBuffers[i]?.Dispose (); - - frameBuffers = new Framebuffer[swapChain.ImageCount]; - - for (int i = 0; i < swapChain.ImageCount; ++i) { - frameBuffers[i] = new Framebuffer (pipeline.RenderPass, swapChain.Width, swapChain.Height, - (pipeline.Samples == VkSampleCountFlags.SampleCount1) ? new Image[] { - swapChain.images[i], - null - } : new Image[] { - null, - null, - swapChain.images[i] - }); - } - - buildCommandBuffers (); - } - - protected override void Dispose (bool disposing) { - if (disposing) { - if (!isDisposed) { - dev.WaitIdle (); - for (int i = 0; i < swapChain.ImageCount; ++i) - frameBuffers[i]?.Dispose (); - model.Dispose (); - pipeline.Dispose (); - descLayoutMatrix.Dispose (); - descLayoutTextures.Dispose (); - descriptorPool.Dispose (); - - uboMats.Dispose (); - } - } - - base.Dispose (disposing); - } - } -} diff --git a/samples/Model/packages.config b/samples/Model/packages.config deleted file mode 100644 index 98f3bc2..0000000 --- a/samples/Model/packages.config +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/samples/Model/shaders/pbrtest.frag b/samples/Model/shaders/pbrtest.frag deleted file mode 100644 index bc850e1..0000000 --- a/samples/Model/shaders/pbrtest.frag +++ /dev/null @@ -1,193 +0,0 @@ -#version 450 - -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable - -layout (binding = 0) uniform UBO -{ - mat4 projectionMatrix; - mat4 viewMatrix; - mat4 modelMatrix; - vec4 lightPos; - float gamma; - float exposure; -} ubo; - -layout (set = 1, binding = 0) uniform sampler2D samplerColor; -layout (set = 1, binding = 1) uniform sampler2D samplerNormal; -layout (set = 1, binding = 2) uniform sampler2D samplerOcclusion; -layout (set = 1, binding = 3) uniform sampler2D samplerMetalRoughness; -layout (set = 1, binding = 4) uniform sampler2D samplerEmissive; - -layout (location = 0) in vec2 inUV; -layout (location = 1) in vec3 inN; -layout (location = 2) in vec3 inV; -layout (location = 3) in vec3 inWorldPos; - -layout (location = 0) out vec4 outFragColor; - -layout(push_constant) uniform PushConsts { - layout(offset = 64) - vec4 baseColorFactor; - vec4 emissiveFactor; - uint availableAttachments; - uint alphaMode; - float alphaCutoff; - float metallicFactor; - float roughnessFactor; -} pc; - -const uint MAP_COLOR = 0x1; -const uint MAP_NORMAL = 0x2; -const uint MAP_AO = 0x4; -const uint MAP_METAL = 0x8; -const uint MAP_ROUGHNESS = 0x16; -const uint MAP_METALROUGHNESS = 0x32; -const uint MAP_EMISSIVE = 0x64; - -const float PI = 3.141592653589793; - -vec3 light = vec3(1.0,.0,1.0); - -// From http://filmicgames.com/archives/75 -vec3 Uncharted2Tonemap(vec3 x) -{ - float A = 0.15; - float B = 0.50; - float C = 0.10; - float D = 0.20; - float E = 0.02; - float F = 0.30; - return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F; -} - -// Normal Distribution function -------------------------------------- -float D_GGX(float dotNH, float roughness) -{ - float alpha = roughness * roughness; - float alpha2 = alpha * alpha; - float denom = dotNH * dotNH * (alpha2 - 1.0) + 1.0; - return (alpha2)/(PI * denom*denom); -} - -// Geometric Shadowing function -------------------------------------- -float G_SchlicksmithGGX(float dotNL, float dotNV, float roughness) -{ - float r = (roughness + 1.0); - float k = (r*r) / 8.0; - float GL = dotNL / (dotNL * (1.0 - k) + k); - float GV = dotNV / (dotNV * (1.0 - k) + k); - return GL * GV; -} - -// Fresnel function ---------------------------------------------------- -vec3 F_Schlick(float cosTheta, vec3 F0) -{ - return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0); -} -vec3 F_SchlickR(float cosTheta, vec3 F0, float roughness) -{ - return F0 + (max(vec3(1.0 - roughness), F0) - F0) * pow(1.0 - cosTheta, 5.0); -} - -vec3 specularContribution(vec3 L, vec3 V, vec3 N, vec3 F0, float metallic, float roughness, vec3 albedo) -{ - // Precalculate vectors and dot products - vec3 H = normalize (V + L); - float dotNH = clamp(dot(N, H), 0.0, 1.0); - float dotNV = clamp(dot(N, V), 0.0, 1.0); - float dotNL = clamp(dot(N, L), 0.0, 1.0); - - // Light color fixed - vec3 lightColor = vec3(1.0); - - vec3 color = vec3(0.0); - - if (dotNL > 0.0) { - // D = Normal distribution (Distribution of the microfacets) - float D = D_GGX(dotNH, roughness); - // G = Geometric shadowing term (Microfacets shadowing) - float G = G_SchlicksmithGGX(dotNL, dotNV, roughness); - // F = Fresnel factor (Reflectance depending on angle of incidence) - vec3 F = F_Schlick(dotNV, F0); - vec3 spec = D * F * G / (4.0 * dotNL * dotNV + 0.001); - vec3 kD = (vec3(1.0) - F) * (1.0 - metallic); - color += (kD * albedo / PI + spec) * dotNL; - } - - return color; -} - -// See http://www.thetenthplanet.de/archives/1180 -vec3 perturbNormal(vec3 inNormal, vec3 tangentNormal) -{ - - - vec3 q1 = dFdx(inWorldPos); - vec3 q2 = dFdy(inWorldPos); - vec2 st1 = dFdx(inUV); - vec2 st2 = dFdy(inUV); - - vec3 N = normalize(inNormal); - vec3 T = normalize(q1 * st2.t - q2 * st1.t); - vec3 B = -normalize(cross(N, T)); - mat3 TBN = mat3(T, B, N); - - return normalize(TBN * tangentNormal); -} -void main() -{ - vec3 emit = vec3(0); - vec4 base_color = pc.baseColorFactor; - float rough = pc.roughnessFactor; - float metallic = pc.metallicFactor; - - if ((pc.availableAttachments & MAP_COLOR) == MAP_COLOR) - base_color *= texture(samplerColor, inUV); - if ((pc.availableAttachments & MAP_METALROUGHNESS) == MAP_METALROUGHNESS) { - rough *= clamp(texture(samplerMetalRoughness, inUV).g, 0.04, 1.0); - metallic *= texture(samplerMetalRoughness, inUV).b; - } - if ((pc.availableAttachments & MAP_EMISSIVE) == MAP_EMISSIVE) - emit = pc.emissiveFactor.rgb * texture(samplerEmissive, inUV).rgb; - - - vec3 N = ((pc.availableAttachments & MAP_NORMAL) == MAP_NORMAL) ? - perturbNormal(inN, texture(samplerNormal, inUV).xyz * 2.0 - 1.0) : - normalize(inN); - vec3 V = normalize(inV); - vec3 R = -normalize(reflect(V, N)); - - vec3 F0 = vec3(0.04); - F0 = mix(F0, base_color.rgb, metallic); - float alpha = pow(rough, 2.0); - - vec3 L = normalize(light); - vec3 Lo = specularContribution(L, V, N, F0, metallic, rough, base_color.rgb); - - vec3 reflection = vec3(rough);// prefilteredReflection(R, rough).rgb; - vec3 irradiance = vec3(0.8);//texture(samplerIrradiance, N).rgb; - - // Diffuse based on irradiance - vec3 diffuse = irradiance * base_color.rgb; - - vec3 F = F_SchlickR(max(dot(N, V), 0.0), F0, rough); - - vec3 specular = reflection * F;//(F * brdf.x + brdf.y); - - // Ambient part - vec3 kD = 1.0 - F; - kD *= 1.0 - metallic; - - float ao = ((pc.availableAttachments & MAP_AO) == MAP_AO) ? texture(samplerOcclusion, inUV).r : 1.0f; - vec3 ambient = (kD * diffuse + specular) * ao; - vec3 color = ambient + Lo; - - // Tone mapping - color = Uncharted2Tonemap(color * ubo.exposure); - color = color * (1.0f / Uncharted2Tonemap(vec3(11.2f))); - // Gamma correction - color = pow(color, vec3(1.0f / ubo.gamma)) + emit; - - outFragColor = vec4(color , base_color.a); -} \ No newline at end of file diff --git a/samples/Model/shaders/pbrtest.vert b/samples/Model/shaders/pbrtest.vert deleted file mode 100644 index ffb1432..0000000 --- a/samples/Model/shaders/pbrtest.vert +++ /dev/null @@ -1,48 +0,0 @@ -#version 450 - -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable - -layout (location = 0) in vec3 inPos; -layout (location = 1) in vec3 inNormal; -layout (location = 2) in vec2 inUV; - -layout (binding = 0) uniform UBO -{ - mat4 projectionMatrix; - mat4 viewMatrix; - mat4 modelMatrix; - vec4 lightPos; - float gamma; - float exposure; -} ubo; - -layout (location = 0) out vec2 outUV; -layout (location = 1) out vec3 outN; -layout (location = 2) out vec3 outV;//ViewDir -layout (location = 3) out vec3 outWorldPos; - -out gl_PerVertex -{ - vec4 gl_Position; -}; - -layout(push_constant) uniform PushConsts { - mat4 model; -} pc; - -void main() -{ - outUV = inUV; - - mat4 mod = ubo.modelMatrix * pc.model; - vec4 pos = mod * vec4(inPos.xyz, 1.0); - - //outN = normalize(transpose(inverse(mat3(mod))) * inNormal); - outN = normalize(mat3(mod)* inNormal); - - mat4 viewInv = inverse(ubo.viewMatrix); - outV = -(ubo.viewMatrix * pos).xyz;//normalize(vec3(viewInv * vec4(0.0, 0.0, 0.0, 1.0) - pos)); - outWorldPos = pos.xyz; - gl_Position = ubo.projectionMatrix * ubo.viewMatrix * pos; -} diff --git a/samples/Pbr/main.cs b/samples/Pbr/main.cs deleted file mode 100644 index 857da3f..0000000 --- a/samples/Pbr/main.cs +++ /dev/null @@ -1,311 +0,0 @@ -using System; -using System.Numerics; -using System.Runtime.InteropServices; -using Glfw; -using CVKL; -using VK; - -namespace PbrSample { - class Program : VkWindow { - static void Main (string[] args) { - using (Program vke = new Program ()) { - vke.Run (); - } - } - - public struct Matrices { - public Matrix4x4 projection; - public Matrix4x4 view; - public Matrix4x4 model; - public Vector4 lightPos; - public float gamma; - public float exposure; - } - - Matrices matrices = new Matrices { - lightPos = new Vector4 (1.0f, 0.0f, 0.0f, 1.0f), - gamma = 1.0f, - exposure = 2.0f, - }; - - Framebuffer[] frameBuffers; - - HostBuffer uboMats; - - DescriptorPool descriptorPool; - DescriptorSetLayout descLayoutMain; - DescriptorSetLayout descLayoutTextures; - - DescriptorSet dsSkybox; - DescriptorSet dsMain; - - GraphicPipeline pipeline; - GraphicPipeline skyboxPL; - - Model model; - - GPUBuffer vboSkybox; - Image cubemap; - string[] cubemapPathes = { - "../data/textures/papermill.ktx", - "../data/textures/cubemap_yokohama_bc3_unorm.ktx", - "../data/textures/gcanyon_cube.ktx", - "../data/textures/pisa_cube.ktx", - "../data/textures/uffizi_cube.ktx", - }; - static float[] box_vertices = { - -1.0f,-1.0f,-1.0f, 0.0f, 1.0f, // -X side - -1.0f,-1.0f, 1.0f, 1.0f, 1.0f, - -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, - -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, - -1.0f, 1.0f,-1.0f, 0.0f, 0.0f, - -1.0f,-1.0f,-1.0f, 0.0f, 1.0f, - - -1.0f,-1.0f,-1.0f, 1.0f, 1.0f, // -Z side - 1.0f, 1.0f,-1.0f, 0.0f, 0.0f, - 1.0f,-1.0f,-1.0f, 0.0f, 1.0f, - -1.0f,-1.0f,-1.0f, 1.0f, 1.0f, - -1.0f, 1.0f,-1.0f, 1.0f, 0.0f, - 1.0f, 1.0f,-1.0f, 0.0f, 0.0f, - - -1.0f,-1.0f,-1.0f, 1.0f, 0.0f, // -Y side - 1.0f,-1.0f,-1.0f, 1.0f, 1.0f, - 1.0f,-1.0f, 1.0f, 0.0f, 1.0f, - -1.0f,-1.0f,-1.0f, 1.0f, 0.0f, - 1.0f,-1.0f, 1.0f, 0.0f, 1.0f, - -1.0f,-1.0f, 1.0f, 0.0f, 0.0f, - - -1.0f, 1.0f,-1.0f, 1.0f, 0.0f, // +Y side - -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, - 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, - -1.0f, 1.0f,-1.0f, 1.0f, 0.0f, - 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, - 1.0f, 1.0f,-1.0f, 1.0f, 1.0f, - - 1.0f, 1.0f,-1.0f, 1.0f, 0.0f, // +X side - 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, - 1.0f,-1.0f, 1.0f, 0.0f, 1.0f, - 1.0f,-1.0f, 1.0f, 0.0f, 1.0f, - 1.0f,-1.0f,-1.0f, 1.0f, 1.0f, - 1.0f, 1.0f,-1.0f, 1.0f, 0.0f, - - -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, // +Z side - -1.0f,-1.0f, 1.0f, 0.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, - -1.0f,-1.0f, 1.0f, 0.0f, 1.0f, - 1.0f,-1.0f, 1.0f, 1.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, - }; - - Program () : base () { - camera.Model = Matrix4x4.CreateRotationX (Utils.DegreesToRadians (-90)) * Matrix4x4.CreateRotationY (Utils.DegreesToRadians (180)); - camera.SetRotation (-0.1f, -0.4f); - camera.SetPosition (0, 0, -3); - - vboSkybox = new GPUBuffer (presentQueue, cmdPool, VkBufferUsageFlags.VertexBuffer, box_vertices); - - cubemap = KTX.KTX.Load (presentQueue, cmdPool, cubemapPathes[0], - VkImageUsageFlags.Sampled, VkMemoryPropertyFlags.DeviceLocal, true); - cubemap.CreateView (VkImageViewType.Cube,VkImageAspectFlags.Color,6); - cubemap.CreateSampler (); - - init (); - - //model = new Model (dev, presentQueue, cmdPool, "/mnt/devel/vkChess/data/chess.gltf"); - model = new Model (presentQueue, "../data/models/DamagedHelmet/glTF/DamagedHelmet.gltf"); - model.WriteMaterialsDescriptorSets (descLayoutTextures, - VK.AttachmentType.Color, - VK.AttachmentType.Normal, - VK.AttachmentType.AmbientOcclusion, - VK.AttachmentType.MetalRoughness, - VK.AttachmentType.Emissive); - } - - void init (VkSampleCountFlags samples = VkSampleCountFlags.SampleCount4) { - descriptorPool = new DescriptorPool (dev, 2, - new VkDescriptorPoolSize (VkDescriptorType.UniformBuffer, 2), - new VkDescriptorPoolSize (VkDescriptorType.CombinedImageSampler, 2) - ); - - descLayoutMain = new DescriptorSetLayout (dev, - new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Vertex|VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer), - new VkDescriptorSetLayoutBinding (1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)); - - descLayoutTextures = new DescriptorSetLayout (dev, - new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), - new VkDescriptorSetLayoutBinding (1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), - new VkDescriptorSetLayoutBinding (2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), - new VkDescriptorSetLayoutBinding (3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), - new VkDescriptorSetLayoutBinding (4, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) - ); - - dsMain = descriptorPool.Allocate (descLayoutMain); - dsSkybox = descriptorPool.Allocate (descLayoutMain); - - GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, samples); - - cfg.Layout = new PipelineLayout (dev, descLayoutMain, descLayoutTextures); - cfg.Layout.AddPushConstants ( - new VkPushConstantRange (VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf ()), - new VkPushConstantRange (VkShaderStageFlags.Fragment, (uint)Marshal.SizeOf (), 64) - ); - cfg.RenderPass = new RenderPass (dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat (), samples); - cfg.AddVertexBinding (0); - cfg.SetVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat); - - cfg.AddShader (VkShaderStageFlags.Vertex, "shaders/pbrtest.vert.spv"); - cfg.AddShader (VkShaderStageFlags.Fragment, "shaders/pbrtest.frag.spv"); - - pipeline = new GraphicPipeline (cfg); - - #region skybox pipeline - cfg.ResetShadersAndVerticesInfos (); - - cfg.AddVertexBinding (0, 5 * sizeof(float)); - cfg.SetVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat); - cfg.AddShader (VkShaderStageFlags.Vertex, "shaders/skybox.vert.spv"); - cfg.AddShader (VkShaderStageFlags.Fragment, "shaders/skybox.frag.spv"); - cfg.depthStencilState.depthTestEnable = false; - cfg.depthStencilState.depthWriteEnable = false; - - skyboxPL = new GraphicPipeline (cfg); - #endregion - - uboMats = new HostBuffer (dev, VkBufferUsageFlags.UniformBuffer, (ulong)Marshal.SizeOf()*2); - uboMats.Map ();//permanent map - - DescriptorSetWrites uboUpdate = new DescriptorSetWrites (descLayoutMain); - uboUpdate.Write (dev, dsMain, uboMats.Descriptor, cubemap.Descriptor); - uboMats.Descriptor.offset = (ulong)Marshal.SizeOf (); - uboUpdate.Write (dev, dsSkybox, uboMats.Descriptor, cubemap.Descriptor); - } - - void buildCommandBuffers () { - for (int i = 0; i < swapChain.ImageCount; ++i) { - cmds[i]?.Free (); - cmds[i] = cmdPool.AllocateCommandBuffer (); - cmds[i].Start (); - - recordDraw (cmds[i], frameBuffers[i]); - - cmds[i].End (); - } - } - void recordDraw (CommandBuffer cmd, Framebuffer fb) { - pipeline.RenderPass.Begin (cmd, fb); - - cmd.SetViewport (fb.Width, fb.Height); - cmd.SetScissor (fb.Width, fb.Height); - - skyboxPL.Bind (cmd); - cmd.BindDescriptorSet (skyboxPL.Layout, dsSkybox); - cmd.BindVertexBuffer (vboSkybox); - cmd.Draw (36); - - pipeline.Bind (cmd); - cmd.BindDescriptorSet (pipeline.Layout, dsMain); - model.Bind (cmd); - model.DrawAll (cmd, pipeline.Layout); - - pipeline.RenderPass.End (cmd); - } - - void updateMatrices () { - - camera.AspectRatio = (float)swapChain.Width / swapChain.Height; - - matrices.projection = camera.Projection; - matrices.view = camera.View; - matrices.model = camera.Model; - uboMats.Update (matrices, (uint)Marshal.SizeOf ()); - matrices.view *= Matrix4x4.CreateTranslation(-matrices.view.Translation); - matrices.model = Matrix4x4.Identity; - uboMats.Update (matrices, (uint)Marshal.SizeOf (), (uint)Marshal.SizeOf ()); - } - - public override void UpdateView () { - updateMatrices (); - updateViewRequested = false; - } - - protected override void onMouseMove (double xPos, double yPos) { - double diffX = lastMouseX - xPos; - double diffY = lastMouseY - yPos; - if (MouseButton[0]) { - camera.Rotate ((float)-diffX,(float)-diffY); - } else if (MouseButton[1]) { - camera.Zoom ((float)diffY); - } - - updateViewRequested = true; - } - - protected override void onKeyDown (Key key, int scanCode, Modifier modifiers) { - switch (key) { - case Key.F1: - if (modifiers.HasFlag (Modifier.Shift)) - matrices.exposure -= 0.3f; - else - matrices.exposure += 0.3f; - break; - case Key.F2: - if (modifiers.HasFlag (Modifier.Shift)) - matrices.gamma -= 0.1f; - else - matrices.gamma += 0.1f; - break; - default: - base.onKeyDown (key, scanCode, modifiers); - return; - } - updateViewRequested = true; - } - - protected override void OnResize () { - - updateMatrices (); - - if (frameBuffers!=null) - for (int i = 0; i < swapChain.ImageCount; ++i) - frameBuffers[i]?.Dispose (); - - frameBuffers = new Framebuffer[swapChain.ImageCount]; - - for (int i = 0; i < swapChain.ImageCount; ++i) { - frameBuffers[i] = new Framebuffer (pipeline.RenderPass, swapChain.Width, swapChain.Height, - (pipeline.Samples == VkSampleCountFlags.SampleCount1) ? new Image[] { - swapChain.images[i], - null - } : new Image[] { - null, - null, - swapChain.images[i] - }); - } - - buildCommandBuffers (); - } - - protected override void Dispose (bool disposing) { - if (disposing) { - if (!isDisposed) { - dev.WaitIdle (); - for (int i = 0; i < swapChain.ImageCount; ++i) - frameBuffers[i]?.Dispose (); - model.Dispose (); - vboSkybox.Dispose (); - pipeline.Dispose (); - skyboxPL.Dispose (); - descLayoutMain.Dispose (); - descLayoutTextures.Dispose (); - descriptorPool.Dispose (); - cubemap.Dispose (); - - uboMats.Dispose (); - } - } - - base.Dispose (disposing); - } - } -} diff --git a/samples/Pbr/packages.config b/samples/Pbr/packages.config deleted file mode 100644 index 5f9100e..0000000 --- a/samples/Pbr/packages.config +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/samples/Pbr/pbr.csproj b/samples/Pbr/pbr.csproj deleted file mode 100644 index 2a43a15..0000000 --- a/samples/Pbr/pbr.csproj +++ /dev/null @@ -1,70 +0,0 @@ - - - - {1F18E74F-AEE8-481C-8FDF-89D81CBB30BE} - Exe - pbr - v4.7.1 - $(SolutionDir)build\$(Configuration)\samples\pbr - $(SolutionDir)build\obj\$(Configuration) - - - true - full - false - DEBUG;DEBUG_MARKER - prompt - 4 - true - - - true - prompt - 4 - true - - - - - data\%(RecursiveDir)%(Filename)%(Extension) - - - - - - - - ..\..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll - - - - ..\..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll - - - ..\..\packages\glTF2Loader.1.1.3-alpha\lib\net35\glTFLoader.dll - - - ..\..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll - - - ..\..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll - - - ..\..\packages\System.Memory.4.5.2\lib\netstandard2.0\System.Memory.dll - - - ..\..\packages\Vulkan.0.1.2.5-alpha\lib\netstandard2.0\VK.dll - - - - - - - - {32B7E80D-BEA7-4811-B82D-CC2533069F0A} - CVKL - - - - - diff --git a/samples/Pbr/shaders/filtercube.vert b/samples/Pbr/shaders/filtercube.vert deleted file mode 100644 index 1226e28..0000000 --- a/samples/Pbr/shaders/filtercube.vert +++ /dev/null @@ -1,19 +0,0 @@ -#version 450 - -layout (location = 0) in vec3 inPos; - -layout(push_constant) uniform PushConsts { - layout (offset = 0) mat4 mvp; -} pushConsts; - -layout (location = 0) out vec3 outUVW; - -out gl_PerVertex { - vec4 gl_Position; -}; - -void main() -{ - outUVW = inPos; - gl_Position = pushConsts.mvp * vec4(inPos.xyz, 1.0); -} diff --git a/samples/Pbr/shaders/genbrdflut.frag b/samples/Pbr/shaders/genbrdflut.frag deleted file mode 100644 index b6290dd..0000000 --- a/samples/Pbr/shaders/genbrdflut.frag +++ /dev/null @@ -1,90 +0,0 @@ -#version 450 - -layout (location = 0) in vec2 inUV; -layout (location = 0) out vec4 outColor; -layout (constant_id = 0) const uint NUM_SAMPLES = 1024u; - -const float PI = 3.1415926536; - -// Based omn http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/ -float random(vec2 co) -{ - float a = 12.9898; - float b = 78.233; - float c = 43758.5453; - float dt= dot(co.xy ,vec2(a,b)); - float sn= mod(dt,3.14); - return fract(sin(sn) * c); -} - -vec2 hammersley2d(uint i, uint N) -{ - // Radical inverse based on http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html - uint bits = (i << 16u) | (i >> 16u); - bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u); - bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u); - bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u); - bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u); - float rdi = float(bits) * 2.3283064365386963e-10; - return vec2(float(i) /float(N), rdi); -} - -// Based on http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_slides.pdf -vec3 importanceSample_GGX(vec2 Xi, float roughness, vec3 normal) -{ - // Maps a 2D point to a hemisphere with spread based on roughness - float alpha = roughness * roughness; - float phi = 2.0 * PI * Xi.x + random(normal.xz) * 0.1; - float cosTheta = sqrt((1.0 - Xi.y) / (1.0 + (alpha*alpha - 1.0) * Xi.y)); - float sinTheta = sqrt(1.0 - cosTheta * cosTheta); - vec3 H = vec3(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta); - - // Tangent space - vec3 up = abs(normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0); - vec3 tangentX = normalize(cross(up, normal)); - vec3 tangentY = normalize(cross(normal, tangentX)); - - // Convert to world Space - return normalize(tangentX * H.x + tangentY * H.y + normal * H.z); -} - -// Geometric Shadowing function -float G_SchlicksmithGGX(float dotNL, float dotNV, float roughness) -{ - float k = (roughness * roughness) / 2.0; - float GL = dotNL / (dotNL * (1.0 - k) + k); - float GV = dotNV / (dotNV * (1.0 - k) + k); - return GL * GV; -} - -vec2 BRDF(float NoV, float roughness) -{ - // Normal always points along z-axis for the 2D lookup - const vec3 N = vec3(0.0, 0.0, 1.0); - vec3 V = vec3(sqrt(1.0 - NoV*NoV), 0.0, NoV); - - vec2 LUT = vec2(0.0); - for(uint i = 0u; i < NUM_SAMPLES; i++) { - vec2 Xi = hammersley2d(i, NUM_SAMPLES); - vec3 H = importanceSample_GGX(Xi, roughness, N); - vec3 L = 2.0 * dot(V, H) * H - V; - - float dotNL = max(dot(N, L), 0.0); - float dotNV = max(dot(N, V), 0.0); - float dotVH = max(dot(V, H), 0.0); - float dotNH = max(dot(H, N), 0.0); - - if (dotNL > 0.0) { - float G = G_SchlicksmithGGX(dotNL, dotNV, roughness); - float G_Vis = (G * dotVH) / (dotNH * dotNV); - float Fc = pow(1.0 - dotVH, 5.0); - LUT += vec2((1.0 - Fc) * G_Vis, Fc * G_Vis); - } - } - return LUT / float(NUM_SAMPLES); -} - -void main() -{ - outColor = vec4(BRDF(inUV.s, 1.0-inUV.t), 0.0, 1.0); -} \ No newline at end of file diff --git a/samples/Pbr/shaders/genbrdflut.vert b/samples/Pbr/shaders/genbrdflut.vert deleted file mode 100644 index f3dd233..0000000 --- a/samples/Pbr/shaders/genbrdflut.vert +++ /dev/null @@ -1,9 +0,0 @@ -#version 450 - -layout (location = 0) out vec2 outUV; - -void main() -{ - outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2); - gl_Position = vec4(outUV * 2.0f - 1.0f, 0.0f, 1.0f); -} \ No newline at end of file diff --git a/samples/Pbr/shaders/irradiancecube.frag b/samples/Pbr/shaders/irradiancecube.frag deleted file mode 100644 index 3232db4..0000000 --- a/samples/Pbr/shaders/irradiancecube.frag +++ /dev/null @@ -1,37 +0,0 @@ -// Generates an irradiance cube from an environment map using convolution - -#version 450 - -layout (location = 0) in vec3 inPos; -layout (location = 0) out vec4 outColor; -layout (binding = 0) uniform samplerCube samplerEnv; - -layout(push_constant) uniform PushConsts { - layout (offset = 64) float deltaPhi; - layout (offset = 68) float deltaTheta; -} consts; - -#define PI 3.1415926535897932384626433832795 - -void main() -{ - vec3 N = normalize(inPos); - vec3 up = vec3(0.0, 1.0, 0.0); - vec3 right = normalize(cross(up, N)); - up = cross(N, right); - - const float TWO_PI = PI * 2.0; - const float HALF_PI = PI * 0.5; - - vec3 color = vec3(0.0); - uint sampleCount = 0u; - for (float phi = 0.0; phi < TWO_PI; phi += consts.deltaPhi) { - for (float theta = 0.0; theta < HALF_PI; theta += consts.deltaTheta) { - vec3 tempVec = cos(phi) * right + sin(phi) * up; - vec3 sampleVector = cos(theta) * N + sin(theta) * tempVec; - color += texture(samplerEnv, sampleVector).rgb * cos(theta) * sin(theta); - sampleCount++; - } - } - outColor = vec4(PI * color / float(sampleCount), 1.0); -} diff --git a/samples/Pbr/shaders/pbr.vert b/samples/Pbr/shaders/pbr.vert deleted file mode 100644 index 03d24da..0000000 --- a/samples/Pbr/shaders/pbr.vert +++ /dev/null @@ -1,58 +0,0 @@ -#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; -layout (location = 4) in vec4 inJoint0; -layout (location = 5) in vec4 inWeight0; - -layout (set = 0, binding = 0) uniform UBO -{ - mat4 projection; - mat4 model; - mat4 view; - vec3 camPos; -} ubo; - -#define MAX_NUM_JOINTS 128 - -layout (set = 2, binding = 0) uniform UBONode { - mat4 matrix; - mat4 jointMatrix[MAX_NUM_JOINTS]; - float jointCount; -} node; - -layout (location = 0) out vec3 outWorldPos; -layout (location = 1) out vec3 outNormal; -layout (location = 2) out vec2 outUV0; -layout (location = 3) out vec2 outUV1; - -out gl_PerVertex -{ - vec4 gl_Position; -}; - -void main() -{ - vec4 locPos; - if (node.jointCount > 0.0) { - // Mesh is skinned - mat4 skinMat = - inWeight0.x * node.jointMatrix[int(inJoint0.x)] + - inWeight0.y * node.jointMatrix[int(inJoint0.y)] + - inWeight0.z * node.jointMatrix[int(inJoint0.z)] + - inWeight0.w * node.jointMatrix[int(inJoint0.w)]; - - locPos = ubo.model * node.matrix * skinMat * vec4(inPos, 1.0); - outNormal = normalize(transpose(inverse(mat3(ubo.model * node.matrix * skinMat))) * inNormal); - } else { - locPos = ubo.model * node.matrix * vec4(inPos, 1.0); - outNormal = normalize(transpose(inverse(mat3(ubo.model * node.matrix))) * inNormal); - } - locPos.y = -locPos.y; - outWorldPos = locPos.xyz / locPos.w; - outUV0 = inUV0; - outUV1 = inUV1; - gl_Position = ubo.projection * ubo.view * vec4(outWorldPos, 1.0); -} diff --git a/samples/Pbr/shaders/pbr_khr.frag b/samples/Pbr/shaders/pbr_khr.frag deleted file mode 100644 index bdf9fce..0000000 --- a/samples/Pbr/shaders/pbr_khr.frag +++ /dev/null @@ -1,415 +0,0 @@ -// PBR shader based on the Khronos WebGL PBR implementation -// See https://github.com/KhronosGroup/glTF-WebGL-PBR -// Supports both metallic roughness and specular glossiness inputs - -#version 450 - -layout (location = 0) in vec3 inWorldPos; -layout (location = 1) in vec3 inNormal; -layout (location = 2) in vec2 inUV0; -layout (location = 3) in vec2 inUV1; - -// Scene bindings - -layout (set = 0, binding = 0) uniform UBO { - mat4 projection; - mat4 model; - mat4 view; - vec3 camPos; -} ubo; - -layout (set = 0, binding = 1) uniform UBOParams { - vec4 lightDir; - float exposure; - float gamma; - float prefilteredCubeMipLevels; - float scaleIBLAmbient; - float debugViewInputs; - float debugViewEquation; -} uboParams; - -layout (set = 0, binding = 2) uniform samplerCube samplerIrradiance; -layout (set = 0, binding = 3) uniform samplerCube prefilteredMap; -layout (set = 0, binding = 4) uniform sampler2D samplerBRDFLUT; - -// Material bindings - -layout (set = 1, binding = 0) uniform sampler2D colorMap; -layout (set = 1, binding = 1) uniform sampler2D physicalDescriptorMap; -layout (set = 1, binding = 2) uniform sampler2D normalMap; -layout (set = 1, binding = 3) uniform sampler2D aoMap; -layout (set = 1, binding = 4) uniform sampler2D emissiveMap; - -layout (push_constant) uniform Material { - vec4 baseColorFactor; - vec4 emissiveFactor; - vec4 diffuseFactor; - vec4 specularFactor; - float workflow; - int baseColorTextureSet; - int physicalDescriptorTextureSet; - int normalTextureSet; - int occlusionTextureSet; - int emissiveTextureSet; - float metallicFactor; - float roughnessFactor; - float alphaMask; - float alphaMaskCutoff; -} material; - -layout (location = 0) out vec4 outColor; - -// Encapsulate the various inputs used by the various functions in the shading equation -// We store values in this struct to simplify the integration of alternative implementations -// of the shading terms, outlined in the Readme.MD Appendix. -struct PBRInfo -{ - float NdotL; // cos angle between normal and light direction - float NdotV; // cos angle between normal and view direction - float NdotH; // cos angle between normal and half vector - float LdotH; // cos angle between light direction and half vector - float VdotH; // cos angle between view direction and half vector - float perceptualRoughness; // roughness value, as authored by the model creator (input to shader) - float metalness; // metallic value at the surface - vec3 reflectance0; // full reflectance color (normal incidence angle) - vec3 reflectance90; // reflectance color at grazing angle - float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2]) - vec3 diffuseColor; // color contribution from diffuse lighting - vec3 specularColor; // color contribution from specular lighting -}; - -const float M_PI = 3.141592653589793; -const float c_MinRoughness = 0.04; - -const float PBR_WORKFLOW_METALLIC_ROUGHNESS = 0.0; -const float PBR_WORKFLOW_SPECULAR_GLOSINESS = 1.0f; - -#define MANUAL_SRGB 1 - -vec3 Uncharted2Tonemap(vec3 color) -{ - float A = 0.15; - float B = 0.50; - float C = 0.10; - float D = 0.20; - float E = 0.02; - float F = 0.30; - float W = 11.2; - return ((color*(A*color+C*B)+D*E)/(color*(A*color+B)+D*F))-E/F; -} - -vec4 tonemap(vec4 color) -{ - vec3 outcol = Uncharted2Tonemap(color.rgb * uboParams.exposure); - outcol = outcol * (1.0f / Uncharted2Tonemap(vec3(11.2f))); - return vec4(pow(outcol, vec3(1.0f / uboParams.gamma)), color.a); -} - -vec4 SRGBtoLINEAR(vec4 srgbIn) -{ - #ifdef MANUAL_SRGB - #ifdef SRGB_FAST_APPROXIMATION - vec3 linOut = pow(srgbIn.xyz,vec3(2.2)); - #else //SRGB_FAST_APPROXIMATION - vec3 bLess = step(vec3(0.04045),srgbIn.xyz); - vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess ); - #endif //SRGB_FAST_APPROXIMATION - return vec4(linOut,srgbIn.w);; - #else //MANUAL_SRGB - return srgbIn; - #endif //MANUAL_SRGB -} - -// Find the normal for this fragment, pulling either from a predefined normal map -// or from the interpolated mesh normal and tangent attributes. -vec3 getNormal() -{ - // Perturb normal, see http://www.thetenthplanet.de/archives/1180 - vec3 tangentNormal = texture(normalMap, material.normalTextureSet == 0 ? inUV0 : inUV1).xyz * 2.0 - 1.0; - - vec3 q1 = dFdx(inWorldPos); - vec3 q2 = dFdy(inWorldPos); - vec2 st1 = dFdx(inUV0); - vec2 st2 = dFdy(inUV0); - - vec3 N = normalize(inNormal); - vec3 T = normalize(q1 * st2.t - q2 * st1.t); - vec3 B = -normalize(cross(N, T)); - mat3 TBN = mat3(T, B, N); - - return normalize(TBN * tangentNormal); -} - -// Calculation of the lighting contribution from an optional Image Based Light source. -// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1]. -// See our README.md on Environment Maps [3] for additional discussion. -vec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection) -{ - float lod = (pbrInputs.perceptualRoughness * uboParams.prefilteredCubeMipLevels); - // retrieve a scale and bias to F0. See [1], Figure 3 - vec3 brdf = (texture(samplerBRDFLUT, vec2(pbrInputs.NdotV, 1.0 - pbrInputs.perceptualRoughness))).rgb; - vec3 diffuseLight = SRGBtoLINEAR(tonemap(texture(samplerIrradiance, n))).rgb; - - vec3 specularLight = SRGBtoLINEAR(tonemap(textureLod(prefilteredMap, reflection, lod))).rgb; - - vec3 diffuse = diffuseLight * pbrInputs.diffuseColor; - vec3 specular = specularLight * (pbrInputs.specularColor * brdf.x + brdf.y); - - // For presentation, this allows us to disable IBL terms - // For presentation, this allows us to disable IBL terms - diffuse *= uboParams.scaleIBLAmbient; - specular *= uboParams.scaleIBLAmbient; - - return diffuse + specular; -} - -// Basic Lambertian diffuse -// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog -// See also [1], Equation 1 -vec3 diffuse(PBRInfo pbrInputs) -{ - return pbrInputs.diffuseColor / M_PI; -} - -// The following equation models the Fresnel reflectance term of the spec equation (aka F()) -// Implementation of fresnel from [4], Equation 15 -vec3 specularReflection(PBRInfo pbrInputs) -{ - return pbrInputs.reflectance0 + (pbrInputs.reflectance90 - pbrInputs.reflectance0) * pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0); -} - -// This calculates the specular geometric attenuation (aka G()), -// where rougher material will reflect less light back to the viewer. -// This implementation is based on [1] Equation 4, and we adopt their modifications to -// alphaRoughness as input as originally proposed in [2]. -float geometricOcclusion(PBRInfo pbrInputs) -{ - float NdotL = pbrInputs.NdotL; - float NdotV = pbrInputs.NdotV; - float r = pbrInputs.alphaRoughness; - - float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL))); - float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV))); - return attenuationL * attenuationV; -} - -// The following equation(s) model the distribution of microfacet normals across the area being drawn (aka D()) -// Implementation from "Average Irregularity Representation of a Roughened Surface for Ray Reflection" by T. S. Trowbridge, and K. P. Reitz -// Follows the distribution function recommended in the SIGGRAPH 2013 course notes from EPIC Games [1], Equation 3. -float microfacetDistribution(PBRInfo pbrInputs) -{ - float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness; - float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0; - return roughnessSq / (M_PI * f * f); -} - -// Gets metallic factor from specular glossiness workflow inputs -float convertMetallic(vec3 diffuse, vec3 specular, float maxSpecular) { - float perceivedDiffuse = sqrt(0.299 * diffuse.r * diffuse.r + 0.587 * diffuse.g * diffuse.g + 0.114 * diffuse.b * diffuse.b); - float perceivedSpecular = sqrt(0.299 * specular.r * specular.r + 0.587 * specular.g * specular.g + 0.114 * specular.b * specular.b); - if (perceivedSpecular < c_MinRoughness) { - return 0.0; - } - float a = c_MinRoughness; - float b = perceivedDiffuse * (1.0 - maxSpecular) / (1.0 - c_MinRoughness) + perceivedSpecular - 2.0 * c_MinRoughness; - float c = c_MinRoughness - perceivedSpecular; - float D = max(b * b - 4.0 * a * c, 0.0); - return clamp((-b + sqrt(D)) / (2.0 * a), 0.0, 1.0); -} - -void main() -{ - float perceptualRoughness; - float metallic; - vec3 diffuseColor; - vec4 baseColor; - - vec3 f0 = vec3(0.04); - - if (material.alphaMask == 1.0f) { - if (material.baseColorTextureSet > -1) { - baseColor = SRGBtoLINEAR(texture(colorMap, material.baseColorTextureSet == 0 ? inUV0 : inUV1)) * material.baseColorFactor; - } else { - baseColor = material.baseColorFactor; - } - if (baseColor.a < material.alphaMaskCutoff) { - discard; - } - } - - if (material.workflow == PBR_WORKFLOW_METALLIC_ROUGHNESS) { - // Metallic and Roughness material properties are packed together - // In glTF, these factors can be specified by fixed scalar values - // or from a metallic-roughness map - perceptualRoughness = material.roughnessFactor; - metallic = material.metallicFactor; - if (material.physicalDescriptorTextureSet > -1) { - // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel. - // This layout intentionally reserves the 'r' channel for (optional) occlusion map data - vec4 mrSample = texture(physicalDescriptorMap, material.physicalDescriptorTextureSet == 0 ? inUV0 : inUV1); - perceptualRoughness = mrSample.g * perceptualRoughness; - metallic = mrSample.b * metallic; - } else { - perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0); - metallic = clamp(metallic, 0.0, 1.0); - } - // Roughness is authored as perceptual roughness; as is convention, - // convert to material roughness by squaring the perceptual roughness [2]. - - // The albedo may be defined from a base texture or a flat color - if (material.baseColorTextureSet > -1) { - baseColor = SRGBtoLINEAR(texture(colorMap, material.baseColorTextureSet == 0 ? inUV0 : inUV1)) * material.baseColorFactor; - } else { - baseColor = material.baseColorFactor; - } - } - - if (material.workflow == PBR_WORKFLOW_SPECULAR_GLOSINESS) { - // Values from specular glossiness workflow are converted to metallic roughness - if (material.physicalDescriptorTextureSet > -1) { - perceptualRoughness = 1.0 - texture(physicalDescriptorMap, material.physicalDescriptorTextureSet == 0 ? inUV0 : inUV1).a; - } else { - perceptualRoughness = 0.0; - } - - const float epsilon = 1e-6; - - vec4 diffuse = SRGBtoLINEAR(texture(colorMap, inUV0)); - vec3 specular = SRGBtoLINEAR(texture(physicalDescriptorMap, inUV0)).rgb; - - float maxSpecular = max(max(specular.r, specular.g), specular.b); - - // Convert metallic value from specular glossiness inputs - metallic = convertMetallic(diffuse.rgb, specular, maxSpecular); - - vec3 baseColorDiffusePart = diffuse.rgb * ((1.0 - maxSpecular) / (1 - c_MinRoughness) / max(1 - metallic, epsilon)) * material.diffuseFactor.rgb; - vec3 baseColorSpecularPart = specular - (vec3(c_MinRoughness) * (1 - metallic) * (1 / max(metallic, epsilon))) * material.specularFactor.rgb; - baseColor = vec4(mix(baseColorDiffusePart, baseColorSpecularPart, metallic * metallic), diffuse.a); - - } - - diffuseColor = baseColor.rgb * (vec3(1.0) - f0); - diffuseColor *= 1.0 - metallic; - - float alphaRoughness = perceptualRoughness * perceptualRoughness; - - vec3 specularColor = mix(f0, baseColor.rgb, metallic); - - // Compute reflectance. - float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b); - - // For typical incident reflectance range (between 4% to 100%) set the grazing reflectance to 100% for typical fresnel effect. - // For very low reflectance range on highly diffuse objects (below 4%), incrementally reduce grazing reflecance to 0%. - float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0); - vec3 specularEnvironmentR0 = specularColor.rgb; - vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90; - - vec3 n = (material.normalTextureSet > -1) ? getNormal() : normalize(inNormal); - vec3 v = normalize(ubo.camPos - inWorldPos); // Vector from surface point to camera - vec3 l = normalize(uboParams.lightDir.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; - - float NdotL = clamp(dot(n, l), 0.001, 1.0); - float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0); - float NdotH = clamp(dot(n, h), 0.0, 1.0); - float LdotH = clamp(dot(l, h), 0.0, 1.0); - float VdotH = clamp(dot(v, h), 0.0, 1.0); - - PBRInfo pbrInputs = PBRInfo( - NdotL, - NdotV, - NdotH, - LdotH, - VdotH, - perceptualRoughness, - metallic, - specularEnvironmentR0, - specularEnvironmentR90, - alphaRoughness, - diffuseColor, - specularColor - ); - - // Calculate the shading terms for the microfacet specular shading model - vec3 F = specularReflection(pbrInputs); - float G = geometricOcclusion(pbrInputs); - float D = microfacetDistribution(pbrInputs); - - const vec3 u_LightColor = vec3(1.0); - - // Calculation of analytical lighting contribution - vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs); - vec3 specContrib = F * G * D / (4.0 * NdotL * NdotV); - // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law) - vec3 color = NdotL * u_LightColor * (diffuseContrib + specContrib); - - // Calculate lighting contribution from image based lighting source (IBL) - color += getIBLContribution(pbrInputs, n, reflection); - - const float u_OcclusionStrength = 1.0f; - // Apply optional PBR terms for additional (optional) shading - if (material.occlusionTextureSet > -1) { - float ao = texture(aoMap, (material.occlusionTextureSet == 0 ? inUV0 : inUV1)).r; - color = mix(color, color * ao, u_OcclusionStrength); - } - - const float u_EmissiveFactor = 1.0f; - if (material.emissiveTextureSet > -1) { - vec3 emissive = SRGBtoLINEAR(texture(emissiveMap, material.emissiveTextureSet == 0 ? inUV0 : inUV1)).rgb * u_EmissiveFactor; - color += emissive; - } - - outColor = vec4(color, baseColor.a); - - // Shader inputs debug visualization - if (uboParams.debugViewInputs > 0.0) { - int index = int(uboParams.debugViewInputs); - switch (index) { - case 1: - outColor.rgba = material.baseColorTextureSet > -1 ? texture(colorMap, material.baseColorTextureSet == 0 ? inUV0 : inUV1) : vec4(1.0f); - break; - case 2: - outColor.rgb = (material.normalTextureSet > -1) ? texture(normalMap, material.normalTextureSet == 0 ? inUV0 : inUV1).rgb : normalize(inNormal); - break; - case 3: - outColor.rgb = (material.occlusionTextureSet > -1) ? texture(aoMap, material.occlusionTextureSet == 0 ? inUV0 : inUV1).rrr : vec3(0.0f); - break; - case 4: - outColor.rgb = (material.emissiveTextureSet > -1) ? texture(emissiveMap, material.emissiveTextureSet == 0 ? inUV0 : inUV1).rgb : vec3(0.0f); - break; - case 5: - outColor.rgb = texture(physicalDescriptorMap, inUV0).bbb; - break; - case 6: - outColor.rgb = texture(physicalDescriptorMap, inUV0).ggg; - break; - } - outColor = SRGBtoLINEAR(outColor); - } - - // PBR equation debug visualization - // "none", "Diff (l,n)", "F (l,h)", "G (l,v,h)", "D (h)", "Specular" - if (uboParams.debugViewEquation > 0.0) { - int index = int(uboParams.debugViewEquation); - switch (index) { - case 1: - outColor.rgb = diffuseContrib; - break; - case 2: - outColor.rgb = F; - break; - case 3: - outColor.rgb = vec3(G); - break; - case 4: - outColor.rgb = vec3(D); - break; - case 5: - outColor.rgb = specContrib; - break; - } - } - -} diff --git a/samples/Pbr/shaders/pbrtest.frag b/samples/Pbr/shaders/pbrtest.frag deleted file mode 100644 index 4325601..0000000 --- a/samples/Pbr/shaders/pbrtest.frag +++ /dev/null @@ -1,193 +0,0 @@ -#version 450 - -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable - -layout (binding = 0) uniform UBO -{ - mat4 projectionMatrix; - mat4 viewMatrix; - mat4 modelMatrix; - vec4 lightPos; - float gamma; - float exposure; -} ubo; - -layout (set = 0, binding = 1) uniform samplerCube samplerCubemap; - -layout (set = 1, binding = 0) uniform sampler2D samplerColor; -layout (set = 1, binding = 1) uniform sampler2D samplerNormal; -layout (set = 1, binding = 2) uniform sampler2D samplerOcclusion; -layout (set = 1, binding = 3) uniform sampler2D samplerMetalRoughness; -layout (set = 1, binding = 4) uniform sampler2D samplerEmissive; - -layout (location = 0) in vec2 inUV; -layout (location = 1) in vec3 inN; -layout (location = 2) in vec3 inV; -layout (location = 3) in vec3 inWorldPos; - -layout (location = 0) out vec4 outFragColor; - -layout(push_constant) uniform PushConsts { - layout(offset = 64) - vec4 baseColorFactor; - vec4 emissiveFactor; - uint availableAttachments; - uint alphaMode; - float alphaCutoff; - float metallicFactor; - float roughnessFactor; -} pc; - -const uint MAP_COLOR = 0x1; -const uint MAP_NORMAL = 0x2; -const uint MAP_AO = 0x4; -const uint MAP_METAL = 0x8; -const uint MAP_ROUGHNESS = 0x16; -const uint MAP_METALROUGHNESS = 0x32; -const uint MAP_EMISSIVE = 0x64; - -const float PI = 3.141592653589793; - -// From http://filmicgames.com/archives/75 -vec3 Uncharted2Tonemap(vec3 x) -{ - float A = 0.15; - float B = 0.50; - float C = 0.10; - float D = 0.20; - float E = 0.02; - float F = 0.30; - return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F; -} - -// Normal Distribution function -------------------------------------- -float D_GGX(float dotNH, float roughness) -{ - float alpha = roughness * roughness; - float alpha2 = alpha * alpha; - float denom = dotNH * dotNH * (alpha2 - 1.0) + 1.0; - return (alpha2)/(PI * denom*denom); -} - -// Geometric Shadowing function -------------------------------------- -float G_SchlicksmithGGX(float dotNL, float dotNV, float roughness) -{ - float r = (roughness + 1.0); - float k = (r*r) / 8.0; - float GL = dotNL / (dotNL * (1.0 - k) + k); - float GV = dotNV / (dotNV * (1.0 - k) + k); - return GL * GV; -} - -// Fresnel function ---------------------------------------------------- -vec3 F_Schlick(float cosTheta, vec3 F0) -{ - return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0); -} -vec3 F_SchlickR(float cosTheta, vec3 F0, float roughness) -{ - return F0 + (max(vec3(1.0 - roughness), F0) - F0) * pow(1.0 - cosTheta, 5.0); -} - -vec3 specularContribution(vec3 L, vec3 V, vec3 N, vec3 F0, float metallic, float roughness, vec3 albedo) -{ - // Precalculate vectors and dot products - vec3 H = normalize (V + L); - float dotNH = clamp(dot(N, H), 0.0, 1.0); - float dotNV = clamp(dot(N, V), 0.0, 1.0); - float dotNL = clamp(dot(N, L), 0.0, 1.0); - - // Light color fixed - vec3 lightColor = vec3(1.0); - - vec3 color = vec3(0.0); - - if (dotNL > 0.0) { - // D = Normal distribution (Distribution of the microfacets) - float D = D_GGX(dotNH, roughness); - // G = Geometric shadowing term (Microfacets shadowing) - float G = G_SchlicksmithGGX(dotNL, dotNV, roughness); - // F = Fresnel factor (Reflectance depending on angle of incidence) - vec3 F = F_Schlick(dotNV, F0); - vec3 spec = D * F * G / (4.0 * dotNL * dotNV + 0.001); - vec3 kD = (vec3(1.0) - F) * (1.0 - metallic); - color += (kD * albedo / PI + spec) * dotNL; - } - - return color; -} - -// See http://www.thetenthplanet.de/archives/1180 -vec3 perturbNormal(vec3 inNormal, vec3 tangentNormal) -{ - - - vec3 q1 = dFdx(inWorldPos); - vec3 q2 = dFdy(inWorldPos); - vec2 st1 = dFdx(inUV); - vec2 st2 = dFdy(inUV); - - vec3 N = normalize(inNormal); - vec3 T = normalize(q1 * st2.t - q2 * st1.t); - vec3 B = -normalize(cross(N, T)); - mat3 TBN = mat3(T, B, N); - - return normalize(TBN * tangentNormal); -} -void main() -{ - vec3 emit = vec3(0); - vec4 base_color = pc.baseColorFactor; - float rough = pc.roughnessFactor; - float metallic = pc.metallicFactor; - - if ((pc.availableAttachments & MAP_COLOR) == MAP_COLOR) - base_color *= texture(samplerColor, inUV); - if ((pc.availableAttachments & MAP_METALROUGHNESS) == MAP_METALROUGHNESS) { - rough *= clamp(texture(samplerMetalRoughness, inUV).g, 0.04, 1.0); - metallic *= texture(samplerMetalRoughness, inUV).b; - } - if ((pc.availableAttachments & MAP_EMISSIVE) == MAP_EMISSIVE) - emit = pc.emissiveFactor.rgb * texture(samplerEmissive, inUV).rgb; - - - vec3 N = ((pc.availableAttachments & MAP_NORMAL) == MAP_NORMAL) ? - perturbNormal(inN, texture(samplerNormal, inUV).xyz * 2.0 - 1.0) : - normalize(inN); - vec3 V = normalize(inV); - vec3 R = -normalize(reflect(V, N)); - - vec3 F0 = vec3(0.04); - F0 = mix(F0, base_color.rgb, metallic); - float alpha = pow(rough, 2.0); - - vec3 L = normalize(ubo.lightPos.xyz); - vec3 Lo = specularContribution(L, V, N, F0, metallic, rough, base_color.rgb); - - vec3 reflection = texture(samplerCubemap, R).rgb * (1.0-rough);//vec3(rough); - vec3 irradiance = vec3(0.8);//texture(samplerIrradiance, N).rgb; - - // Diffuse based on irradiance - vec3 diffuse = irradiance * base_color.rgb; - - vec3 F = F_SchlickR(max(dot(N, V), 0.0), F0, rough); - - vec3 specular = reflection * F;//(F * brdf.x + brdf.y); - - // Ambient part - vec3 kD = 1.0 - F; - kD *= 1.0 - metallic; - - float ao = ((pc.availableAttachments & MAP_AO) == MAP_AO) ? texture(samplerOcclusion, inUV).r : 1.0f; - vec3 ambient = (kD * diffuse + specular) * ao; - vec3 color = ambient + Lo; - - // Tone mapping - color = Uncharted2Tonemap(color * ubo.exposure); - color = color * (1.0f / Uncharted2Tonemap(vec3(11.2f))); - // Gamma correction - color = pow(color, vec3(1.0f / ubo.gamma)) + emit; - - outFragColor = vec4(color , base_color.a); -} \ No newline at end of file diff --git a/samples/Pbr/shaders/pbrtest.vert b/samples/Pbr/shaders/pbrtest.vert deleted file mode 100644 index 25907bb..0000000 --- a/samples/Pbr/shaders/pbrtest.vert +++ /dev/null @@ -1,49 +0,0 @@ -#version 450 - -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable - -layout (location = 0) in vec3 inPos; -layout (location = 1) in vec3 inNormal; -layout (location = 2) in vec2 inUV; - -layout (binding = 0) uniform UBO -{ - mat4 projectionMatrix; - mat4 viewMatrix; - mat4 modelMatrix; - vec4 lightPos; - float gamma; - float exposure; -} ubo; - -layout (location = 0) out vec2 outUV; -layout (location = 1) out vec3 outN; -layout (location = 2) out vec3 outV;//ViewDir -layout (location = 3) out vec3 outWorldPos; - -out gl_PerVertex -{ - vec4 gl_Position; -}; - -layout(push_constant) uniform PushConsts { - mat4 model; -} pc; - -void main() -{ - outUV = inUV; - - mat4 mod = ubo.modelMatrix * pc.model; - vec4 pos = mod * vec4(inPos.xyz, 1.0); - - outN = normalize(transpose(inverse(mat3(mod))) * inNormal); - //outN = normalize(mat3(mod)* inNormal); - - mat4 viewInv = inverse(ubo.viewMatrix); - //outV = -(ubo.viewMatrix * pos).xyz; - outV = normalize(vec3(viewInv * vec4(0.0, 0.0, 0.0, 1.0) - pos)); - outWorldPos = pos.xyz; - gl_Position = ubo.projectionMatrix * ubo.viewMatrix * pos; -} diff --git a/samples/Pbr/shaders/prefilterenvmap.frag b/samples/Pbr/shaders/prefilterenvmap.frag deleted file mode 100644 index ae1212e..0000000 --- a/samples/Pbr/shaders/prefilterenvmap.frag +++ /dev/null @@ -1,105 +0,0 @@ -#version 450 - -layout (location = 0) in vec3 inPos; -layout (location = 0) out vec4 outColor; - -layout (binding = 0) uniform samplerCube samplerEnv; - -layout(push_constant) uniform PushConsts { - layout (offset = 64) float roughness; - layout (offset = 68) uint numSamples; -} consts; - -const float PI = 3.1415926536; - -// Based omn http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/ -float random(vec2 co) -{ - float a = 12.9898; - float b = 78.233; - float c = 43758.5453; - float dt= dot(co.xy ,vec2(a,b)); - float sn= mod(dt,3.14); - return fract(sin(sn) * c); -} - -vec2 hammersley2d(uint i, uint N) -{ - // Radical inverse based on http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html - uint bits = (i << 16u) | (i >> 16u); - bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u); - bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u); - bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u); - bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u); - float rdi = float(bits) * 2.3283064365386963e-10; - return vec2(float(i) /float(N), rdi); -} - -// Based on http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_slides.pdf -vec3 importanceSample_GGX(vec2 Xi, float roughness, vec3 normal) -{ - // Maps a 2D point to a hemisphere with spread based on roughness - float alpha = roughness * roughness; - float phi = 2.0 * PI * Xi.x + random(normal.xz) * 0.1; - float cosTheta = sqrt((1.0 - Xi.y) / (1.0 + (alpha*alpha - 1.0) * Xi.y)); - float sinTheta = sqrt(1.0 - cosTheta * cosTheta); - vec3 H = vec3(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta); - - // Tangent space - vec3 up = abs(normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0); - vec3 tangentX = normalize(cross(up, normal)); - vec3 tangentY = normalize(cross(normal, tangentX)); - - // Convert to world Space - return normalize(tangentX * H.x + tangentY * H.y + normal * H.z); -} - -// Normal Distribution function -float D_GGX(float dotNH, float roughness) -{ - float alpha = roughness * roughness; - float alpha2 = alpha * alpha; - float denom = dotNH * dotNH * (alpha2 - 1.0) + 1.0; - return (alpha2)/(PI * denom*denom); -} - -vec3 prefilterEnvMap(vec3 R, float roughness) -{ - vec3 N = R; - vec3 V = R; - vec3 color = vec3(0.0); - float totalWeight = 0.0; - float envMapDim = float(textureSize(samplerEnv, 0).s); - for(uint i = 0u; i < consts.numSamples; i++) { - vec2 Xi = hammersley2d(i, consts.numSamples); - vec3 H = importanceSample_GGX(Xi, roughness, N); - vec3 L = 2.0 * dot(V, H) * H - V; - float dotNL = clamp(dot(N, L), 0.0, 1.0); - if(dotNL > 0.0) { - // Filtering based on https://placeholderart.wordpress.com/2015/07/28/implementation-notes-runtime-environment-map-filtering-for-image-based-lighting/ - - float dotNH = clamp(dot(N, H), 0.0, 1.0); - float dotVH = clamp(dot(V, H), 0.0, 1.0); - - // Probability Distribution Function - float pdf = D_GGX(dotNH, roughness) * dotNH / (4.0 * dotVH) + 0.0001; - // Slid angle of current smple - float omegaS = 1.0 / (float(consts.numSamples) * pdf); - // Solid angle of 1 pixel across all cube faces - float omegaP = 4.0 * PI / (6.0 * envMapDim * envMapDim); - // Biased (+1.0) mip level for better result - float mipLevel = roughness == 0.0 ? 0.0 : max(0.5 * log2(omegaS / omegaP) + 1.0, 0.0f); - color += textureLod(samplerEnv, L, mipLevel).rgb * dotNL; - totalWeight += dotNL; - - } - } - return (color / totalWeight); -} - - -void main() -{ - vec3 N = normalize(inPos); - outColor = vec4(prefilterEnvMap(N, consts.roughness), 1.0); -} diff --git a/samples/Pbr/shaders/skybox.frag b/samples/Pbr/shaders/skybox.frag deleted file mode 100644 index fa10f82..0000000 --- a/samples/Pbr/shaders/skybox.frag +++ /dev/null @@ -1,15 +0,0 @@ -#version 450 - -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable - -layout (binding = 1) uniform samplerCube skybox; - -layout (location = 0) in vec3 TexCoords; - -layout (location = 0) out vec4 outFragColor; - -void main() -{ - outFragColor = texture(skybox, TexCoords); -} diff --git a/samples/Pbr/shaders/skybox.vert b/samples/Pbr/shaders/skybox.vert deleted file mode 100644 index 1925ec9..0000000 --- a/samples/Pbr/shaders/skybox.vert +++ /dev/null @@ -1,30 +0,0 @@ -#version 450 - -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable - -layout (location = 0) in vec3 inPos; -layout (location = 1) in vec2 inUV; - -layout (location = 0) out vec3 outUVW; - -layout (binding = 0) uniform UBO -{ - mat4 projection; - mat4 view; - mat4 model; - vec4 lightPos; - float gamma; - float exposure; -} ubo; - -out gl_PerVertex -{ - vec4 gl_Position; -}; - -void main() -{ - outUVW = inPos; - gl_Position = ubo.projection * ubo.view * vec4(inPos, 1.0); -} diff --git a/samples/Pbr/shaders/skybox_sw.frag b/samples/Pbr/shaders/skybox_sw.frag deleted file mode 100644 index a861ec4..0000000 --- a/samples/Pbr/shaders/skybox_sw.frag +++ /dev/null @@ -1,55 +0,0 @@ -#version 450 - -layout (binding = 2) uniform samplerCube samplerEnv; - -layout (location = 0) in vec3 inUVW; -layout (location = 0) out vec4 outColor; - -layout (set = 0, binding = 1) uniform UBOParams { - vec4 _pad0; - float exposure; - float gamma; -} uboParams; - -// From http://filmicworlds.com/blog/filmic-tonemapping-operators/ -vec3 Uncharted2Tonemap(vec3 color) -{ - float A = 0.15; - float B = 0.50; - float C = 0.10; - float D = 0.20; - float E = 0.02; - float F = 0.30; - float W = 11.2; - return ((color*(A*color+C*B)+D*E)/(color*(A*color+B)+D*F))-E/F; -} - -vec4 tonemap(vec4 color) -{ - vec3 outcol = Uncharted2Tonemap(color.rgb * uboParams.exposure); - outcol = outcol * (1.0f / Uncharted2Tonemap(vec3(11.2f))); - return vec4(pow(outcol, vec3(1.0f / uboParams.gamma)), color.a); -} - -#define MANUAL_SRGB 1 - -vec4 SRGBtoLINEAR(vec4 srgbIn) -{ - #ifdef MANUAL_SRGB - #ifdef SRGB_FAST_APPROXIMATION - vec3 linOut = pow(srgbIn.xyz,vec3(2.2)); - #else //SRGB_FAST_APPROXIMATION - vec3 bLess = step(vec3(0.04045),srgbIn.xyz); - vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess ); - #endif //SRGB_FAST_APPROXIMATION - return vec4(linOut,srgbIn.w);; - #else //MANUAL_SRGB - return srgbIn; - #endif //MANUAL_SRGB -} - -void main() -{ - vec3 color = SRGBtoLINEAR(tonemap(textureLod(samplerEnv, inUVW, 1.5))).rgb; - outColor = vec4(color * 1.0, 1.0); -} \ No newline at end of file diff --git a/samples/Pbr/shaders/skybox_sw.vert b/samples/Pbr/shaders/skybox_sw.vert deleted file mode 100644 index c51c4b5..0000000 --- a/samples/Pbr/shaders/skybox_sw.vert +++ /dev/null @@ -1,28 +0,0 @@ -#version 450 - -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable - -layout (location = 0) in vec3 inPos; -layout (location = 1) in vec3 inNormal; -layout (location = 2) in vec2 inUV; - -layout (binding = 0) uniform UBO -{ - mat4 projection; - mat4 pad; - mat4 model; -} ubo; - -layout (location = 0) out vec3 outUVW; - -out gl_PerVertex -{ - vec4 gl_Position; -}; - -void main() -{ - outUVW = inPos; - gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0); -} diff --git a/samples/Pbr/shaders/ui.frag b/samples/Pbr/shaders/ui.frag deleted file mode 100644 index e0d7995..0000000 --- a/samples/Pbr/shaders/ui.frag +++ /dev/null @@ -1,13 +0,0 @@ -#version 450 - -layout (binding = 0) uniform sampler2D fontSampler; - -layout (location = 0) in vec2 inUV; -layout (location = 1) in vec4 inColor; - -layout (location = 0) out vec4 outColor; - -void main() -{ - outColor = inColor * texture(fontSampler, inUV); -} \ No newline at end of file diff --git a/samples/Pbr/shaders/ui.vert b/samples/Pbr/shaders/ui.vert deleted file mode 100644 index ddb63a4..0000000 --- a/samples/Pbr/shaders/ui.vert +++ /dev/null @@ -1,25 +0,0 @@ -#version 450 - -layout (location = 0) in vec2 inPos; -layout (location = 1) in vec2 inUV; -layout (location = 2) in vec4 inColor; - -layout (push_constant) uniform PushConstants { - vec2 scale; - vec2 translate; -} pushConstants; - -layout (location = 0) out vec2 outUV; -layout (location = 1) out vec4 outColor; - -out gl_PerVertex -{ - vec4 gl_Position; -}; - -void main() -{ - outUV = inUV; - outColor = inColor; - gl_Position = vec4(inPos * pushConstants.scale + pushConstants.translate, 0.0, 1.0); -} \ No newline at end of file diff --git a/samples/Textured/Textured.csproj b/samples/Textured/Textured.csproj index a7ab317..350058d 100644 --- a/samples/Textured/Textured.csproj +++ b/samples/Textured/Textured.csproj @@ -28,11 +28,11 @@ - ..\..\packages\Vulkan.0.1.2.5-alpha\lib\netstandard2.0\VK.dll + ..\..\packages\Vulkan.0.1.2.6\lib\netstandard2.0\VK.dll - + {32B7E80D-BEA7-4811-B82D-CC2533069F0A} CVKL diff --git a/samples/Textured/packages.config b/samples/Textured/packages.config index eef242f..4953cd2 100644 --- a/samples/Textured/packages.config +++ b/samples/Textured/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/samples/TexturedCube/TexturedCube.csproj b/samples/TexturedCube/TexturedCube.csproj index b7ab186..2274e52 100644 --- a/samples/TexturedCube/TexturedCube.csproj +++ b/samples/TexturedCube/TexturedCube.csproj @@ -33,14 +33,14 @@ - + + + + {32B7E80D-BEA7-4811-B82D-CC2533069F0A} CVKL - - - diff --git a/samples/Triangle/Triangle.csproj b/samples/Triangle/Triangle.csproj index 2240438..5039c7e 100644 --- a/samples/Triangle/Triangle.csproj +++ b/samples/Triangle/Triangle.csproj @@ -47,7 +47,7 @@ - + {32B7E80D-BEA7-4811-B82D-CC2533069F0A} CVKL diff --git a/samples/VkvgCrowTest/PbrPipeline.cs b/samples/VkvgCrowTest/PbrPipeline.cs index f2811d1..f285f8a 100644 --- a/samples/VkvgCrowTest/PbrPipeline.cs +++ b/samples/VkvgCrowTest/PbrPipeline.cs @@ -92,7 +92,7 @@ namespace CVKL { VK.AttachmentType.Color, VK.AttachmentType.Normal, VK.AttachmentType.AmbientOcclusion, - VK.AttachmentType.MetalRoughness, + VK.AttachmentType.PhysicalProps, VK.AttachmentType.Emissive); } diff --git a/samples/deferred/PbrPipeline.cs b/samples/deferred/PbrPipeline.cs index 04f97da..61122be 100644 --- a/samples/deferred/PbrPipeline.cs +++ b/samples/deferred/PbrPipeline.cs @@ -92,7 +92,7 @@ namespace CVKL { VK.AttachmentType.Color, VK.AttachmentType.Normal, VK.AttachmentType.AmbientOcclusion, - VK.AttachmentType.MetalRoughness, + VK.AttachmentType.PhysicalProps, VK.AttachmentType.Emissive); } diff --git a/samples/deferred/deferred.csproj b/samples/deferred/deferred.csproj index 0a98f73..a6236ba 100644 --- a/samples/deferred/deferred.csproj +++ b/samples/deferred/deferred.csproj @@ -57,14 +57,14 @@ ..\..\packages\vkvg.net.0.2.0\lib\netstandard2.0\vkvg.net.dll - ..\..\packages\Vulkan.0.1.2.5-alpha\lib\netstandard2.0\VK.dll + ..\..\packages\Vulkan.0.1.2.6\lib\netstandard2.0\VK.dll - + {32B7E80D-BEA7-4811-B82D-CC2533069F0A} CVKL diff --git a/samples/deferred/main.cs b/samples/deferred/main.cs index a2bb9c1..b3781d5 100644 --- a/samples/deferred/main.cs +++ b/samples/deferred/main.cs @@ -174,7 +174,7 @@ namespace deferred { VK.AttachmentType.Color, VK.AttachmentType.Normal, VK.AttachmentType.AmbientOcclusion, - VK.AttachmentType.MetalRoughness, + VK.AttachmentType.PhysicalProps, VK.AttachmentType.Emissive); } diff --git a/samples/deferred/mainShadow.cs b/samples/deferred/mainShadow.cs index 02df530..0bc3103 100644 --- a/samples/deferred/mainShadow.cs +++ b/samples/deferred/mainShadow.cs @@ -215,7 +215,7 @@ namespace deferredShadow { VK.AttachmentType.Color, VK.AttachmentType.Normal, VK.AttachmentType.AmbientOcclusion, - VK.AttachmentType.MetalRoughness, + VK.AttachmentType.PhysicalProps, VK.AttachmentType.Emissive); } diff --git a/samples/deferred/mainWithDebugDrawer.cs b/samples/deferred/mainWithDebugDrawer.cs index 1dfc768..7611e0d 100644 --- a/samples/deferred/mainWithDebugDrawer.cs +++ b/samples/deferred/mainWithDebugDrawer.cs @@ -209,7 +209,7 @@ namespace deferredDebug { VK.AttachmentType.Color, VK.AttachmentType.Normal, VK.AttachmentType.AmbientOcclusion, - VK.AttachmentType.MetalRoughness, + VK.AttachmentType.PhysicalProps, VK.AttachmentType.Emissive); } diff --git a/samples/deferred/modelWithVkvgStats.cs b/samples/deferred/modelWithVkvgStats.cs index 41fceb4..f4ea123 100644 --- a/samples/deferred/modelWithVkvgStats.cs +++ b/samples/deferred/modelWithVkvgStats.cs @@ -122,7 +122,7 @@ namespace modelWithVkvgStats { VK.AttachmentType.Color, VK.AttachmentType.Normal, VK.AttachmentType.AmbientOcclusion, - VK.AttachmentType.MetalRoughness, + VK.AttachmentType.PhysicalProps, VK.AttachmentType.Emissive); } diff --git a/samples/deferred/packages.config b/samples/deferred/packages.config index 069f5cc..55ba896 100644 --- a/samples/deferred/packages.config +++ b/samples/deferred/packages.config @@ -7,5 +7,5 @@ - + \ No newline at end of file diff --git a/samples/pbrSashaWillem/EnvironmentPipeline.cs b/samples/pbrSashaWillem/EnvironmentPipeline.cs index 5ad2e7d..d775500 100644 --- a/samples/pbrSashaWillem/EnvironmentPipeline.cs +++ b/samples/pbrSashaWillem/EnvironmentPipeline.cs @@ -33,6 +33,7 @@ namespace CVKL { cubemap.CreateView (VkImageViewType.Cube, VkImageAspectFlags.Color, 6, 0, cubemap.CreateInfo.mipLevels); cubemap.CreateSampler (VkSamplerAddressMode.ClampToEdge); cubemap.SetName ("skybox Texture"); + cubemap.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal; GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, renderPass.Samples, false); cfg.RenderPass = renderPass; diff --git a/samples/pbrSashaWillem/PbrModel.cs b/samples/pbrSashaWillem/PbrModel.cs index 7b9fb9a..04a03dc 100644 --- a/samples/pbrSashaWillem/PbrModel.cs +++ b/samples/pbrSashaWillem/PbrModel.cs @@ -60,17 +60,13 @@ namespace CVKL { public Vector4 diffuseFactor; public Vector4 specularFactor; public float workflow; - public int baseColorTextureSet; - public int physicalDescriptorTextureSet; - public int normalTextureSet; - public int occlusionTextureSet; - public int emissiveTextureSet; + public AttachmentType TexCoord0; + public AttachmentType TexCoord1; public float metallicFactor; public float roughnessFactor; public float alphaMask; public float alphaMaskCutoff; int pad0; - int pad1; } Image[] textures; @@ -148,18 +144,19 @@ namespace CVKL { for (int i = 0; i < mats.Length; i++) { materials[i] = new PbrMaterial { + workflow = (float)mats[i].workflow, baseColorFactor = mats[i].baseColorFactor, emissiveFactor = mats[i].emissiveFactor, metallicFactor = mats[i].metallicFactor, roughnessFactor = mats[i].roughnessFactor, + TexCoord0 = mats[i].availableAttachments, + TexCoord1 = mats[i].availableAttachments1, alphaMask = 0f, alphaMaskCutoff = 0.0f, diffuseFactor = new Vector4(0), specularFactor = new Vector4 (0) }; - materials[i].workflow = 0; - descriptorSets[i] = descriptorPool.Allocate (layout); descriptorSets[i].Handle.SetDebugMarkerName (dev, "descSet " + mats[i].Name); @@ -173,43 +170,28 @@ namespace CVKL { case AttachmentType.None: break; case AttachmentType.Color: - if (mats[i].availableAttachments.HasFlag (AttachmentType.Color)) { + if (mats[i].availableAttachments.HasFlag (AttachmentType.Color)) uboUpdate.AddWriteInfo (descriptorSets[i], dslb, textures[(int)mats[i].baseColorTexture].Descriptor); - materials[i].baseColorTextureSet = mats[i].texCoordSets.baseColor; - } else - materials[i].baseColorTextureSet = -1; break; case AttachmentType.Normal: - if (mats[i].availableAttachments.HasFlag (AttachmentType.Normal)){ + if (mats[i].availableAttachments.HasFlag (AttachmentType.Normal)) uboUpdate.AddWriteInfo (descriptorSets[i], dslb, textures[(int)mats[i].normalTexture].Descriptor); - materials[i].normalTextureSet = mats[i].texCoordSets.normal; - } else - materials[i].normalTextureSet = -1; break; case AttachmentType.AmbientOcclusion: - if (mats[i].availableAttachments.HasFlag (AttachmentType.AmbientOcclusion)){ + if (mats[i].availableAttachments.HasFlag (AttachmentType.AmbientOcclusion)) uboUpdate.AddWriteInfo (descriptorSets[i], dslb, textures[(int)mats[i].occlusionTexture].Descriptor); - materials[i].occlusionTextureSet = mats[i].texCoordSets.occlusion; - } else - materials[i].occlusionTextureSet = -1; break; - case AttachmentType.MetalRoughness: - if (mats[i].availableAttachments.HasFlag (AttachmentType.MetalRoughness)){ + case AttachmentType.PhysicalProps: + if (mats[i].availableAttachments.HasFlag (AttachmentType.PhysicalProps)) uboUpdate.AddWriteInfo (descriptorSets[i], dslb, textures[(int)mats[i].metallicRoughnessTexture].Descriptor); - materials[i].physicalDescriptorTextureSet = mats[i].texCoordSets.metallicRoughness; - } else - materials[i].physicalDescriptorTextureSet = -1; break; case AttachmentType.Metal: break; case AttachmentType.Roughness: break; case AttachmentType.Emissive: - if (mats[i].availableAttachments.HasFlag (AttachmentType.Emissive)){ + if (mats[i].availableAttachments.HasFlag (AttachmentType.Emissive)) uboUpdate.AddWriteInfo (descriptorSets[i], dslb, textures[(int)mats[i].emissiveTexture].Descriptor); - materials[i].emissiveTextureSet = mats[i].texCoordSets.emissive; - } else - materials[i].emissiveTextureSet = -1; break; } } diff --git a/samples/pbrSashaWillem/PbrPipeline.cs b/samples/pbrSashaWillem/PbrPipeline.cs index a7b8a16..8341b26 100644 --- a/samples/pbrSashaWillem/PbrPipeline.cs +++ b/samples/pbrSashaWillem/PbrPipeline.cs @@ -122,7 +122,7 @@ namespace CVKL { model = new PbrModel2 (staggingQ, modelPathes[0], descLayoutTextures, AttachmentType.Color, - AttachmentType.MetalRoughness, + AttachmentType.PhysicalProps, AttachmentType.Normal, AttachmentType.AmbientOcclusion, AttachmentType.Emissive); diff --git a/samples/pbrSashaWillem/main.cs b/samples/pbrSashaWillem/main.cs index bbcaba1..f418cca 100644 --- a/samples/pbrSashaWillem/main.cs +++ b/samples/pbrSashaWillem/main.cs @@ -21,7 +21,7 @@ namespace pbrSachaWillem { //features.samplerAnisotropy = true; } - VkSampleCountFlags samples = VkSampleCountFlags.SampleCount8; + VkSampleCountFlags samples = VkSampleCountFlags.SampleCount4; Framebuffer[] frameBuffers; PBRPipeline pbrPipeline; diff --git a/samples/pbrSashaWillem/shaders/pbr_khr.frag b/samples/pbrSashaWillem/shaders/pbr_khr.frag index 148dca3..3dd1963 100644 --- a/samples/pbrSashaWillem/shaders/pbr_khr.frag +++ b/samples/pbrSashaWillem/shaders/pbr_khr.frag @@ -35,19 +35,23 @@ struct Material { vec4 diffuseFactor; vec4 specularFactor; float workflow; - int baseColorTextureSet; - int physicalDescriptorTextureSet; - int normalTextureSet; - int occlusionTextureSet; - int emissiveTextureSet; + uint tex0; + uint tex1; float metallicFactor; float roughnessFactor; float alphaMask; float alphaMaskCutoff; int pad0; - int pad1; }; +const uint MAP_COLOR = 0x1; +const uint MAP_NORMAL = 0x2; +const uint MAP_AO = 0x4; +const uint MAP_METAL = 0x8; +const uint MAP_ROUGHNESS = 0x10; +const uint MAP_METALROUGHNESS = 0x20; +const uint MAP_EMISSIVE = 0x40; + layout (set = 0, binding = 5) uniform UBOMaterials { Material materials[16]; }; @@ -94,8 +98,8 @@ struct PBRInfo const float M_PI = 3.141592653589793; const float c_MinRoughness = 0.04; -const float PBR_WORKFLOW_METALLIC_ROUGHNESS = 0.0; -const float PBR_WORKFLOW_SPECULAR_GLOSINESS = 1.0f; +const float PBR_WORKFLOW_METALLIC_ROUGHNESS = 1.0; +const float PBR_WORKFLOW_SPECULAR_GLOSINESS = 2.0f; #define MANUAL_SRGB 1 @@ -137,9 +141,15 @@ vec4 SRGBtoLINEAR(vec4 srgbIn) // or from the interpolated mesh normal and tangent attributes. vec3 getNormal() { + vec3 tangentNormal; // Perturb normal, see http://www.thetenthplanet.de/archives/1180 - vec3 tangentNormal = texture(normalMap, materials[materialIdx].normalTextureSet == 0 ? inUV0 : inUV1).xyz * 2.0 - 1.0; - + if ((materials[materialIdx].tex0 & MAP_NORMAL) == MAP_NORMAL) + tangentNormal = texture(normalMap, inUV0).xyz * 2.0 - 1.0; + else if ((materials[materialIdx].tex1 & MAP_NORMAL) == MAP_NORMAL) + tangentNormal = texture(normalMap, inUV1).xyz * 2.0 - 1.0; + else + return normalize(inNormal); + vec3 q1 = dFdx(inWorldPos); vec3 q2 = dFdy(inWorldPos); vec2 st1 = dFdx(inUV0); @@ -235,55 +245,47 @@ void main() float perceptualRoughness; float metallic; vec3 diffuseColor; - vec4 baseColor; + vec4 baseColor; vec3 f0 = vec3(0.04); - - if (materials[materialIdx].alphaMask == 1.0f) { - if (materials[materialIdx].baseColorTextureSet > -1) { - baseColor = SRGBtoLINEAR(texture(colorMap, materials[materialIdx].baseColorTextureSet == 0 ? inUV0 : inUV1)) * materials[materialIdx].baseColorFactor; - } else { - baseColor = materials[materialIdx].baseColorFactor; - } - if (baseColor.a < materials[materialIdx].alphaMaskCutoff) { - discard; - } - } - + + baseColor = materials[materialIdx].baseColorFactor; + if (materials[materialIdx].workflow == PBR_WORKFLOW_METALLIC_ROUGHNESS) { - // Metallic and Roughness material properties are packed together - // In glTF, these factors can be specified by fixed scalar values - // or from a metallic-roughness map perceptualRoughness = materials[materialIdx].roughnessFactor; - metallic = materials[materialIdx].metallicFactor; - if (materials[materialIdx].physicalDescriptorTextureSet > -1) { - // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel. - // This layout intentionally reserves the 'r' channel for (optional) occlusion map data - vec4 mrSample = texture(physicalDescriptorMap, materials[materialIdx].physicalDescriptorTextureSet == 0 ? inUV0 : inUV1); - perceptualRoughness = mrSample.g * perceptualRoughness; - metallic = mrSample.b * metallic; - } else { - perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0); - metallic = clamp(metallic, 0.0, 1.0); - } - // Roughness is authored as perceptual roughness; as is convention, - // convert to material roughness by squaring the perceptual roughness [2]. + metallic = materials[materialIdx].metallicFactor; + // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel. + // This layout intentionally reserves the 'r' channel for (optional) occlusion map data + if ((materials[materialIdx].tex0 & MAP_METALROUGHNESS) == MAP_METALROUGHNESS){ + perceptualRoughness *= texture(physicalDescriptorMap, inUV0).g; + metallic *= texture(physicalDescriptorMap, inUV0).b; + }else if ((materials[materialIdx].tex1 & MAP_METALROUGHNESS) == MAP_METALROUGHNESS){ + perceptualRoughness *= texture(physicalDescriptorMap, inUV1).g; + metallic *= texture(physicalDescriptorMap, inUV1).b; + } + perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0); + metallic = clamp(metallic, 0.0, 1.0); // The albedo may be defined from a base texture or a flat color - if (materials[materialIdx].baseColorTextureSet > -1) { - baseColor = SRGBtoLINEAR(texture(colorMap, materials[materialIdx].baseColorTextureSet == 0 ? inUV0 : inUV1)) * materials[materialIdx].baseColorFactor; - } else { - baseColor = materials[materialIdx].baseColorFactor; - } + if ((materials[materialIdx].tex0 & MAP_COLOR) == MAP_COLOR) + baseColor *= SRGBtoLINEAR(texture(colorMap, inUV0)); + else if ((materials[materialIdx].tex1 & MAP_COLOR) == MAP_COLOR) + baseColor *= SRGBtoLINEAR(texture(colorMap, inUV1)); + } + + if (materials[materialIdx].alphaMask == 1.0f) { + if (baseColor.a < materials[materialIdx].alphaMaskCutoff) + discard; } if (materials[materialIdx].workflow == PBR_WORKFLOW_SPECULAR_GLOSINESS) { // Values from specular glossiness workflow are converted to metallic roughness - if (materials[materialIdx].physicalDescriptorTextureSet > -1) { - perceptualRoughness = 1.0 - texture(physicalDescriptorMap, materials[materialIdx].physicalDescriptorTextureSet == 0 ? inUV0 : inUV1).a; - } else { + if ((materials[materialIdx].tex0 & MAP_METALROUGHNESS) == MAP_METALROUGHNESS) + perceptualRoughness = 1.0 - texture(physicalDescriptorMap, inUV0).a; + else if ((materials[materialIdx].tex1 & MAP_METALROUGHNESS) == MAP_METALROUGHNESS) + perceptualRoughness = 1.0 - texture(physicalDescriptorMap, inUV1).a; + else perceptualRoughness = 0.0; - } const float epsilon = 1e-6; @@ -317,7 +319,7 @@ void main() vec3 specularEnvironmentR0 = specularColor.rgb; vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90; - vec3 n = (materials[materialIdx].normalTextureSet > -1) ? getNormal() : normalize(inNormal); + vec3 n = getNormal(); vec3 v = normalize(ubo.camPos - inWorldPos); // Vector from surface point to camera vec3 l = normalize(uboParams.lightDir.xyz); // Vector from surface point to light vec3 h = normalize(l+v); // Half vector between both l and v @@ -362,17 +364,18 @@ void main() color += getIBLContribution(pbrInputs, n, reflection); const float u_OcclusionStrength = 1.0f; - // Apply optional PBR terms for additional (optional) shading - if (materials[materialIdx].occlusionTextureSet > -1) { - float ao = texture(aoMap, (materials[materialIdx].occlusionTextureSet == 0 ? inUV0 : inUV1)).r; - color = mix(color, color * ao, u_OcclusionStrength); - } - const float u_EmissiveFactor = 1.0f; - if (materials[materialIdx].emissiveTextureSet > -1) { - vec3 emissive = SRGBtoLINEAR(texture(emissiveMap, materials[materialIdx].emissiveTextureSet == 0 ? inUV0 : inUV1)).rgb * u_EmissiveFactor; - color += emissive; - } + + // Apply optional PBR terms for additional (optional) shading + if ((materials[materialIdx].tex0 & MAP_AO) == MAP_AO) + color = mix(color, color * texture(aoMap, inUV0).r, u_OcclusionStrength); + else if ((materials[materialIdx].tex1 & MAP_AO) == MAP_AO) + color = mix(color, color * texture(aoMap, inUV1).r, u_OcclusionStrength); + + if ((materials[materialIdx].tex0 & MAP_EMISSIVE) == MAP_EMISSIVE) + color += SRGBtoLINEAR(texture(emissiveMap, inUV0)).rgb * u_EmissiveFactor; + else if ((materials[materialIdx].tex1 & MAP_EMISSIVE) == MAP_EMISSIVE) + color += SRGBtoLINEAR(texture(emissiveMap, inUV1)).rgb * u_EmissiveFactor; outColor = vec4(color, baseColor.a); @@ -381,9 +384,14 @@ void main() int index = int(uboParams.debugViewInputs); switch (index) { case 1: - outColor.rgba = materials[materialIdx].baseColorTextureSet > -1 ? texture(colorMap, materials[materialIdx].baseColorTextureSet == 0 ? inUV0 : inUV1) : vec4(1.0f); + if ((materials[materialIdx].tex0 & MAP_COLOR) == MAP_COLOR) + outColor.rgba = texture(colorMap, inUV0); + else if ((materials[materialIdx].tex1 & MAP_COLOR) == MAP_COLOR) + outColor.rgba = texture(colorMap, inUV1); + else + outColor.rgba = vec4(1.0f); break; - case 2: + /*case 2: outColor.rgb = (materials[materialIdx].normalTextureSet > -1) ? texture(normalMap, materials[materialIdx].normalTextureSet == 0 ? inUV0 : inUV1).rgb : normalize(inNormal); break; case 3: @@ -397,7 +405,7 @@ void main() break; case 6: outColor.rgb = texture(physicalDescriptorMap, inUV0).ggg; - break; + break;*/ } outColor = SRGBtoLINEAR(outColor); } diff --git a/samples/vkvg_overlay/Camera2.cs b/samples/vkvg_overlay/Camera2.cs deleted file mode 100644 index 657564b..0000000 --- a/samples/vkvg_overlay/Camera2.cs +++ /dev/null @@ -1,102 +0,0 @@ -using System; -using System.Numerics; -using System.Runtime.InteropServices; - -using Vulkan; -using static CVKL.Camera; - -namespace CVKL { - public class Camera2 { - - float fov, aspectRatio, zNear = 0.1f, zFar = 256f; - float moveSpeed = 1, rotSpeed = 0.01f, zoomSpeed = 0.01f; - Vector3 rotation = new Vector3 (-1.5f, 2.7f, 0f); - Vector3 position = new Vector3 (0, 0, -2); - float zoom = 1.0f; - - public CamType Type; - - public float AspectRatio { - get { return aspectRatio; } - set { - aspectRatio = value; - Update (); - } - } - public float FieldOfView { - get { return fov; } - set { - fov = value; - Update (); - } - } - public Matrix4x4 Perspective { - get { return Matrix4x4.CreatePerspectiveFieldOfView (fov, aspectRatio, zNear, zFar); } - } - - public Camera2 (float fieldOfView, float aspectRatio) { - fov = fieldOfView; - this.aspectRatio = aspectRatio; - Update (); - } - - public void Rotate (float x, float y, float z = 0) { - rotation.Y += rotSpeed * x; - rotation.X += rotSpeed * y; - Update (); - } - public void Move (float x, float y, float z = 0) { - position.X += moveSpeed * x; - position.Y += moveSpeed * y; - position.Z += moveSpeed * z; - Update (); - } - public void Zoom (float factor) { - zoom += zoomSpeed * factor; - Update (); - } - - public Matrix4x4 Projection { get; private set;} - public Matrix4x4 View { get; private set;} - public Matrix4x4 Model { get; private set;} - - public Matrix4x4 SkyboxView { - get { - return - Matrix4x4.CreateFromAxisAngle (Vector3.UnitZ, rotation.Z) * - Matrix4x4.CreateFromAxisAngle (Vector3.UnitY, rotation.Y) * - Matrix4x4.CreateFromAxisAngle (Vector3.UnitX, rotation.X); - } - } - - //public void Update () { - // Projection = Matrix4x4.CreatePerspectiveFieldOfView (fov, aspectRatio, zNear, zFar); - // Matrix4x4 rot = - // Matrix4x4.CreateFromAxisAngle (Vector3.UnitX, rotation.X) * - // Matrix4x4.CreateFromAxisAngle (Vector3.UnitY, rotation.Y) * - // Matrix4x4.CreateFromAxisAngle (Vector3.UnitZ, rotation.Z); - // if (Type == CamType.LookAt) { - // View = Matrix4x4.CreateFromAxisAngle (Vector3.UnitX, rotation.X) * - // Matrix4x4.CreateFromAxisAngle (Vector3.UnitY, rotation.Y) * - // Matrix4x4.CreateFromAxisAngle (Vector3.UnitZ, rotation.Z) * - // Matrix4x4.CreateTranslation (position); - // } else { - // View = Matrix4x4.CreateTranslation (position) * - // Matrix4x4.CreateFromAxisAngle (Vector3.UnitZ, rotation.Z) * - // Matrix4x4.CreateFromAxisAngle (Vector3.UnitY, rotation.Y) * - // Matrix4x4.CreateFromAxisAngle (Vector3.UnitX, rotation.X); - // } - // Model = Matrix4x4.Identity; - //} - public void Update () { - Projection = Matrix4x4.CreatePerspectiveFieldOfView (fov, aspectRatio, zNear, zFar); - //matrices.view = Matrix4x4.CreateLookAt (new Vector3 (0, 0, -1), new Vector3 (0, 0, 0), Vector3.UnitY);//Matrix4x4.CreateTranslation (0, 0, -2.5f); - View = Matrix4x4.CreateTranslation (0, 0, -2.5f * zoom); - Model = - Matrix4x4.CreateFromAxisAngle (Vector3.UnitX, rotation.X) * - Matrix4x4.CreateFromAxisAngle (Vector3.UnitY, rotation.Y) * - Matrix4x4.CreateFromAxisAngle (Vector3.UnitZ, rotation.Z); - } - - } -} diff --git a/samples/vkvg_overlay/main.cs b/samples/vkvg_overlay/main.cs deleted file mode 100644 index a601467..0000000 --- a/samples/vkvg_overlay/main.cs +++ /dev/null @@ -1,384 +0,0 @@ -using System.Numerics; -using System.Runtime.InteropServices; -using Glfw; -using VK; -using CVKL; -using static CVKL.Camera; - -namespace ModelSample { - class Program : VkWindow { - static void Main (string[] args) { - using (Program vke = new Program ()) { - vke.Run (); - } - } - - PipelineStatisticsQueryPool statPool; - TimestampQueryPool timestampQPool; - - ulong[] results; - - protected override void configureEnabledFeatures (ref VkPhysicalDeviceFeatures features) { - base.configureEnabledFeatures (ref features); - features.pipelineStatisticsQuery = true; - } - public struct Matrices { - public Matrix4x4 projection; - public Matrix4x4 view; - public Matrix4x4 model; - public Vector4 lightPos; - public float gamma; - public float exposure; - } - - public Matrices matrices = new Matrices { - lightPos = new Vector4 (0.0f, 0.0f, -2.0f, 1.0f), - gamma = 1.0f, - exposure = 2.0f, - }; - - HostBuffer uboMats; - - DescriptorPool descriptorPool; - DescriptorSetLayout descLayoutMatrix; - DescriptorSetLayout descLayoutTextures; - DescriptorSet dsMats; - - GraphicPipeline pipeline; - GraphicPipeline uiPipeline; - Framebuffer[] frameBuffers; - - Model model; - - Camera2 Camera = new Camera2 (Utils.DegreesToRadians (60f), 1f); - - vkvg.Device vkvgDev; - vkvg.Surface vkvgSurf; - Image vkvgImage; - - void vkvgDraw () { - - using (vkvg.Context ctx = new vkvg.Context (vkvgSurf)) { - ctx.Operator = vkvg.Operator.Clear; - ctx.Paint (); - ctx.Operator = vkvg.Operator.Over; - - ctx.LineWidth = 1; - ctx.SetSource (0.1, 0.1, 0.1, 0.3); - ctx.Rectangle (5.5, 5.5, 400, 250); - ctx.FillPreserve (); - ctx.Flush (); - ctx.SetSource (0.8, 0.8, 0.8); - ctx.Stroke (); - - ctx.FontFace = "mono"; - ctx.FontSize = 10; - int x = 16; - int y = 40, dy = 16; - ctx.MoveTo (x, y); - ctx.ShowText (string.Format ($"fps: {fps,5} ")); - ctx.MoveTo (x + 200, y - 0.5); - ctx.Rectangle (x + 200, y - 8.5, 0.1 * fps, 10); - ctx.SetSource (0.1, 0.9, 0.1); - ctx.Fill (); - ctx.SetSource (0.8, 0.8, 0.8); - y += dy; - ctx.MoveTo (x, y); - ctx.ShowText (string.Format ($"Exposure:{matrices.exposure,5} ")); - y += dy; - ctx.MoveTo (x, y); - ctx.ShowText (string.Format ($"Gamma: {matrices.gamma,5} ")); - if (results == null) - return; - - y += dy*2; - ctx.MoveTo (x, y); - ctx.ShowText ("Pipeline Statistics"); - ctx.MoveTo (x-2, 2.5+y); - ctx.LineTo (x+160, 2.5+y); - ctx.Stroke (); - y += 4; - x += 20; - - for (int i = 0; i < statPool.RequestedStats.Length; i++) { - y += dy; - ctx.MoveTo (x, y); - ctx.ShowText (string.Format ($"{statPool.RequestedStats[i].ToString(),-30} :{results[i],12:0,0} ")); - } - - y += dy; - ctx.MoveTo (x, y); - ctx.ShowText (string.Format ($"{"Elapsed microsecond",-20} :{timestampQPool.ElapsedMiliseconds:0.0000} ")); - } - } - - Program () : base () { - vkvgDev = new vkvg.Device (instance.Handle, phy.Handle, dev.VkDev.Handle, presentQueue.qFamIndex, - vkvg.SampleCount.Sample_4, presentQueue.index); - - init (); - //model = new Model (presentQueue, "/mnt/devel/vkChess/data/chess.gltf"); - model = new Model (presentQueue, "../data/models/DamagedHelmet/glTF/DamagedHelmet.gltf"); - model.WriteMaterialsDescriptorSets (descLayoutTextures, - VK.AttachmentType.Color, - VK.AttachmentType.Normal, - VK.AttachmentType.AmbientOcclusion, - VK.AttachmentType.MetalRoughness, - VK.AttachmentType.Emissive); - } - - void init (VkSampleCountFlags samples = VkSampleCountFlags.SampleCount4) { - descriptorPool = new DescriptorPool (dev, 2, - new VkDescriptorPoolSize (VkDescriptorType.UniformBuffer), - new VkDescriptorPoolSize (VkDescriptorType.CombinedImageSampler) - ); - - descLayoutMatrix = new DescriptorSetLayout (dev, - new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Vertex|VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer), - new VkDescriptorSetLayoutBinding (1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) - ); - - descLayoutTextures = new DescriptorSetLayout (dev, - new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), - new VkDescriptorSetLayoutBinding (1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), - new VkDescriptorSetLayoutBinding (2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), - new VkDescriptorSetLayoutBinding (3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), - new VkDescriptorSetLayoutBinding (4, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) - ); - - dsMats = descriptorPool.Allocate (descLayoutMatrix); - - GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, samples); - - cfg.Layout = new PipelineLayout (dev, descLayoutMatrix, descLayoutTextures); - cfg.Layout.AddPushConstants ( - new VkPushConstantRange (VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf ()), - new VkPushConstantRange (VkShaderStageFlags.Fragment, (uint)Marshal.SizeOf (), 64) - ); - cfg.RenderPass = new RenderPass (dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat (), samples); - - cfg.AddVertexBinding (0); - cfg.SetVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat); - - cfg.AddShader (VkShaderStageFlags.Vertex, "shaders/pbrtest.vert.spv"); - cfg.AddShader (VkShaderStageFlags.Fragment, "shaders/pbrtest.frag.spv"); - - pipeline = new GraphicPipeline (cfg); - - cfg.ResetShadersAndVerticesInfos (); - cfg.AddShader (VkShaderStageFlags.Vertex, "shaders/FullScreenQuad.vert.spv"); - cfg.AddShader (VkShaderStageFlags.Fragment, "shaders/simpletexture.frag.spv"); - - cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState (true); - - uiPipeline = new GraphicPipeline (cfg); - - uboMats = new HostBuffer (dev, VkBufferUsageFlags.UniformBuffer, (ulong)Marshal.SizeOf()); - uboMats.Map ();//permanent map - - DescriptorSetWrites uboUpdate = new DescriptorSetWrites (dsMats, descLayoutMatrix.Bindings[0]); - uboUpdate.Write (dev, uboMats.Descriptor); - - cfg.Layout.SetName ("Main Pipeline layout"); - uboMats.SetName ("uboMats"); - descriptorPool.SetName ("main pool"); - descLayoutTextures.SetName ("descLayoutTextures"); - - statPool = new PipelineStatisticsQueryPool (dev, - VkQueryPipelineStatisticFlags.InputAssemblyVertices | - VkQueryPipelineStatisticFlags.InputAssemblyPrimitives | - VkQueryPipelineStatisticFlags.ClippingInvocations | - VkQueryPipelineStatisticFlags.ClippingPrimitives | - VkQueryPipelineStatisticFlags.FragmentShaderInvocations); - - timestampQPool = new TimestampQueryPool (dev); - - } - - void buildCommandBuffers () { - for (int i = 0; i < swapChain.ImageCount; ++i) { - cmds[i]?.Free (); - cmds[i] = cmdPool.AllocateAndStart (); - - statPool.Begin (cmds[i]); - cmds[i].BeginRegion ("draw" + i, 0.5f, 1f, 0f); - cmds[i].Handle.SetDebugMarkerName (dev, "cmd Draw" + i); - recordDraw (cmds[i], frameBuffers[i]); - cmds[i].EndRegion (); - statPool.End (cmds[i]); - cmds[i].End (); - } - } - void recordDraw (CommandBuffer cmd, Framebuffer fb) { - cmd.BeginRegion ("models", 0.5f, 1f, 0f); - pipeline.RenderPass.Begin (cmd, fb); - - cmd.SetViewport (fb.Width, fb.Height); - cmd.SetScissor (fb.Width, fb.Height); - - cmd.BindDescriptorSet (pipeline.Layout, dsMats); - pipeline.Bind (cmd); - model.Bind (cmd); - model.DrawAll (cmd, pipeline.Layout); - - cmd.EndRegion (); - cmd.BeginRegion ("vkvg", 0.5f, 1f, 0f); - uiPipeline.Bind (cmd); - - timestampQPool.Start (cmd); - - vkvgImage.SetLayout (cmd, VkImageAspectFlags.Color, VkImageLayout.ColorAttachmentOptimal, VkImageLayout.ShaderReadOnlyOptimal, - VkPipelineStageFlags.ColorAttachmentOutput, VkPipelineStageFlags.FragmentShader); - - cmd.Draw (3, 1, 0, 0); - - vkvgImage.SetLayout (cmd, VkImageAspectFlags.Color, VkImageLayout.ShaderReadOnlyOptimal, VkImageLayout.ColorAttachmentOptimal, - VkPipelineStageFlags.FragmentShader, VkPipelineStageFlags.BottomOfPipe); - - timestampQPool.End (cmd); - - pipeline.RenderPass.End (cmd); - cmd.EndRegion (); - } - - void updateMatrices () { - - Camera.AspectRatio = (float)swapChain.Width / swapChain.Height; - - matrices.projection = Camera.Projection; - matrices.view = Camera.View; - matrices.model = Camera.Model; - uboMats.Update (matrices, (uint)Marshal.SizeOf ()); - } - - public override void UpdateView () { - updateMatrices (); - updateViewRequested = false; - } - - protected override void onMouseMove (double xPos, double yPos) { - double diffX = lastMouseX - xPos; - double diffY = lastMouseY - yPos; - if (MouseButton[0]) { - Camera.Rotate ((float)-diffX,(float)-diffY); - } else if (MouseButton[1]) { - Camera.Zoom ((float)diffY); - } - - updateViewRequested = true; - } - - protected override void onKeyDown (Key key, int scanCode, Modifier modifiers) { - switch (key) { - case Key.Up: - Camera.Rotate (0, 0, 1); - break; - case Key.Down: - Camera.Move (0, 0, -1); - break; - case Key.Left: - Camera.Move (1, 0, 0); - break; - case Key.Right: - Camera.Move (-1, 0, 0); - break; - case Key.PageUp: - Camera.Move (0, 1, 0); - break; - case Key.PageDown: - Camera.Move (0, -1, 0); - break; - case Key.F1: - if (modifiers.HasFlag (Modifier.Shift)) - matrices.exposure -= 0.3f; - else - matrices.exposure += 0.3f; - break; - case Key.F2: - if (modifiers.HasFlag (Modifier.Shift)) - matrices.gamma -= 0.1f; - else - matrices.gamma += 0.1f; - break; - case Key.F3: - if (Camera.Type == CamType.FirstPerson) - Camera.Type = CamType.LookAt; - else - Camera.Type = CamType.FirstPerson; - break; - default: - base.onKeyDown (key, scanCode, modifiers); - return; - } - updateViewRequested = true; - } - - - public override void Update () { - results = statPool.GetResults (); - vkvgDraw (); - } - protected override void OnResize () { - - vkvgImage?.Dispose (); - vkvgSurf?.Dispose (); - vkvgSurf = new vkvg.Surface (vkvgDev, (int)swapChain.Width, (int)swapChain.Height); - vkvgImage = new Image (dev, new VkImage ((ulong)vkvgSurf.VkImage.ToInt64 ()), VkFormat.B8g8r8a8Unorm, - VkImageUsageFlags.ColorAttachment, (uint)vkvgSurf.Width, (uint)vkvgSurf.Height); - vkvgImage.CreateView (VkImageViewType.ImageView2D, VkImageAspectFlags.Color); - vkvgImage.CreateSampler (VkFilter.Nearest,VkFilter.Nearest, VkSamplerMipmapMode.Nearest, VkSamplerAddressMode.ClampToBorder); - - vkvgImage.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal; - DescriptorSetWrites uboUpdate = new DescriptorSetWrites (dsMats, descLayoutMatrix.Bindings[1]); - uboUpdate.Write (dev, vkvgImage.Descriptor); - - updateMatrices (); - - if (frameBuffers!=null) - for (int i = 0; i < swapChain.ImageCount; ++i) - frameBuffers[i]?.Dispose (); - - frameBuffers = new Framebuffer[swapChain.ImageCount]; - - for (int i = 0; i < swapChain.ImageCount; ++i) { - frameBuffers[i] = new Framebuffer (pipeline.RenderPass, swapChain.Width, swapChain.Height, - (pipeline.Samples == VkSampleCountFlags.SampleCount1) ? new Image[] { - swapChain.images[i], - null - } : new Image[] { - null, - null, - swapChain.images[i] - }); - frameBuffers[i].SetName ("main FB " + i); - - } - - buildCommandBuffers (); - } - - protected override void Dispose (bool disposing) { - if (disposing) { - if (!isDisposed) { - dev.WaitIdle (); - for (int i = 0; i < swapChain.ImageCount; ++i) - frameBuffers[i]?.Dispose (); - model.Dispose (); - pipeline.Dispose (); - descLayoutMatrix.Dispose (); - descLayoutTextures.Dispose (); - descriptorPool.Dispose (); - - uboMats.Dispose (); - vkvgSurf?.Dispose (); - vkvgDev.Dispose (); - - timestampQPool.Dispose (); - statPool.Dispose (); - } - } - - base.Dispose (disposing); - } - } -} diff --git a/samples/vkvg_overlay/packages.config b/samples/vkvg_overlay/packages.config deleted file mode 100644 index 069f5cc..0000000 --- a/samples/vkvg_overlay/packages.config +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/samples/vkvg_overlay/shaders/FullScreenQuad.vert b/samples/vkvg_overlay/shaders/FullScreenQuad.vert deleted file mode 100644 index 826720b..0000000 --- a/samples/vkvg_overlay/shaders/FullScreenQuad.vert +++ /dev/null @@ -1,10 +0,0 @@ -#version 450 - -layout (location = 0) out vec2 outUV; - -void main() -{ - outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2); - gl_Position = vec4(outUV * 2.0f + -1.0f, 0.0f, 1.0f); - //gl_Position = vec4(outUV -1.0f, 0.0f, 1.0f); -} diff --git a/samples/vkvg_overlay/shaders/model.frag b/samples/vkvg_overlay/shaders/model.frag deleted file mode 100644 index 59944a4..0000000 --- a/samples/vkvg_overlay/shaders/model.frag +++ /dev/null @@ -1,110 +0,0 @@ -#version 450 - -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable - -layout (set = 1, binding = 0) uniform sampler2D samplerColor; -layout (set = 1, binding = 1) uniform sampler2D samplerNormal; -layout (set = 1, binding = 2) uniform sampler2D samplerOcclusion; -layout (set = 1, binding = 3) uniform sampler2D samplerMetalRoughness; -layout (set = 1, binding = 4) uniform sampler2D samplerEmissive; - -layout (location = 0) in vec2 inUV; -layout (location = 1) in vec3 inN; -layout (location = 2) in vec3 inV;//ViewDir - -layout (location = 0) out vec4 outFragColor; - -layout(push_constant) uniform PushConsts { - layout(offset = 64) - vec4 baseColorFactor; - vec4 emissiveFactor; - uint availableAttachments; - uint alphaMode; - float alphaCutoff; - float metallicFactor; - float roughnessFactor; -} pc; - -const uint MAP_COLOR = 0x1; -const uint MAP_NORMAL = 0x2; -const uint MAP_AMBIENTOCCLUSION = 0x4; -const uint MAP_METAL = 0x8; -const uint MAP_ROUGHNESS = 0x16; -const uint MAP_METALROUGHNESS = 0x32; -const uint MAP_EMISSIVE = 0x64; -const float M_PI = 3.141592653589793; - -vec3 light = vec3(1.0,.0,1.0); - -// http://www.thetenthplanet.de/archives/1180 -mat3 cotangent_frame(vec3 N, vec3 p, vec2 uv) -{ - // get edge vectors of the pixel triangle - vec3 dp1 = dFdx( p ); - vec3 dp2 = dFdy( p ); - vec2 duv1 = dFdx( uv ); - vec2 duv2 = dFdy( uv ); - - // solve the linear system - vec3 dp2perp = cross( dp2, N ); - vec3 dp1perp = cross( N, dp1 ); - vec3 T = dp2perp * duv1.x + dp1perp * duv2.x; - vec3 B = dp2perp * duv1.y + dp1perp * duv2.y; - - // construct a scale-invariant frame - float invmax = inversesqrt( max( dot(T,T), dot(B,B) ) ); - return mat3( T * invmax, B * invmax, N ); -} - -vec3 perturb_normal( vec3 N, vec3 V, vec2 texcoord ) -{ - // assume N, the interpolated vertex normal and - // V, the view vector (vertex to eye) - vec3 map = texture(samplerNormal, texcoord).xyz; - map = map * 255./127. - 128./127.; - mat3 TBN = cotangent_frame(N, -V, texcoord); - return normalize(TBN * map); -} - - -void main() -{ - vec4 base_color = pc.baseColorFactor; - if ((pc.availableAttachments & MAP_COLOR) == MAP_COLOR) - base_color *= texture(samplerColor, inUV); - float rough = pc.roughnessFactor; - float metallic = pc.metallicFactor; - if ((pc.availableAttachments & MAP_METALROUGHNESS) == MAP_METALROUGHNESS) { - rough *= texture(samplerMetalRoughness, inUV).g; - metallic *= texture(samplerMetalRoughness, inUV).b; - } - - vec3 emit; - if ((pc.availableAttachments & MAP_EMISSIVE) == MAP_EMISSIVE) - emit = pc.emissiveFactor.rgb * texture(samplerEmissive, inUV).rgb; - - vec3 n = normalize(inN); - vec3 l = normalize(light); - vec3 pn = perturb_normal(n, inV, inUV); - - float lambert = max(0.0, dot(pn, l)); - - vec3 f0 = vec3(0.04); - vec3 diff = base_color.rgb * (vec3(1.0) - f0); - diff *= 1.0 - metallic; - diff *= lambert * texture(samplerOcclusion, inUV).r; - diff += emit; - - vec3 spec = mix(f0, base_color.rgb, metallic); - - vec3 amb = vec3(0.1); - if (lambert >= 0.0) { - vec3 rd = reflect(-l, pn); - float s = dot(rd, normalize(inV)); - spec = vec3(0.9,0.9,0.9)* //light.specular.xyz * material.specular.xyz * - pow(max(0.0, s), 10.0); //0.5 = mat shininess - } - - outFragColor = vec4(diff + amb + spec , base_color.a); // -} \ No newline at end of file diff --git a/samples/vkvg_overlay/shaders/model.vert b/samples/vkvg_overlay/shaders/model.vert deleted file mode 100644 index 37b83d7..0000000 --- a/samples/vkvg_overlay/shaders/model.vert +++ /dev/null @@ -1,44 +0,0 @@ -#version 450 - -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable - -layout (location = 0) in vec3 inPos; -layout (location = 1) in vec3 inNormal; -layout (location = 2) in vec2 inUV; - -layout (binding = 0) uniform UBO -{ - mat4 projectionMatrix; - mat4 viewMatrix; - mat4 modelMatrix; -} ubo; - -layout (location = 0) out vec2 outUV; -layout (location = 1) out vec3 outN; -layout (location = 2) out vec3 outV;//ViewDir - -out gl_PerVertex -{ - vec4 gl_Position; -}; - -layout(push_constant) uniform PushConsts { - mat4 model; -} pc; - -void main() -{ - outUV = inUV; - - mat4 mod = ubo.modelMatrix * pc.model; - vec4 pos = mod * vec4(inPos.xyz, 1.0); - - //outN = normalize(transpose(inverse(mat3(mod))) * inNormal); - outN = normalize(mat3(mod)* inNormal); - - mat4 viewInv = inverse(ubo.viewMatrix); - outV = -(ubo.viewMatrix * pos).xyz;//normalize(vec3(viewInv * vec4(0.0, 0.0, 0.0, 1.0) - pos)); - - gl_Position = ubo.projectionMatrix * ubo.viewMatrix * pos; -} diff --git a/samples/vkvg_overlay/shaders/pbrtest.frag b/samples/vkvg_overlay/shaders/pbrtest.frag deleted file mode 100644 index bc850e1..0000000 --- a/samples/vkvg_overlay/shaders/pbrtest.frag +++ /dev/null @@ -1,193 +0,0 @@ -#version 450 - -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable - -layout (binding = 0) uniform UBO -{ - mat4 projectionMatrix; - mat4 viewMatrix; - mat4 modelMatrix; - vec4 lightPos; - float gamma; - float exposure; -} ubo; - -layout (set = 1, binding = 0) uniform sampler2D samplerColor; -layout (set = 1, binding = 1) uniform sampler2D samplerNormal; -layout (set = 1, binding = 2) uniform sampler2D samplerOcclusion; -layout (set = 1, binding = 3) uniform sampler2D samplerMetalRoughness; -layout (set = 1, binding = 4) uniform sampler2D samplerEmissive; - -layout (location = 0) in vec2 inUV; -layout (location = 1) in vec3 inN; -layout (location = 2) in vec3 inV; -layout (location = 3) in vec3 inWorldPos; - -layout (location = 0) out vec4 outFragColor; - -layout(push_constant) uniform PushConsts { - layout(offset = 64) - vec4 baseColorFactor; - vec4 emissiveFactor; - uint availableAttachments; - uint alphaMode; - float alphaCutoff; - float metallicFactor; - float roughnessFactor; -} pc; - -const uint MAP_COLOR = 0x1; -const uint MAP_NORMAL = 0x2; -const uint MAP_AO = 0x4; -const uint MAP_METAL = 0x8; -const uint MAP_ROUGHNESS = 0x16; -const uint MAP_METALROUGHNESS = 0x32; -const uint MAP_EMISSIVE = 0x64; - -const float PI = 3.141592653589793; - -vec3 light = vec3(1.0,.0,1.0); - -// From http://filmicgames.com/archives/75 -vec3 Uncharted2Tonemap(vec3 x) -{ - float A = 0.15; - float B = 0.50; - float C = 0.10; - float D = 0.20; - float E = 0.02; - float F = 0.30; - return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F; -} - -// Normal Distribution function -------------------------------------- -float D_GGX(float dotNH, float roughness) -{ - float alpha = roughness * roughness; - float alpha2 = alpha * alpha; - float denom = dotNH * dotNH * (alpha2 - 1.0) + 1.0; - return (alpha2)/(PI * denom*denom); -} - -// Geometric Shadowing function -------------------------------------- -float G_SchlicksmithGGX(float dotNL, float dotNV, float roughness) -{ - float r = (roughness + 1.0); - float k = (r*r) / 8.0; - float GL = dotNL / (dotNL * (1.0 - k) + k); - float GV = dotNV / (dotNV * (1.0 - k) + k); - return GL * GV; -} - -// Fresnel function ---------------------------------------------------- -vec3 F_Schlick(float cosTheta, vec3 F0) -{ - return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0); -} -vec3 F_SchlickR(float cosTheta, vec3 F0, float roughness) -{ - return F0 + (max(vec3(1.0 - roughness), F0) - F0) * pow(1.0 - cosTheta, 5.0); -} - -vec3 specularContribution(vec3 L, vec3 V, vec3 N, vec3 F0, float metallic, float roughness, vec3 albedo) -{ - // Precalculate vectors and dot products - vec3 H = normalize (V + L); - float dotNH = clamp(dot(N, H), 0.0, 1.0); - float dotNV = clamp(dot(N, V), 0.0, 1.0); - float dotNL = clamp(dot(N, L), 0.0, 1.0); - - // Light color fixed - vec3 lightColor = vec3(1.0); - - vec3 color = vec3(0.0); - - if (dotNL > 0.0) { - // D = Normal distribution (Distribution of the microfacets) - float D = D_GGX(dotNH, roughness); - // G = Geometric shadowing term (Microfacets shadowing) - float G = G_SchlicksmithGGX(dotNL, dotNV, roughness); - // F = Fresnel factor (Reflectance depending on angle of incidence) - vec3 F = F_Schlick(dotNV, F0); - vec3 spec = D * F * G / (4.0 * dotNL * dotNV + 0.001); - vec3 kD = (vec3(1.0) - F) * (1.0 - metallic); - color += (kD * albedo / PI + spec) * dotNL; - } - - return color; -} - -// See http://www.thetenthplanet.de/archives/1180 -vec3 perturbNormal(vec3 inNormal, vec3 tangentNormal) -{ - - - vec3 q1 = dFdx(inWorldPos); - vec3 q2 = dFdy(inWorldPos); - vec2 st1 = dFdx(inUV); - vec2 st2 = dFdy(inUV); - - vec3 N = normalize(inNormal); - vec3 T = normalize(q1 * st2.t - q2 * st1.t); - vec3 B = -normalize(cross(N, T)); - mat3 TBN = mat3(T, B, N); - - return normalize(TBN * tangentNormal); -} -void main() -{ - vec3 emit = vec3(0); - vec4 base_color = pc.baseColorFactor; - float rough = pc.roughnessFactor; - float metallic = pc.metallicFactor; - - if ((pc.availableAttachments & MAP_COLOR) == MAP_COLOR) - base_color *= texture(samplerColor, inUV); - if ((pc.availableAttachments & MAP_METALROUGHNESS) == MAP_METALROUGHNESS) { - rough *= clamp(texture(samplerMetalRoughness, inUV).g, 0.04, 1.0); - metallic *= texture(samplerMetalRoughness, inUV).b; - } - if ((pc.availableAttachments & MAP_EMISSIVE) == MAP_EMISSIVE) - emit = pc.emissiveFactor.rgb * texture(samplerEmissive, inUV).rgb; - - - vec3 N = ((pc.availableAttachments & MAP_NORMAL) == MAP_NORMAL) ? - perturbNormal(inN, texture(samplerNormal, inUV).xyz * 2.0 - 1.0) : - normalize(inN); - vec3 V = normalize(inV); - vec3 R = -normalize(reflect(V, N)); - - vec3 F0 = vec3(0.04); - F0 = mix(F0, base_color.rgb, metallic); - float alpha = pow(rough, 2.0); - - vec3 L = normalize(light); - vec3 Lo = specularContribution(L, V, N, F0, metallic, rough, base_color.rgb); - - vec3 reflection = vec3(rough);// prefilteredReflection(R, rough).rgb; - vec3 irradiance = vec3(0.8);//texture(samplerIrradiance, N).rgb; - - // Diffuse based on irradiance - vec3 diffuse = irradiance * base_color.rgb; - - vec3 F = F_SchlickR(max(dot(N, V), 0.0), F0, rough); - - vec3 specular = reflection * F;//(F * brdf.x + brdf.y); - - // Ambient part - vec3 kD = 1.0 - F; - kD *= 1.0 - metallic; - - float ao = ((pc.availableAttachments & MAP_AO) == MAP_AO) ? texture(samplerOcclusion, inUV).r : 1.0f; - vec3 ambient = (kD * diffuse + specular) * ao; - vec3 color = ambient + Lo; - - // Tone mapping - color = Uncharted2Tonemap(color * ubo.exposure); - color = color * (1.0f / Uncharted2Tonemap(vec3(11.2f))); - // Gamma correction - color = pow(color, vec3(1.0f / ubo.gamma)) + emit; - - outFragColor = vec4(color , base_color.a); -} \ No newline at end of file diff --git a/samples/vkvg_overlay/shaders/pbrtest.vert b/samples/vkvg_overlay/shaders/pbrtest.vert deleted file mode 100644 index ffb1432..0000000 --- a/samples/vkvg_overlay/shaders/pbrtest.vert +++ /dev/null @@ -1,48 +0,0 @@ -#version 450 - -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable - -layout (location = 0) in vec3 inPos; -layout (location = 1) in vec3 inNormal; -layout (location = 2) in vec2 inUV; - -layout (binding = 0) uniform UBO -{ - mat4 projectionMatrix; - mat4 viewMatrix; - mat4 modelMatrix; - vec4 lightPos; - float gamma; - float exposure; -} ubo; - -layout (location = 0) out vec2 outUV; -layout (location = 1) out vec3 outN; -layout (location = 2) out vec3 outV;//ViewDir -layout (location = 3) out vec3 outWorldPos; - -out gl_PerVertex -{ - vec4 gl_Position; -}; - -layout(push_constant) uniform PushConsts { - mat4 model; -} pc; - -void main() -{ - outUV = inUV; - - mat4 mod = ubo.modelMatrix * pc.model; - vec4 pos = mod * vec4(inPos.xyz, 1.0); - - //outN = normalize(transpose(inverse(mat3(mod))) * inNormal); - outN = normalize(mat3(mod)* inNormal); - - mat4 viewInv = inverse(ubo.viewMatrix); - outV = -(ubo.viewMatrix * pos).xyz;//normalize(vec3(viewInv * vec4(0.0, 0.0, 0.0, 1.0) - pos)); - outWorldPos = pos.xyz; - gl_Position = ubo.projectionMatrix * ubo.viewMatrix * pos; -} diff --git a/samples/vkvg_overlay/shaders/simpletexture.frag b/samples/vkvg_overlay/shaders/simpletexture.frag deleted file mode 100644 index cee63cb..0000000 --- a/samples/vkvg_overlay/shaders/simpletexture.frag +++ /dev/null @@ -1,15 +0,0 @@ -#version 450 - -#extension GL_ARB_separate_shader_objects : enable -#extension GL_ARB_shading_language_420pack : enable - -layout (set = 0, binding = 1) uniform sampler2D samplerColor; - -layout (location = 0) in vec2 inUV; - -layout (location = 0) out vec4 outFragColor; - -void main() -{ - outFragColor = texture(samplerColor, inUV); -} diff --git a/samples/vkvg_overlay/vkvg_overlay.csproj b/samples/vkvg_overlay/vkvg_overlay.csproj deleted file mode 100644 index 65e3c91..0000000 --- a/samples/vkvg_overlay/vkvg_overlay.csproj +++ /dev/null @@ -1,73 +0,0 @@ - - - - {1F05E74F-AEE8-481C-8FDF-89D81CCC30BE} - Exe - vkvg_overlay - v4.7.1 - $(SolutionDir)build\$(Configuration)\samples\vkvg_overlay - $(SolutionDir)build\obj\$(Configuration) - - - true - full - false - DEBUG;DEBUG_MARKER - prompt - 4 - true - - - true - prompt - 4 - true - - - - - - data\%(RecursiveDir)%(Filename)%(Extension) - - - - - - - ..\..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll - - - - ..\..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll - - - ..\..\packages\glTF2Loader.1.1.3-alpha\lib\net35\glTFLoader.dll - - - ..\..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll - - - ..\..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll - - - ..\..\packages\System.Memory.4.5.2\lib\netstandard2.0\System.Memory.dll - - - ..\..\packages\vkvg.net.0.2.0\lib\netstandard2.0\vkvg.net.dll - - - ..\..\packages\Vulkan.0.1.2.5-alpha\lib\netstandard2.0\VK.dll - - - - - - - - {32B7E80D-BEA7-4811-B82D-CC2533069F0A} - CVKL - - - - - diff --git a/samples/vkvg_tests/packages.config b/samples/vkvg_tests/packages.config index 7abe866..773c14e 100644 --- a/samples/vkvg_tests/packages.config +++ b/samples/vkvg_tests/packages.config @@ -7,5 +7,5 @@ - + \ No newline at end of file diff --git a/samples/vkvg_tests/vkvg_tests.csproj b/samples/vkvg_tests/vkvg_tests.csproj index ef6cb7e..4581ca2 100644 --- a/samples/vkvg_tests/vkvg_tests.csproj +++ b/samples/vkvg_tests/vkvg_tests.csproj @@ -54,7 +54,7 @@ ..\..\packages\System.Memory.4.5.2\lib\netstandard2.0\System.Memory.dll - ..\..\packages\Vulkan.0.1.2.5-alpha\lib\netstandard2.0\VK.dll + ..\..\packages\Vulkan.0.1.2.6\lib\netstandard2.0\VK.dll ..\..\packages\vkvg.net.0.2.1-beta\lib\netstandard2.0\vkvg.net.dll @@ -64,7 +64,7 @@ - + {32B7E80D-BEA7-4811-B82D-CC2533069F0A} CVKL -- cgit v1.3.1-4-g156e