aboutsummaryrefslogtreecommitdiffstatsci
path: root/samples
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2019-04-25 20:53:19 +0200
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2019-04-25 20:53:19 +0200
commitbb9f94f7cd2a0ddcc6fb613c1c6e82ba65c571ec (patch)
treebcc72b56f058ca0817e85b9d14def58116678632 /samples
parent51cc7c308585261433e3b11556d9e09846968650 (diff)
specialization infos helper class
Diffstat (limited to 'samples')
-rw-r--r--samples/deferred/EnvironmentPipeline.cs31
-rw-r--r--samples/deferred/main.cs33
-rw-r--r--samples/deferred/shaders/GBuffPbr.frag6
3 files changed, 31 insertions, 39 deletions
diff --git a/samples/deferred/EnvironmentPipeline.cs b/samples/deferred/EnvironmentPipeline.cs
index 063f5e2..68128cc 100644
--- a/samples/deferred/EnvironmentPipeline.cs
+++ b/samples/deferred/EnvironmentPipeline.cs
@@ -14,7 +14,6 @@ namespace CVKL {
public Image irradianceCube { get; private set; }
public Image prefilterCube { get; set; }
- public Image debugImg;
public int debugMip = 0;
public int debugFace = 0;
@@ -51,11 +50,6 @@ namespace CVKL {
}
- //public void WriteDesc (VkDescriptorBufferInfo matrixDesc) {
- // DescriptorSetWrites uboUpdate = new DescriptorSetWrites (descLayoutMain);
- // uboUpdate.Write (Dev, dsSkybox, matrixDesc, cubemap.Descriptor);
- //}
-
public void RecordDraw (CommandBuffer cmd) {
Bind (cmd);
cmd.BindVertexBuffer (vboSkybox);
@@ -265,7 +259,7 @@ namespace CVKL {
cmd.PushConstant (pl.Layout, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, deltaTheta, (uint)Marshal.SizeOf<Matrix4x4> () + 4);
} else {
cmd.PushConstant (pl.Layout, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, roughness, (uint)Marshal.SizeOf<Matrix4x4> ());
- cmd.PushConstant (pl.Layout, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, 32u, (uint)Marshal.SizeOf<Matrix4x4> () + 4);
+ cmd.PushConstant (pl.Layout, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, 512u, (uint)Marshal.SizeOf<Matrix4x4> () + 4);
}
cmd.BindDescriptorSet (pl.Layout, dset);
@@ -288,27 +282,6 @@ namespace CVKL {
1, region.Pin ());
region.Unpin ();
- /*
- //debug img
- if (target == CBTarget.PREFILTEREDENV && m == debugMip && f == debugFace) {
- debugImg?.Dispose ();
- debugImg = new Image (Dev, VkFormat.R16g16b16a16Sfloat, VkImageUsageFlags.Sampled | VkImageUsageFlags.TransferDst, VkMemoryPropertyFlags.DeviceLocal,
- (uint)viewPortSize, (uint)viewPortSize);
- debugImg.CreateView ();
- debugImg.CreateSampler ();
- region.dstSubresource.baseArrayLayer = 0;
- region.dstSubresource.mipLevel = 0;
- debugImg.SetLayout (cmd, VkImageAspectFlags.Color,
- VkImageLayout.Undefined, VkImageLayout.TransferDstOptimal);
- Vk.vkCmdCopyImage (cmd.Handle,
- imgFbOffscreen.Handle, VkImageLayout.TransferSrcOptimal,
- debugImg.Handle, VkImageLayout.TransferDstOptimal,
- 1, region.Pin ());
- debugImg.SetLayout (cmd, VkImageAspectFlags.Color,
- VkImageLayout.TransferDstOptimal, VkImageLayout.ShaderReadOnlyOptimal);
- region.Unpin ();
- }*/
-
imgFbOffscreen.SetLayout (cmd, VkImageAspectFlags.Color,
VkImageLayout.TransferSrcOptimal, VkImageLayout.ColorAttachmentOptimal);
@@ -346,8 +319,6 @@ namespace CVKL {
irradianceCube.Dispose ();
prefilterCube.Dispose ();
- debugImg?.Dispose ();
-
base.Dispose (disposing);
}
}
diff --git a/samples/deferred/main.cs b/samples/deferred/main.cs
index 929026c..1b1d720 100644
--- a/samples/deferred/main.cs
+++ b/samples/deferred/main.cs
@@ -36,6 +36,7 @@ namespace deferred {
}
DebugView currentDebugView = DebugView.none;
+
public struct Matrices {
public Matrix4x4 projection;
public Matrix4x4 model;
@@ -46,19 +47,31 @@ namespace deferred {
public float gamma;
public float prefilteredCubeMipLevels;
public float scaleIBLAmbient;
- public float debugViewInputs;
+ public uint lightsCount;
public float debugViewEquation;
}
+ public struct Light {
+ public Vector4 position;
+ public Vector4 color;
+ }
+
public Matrices matrices = new Matrices {
lightPos = Vector4.Normalize (new Vector4 (0.7f, 0.6f, 0.2f, 0.0f)),
gamma = 1.2f,
exposure = 2.0f,
scaleIBLAmbient = 1.0f,
- debugViewInputs = 0,
+ lightsCount = 1,
debugViewEquation = 0
};
+ Light[] lights = {
+ new Light {
+ position = new Vector4(1,1,1,0),
+ color = new Vector4(1)
+ }
+ };
+
Framebuffer[] frameBuffers;
Image gbColorRough, gbEmitMetal, gbN_AO, gbPos, hdrImg;
@@ -84,7 +97,10 @@ namespace deferred {
const int SP_TONE_MAPPING = 3;
Program () {
+ camera = new Camera (Utils.DegreesToRadians (45f), 1f, 0.1f, 16f);
+
init ();
+
camera.SetPosition (0, 0, 3);
camera.Model = Matrix4x4.CreateScale (1f / Math.Max (Math.Max (modelAABB.max.X, modelAABB.max.Y), modelAABB.max.Z));
//camera.Model = Matrix4x4.CreateScale (0.02f);
@@ -204,10 +220,16 @@ namespace deferred {
cfg.AddVertexBinding<PbrModel.Vertex> (0);
cfg.SetVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat, VkFormat.R32g32Sfloat);
- cfg.AddShader (VkShaderStageFlags.Vertex, "shaders/GBuffPbr.vert.spv");
- cfg.AddShader (VkShaderStageFlags.Fragment, "shaders/GBuffPbr.frag.spv");
- gBuffPipeline = new GraphicPipeline (cfg);
+ using (SpecializationInfo constants = new SpecializationInfo (
+ new SpecializationConstant<float> (0, camera.NearPlane),
+ new SpecializationConstant<float> (1, camera.FarPlane))) {
+
+ cfg.AddShader (VkShaderStageFlags.Vertex, "shaders/GBuffPbr.vert.spv");
+ cfg.AddShader (VkShaderStageFlags.Fragment, "shaders/GBuffPbr.frag.spv", constants);
+
+ gBuffPipeline = new GraphicPipeline (cfg);
+ }
//COMPOSE PIPELINE
cfg.blendAttachments.Clear ();
@@ -345,7 +367,6 @@ namespace deferred {
camera.Position.Z * (float)Math.Cos (camera.Rotation.Y) * (float)Math.Cos (camera.Rotation.X),
0
);
- //matrices.debugViewInputs = (float)currentDebugView;
uboMats.Update (matrices, (uint)Marshal.SizeOf<Matrices> ());
diff --git a/samples/deferred/shaders/GBuffPbr.frag b/samples/deferred/shaders/GBuffPbr.frag
index cd46c6a..0a98717 100644
--- a/samples/deferred/shaders/GBuffPbr.frag
+++ b/samples/deferred/shaders/GBuffPbr.frag
@@ -5,6 +5,9 @@
#define MANUAL_SRGB 0
#define DEBUG 0
+layout (constant_id = 0) const float NEAR_PLANE = 0.1f;
+layout (constant_id = 1) const float FAR_PLANE = 256.0f;
+
struct Material {
vec4 baseColorFactor;
vec4 emissiveFactor;
@@ -137,9 +140,6 @@ float convertMetallic(vec3 diffuse, vec3 specular, float maxSpecular) {
return clamp((-b + sqrt(D)) / (2.0 * a), 0.0, 1.0);
}
-layout (constant_id = 0) const float NEAR_PLANE = 0.1f;
-layout (constant_id = 1) const float FAR_PLANE = 256.0f;
-
float linearDepth(float depth)
{
float z = depth * 2.0f - 1.0f;