<PackageId>vke.DistanceFieldFont</PackageId>
<AssemblyVersion>0.1.0</AssemblyVersion>
<Description>vke.net signed distance field font addons, BMFont file format</Description>
- <PackageTags>C# vulkan CVKL gltf</PackageTags>
+ <PackageTags>vulkan C# vke.net gltf</PackageTags>
<PackageVersion>$(AssemblyVersion)-beta</PackageVersion>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
using System;
-using System.Collections.Generic;
using System.Numerics;
using System.Runtime.InteropServices;
-using VK;
+using Vulkan;
-namespace CVKL {
+namespace vke.Environment {
public class EnvironmentCube : GraphicPipeline {
GPUBuffer vboSkybox;
cfg.Layout = plLayout;
cfg.AddVertexBinding (0, 3 * sizeof (float));
cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat);
- cfg.AddShader (VkShaderStageFlags.Vertex, "#CVKLEnvironment.skybox.vert.spv");
- cfg.AddShader (VkShaderStageFlags.Fragment, "#CVKLEnvironment.skybox.frag.spv");
+ cfg.AddShader (VkShaderStageFlags.Vertex, "#EnvironmentPipeline.skybox.vert.spv");
+ cfg.AddShader (VkShaderStageFlags.Fragment, "#EnvironmentPipeline.skybox.frag.spv");
cfg.multisampleState.rasterizationSamples = Samples;
layout = cfg.Layout;
lutBrdf.CreateView ();
lutBrdf.CreateSampler (VkSamplerAddressMode.ClampToEdge);
- GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount1, false);
+ GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount1, false, dim, dim);
cfg.Layout = new PipelineLayout (Dev, new DescriptorSetLayout (Dev));
cfg.RenderPass = new RenderPass (Dev);
cfg.RenderPass.AddAttachment (format, VkImageLayout.ShaderReadOnlyOptimal);
cfg.RenderPass.ClearValues.Add (new VkClearValue { color = new VkClearColorValue (0, 0, 0) });
cfg.RenderPass.AddSubpass (new SubPass (VkImageLayout.ColorAttachmentOptimal));
- cfg.AddShader (VkShaderStageFlags.Vertex, "#CVKLEnvironment.genbrdflut.vert.spv");
- cfg.AddShader (VkShaderStageFlags.Fragment, "#CVKLEnvironment.genbrdflut.frag.spv");
+ cfg.AddShader (VkShaderStageFlags.Vertex, "#EnvironmentPipeline.genbrdflut.vert.spv");
+ cfg.AddShader (VkShaderStageFlags.Fragment, "#EnvironmentPipeline.genbrdflut.frag.spv");
using (GraphicPipeline pl = new GraphicPipeline (cfg)) {
- using (Framebuffer fb = new Framebuffer (cfg.RenderPass, dim, dim, lutBrdf)) {
+ using (FrameBuffer fb = new FrameBuffer (cfg.RenderPass, dim, dim, lutBrdf)) {
CommandBuffer cmd = cmdPool.AllocateCommandBuffer ();
cmd.Start (VkCommandBufferUsageFlags.OneTimeSubmit);
pl.RenderPass.Begin (cmd, fb);
- cmd.SetViewport (dim, dim);
- cmd.SetScissor (dim, dim);
pl.Bind (cmd);
cmd.Draw (3, 1, 0, 0);
pl.RenderPass.End (cmd);
new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler));
- GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount1, false);
+ GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount1, false, (int)dim, (int)dim);
cfg.Layout = new PipelineLayout (Dev, dsLayout);
cfg.Layout.AddPushConstants (
new VkPushConstantRange (VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, (uint)Marshal.SizeOf<Matrix4x4> () + 8));
cfg.AddVertexBinding (0, 3 * sizeof (float));
cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat);
- cfg.AddShader (VkShaderStageFlags.Vertex, "#CVKLEnvironment.filtercube.vert.spv");
+ cfg.AddShader (VkShaderStageFlags.Vertex, "#EnvironmentPipeline.filtercube.vert.spv");
if (target == CBTarget.PREFILTEREDENV)
- cfg.AddShader (VkShaderStageFlags.Fragment, "#CVKLEnvironment.prefilterenvmap.frag.spv");
+ cfg.AddShader (VkShaderStageFlags.Fragment, "#EnvironmentPipeline.prefilterenvmap.frag.spv");
else
- cfg.AddShader (VkShaderStageFlags.Fragment, "#CVKLEnvironment.irradiancecube.frag.spv");
+ cfg.AddShader (VkShaderStageFlags.Fragment, "#EnvironmentPipeline.irradiancecube.frag.spv");
Matrix4x4[] matrices = {
// POSITIVE_X
dsUpdate.Write (Dev, dset, cubemap.Descriptor);
Dev.WaitIdle ();
- using (Framebuffer fb = new Framebuffer (pl.RenderPass, dim, dim, imgFbOffscreen)) {
+ using (FrameBuffer fb = new FrameBuffer (pl.RenderPass, dim, dim, imgFbOffscreen)) {
CommandBuffer cmd = cmdPool.AllocateCommandBuffer ();
cmd.Start (VkCommandBufferUsageFlags.OneTimeSubmit);
float roughness = 0;
- cmd.SetScissor (dim, dim);
- cmd.SetViewport ((float)(dim), (float)dim);
-
for (int m = 0; m < numMips; m++) {
roughness = (float)m / ((float)numMips - 1f);
<Project Sdk="Microsoft.NET.Sdk">
- <Import Project="$(RootDirectory)netfx.props" />
<PropertyGroup>
- <AssemblyName>CVKLEnvironment</AssemblyName>
- <PackageId>CVKLEnvironmentPipeline</PackageId>
+ <AssemblyName>EnvironmentPipeline</AssemblyName>
+ <PackageId>vke.EnvironmentPipeline</PackageId>
<AssemblyVersion>0.1.0</AssemblyVersion>
- <Description>CVKL Environment cube</Description>
- <PackageTags>vulkan CVKL</PackageTags>
+ <Description>vke.net Environment cube pipeline</Description>
+ <PackageTags>vulkan c# vke.net</PackageTags>
<PackageVersion>$(AssemblyVersion)-beta</PackageVersion>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
- <PackageProjectUrl>https://github.com/jpbruyere/vk.net/blob/master/README.md</PackageProjectUrl>
+ <PackageProjectUrl>https://github.com/jpbruyere/vke.net/blob/master/README.md</PackageProjectUrl>
<License>MIT</License>
<PackageReleaseNotes></PackageReleaseNotes>
<SynchReleaseVersion>false</SynchReleaseVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
-
</Project>
+++ /dev/null
-#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);
-}
+++ /dev/null
-#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);
-}
protected override void onMouseMove (double xPos, double yPos) {
double diffX = lastMouseX - xPos;
double diffY = lastMouseY - yPos;
- if (MouseButton[0]) {
+ if (MouseButton [0]) {
rotY -= rotSpeed * (float)diffX;
rotX += rotSpeed * (float)diffY;
- } else if (MouseButton[1]) {
+ } else if (MouseButton [1]) {
zoom += zoomSpeed * (float)diffY;
- }
+ } else
+ return;
updateViewRequested = true;
}
void buildCommandBuffers() {
protected override void OnResize () {
base.OnResize ();
+ UpdateView ();
frameBuffers?.Dispose();
frameBuffers = pipeline.RenderPass.CreateFrameBuffers(swapChain);
cfg.RenderPass.ClearValues[0] = new VkClearValue { color = new VkClearColorValue (0.0f, 0.1f, 0.0f) };
cfg.ResetShadersAndVerticesInfos ();
- cfg.AddShader (VkShaderStageFlags.Vertex, "#compute.FullScreenQuad.vert.spv");
+ cfg.AddShader (VkShaderStageFlags.Vertex, "#vke.FullScreenQuad.vert.spv");
cfg.AddShader (VkShaderStageFlags.Fragment, "#compute.simpletexture.frag.spv");
cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState (true);
+++ /dev/null
-#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);
-}
using System.Numerics;
using System.Runtime.InteropServices;
using vke;
+using vke.Environment;
using vke.glTF;
using Vulkan;
cfg.depthStencilState.depthWriteEnable = false;
using (SpecializationInfo constants = new SpecializationInfo (
new SpecializationConstant<uint> (0, (uint)lights.Length))) {
- cfg.AddShader (VkShaderStageFlags.Vertex, "#deferred.FullScreenQuad.vert.spv");
+ cfg.AddShader (VkShaderStageFlags.Vertex, "#vke.FullScreenQuad.vert.spv");
#if WITH_SHADOWS
cfg.AddShader (VkShaderStageFlags.Fragment, "#deferred.compose_with_shadows.frag.spv", constants);
#else
using System;
-using System.Collections.Generic;
using System.Numerics;
using System.Runtime.InteropServices;
using Vulkan;
</PropertyGroup>
<ItemGroup>
- <Compile Include="EnvironmentPipeline.cs;DeferredPbrRenderer.cs;shadowMapRenderer.cs" />
+ <Compile Include="DeferredPbrRenderer.cs;shadowMapRenderer.cs" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\addons\gltfLoader\gltfLoader.csproj" />
+ <ProjectReference Include="..\..\addons\EnvironmentPipeline\EnvironmentPipeline.csproj" />
</ItemGroup>
</Project>
\ No newline at end of file
cfg.RenderPass = new RenderPass (dev, swapChain.ColorFormat, DeferredPbrRenderer.NUM_SAMPLES);
- cfg.AddShader (VkShaderStageFlags.Vertex, "#deferred.FullScreenQuad.vert.spv");
+ cfg.AddShader (VkShaderStageFlags.Vertex, "#vke.FullScreenQuad.vert.spv");
cfg.AddShader (VkShaderStageFlags.Fragment, "#deferred.tone_mapping.frag.spv");
plToneMap = new GraphicPipeline (cfg);
+++ /dev/null
-#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);
-}
+++ /dev/null
-#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);
-}
+++ /dev/null
-#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
+++ /dev/null
-#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
+++ /dev/null
-// 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);//texture(samplerEnv, inPos).rgba;
-}
+++ /dev/null
-#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);
-}
+++ /dev/null
-#version 450
-
-layout (binding = 2) uniform samplerCube samplerEnv;
-
-layout (set = 0, location = 0) in vec3 inUVW;
-
-layout (set = 0, location = 0) out vec4 outColor;
-
-void main()
-{
- outColor = vec4(textureLod(samplerEnv, inUVW, 1.5).rgb, 1.0);
-}
\ No newline at end of file
+++ /dev/null
-#version 450
-
-#extension GL_ARB_separate_shader_objects : enable
-#extension GL_ARB_shading_language_420pack : enable
-
-layout (location = 0) in vec3 inPos;
-
-layout (binding = 0) uniform UBO
-{
- mat4 projection;
- mat4 model;
- mat4 view;
-} ubo;
-
-layout (location = 0) out vec3 outUVW;
-
-out gl_PerVertex
-{
- vec4 gl_Position;
-};
-
-void main()
-{
- outUVW = inPos;
- outUVW.y = -outUVW.y;
- gl_Position = ubo.projection * mat4(mat3(ubo.view)) * vec4(inPos, 1.0);
-}
public DescriptorSet dsMain;
public PbrModel2 model;
- public EnvironmentCube envCube;
-
+ public vke.Environment.EnvironmentCube envCube;
+ string[] cubemapPathes = {
+ Utils.DataDirectory + "textures/papermill.ktx",
+ Utils.DataDirectory + "textures/cubemap_yokohama_bc3_unorm.ktx",
+ Utils.DataDirectory + "textures/gcanyon_cube.ktx",
+ Utils.DataDirectory + "textures/pisa_cube.ktx",
+ Utils.DataDirectory + "textures/uffizi_cube.ktx",
+ };
public PBRPipeline (Queue staggingQ, RenderPass renderPass, PipelineCache pipelineCache = null) :
base (renderPass, pipelineCache, "pbr pipeline") {
dsMain = descriptorPool.Allocate (descLayoutMain);
- envCube = new EnvironmentCube (dsMain, layout, staggingQ, RenderPass);
+ envCube = new Environment.EnvironmentCube (cubemapPathes[0], dsMain, layout, staggingQ, RenderPass);
matrices.prefilteredCubeMipLevels = envCube.prefilterCube.CreateInfo.mipLevels;
uboMats = new HostBuffer (Dev, VkBufferUsageFlags.UniformBuffer, matrices, true);
y += dy;
ctx.MoveTo (x, y);
ctx.ShowText (string.Format ($"{"Debug draw (numpad 0->6)",-30} : {currentDebugView.ToString ()} "));
- y += dy;
+ /*y += dy;
ctx.MoveTo (x, y);
ctx.ShowText (string.Format ($"{"Debug Prefil Face: (f)",-30} : {pbrPipeline.envCube.debugFace.ToString ()} "));
y += dy;
ctx.MoveTo (x, y);
ctx.ShowText (string.Format ($"{"Debug Prefil Mip: (m)",-30} : {pbrPipeline.envCube.debugMip.ToString ()} "));
-
+ */
vkvgPipeline.DrawResources (ctx, (int)Width, (int)Height);
}
}
protected override void onKeyDown (Key key, int scanCode, Modifier modifiers) {
switch (key) {
+ /*
case Key.F:
if (modifiers.HasFlag (Modifier.Shift)) {
pbrPipeline.envCube.debugFace --;
pbrPipeline.envCube.debugMip = 0;
}
queryUpdatePrefilCube = updateViewRequested = true;
- break;
+ break;*/
case Key.P:
showDebugImg = !showDebugImg;
queryUpdatePrefilCube = updateViewRequested = true;
<ItemGroup>
<ProjectReference Include="..\..\addons\gltfLoader\gltfLoader.csproj" />
<ProjectReference Include="..\..\addons\VkvgPipeline\VkvgPipeline.csproj" />
+ <ProjectReference Include="..\..\addons\EnvironmentPipeline\EnvironmentPipeline.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ui\**\*.*">
<LogicalName>deferred.%(Filename)%(Extension)</LogicalName>
</EmbeddedResource>
- <None Include="shaders\**\*.*"/>
+ <None Include="shaders\**\*.*" />
</ItemGroup>
</Project>
+++ /dev/null
-#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);
-}
{
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);
}
foreach (ShaderInfo shader in cfg.shaders)
shaderStages.Add (shader.GetStageCreateInfo (Dev));
- VkPipelineColorBlendStateCreateInfo colorBlendInfo = VkPipelineColorBlendStateCreateInfo.New ();
- colorBlendInfo.logicOpEnable = cfg.ColorBlendLogicOpEnable;
- colorBlendInfo.logicOp = cfg.ColorBlendLogicOp;
- unsafe
- {
- colorBlendInfo.blendConstants[0] = cfg.ColorBlendConstants.X;
- colorBlendInfo.blendConstants[1] = cfg.ColorBlendConstants.Y;
- colorBlendInfo.blendConstants[2] = cfg.ColorBlendConstants.Z;
- colorBlendInfo.blendConstants[3] = cfg.ColorBlendConstants.W;
+ using (PinnedObjects pctx = new PinnedObjects ()) {
+
+ VkPipelineColorBlendStateCreateInfo colorBlendInfo = VkPipelineColorBlendStateCreateInfo.New ();
+ colorBlendInfo.logicOpEnable = cfg.ColorBlendLogicOpEnable;
+ colorBlendInfo.logicOp = cfg.ColorBlendLogicOp;
+ unsafe
+ {
+ colorBlendInfo.blendConstants[0] = cfg.ColorBlendConstants.X;
+ colorBlendInfo.blendConstants[1] = cfg.ColorBlendConstants.Y;
+ colorBlendInfo.blendConstants[2] = cfg.ColorBlendConstants.Z;
+ colorBlendInfo.blendConstants[3] = cfg.ColorBlendConstants.W;
+ }
+ colorBlendInfo.attachmentCount = (uint)cfg.blendAttachments.Count;
+ colorBlendInfo.pAttachments = cfg.blendAttachments.Pin (pctx);
+
+ VkPipelineDynamicStateCreateInfo dynStatesInfo = VkPipelineDynamicStateCreateInfo.New ();
+ dynStatesInfo.dynamicStateCount = (uint)cfg.dynamicStates.Count;
+ dynStatesInfo.pDynamicStates = cfg.dynamicStates.Pin (pctx);
+
+ VkPipelineVertexInputStateCreateInfo vertInputInfo = VkPipelineVertexInputStateCreateInfo.New ();
+ vertInputInfo.vertexBindingDescriptionCount = (uint)cfg.vertexBindings.Count;
+ vertInputInfo.pVertexBindingDescriptions = cfg.vertexBindings.Pin (pctx);
+ vertInputInfo.vertexAttributeDescriptionCount = (uint)cfg.vertexAttributes.Count;
+ vertInputInfo.pVertexAttributeDescriptions = cfg.vertexAttributes.Pin (pctx);
+
+ VkPipelineViewportStateCreateInfo viewportState = VkPipelineViewportStateCreateInfo.New ();
+ if (cfg.Viewports.Count > 0) {
+ viewportState.viewportCount = (uint)cfg.Viewports.Count;
+ viewportState.pViewports = cfg.Viewports.Pin (pctx);
+ } else
+ viewportState.viewportCount = 1;
+
+ if (cfg.Scissors.Count > 0) {
+ viewportState.scissorCount = (uint)cfg.Scissors.Count;
+ viewportState.pScissors = cfg.Scissors.Pin (pctx);
+ } else
+ viewportState.scissorCount = 1;
+
+ VkGraphicsPipelineCreateInfo info = VkGraphicsPipelineCreateInfo.New ();
+ info.renderPass = RenderPass.handle;
+ info.layout = Layout.handle;
+ info.pVertexInputState = vertInputInfo.Pin (pctx);
+ info.pInputAssemblyState = cfg.inputAssemblyState.Pin (pctx);
+ info.pRasterizationState = cfg.rasterizationState.Pin (pctx);
+ info.pColorBlendState = colorBlendInfo.Pin (pctx);
+ info.pMultisampleState = cfg.multisampleState.Pin (pctx);
+ info.pViewportState = viewportState.Pin (pctx);
+ info.pDepthStencilState = cfg.depthStencilState.Pin (pctx);
+ info.pDynamicState = dynStatesInfo.Pin (pctx);
+ info.stageCount = (uint)cfg.shaders.Count;
+ info.pStages = shaderStages.Pin (pctx);
+ info.subpass = cfg.SubpassIndex;
+
+ Utils.CheckResult (vkCreateGraphicsPipelines (Dev.VkDev, Cache == null ? VkPipelineCache.Null : Cache.handle, 1, ref info, IntPtr.Zero, out handle));
+
+ for (int i = 0; i < cfg.shaders.Count; i++)
+ Dev.DestroyShaderModule (shaderStages [i].module);
}
- colorBlendInfo.attachmentCount = (uint)cfg.blendAttachments.Count;
- colorBlendInfo.pAttachments = cfg.blendAttachments.Pin ();
-
- VkPipelineDynamicStateCreateInfo dynStatesInfo = VkPipelineDynamicStateCreateInfo.New ();
- dynStatesInfo.dynamicStateCount = (uint)cfg.dynamicStates.Count;
- dynStatesInfo.pDynamicStates = cfg.dynamicStates.Pin ();
-
- VkPipelineVertexInputStateCreateInfo vertInputInfo = VkPipelineVertexInputStateCreateInfo.New ();
- vertInputInfo.vertexBindingDescriptionCount = (uint)cfg.vertexBindings.Count;
- vertInputInfo.pVertexBindingDescriptions = cfg.vertexBindings.Pin ();
- vertInputInfo.vertexAttributeDescriptionCount = (uint)cfg.vertexAttributes.Count;
- vertInputInfo.pVertexAttributeDescriptions = cfg.vertexAttributes.Pin ();
-
- VkGraphicsPipelineCreateInfo info = VkGraphicsPipelineCreateInfo.New ();
- info.renderPass = RenderPass.handle;
- info.layout = Layout.handle;
- info.pVertexInputState = vertInputInfo.Pin ();
- info.pInputAssemblyState = cfg.inputAssemblyState.Pin ();
- info.pRasterizationState = cfg.rasterizationState.Pin ();
- info.pColorBlendState = colorBlendInfo.Pin ();
- info.pMultisampleState = cfg.multisampleState.Pin ();
- info.pViewportState = cfg.viewportState.Pin ();
- info.pDepthStencilState = cfg.depthStencilState.Pin ();
- info.pDynamicState = dynStatesInfo.Pin ();
- info.stageCount = (uint)cfg.shaders.Count;
- info.pStages = shaderStages.Pin ();
- info.subpass = cfg.SubpassIndex;
-
- Utils.CheckResult (vkCreateGraphicsPipelines (Dev.VkDev, Cache == null ? VkPipelineCache.Null : Cache.handle, 1, ref info, IntPtr.Zero, out handle));
-
- for (int i = 0; i < cfg.shaders.Count; i++)
- Dev.DestroyShaderModule (shaderStages[i].module);
-
- vertInputInfo.Unpin ();
- cfg.inputAssemblyState.Unpin ();
- cfg.rasterizationState.Unpin ();
- colorBlendInfo.Unpin ();
- cfg.multisampleState.Unpin ();
- cfg.viewportState.Unpin ();
- cfg.depthStencilState.Unpin ();
- dynStatesInfo.Unpin ();
- shaderStages.Unpin ();
-
- cfg.vertexAttributes.Unpin ();
- cfg.vertexBindings.Unpin ();
- cfg.dynamicStates.Unpin ();
- cfg.blendAttachments.Unpin ();
}
base.Activate ();
}
public VkPipelineBindPoint bindPoint = VkPipelineBindPoint.Graphics;
public VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = VkPipelineInputAssemblyStateCreateInfo.New ();
public VkPipelineRasterizationStateCreateInfo rasterizationState = VkPipelineRasterizationStateCreateInfo.New ();
- public VkPipelineViewportStateCreateInfo viewportState = VkPipelineViewportStateCreateInfo.New ();
+ public List<VkViewport> Viewports = new List<VkViewport> ();
+ public List<VkRect2D> Scissors = new List<VkRect2D> ();
public VkPipelineDepthStencilStateCreateInfo depthStencilState = VkPipelineDepthStencilStateCreateInfo.New ();
public VkPipelineMultisampleStateCreateInfo multisampleState = VkPipelineMultisampleStateCreateInfo.New ();
public List<VkPipelineColorBlendAttachmentState> blendAttachments = new List<VkPipelineColorBlendAttachmentState> ();
/// <summary>
/// Create a default pipeline configuration with viewport and scissor as dynamic states. One blend attachment is
/// added automatically with blending disabled. (cfg.blendAttachments[0])
+ /// If width and height parameter are omitted viewport and scissor dynamic states are automatically added, else
+ /// a viewport and a vkrect2d are added to the viewport and scissor lists.
/// </summary>
public static GraphicPipelineConfig CreateDefault (VkPrimitiveTopology topology = VkPrimitiveTopology.TriangleList,
- VkSampleCountFlags samples = VkSampleCountFlags.SampleCount1, bool depthTestEnabled = true) {
+ VkSampleCountFlags samples = VkSampleCountFlags.SampleCount1, bool depthTestEnabled = true, int width = -1, int height = -1) {
GraphicPipelineConfig cfg = new GraphicPipelineConfig ();
cfg.inputAssemblyState.topology = topology;
cfg.rasterizationState.depthBiasEnable = False;
cfg.rasterizationState.lineWidth = 1.0f;
- cfg.viewportState.viewportCount = 1;
- cfg.viewportState.scissorCount = 1;
-
cfg.blendAttachments.Add (new VkPipelineColorBlendAttachmentState (false));
- cfg.dynamicStates.Add (VkDynamicState.Viewport);
- cfg.dynamicStates.Add (VkDynamicState.Scissor);
+ if (width < 0) {
+ cfg.dynamicStates.Add (VkDynamicState.Viewport);
+ cfg.dynamicStates.Add (VkDynamicState.Scissor);
+ } else {
+ cfg.Viewports.Add (new VkViewport { height = height, width = width, minDepth = 0f, maxDepth = 1f });
+ cfg.Scissors.Add (new VkRect2D ((uint)width, (uint)height));
+ }
if (depthTestEnabled) {
cfg.depthStencilState.depthTestEnable = True;