diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2019-04-24 04:17:16 +0200 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2019-04-24 04:17:16 +0200 |
| commit | 2d2e2ff4038db052d0186645f5afe4ec9daf2505 (patch) | |
| tree | d8491d9921381ec5d4149fdc014b72e375199dab /samples/Model | |
| parent | 25fc1c7019142137dc67e4fad0c3088d845ab0a8 (diff) | |
use boolean for tex0 and tex1 availability tests
Diffstat (limited to 'samples/Model')
| -rw-r--r-- | samples/Model/Camera2.cs | 102 | ||||
| -rw-r--r-- | samples/Model/Model.csproj | 71 | ||||
| -rw-r--r-- | samples/Model/data/chess.gltf | 3 | ||||
| -rw-r--r-- | samples/Model/main.cs | 242 | ||||
| -rw-r--r-- | samples/Model/packages.config | 10 | ||||
| -rw-r--r-- | samples/Model/shaders/pbrtest.frag | 193 | ||||
| -rw-r--r-- | samples/Model/shaders/pbrtest.vert | 48 |
7 files changed, 0 insertions, 669 deletions
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 @@ -<?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-89D81CBB30BE}</ProjectGuid> - <OutputType>Exe</OutputType> - <RootNamespace>Model</RootNamespace> - <AssemblyName>Model</AssemblyName> - <TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion> - <OutputPath>$(SolutionDir)build\$(Configuration)\samples\Model</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" /> - <Datas Include="..\data\**\*.*"> - <Link>data\%(RecursiveDir)%(Filename)%(Extension)</Link> - </Datas> - <GLSLShader Include="shaders\**\*.frag;shaders\**\*.vert;shaders\**\*.comp" /> - </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="VK"> - <HintPath>..\..\packages\Vulkan.0.1.2.6\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> 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<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); - - 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); - } - - 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<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; - } - - 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 @@ -<?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="Vulkan" version="0.1.2.6" targetFramework="net471" /> -</packages>
\ 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; -} |