diff options
Diffstat (limited to 'samples/vkvg_overlay')
| -rw-r--r-- | samples/vkvg_overlay/Camera2.cs | 102 | ||||
| -rw-r--r-- | samples/vkvg_overlay/main.cs | 384 | ||||
| -rw-r--r-- | samples/vkvg_overlay/packages.config | 11 | ||||
| -rw-r--r-- | samples/vkvg_overlay/shaders/FullScreenQuad.vert | 10 | ||||
| -rw-r--r-- | samples/vkvg_overlay/shaders/model.frag | 110 | ||||
| -rw-r--r-- | samples/vkvg_overlay/shaders/model.vert | 44 | ||||
| -rw-r--r-- | samples/vkvg_overlay/shaders/pbrtest.frag | 193 | ||||
| -rw-r--r-- | samples/vkvg_overlay/shaders/pbrtest.vert | 48 | ||||
| -rw-r--r-- | samples/vkvg_overlay/shaders/simpletexture.frag | 15 | ||||
| -rw-r--r-- | samples/vkvg_overlay/vkvg_overlay.csproj | 73 |
10 files changed, 0 insertions, 990 deletions
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<Matrix4x4> ()), - new VkPushConstantRange (VkShaderStageFlags.Fragment, (uint)Marshal.SizeOf<Model.PbrMaterial> (), 64) - ); - cfg.RenderPass = new RenderPass (dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat (), samples); - - cfg.AddVertexBinding<Model.Vertex> (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<Matrices>()); - 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<Matrices> ()); - } - - 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 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="glTF2Loader" version="1.1.3-alpha" targetFramework="net471" /> - <package id="Newtonsoft.Json" version="12.0.1" targetFramework="net471" /> - <package id="System.Buffers" version="4.5.0" targetFramework="net471" /> - <package id="System.Memory" version="4.5.2" targetFramework="net471" /> - <package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net471" /> - <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net471" /> - <package id="vkvg.net" version="0.2.0" targetFramework="net471" /> - <package id="Vulkan" version="0.1.2.5-alpha" targetFramework="net471" /> -</packages>
\ 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 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <PropertyGroup> - <ProjectGuid>{1F05E74F-AEE8-481C-8FDF-89D81CCC30BE}</ProjectGuid> - <OutputType>Exe</OutputType> - <AssemblyName>vkvg_overlay</AssemblyName> - <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion> - <OutputPath>$(SolutionDir)build\$(Configuration)\samples\vkvg_overlay</OutputPath> - <IntermediateOutputPath>$(SolutionDir)build\obj\$(Configuration)</IntermediateOutputPath> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <DefineConstants>DEBUG;DEBUG_MARKER</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <AllowUnsafeBlocks>true</AllowUnsafeBlocks> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <Optimize>true</Optimize> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <AllowUnsafeBlocks>true</AllowUnsafeBlocks> - </PropertyGroup> - <ItemGroup> - <Compile Include="*.cs" /> - <GLSLShader Include="shaders\**\*.frag;shaders\**\*.vert" /> - <Datas Include="..\data\**\*.*"> - <Link>data\%(RecursiveDir)%(Filename)%(Extension)</Link> - </Datas> - </ItemGroup> - <ItemGroup> - <Reference Include="System.Numerics" /> - <Reference Include="System" /> - <Reference Include="System.Numerics.Vectors"> - <HintPath>..\..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath> - </Reference> - <Reference Include="mscorlib" /> - <Reference Include="Newtonsoft.Json"> - <HintPath>..\..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> - </Reference> - <Reference Include="glTFLoader"> - <HintPath>..\..\packages\glTF2Loader.1.1.3-alpha\lib\net35\glTFLoader.dll</HintPath> - </Reference> - <Reference Include="System.Buffers"> - <HintPath>..\..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll</HintPath> - </Reference> - <Reference Include="System.Runtime.CompilerServices.Unsafe"> - <HintPath>..\..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath> - </Reference> - <Reference Include="System.Memory"> - <HintPath>..\..\packages\System.Memory.4.5.2\lib\netstandard2.0\System.Memory.dll</HintPath> - </Reference> - <Reference Include="vkvg.net"> - <HintPath>..\..\packages\vkvg.net.0.2.0\lib\netstandard2.0\vkvg.net.dll</HintPath> - </Reference> - <Reference Include="VK"> - <HintPath>..\..\packages\Vulkan.0.1.2.5-alpha\lib\netstandard2.0\VK.dll</HintPath> - </Reference> - </ItemGroup> - <ItemGroup> - <None Include="packages.config" /> - </ItemGroup> - <ItemGroup> - <ProjectReference Include="..\..\vke\VKE.csproj"> - <Project>{32B7E80D-BEA7-4811-B82D-CC2533069F0A}</Project> - <Name>CVKL</Name> - </ProjectReference> - </ItemGroup> - <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> - <Import Project="$(SolutionDir)spirv.targets" /> -</Project> |