aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2021-09-10 06:30:44 +0000
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2021-09-10 06:30:44 +0000
commit0198478d81c9cc1d4a27f718982b748b2261b657 (patch)
treedc4363766cc100d9a64430dcd6f01e6d6fa83ed7
parent8bd960d96f3f878155637efafeff8b8b2c2fc57f (diff)
wip
-rw-r--r--data/models/chess.glbbin5150236 -> 5150276 bytes
-rw-r--r--data/models/chess3.glbbin0 -> 13835320 bytes
-rw-r--r--shaders/tone_mapping.frag59
-rw-r--r--shaders/tone_mapping_ssr.frag (renamed from shaders/tone_mapping2.frag)44
-rw-r--r--src/BoardWidget.cs8
-rw-r--r--src/Piece.cs21
-rw-r--r--src/VkChess.cs331
-rw-r--r--src/deferredPbrRendererBase.cs21
-rw-r--r--src/shadowMapRenderer.cs11
-rw-r--r--ui/chess.crow5
-rw-r--r--ui/chess.style31
-rw-r--r--ui/newGame.crow30
-rw-r--r--ui/promote.crow35
-rw-r--r--ui/winOptions.crow69
-rw-r--r--vkChess.net.csproj8
15 files changed, 400 insertions, 273 deletions
diff --git a/data/models/chess.glb b/data/models/chess.glb
index f2f683b..bb6d9f3 100644
--- a/data/models/chess.glb
+++ b/data/models/chess.glb
Binary files differ
diff --git a/data/models/chess3.glb b/data/models/chess3.glb
new file mode 100644
index 0000000..b2c95d2
--- /dev/null
+++ b/data/models/chess3.glb
Binary files differ
diff --git a/shaders/tone_mapping.frag b/shaders/tone_mapping.frag
new file mode 100644
index 0000000..664bb91
--- /dev/null
+++ b/shaders/tone_mapping.frag
@@ -0,0 +1,59 @@
+#version 450
+#extension GL_ARB_separate_shader_objects : enable
+#extension GL_ARB_shading_language_420pack : enable
+
+layout(push_constant) uniform PushConsts {
+ float exposure;
+ float gamma;
+};
+
+vec3 Uncharted2Tonemap(vec3 color)
+{
+ const float A = 0.15;
+ const float B = 0.50;
+ const float C = 0.10;
+ const float D = 0.20;
+ const float E = 0.02;
+ const float F = 0.30;
+ const float W = 11.2;
+ return ((color*(A*color+C*B)+D*E)/(color*(A*color+B)+D*F))-E/F;
+}
+
+vec4 tonemap(vec4 color, float exposure, float gamma)
+{
+ vec3 outcol = Uncharted2Tonemap(color.rgb * exposure);
+ outcol = outcol * (1.0f / Uncharted2Tonemap(vec3(11.2f)));
+ return vec4(pow(outcol, vec3(1.0f / 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
+}
+
+layout (constant_id = 0) const float NEAR_PLANE = 0.1f;
+layout (constant_id = 1) const float FAR_PLANE = 32.0f;
+
+layout (set = 0, binding = 0) uniform sampler2D uiImage;
+layout (set = 0, binding = 1) uniform sampler2D samplerHDR;
+
+layout (location = 0) in vec2 inUV;
+layout (location = 0) out vec4 outColor;
+
+void main()
+{
+ vec4 hdrColor = texture(samplerHDR, inUV);
+ vec4 uiColor = texture(uiImage, inUV);
+ outColor = tonemap(hdrColor, exposure, gamma);
+ outColor = vec4(outColor.rgb * (1 - uiColor.a) + uiColor.rgb * uiColor.a, 1);
+}
diff --git a/shaders/tone_mapping2.frag b/shaders/tone_mapping_ssr.frag
index 84d672c..b751f90 100644
--- a/shaders/tone_mapping2.frag
+++ b/shaders/tone_mapping_ssr.frag
@@ -25,7 +25,7 @@ vec3 Uncharted2Tonemap(vec3 color)
vec4 tonemap(vec4 color, float exposure, float gamma)
{
vec3 outcol = Uncharted2Tonemap(color.rgb * exposure);
- outcol = outcol * (1.0f / Uncharted2Tonemap(vec3(11.2f)));
+ outcol = outcol * (1.0f / Uncharted2Tonemap(vec3(11.2f)));
return vec4(pow(outcol, vec3(1.0f / gamma)), color.a);
}
@@ -56,7 +56,7 @@ layout (set = 0, binding = 4) uniform UBO {
mat4 projection;
mat4 model;
mat4 view;
- vec4 camPos;
+ vec4 camPos;
} ubo;
layout (location = 0) in vec2 inUV;
@@ -70,16 +70,16 @@ bool float_equ (float a, float b) {
float linearDepth(float depth)
{
- float z = depth * 2.0f - 1.0f;
- return (2.0f * NEAR_PLANE * FAR_PLANE) / (FAR_PLANE + NEAR_PLANE - z * (FAR_PLANE - NEAR_PLANE));
+ float z = depth * 2.0f - 1.0f;
+ return (2.0f * NEAR_PLANE * FAR_PLANE) / (FAR_PLANE + NEAR_PLANE - z * (FAR_PLANE - NEAR_PLANE));
}
-void main()
+void main()
{
const float reflectionCoef = 0.4;
//ivec2 ts = textureSize(samplerHDR, 0);
//vec4 hdrColor = texelFetch (samplerHDR, ivec2(gl_FragCoord.xy), gl_SampleID);
-
- //vec4 hdrColor = texelFetch (samplerHDR, inUV);
+
+ //vec4 hdrColor = texelFetch (samplerHDR, inUV);
//vec4 c = texture (bloom, inUV);
//float lum = (0.299*c.r + 0.587*c.g + 0.114*c.b);
//if (lum>1.0)
@@ -91,7 +91,7 @@ void main()
float depth = texture(gbPos, inUV).a;
vec3 n = texture(gbN_AO, inUV).rgb;
-
+
//outColor = vec4 (vec3(linDepth/100.0), 1);
if (float_equ (n.g, 1.0) && float_equ (pos.y, 0.0)) {
//reflecting plane
@@ -127,42 +127,42 @@ void main()
return;*/
hit = true;
break;
- }
+ }
/*cp = textureOffset(gbPos, uv, ivec2 (0,1));
if (abs(linDepthCP - cp.a) < depthTreshold) {
hit = true;
break;
- }
+ }
cp = textureOffset(gbPos, uv, ivec2 (1,0));
if (abs(linDepthCP - cp.a) < depthTreshold) {
hit = true;
break;
- }
+ }
cp = textureOffset(gbPos, uv, ivec2 (0,-1));
if (abs(linDepthCP - cp.a) < depthTreshold) {
hit = true;
break;
- }
+ }
cp = textureOffset(gbPos, uv, ivec2 (-1,0));
if (abs(linDepthCP - cp.a) < depthTreshold) {
hit = true;
break;
- }
+ }
cp = textureOffset(gbPos, uv, ivec2 (1,1));
if (abs(linDepthCP - cp.a) < depthTreshold) {
hit = true;
break;
- }
+ }
cp = textureOffset(gbPos, uv, ivec2 (1,-1));
if (abs(linDepthCP - cp.a) < depthTreshold) {
hit = true;
break;
- }
+ }
cp = textureOffset(gbPos, uv, ivec2 (-1,-1));
if (abs(linDepthCP - cp.a) < depthTreshold) {
hit = true;
break;
- }
+ }
cp = textureOffset(gbPos, uv, ivec2 (-1,1));
if (abs(linDepthCP - cp.a) < depthTreshold) {
hit = true;
@@ -171,24 +171,24 @@ void main()
curLength += s;
//s *= 1.2;
}
-
+
if (hit)
hdrColor = mix (hdrColor, texture(samplerHDR, uv), reflectionCoef);
//hdrColor = vec4 (1,0,0,1);
-
-
+
+
}
outColor = tonemap(hdrColor, exposure, gamma);
outColor = vec4(outColor.rgb * (1 - uiColor.a) + uiColor.rgb * uiColor.a, 1);
//outColor = vec4 (vec3 (depth/100.0), 1);
-
+
/*
outColor = vec4(SRGBtoLINEAR(tonemap(hdrColor.rgb)), hdrColor.a);;*/
-
-/* vec3 mapped = vec3(1.0) - exp(-hdrColor.rgb * pc.exposure);
+
+/* vec3 mapped = vec3(1.0) - exp(-hdrColor.rgb * pc.exposure);
mapped = pow(mapped, vec3(1.0 / pc.gamma));
outColor = vec4(mapped, hdrColor.a);*/
}
diff --git a/src/BoardWidget.cs b/src/BoardWidget.cs
index 80668af..7188a41 100644
--- a/src/BoardWidget.cs
+++ b/src/BoardWidget.cs
@@ -23,11 +23,11 @@ namespace vkChess
RegisterForGraphicUpdate ();
return;
}
- board = value;
+ board = value;
NotifyValueChanged ("Board", board);
RegisterForGraphicUpdate ();
}
- }
+ }
public BoardWidget ():base()
{
sprites = new SvgPicture ("data/Pieces.svg");
@@ -100,7 +100,7 @@ namespace vkChess
spriteName = "w";
else
spriteName = "b";
-
+
switch (board[x,y].Type) {
case PieceType.Pawn:
spriteName += "p";
@@ -126,7 +126,7 @@ namespace vkChess
(int)(gridY + (7 - y) * cellSize),
(int)cellSize,
(int)cellSize),spriteName);
- }
+ }
}
}
}
diff --git a/src/Piece.cs b/src/Piece.cs
index fd95c31..cc10324 100644
--- a/src/Piece.cs
+++ b/src/Piece.cs
@@ -24,8 +24,8 @@ namespace vkChess {
[DebuggerDisplay("{DebuggerDisplay}")]
public class Piece {
- static Vector4 blackColor = new Vector4(0.03f, 0.03f, 0.03f, 1f);
- static Vector4 whiteColor = new Vector4(1.0f, 1.0f, 1.0f, 1f);
+ public static Vector4 blackColor = new Vector4(0.03f, 0.03f, 0.03f, 1f);
+ public static Vector4 whiteColor = new Vector4(1.0f, 1.0f, 1.0f, 1f);
public static HostBuffer<VkChess.InstanceData> instanceBuff;
public static VkChess.InstanceData[] boardDatas;
public static uint flushStart, flushEnd;
@@ -40,13 +40,13 @@ namespace vkChess {
public bool IsPromoted;
public bool HasMoved;
public bool Captured {
- get { return BoardCell < 0; }
+ get => BoardCell < 0;
set {
if (value)
BoardCell = -1;
else
BoardCell = 0;
- }
+ }
}
public void SetCaptured (Vector3 capturePos) {
Captured = true;
@@ -59,7 +59,7 @@ namespace vkChess {
VkChess.InstanceData instData;
- public Piece (ChessColor player, PieceType type, int col, int line) {
+ public Piece (ChessColor player, PieceType type, int col, int line, Vector3 color) {
this.instanceIdx = nextInstanceIdx++;
this.Type = type;
this.Player = player;
@@ -69,7 +69,7 @@ namespace vkChess {
position.Y = initY;
BoardCell = new Crow.Point (col, line);
- instData = new VkChess.InstanceData(Player == ChessColor.White ? whiteColor : blackColor, Matrix4x4.Identity);
+ instData = new VkChess.InstanceData(new Vector4 (color, 1), Matrix4x4.Identity);
if (player == ChessColor.Black && type == PieceType.Knight)
zAngle = MathHelper.Pi;
@@ -155,6 +155,10 @@ namespace vkChess {
else if (flushEnd <= instIdx)
flushEnd = instIdx + 1;
}
+ public void SetColor (Vector3 newColor) {
+ instData.color = new Vector4 (newColor, 1);
+ UpdateBuff (instanceIdx, ref instData);
+ }
public static void UpdateCase (int x, int y, Vector4 colorDiff) {
int index = y * 8 + x;
boardDatas[index].color += colorDiff;
@@ -179,7 +183,7 @@ namespace vkChess {
if (IsPromoted)
Unpromote();
IsPromoted = false;
- HasMoved = false;
+ HasMoved = false;
BoardCell = new Crow.Point (initX, initY);
}
public void MoveTo (Crow.Point newPos, bool animate = false) {
@@ -219,6 +223,9 @@ namespace vkChess {
case 'k':
Type = PieceType.Knight;
break;
+ case 'n':
+ IsPromoted = false;
+ return;
default:
throw new Exception("Unrecognized promotion");
}
diff --git a/src/VkChess.cs b/src/VkChess.cs
index 54751d1..ef7039b 100644
--- a/src/VkChess.cs
+++ b/src/VkChess.cs
@@ -19,9 +19,9 @@ namespace vkChess
public enum PieceType { Pawn, Rook, Knight, Bishop, King, Queen };
public class VkChess : CrowWindow {
-#if NETCOREAPP
+#if NETCOREAPP
static IntPtr resolveUnmanaged (Assembly assembly, String libraryName) {
-
+
switch (libraryName)
{
case "glfw3":
@@ -29,7 +29,7 @@ namespace vkChess
case "rsvg-2.40":
return System.Runtime.InteropServices.NativeLibrary.Load("rsvg-2", assembly, null);
}
- Console.WriteLine ($"[UNRESOLVE] {assembly} {libraryName}");
+ Console.WriteLine ($"[UNRESOLVE] {assembly} {libraryName}");
return IntPtr.Zero;
}
@@ -39,14 +39,14 @@ namespace vkChess
#endif
VkChess(){}
static void Main (string [] args) {
- Instance.VALIDATION = true;
- Instance.RENDER_DOC_CAPTURE = false;
+ //Instance.VALIDATION = true;
+ //Instance.RENDER_DOC_CAPTURE = true;
//SwapChain.PREFERED_FORMAT = VkFormat.B8g8r8a8Unorm;
DeferredPbrRendererBase.MAX_MATERIAL_COUNT = 3;
DeferredPbrRendererBase.MRT_FORMAT = VkFormat.R16g16b16a16Sfloat;
DeferredPbrRendererBase.HDR_FORMAT = VkFormat.R16g16b16a16Sfloat;
- PbrModelTexArray.TEXTURE_DIM = 512;
- ShadowMapRenderer.SHADOWMAP_SIZE = 1024;
+ PbrModelTexArray.TEXTURE_DIM = 1024;
+ ShadowMapRenderer.SHADOWMAP_SIZE = 1024;
using (VkChess app = new VkChess ())
app.Run ();
}
@@ -58,7 +58,7 @@ namespace vkChess
public override string [] EnabledDeviceExtensions => new string [] {
Ext.D.VK_KHR_swapchain,
- Ext.D.VK_KHR_multiview
+ //Ext.D.VK_KHR_multiview
};
protected override void configureEnabledFeatures (VkPhysicalDeviceFeatures available_features, ref VkPhysicalDeviceFeatures enabled_features) {
base.configureEnabledFeatures (available_features, ref enabled_features);
@@ -85,69 +85,74 @@ namespace vkChess
//vke.DebugUtils.Messenger dbgmsg;
#endif
protected override void CreateRenderPass () {
- renderPass = new RenderPass (dev, swapChain.ColorFormat, DeferredPbrRendererBase.NUM_SAMPLES);
- /*renderPass = new RenderPass (dev, VkSampleCountFlags.SampleCount1);
- renderPass.AddAttachment (swapChain.ColorFormat, VkImageLayout.PresentSrcKHR, VkSampleCountFlags.SampleCount1,
- VkAttachmentLoadOp.Load, VkAttachmentStoreOp.DontCare, VkImageLayout.ColorAttachmentOptimal);//final outpout
- SubPass subpass0 = new SubPass ();
- subpass0.AddColorReference (0, VkImageLayout.ColorAttachmentOptimal);
- renderPass.AddSubpass (subpass0);
- renderPass.AddDependency (Vk.SubpassExternal, 0,
- VkPipelineStageFlags.BottomOfPipe, VkPipelineStageFlags.ColorAttachmentOutput,
- VkAccessFlags.MemoryRead, VkAccessFlags.ColorAttachmentWrite);
- renderPass.AddDependency (0, Vk.SubpassExternal,
- VkPipelineStageFlags.ColorAttachmentOutput, VkPipelineStageFlags.BottomOfPipe,
- VkAccessFlags.ColorAttachmentWrite, VkAccessFlags.MemoryRead);*/
- }
+ renderPass = new RenderPass (dev, swapChain.ColorFormat, DeferredPbrRendererBase.NUM_SAMPLES);
+ }
GraphicPipeline plToneMap;
DescriptorSetLayout dslToneMap;
protected override void CreateDescriptors () {
- dsPool = new DescriptorPool (dev, 1,
- new VkDescriptorPoolSize (VkDescriptorType.CombinedImageSampler, 4),
- new VkDescriptorPoolSize (VkDescriptorType.UniformBuffer, 1));
+ dsPool = EnableReflections ?
+ new DescriptorPool (dev, 1,
+ new VkDescriptorPoolSize (VkDescriptorType.CombinedImageSampler, 4),
+ new VkDescriptorPoolSize (VkDescriptorType.UniformBuffer, 1)) :
+ new DescriptorPool (dev, 1,
+ new VkDescriptorPoolSize (VkDescriptorType.CombinedImageSampler, 2));
descSet = dsPool.Allocate (dslToneMap);
}
protected override void CreatePipeline () {
- using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, DeferredPbrRendererBase.NUM_SAMPLES)) {
+ using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, DeferredPbrRendererBase.NUM_SAMPLES)) {
if (DeferredPbrRendererBase.NUM_SAMPLES != VkSampleCountFlags.SampleCount1) {
cfg.multisampleState.sampleShadingEnable = true;
cfg.multisampleState.minSampleShading = 0.5f;
}
dslToneMap = new DescriptorSetLayout (dev, 0,
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.UniformBuffer)
+ new VkDescriptorSetLayoutBinding (1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)
);
- cfg.Layout = new PipelineLayout (dev,
- new VkPushConstantRange (VkShaderStageFlags.Fragment, 20u), dslToneMap);
+ if (EnableReflections) {
+ dslToneMap.Bindings.AddRange ( new VkDescriptorSetLayoutBinding[] {
+ new VkDescriptorSetLayoutBinding (2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
+ new VkDescriptorSetLayoutBinding (3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
+ new VkDescriptorSetLayoutBinding (4, VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer)
+ });
+ cfg.Layout = new PipelineLayout (dev,
+ new VkPushConstantRange (VkShaderStageFlags.Fragment, 20u), dslToneMap);
+ } else
+ cfg.Layout = new PipelineLayout (dev,
+ new VkPushConstantRange (VkShaderStageFlags.Fragment, 8u), dslToneMap);
cfg.RenderPass = renderPass;
cfg.AddShaders (
new ShaderInfo (dev, VkShaderStageFlags.Vertex, "#vke.FullScreenQuad.vert.spv"),
- new ShaderInfo (dev, VkShaderStageFlags.Fragment, "#vkChess.net.tone_mapping2.frag.spv")
+ new ShaderInfo (dev, VkShaderStageFlags.Fragment,
+ EnableReflections ?
+ "#vkChess.net.tone_mapping_ssr.frag.spv" : "#vkChess.net.tone_mapping.frag.spv")
);
plToneMap = new GraphicPipeline (cfg);
}
}
- protected override void recordUICmd (PrimaryCommandBuffer cmd, int imageIndex) {
+ protected override void recordUICmd (PrimaryCommandBuffer cmd, int imageIndex) {
renderPass.Begin(cmd, frameBuffers[imageIndex]);
cmd.SetViewport (frameBuffers[imageIndex].Width, frameBuffers[imageIndex].Height);
cmd.SetScissor (frameBuffers[imageIndex].Width, frameBuffers[imageIndex].Height);
- cmd.PushConstant (plToneMap.Layout, VkShaderStageFlags.Fragment, 16, new float[] { Exposure, Gamma, SSRStep, SSRThreshold }, 0);
- cmd.PushConstant (plToneMap.Layout, VkShaderStageFlags.Fragment, 4, SSRMaxStepCount, 16);
+ if (EnableReflections) {
+ cmd.PushConstant (plToneMap.Layout, VkShaderStageFlags.Fragment, 16, new float[] { Exposure, Gamma, SSRStep, SSRThreshold }, 0);
+ cmd.PushConstant (plToneMap.Layout, VkShaderStageFlags.Fragment, 4, SSRMaxStepCount, 16);
+ } else
+ cmd.PushConstant (plToneMap.Layout, VkShaderStageFlags.Fragment, 16, new float[] { Exposure, Gamma}, 0);
+
plToneMap.BindDescriptorSet (cmd, descSet);
plToneMap.Bind (cmd);
cmd.Draw (3, 1, 0, 0);
renderPass.End (cmd);
- }
+ }
protected override void initVulkan () {
+ DeferredPbrRendererBase.NUM_SAMPLES = SampleCount;
+
initLog ();
base.initVulkan ();
@@ -175,20 +180,19 @@ namespace vkChess
createCamera ();
- DeferredPbrRendererBase.NUM_SAMPLES = SampleCount;
-
- renderer = new DeferredPbrRenderer (dev, swapChain, presentQueue, cubemapPathes [1], camera.NearPlane, camera.FarPlane);
+ renderer = new DeferredPbrRenderer (dev, swapChain, presentQueue, cubemapPathes [0], camera.NearPlane, camera.FarPlane);
renderer.matrices.scaleIBLAmbient = IBLAmbient;
renderer.lights[0].color = new Vector4 (LightStrength);
- //renderer.LoadModel (transferQ, "data/models/chess.glb");
- renderer.LoadModel (transferQ, "/mnt/devel/vkChess.net/data/models/chess.glb");
+ renderer.LoadModel (transferQ, "data/models/chess.glb");
+ //renderer.LoadModel (transferQ, "/mnt/devel/vkChess.net/data/models/chess3.glb");
// Matrix4x4.CreateScale(1f / Math.Max(Math.Max(renderer.modelAABB.Width, renderer.modelAABB.Height), renderer.modelAABB.Depth));
- DescriptorSetWrites dsw = new DescriptorSetWrites (descSet,
- dslToneMap.Bindings[4]);
- dsw.Write (dev, renderer.uboMatrices.Descriptor);
-
+ if (EnableReflections) {
+ DescriptorSetWrites dsw = new DescriptorSetWrites (descSet,
+ dslToneMap.Bindings[4]);
+ dsw.Write (dev, renderer.uboMatrices.Descriptor);
+ }
UpdateFrequency = 5;
@@ -199,8 +203,6 @@ namespace vkChess
initBoard ();
initStockfish ();
-
-
iFace.Load ("ui/chess.crow").DataSource = this;
loadCurrentGame ();
@@ -219,13 +221,13 @@ namespace vkChess
}
string [] cubemapPathes = {
- "data/textures/papermill.ktx",
+ "data/textures/papermill.ktx",
"data/textures/pisa_cube.ktx",
"data/textures/gcanyon_cube.ktx",
};
DeferredPbrRendererBase renderer;
-
+
public struct InstanceData
{
public Vector4 color;
@@ -279,9 +281,10 @@ namespace vkChess
public override void UpdateView () {
dev.WaitIdle ();
-
- renderer.UpdateView (camera);
- updateViewRequested = false;
+ if (updateViewRequested) {
+ renderer.UpdateView (camera);
+ updateViewRequested = false;
+ }
if (instanceBuff == null)
return;
if (renderer.shadowMapRenderer.updateShadowMap)
@@ -313,6 +316,7 @@ namespace vkChess
if (Animation.HasAnimations)
renderer.shadowMapRenderer.updateShadowMap = true;
+ //adapt animation step on current fps
fpsAccum += fps;
fpsAccumCpt++;
if (fpsAccumCpt == fpsAccumLimit) {
@@ -341,9 +345,14 @@ namespace vkChess
base.OnResize ();
renderer.Resize ();
- DescriptorSetWrites dsw = new DescriptorSetWrites (descSet,
- dslToneMap.Bindings[1], dslToneMap.Bindings[2], dslToneMap.Bindings[3]);
- dsw.Write (dev, renderer.HDROutput.Descriptor, renderer.GBuffPosDepthOutput.Descriptor, renderer.GBuffN_AO.Descriptor);
+ if (EnableReflections) {
+ DescriptorSetWrites dsw = new DescriptorSetWrites (descSet,
+ dslToneMap.Bindings[1], dslToneMap.Bindings[2], dslToneMap.Bindings[3]);
+ dsw.Write (dev, renderer.HDROutput.Descriptor, renderer.GBuffPosDepthOutput.Descriptor, renderer.GBuffN_AO.Descriptor);
+ } else {
+ DescriptorSetWrites dsw = new DescriptorSetWrites (descSet, dslToneMap.Bindings[1]);
+ dsw.Write (dev, renderer.HDROutput.Descriptor);
+ }
buildCommandBuffers ();
updateViewRequested = true;
@@ -400,7 +409,7 @@ namespace vkChess
} else if (crow.ProcessMouseWheelChanged ((float)yOffset))
return;*/
camera.Move (0, 0, (float)yOffset * 4f);
- CameraPosition = new Vector3 (camera.Position.X, camera.Position.Y, -camera.Position.Z);
+ CameraPosition = new Vector3 (camera.Position.X, camera.Position.Y, -camera.Position.Z);
}
protected override void onMouseMove (double xPos, double yPos) {
base.onMouseMove (xPos, yPos);
@@ -445,7 +454,7 @@ namespace vkChess
NotifyValueChanged ("DebugCurCellPos", p?.BoardCell);
if (p != null) {
- NotifyValueChanged ("DebugCurCell", getChessCell (p.BoardCell.X, p.BoardCell.Y));
+ NotifyValueChanged ("DebugCurCell", getChessCell (p.BoardCell.X, p.BoardCell.Y));
}else
NotifyValueChanged ("DebugCurCell", "");
}
@@ -498,10 +507,11 @@ namespace vkChess
//check for promotion
Piece mp = board [Active.X, Active.Y];
if (mp.Type == PieceType.Pawn && Selection.Y == GetPawnPromotionY(CurrentPlayer)) {
+ promotePosition = Selection;
showPromoteDialog ();
return;
} else
- processMove (getChessCell (Active.X, Active.Y) + getChessCell (Selection.X, Selection.Y));
+ processMove (getChessCell (Active) + getChessCell (Selection));
if (enableHint)
sendToStockfish ("stop");
@@ -532,14 +542,14 @@ namespace vkChess
saveCurrentGame ();
break;
case Glfw.Key.Keypad0:
- whites [0].X = 0;
- whites [0].Y = 0;
+ whitePieces [0].X = 0;
+ whitePieces [0].Y = 0;
break;
case Glfw.Key.Keypad6:
- whites [0].X++;
+ whitePieces [0].X++;
break;
case Glfw.Key.Keypad8:
- whites [0].Y++;
+ whitePieces [0].Y++;
break;
case Glfw.Key.R:
CurrentState = GameState.Play;
@@ -597,7 +607,7 @@ namespace vkChess
break;
}
}
-
+
void onQuitClick (object sender, MouseButtonEventArgs e) {
Close ();
}
@@ -607,7 +617,7 @@ namespace vkChess
lock (movesMutex) {
bool hintIsEnabled = EnableHint;
EnableHint = false;
-
+
//if (currentState != GameState.Pad && currentState != GameState.Checkmate && !playerIsAi (CurrentPlayer) && playerIsAi (Opponent))//undo ai move
if (!playerIsAi (CurrentPlayer) && playerIsAi (Opponent))
undoLastMove ();
@@ -620,19 +630,19 @@ namespace vkChess
EnableHint = hintIsEnabled;
}
}
-
+
void onFindStockfishPath (object sender, MouseButtonEventArgs e) {
string stockfishDir = string.IsNullOrEmpty(StockfishPath) ?
Directory.GetCurrentDirectory() : System.IO.Path.GetDirectoryName(StockfishPath);
string stockfishExe = string.IsNullOrEmpty(StockfishPath) ?
"" : System.IO.Path.GetFileName(StockfishPath);
-
+
loadIMLFragment<FileDialog> (@"
<FileDialog Caption='Select SDK Folder' CurrentDirectory='" + stockfishDir + @"' SelectedFile='" + stockfishExe + @"'
ShowFiles='true' ShowHidden='true'/>",this)
.OkClicked += (sender, e) => {
StockfishPath = (sender as FileDialog).SelectedFileFullPath;
- };
+ };
}
public CommandGroup Commands => new CommandGroup (
@@ -646,8 +656,8 @@ namespace vkChess
#endif
new Command ("Quit", () => Close())
),
- new Command ("Undo", () => undo()),
- new Command ("Redo", () => Close())
+ new Command ("Undo", () => undo())
+ //new Command ("Redo", () => Close())
);
void terminateCurrentGame () {
if (CurrentState < GameState.Play)
@@ -668,7 +678,7 @@ namespace vkChess
void onNewWhiteGame (object sender, MouseButtonEventArgs e) {
closeWindow ("ui/newGame.crow");
if (CurrentState < GameState.Play)
- return;
+ return;
Log(LogType.Custom1, "New White Game");
terminateCurrentGame();
@@ -691,7 +701,7 @@ namespace vkChess
void onNewBlackGame (object sender, MouseButtonEventArgs e) {
closeWindow ("ui/newGame.crow");
if (CurrentState < GameState.Play)
- return;
+ return;
Log(LogType.Custom1, "New Black Game");
terminateCurrentGame();
@@ -710,12 +720,13 @@ namespace vkChess
sendToStockfish ("go movetime " + AISearchTime.ToString());
else
sendToStockfish ("go depth 1");
-
- Animation.StartAnimation (new AngleAnimation (this, "CameraAngleY", MathHelper.Pi, 0.15f));
+
+ Animation.StartAnimation (new AngleAnimation (this, "CameraAngleY", MathHelper.Pi, 0.15f));
}
void onPromoteToQueenClick (object sender, MouseButtonEventArgs e) {
closeWindow ("ui/promote.crow");
- processMove (getChessCell (Active.X, Active.Y) + getChessCell (Selection.X, Selection.Y) + "q");
+ processMove (getChessCell (Active) + getChessCell (promotePosition) + "q");
+ promotePosition = -1;
if (enableHint)
sendToStockfish ("stop");
else
@@ -723,7 +734,8 @@ namespace vkChess
}
void onPromoteToBishopClick (object sender, MouseButtonEventArgs e) {
closeWindow ("ui/promote.crow");
- processMove (getChessCell (Active.X, Active.Y) + getChessCell (Selection.X, Selection.Y) + "b");
+ processMove (getChessCell (Active) + getChessCell (promotePosition) + "b");
+ promotePosition = -1;
if (enableHint)
sendToStockfish ("stop");
else
@@ -731,7 +743,8 @@ namespace vkChess
}
void onPromoteToRookClick (object sender, MouseButtonEventArgs e) {
closeWindow ("ui/promote.crow");
- processMove (getChessCell (Active.X, Active.Y) + getChessCell (Selection.X, Selection.Y) + "r");
+ processMove (getChessCell (Active) + getChessCell (promotePosition) + "r");
+ promotePosition = -1;
if (enableHint)
sendToStockfish ("stop");
else
@@ -739,7 +752,8 @@ namespace vkChess
}
void onPromoteToKnightClick (object sender, MouseButtonEventArgs e) {
closeWindow ("ui/promote.crow");
- processMove (getChessCell (Active.X, Active.Y) + getChessCell (Selection.X, Selection.Y) + "k");
+ processMove (getChessCell (Active) + getChessCell (promotePosition) + "k");
+ promotePosition = -1;
if (enableHint)
sendToStockfish ("stop");
else
@@ -802,6 +816,15 @@ namespace vkChess
NotifyValueChanged ("SampleCount", value);
}
}
+ public bool EnableReflections {
+ get => Configuration.Global.Get<bool> ("EnableReflections", false);
+ set {
+ if (value == EnableReflections)
+ return;
+ Configuration.Global.Set ("EnableReflections", value);
+ NotifyValueChanged ("EnableReflections", value);
+ }
+ }
public float SSRStep {
get => Configuration.Global.Get<float> ("SSRStep", 0.1f);
set {
@@ -843,47 +866,22 @@ namespace vkChess
updateViewRequested = true;
}
}
- /*public float CameraY {
- get => Configuration.Global.Get<float> ("CameraY", 0);
- set {
- if (value == CameraY)
- return;
- Configuration.Global.Set ("CameraY", value);
- NotifyValueChanged ("CameraY", value);
- camera.SetPosition (0, CameraY, -CameraZ);
- updateViewRequested = true;
- }
- }
- public float CameraZ {
- get => Configuration.Global.Get<float> ("CameraZ", 12);
- set {
- if (value == CameraZ)
- return;
- Configuration.Global.Set ("CameraZ", value);
- NotifyValueChanged ("CameraZ", value);
- camera.SetPosition (0, CameraY, -CameraZ);
- updateViewRequested = true;
- }
- }
- public float CameraAngle {
- get => Configuration.Global.Get<float> ("CameraAngle", 0.6f);
- set {
- if (value == CameraAngle)
- return;
- Configuration.Global.Set ("CameraAngle", value);
- NotifyValueChanged ("CameraAngle", value);
- camera.SetRotation (CameraAngle, 0, 0);
- updateViewRequested = true;
- }
- }*/
+
+ float normalizeAngle (float a) => a - (int)(a / MathHelper.TwoPi);
public Vector3 CameraRotation {
get => ExtensionMethods.ParseVec3 (Configuration.Global.Get<string> ("CameraRotation", "<0.6,0,0>"));
set {
if (value == CameraRotation)
return;
- Configuration.Global.Set ("CameraRotation", value.ToString());
- NotifyValueChanged ("CameraRotation", value);
- camera.SetRotation (CameraRotation.X, CameraRotation.Y, CameraRotation.Z);
+
+ Vector3 tmp = new Vector3 (
+ normalizeAngle (value.X),
+ normalizeAngle (value.Y),
+ normalizeAngle (value.Z)
+ );
+ Configuration.Global.Set ("CameraRotation", tmp.ToString());
+ NotifyValueChanged ("CameraRotation", tmp);
+ camera.SetRotation (tmp.X, tmp.Y, tmp.Z);
updateViewRequested = true;
}
}
@@ -897,7 +895,7 @@ namespace vkChess
camera.SetPosition (CameraPosition.X, CameraPosition.Y, -CameraPosition.Z);
updateViewRequested = true;
}
- }
+ }
public float CellHighlightIntensity {
get => Configuration.Global.Get<float> ("CellHighlightIntensity", 5.0f);
set {
@@ -918,6 +916,33 @@ namespace vkChess
updateCellHighlighting();
}
}
+ public Vector3 BlackColor {
+ get => ExtensionMethods.ParseVec3 (Configuration.Global.Get<string> ("BlackColor", "<0.03, 0.03, 0.03>"));
+ set {
+ if (value == BlackColor)
+ return;
+
+ Configuration.Global.Set ("BlackColor", value.ToString());
+ NotifyValueChanged ("BlackColor", value);
+
+ foreach (Piece p in blackPieces)
+ p.SetColor (value);
+ }
+ }
+ public Vector3 WhiteColor {
+ get => ExtensionMethods.ParseVec3 (Configuration.Global.Get<string> ("WhiteColor", "<1, 1, 1>"));
+ set {
+ if (value == WhiteColor)
+ return;
+
+ Configuration.Global.Set ("WhiteColor", value.ToString());
+ NotifyValueChanged ("WhiteColor", value);
+
+ foreach (Piece p in whitePieces)
+ p.SetColor (value);
+ }
+ }
+
#endregion
#region LOGS
@@ -925,7 +950,7 @@ namespace vkChess
ObservableList<LogEntry> logs = new ObservableList<LogEntry>();
public ObservableList<LogEntry> MainLog => logs;
void initLog () {
- LogContextMenu = new CommandGroup (new Command("Clear Log", () => ResetLog()));
+ LogContextMenu = new CommandGroup (new Command("Clear Log", () => ResetLog()));
}
public void Log(LogType type, string message) {
if (string.IsNullOrEmpty (message))
@@ -1028,7 +1053,7 @@ namespace vkChess
if (CurrentState >= GameState.Play)
startTurn ();
-
+
}
}
public bool BlacksAreAI {
@@ -1036,7 +1061,7 @@ namespace vkChess
set {
if (value == BlacksAreAI)
return;
-
+
if (CurrentState >= GameState.Play)
terminateCurrentGame ();
@@ -1045,7 +1070,7 @@ namespace vkChess
if (CurrentState >= GameState.Play)
startTurn ();
-
+
}
}
string stockfishPositionCommand
@@ -1084,16 +1109,16 @@ namespace vkChess
void resync3DScene () {
replaySilently ();
- foreach (Piece p in whites)
+ foreach (Piece p in whitePieces)
p.MoveTo (p.BoardCell, true);
- foreach (Piece p in blacks)
+ foreach (Piece p in blackPieces)
p.MoveTo (p.BoardCell, true);
syncStockfish();
}
void initStockfish () {
- if (currentState == GameState.Init)
+ if (currentState == GameState.Init)
throw new Exception ("init stockfish impossible: 3d scene must be initialized first.");
currentState = GameState.SceneInitialized;
@@ -1124,12 +1149,12 @@ namespace vkChess
stockfish.OutputDataReceived += dataReceived;
stockfish.ErrorDataReceived += dataReceived;
stockfish.Exited += P_Exited;
-
+
stockfish.Start ();
stockfish.BeginOutputReadLine ();
stockfish.PriorityClass = ProcessPriorityClass.BelowNormal;
-
+
}
void syncStockfish () {
if (currentState < GameState.Play)
@@ -1242,8 +1267,8 @@ namespace vkChess
}
Piece [,] board;
- Piece [] whites;
- Piece [] blacks;
+ Piece [] whitePieces;
+ Piece [] blackPieces;
bool playerIsAi (ChessColor player) => player == ChessColor.White ? WhitesAreAI : BlacksAreAI;
volatile GameState currentState = GameState.Init;
@@ -1306,6 +1331,7 @@ namespace vkChess
}
}
ChessColor currentPlayer;
+ Point promotePosition = -1;
public ChessColor CurrentPlayer {
get => currentPlayer;
@@ -1321,10 +1347,10 @@ namespace vkChess
get { return CurrentPlayer == ChessColor.White ? ChessColor.Black : ChessColor.White; }
}
public Piece [] OpponentPieces {
- get { return CurrentPlayer == ChessColor.White ? blacks : whites; }
+ get { return CurrentPlayer == ChessColor.White ? blackPieces : whitePieces; }
}
public Piece [] CurrentPlayerPieces {
- get { return CurrentPlayer == ChessColor.White ? whites : blacks; }
+ get { return CurrentPlayer == ChessColor.White ? whitePieces : blackPieces; }
}
public int GetPawnPromotionY (ChessColor color) => color == ChessColor.White ? 7 : 0;
@@ -1420,7 +1446,7 @@ namespace vkChess
Active = -1;
board = new Piece [8, 8];
- instanceBuff = new HostBuffer<InstanceData> (dev, VkBufferUsageFlags.VertexBuffer, 97, true, false);
+ instanceBuff = new HostBuffer<InstanceData> (dev, VkBufferUsageFlags.VertexBuffer, 98, true, false);
instanceBuff.SetName ("instances buff");
Piece.instanceBuff = instanceBuff;
@@ -1437,7 +1463,7 @@ namespace vkChess
addPiece (ChessColor.White, PieceType.Pawn, i, 1);
for (int i = 0; i < 8; i++)
addPiece (ChessColor.Black, PieceType.Pawn, i, 6);
-
+
addPiece (ChessColor.White, PieceType.Bishop, 2, 0);
addPiece (ChessColor.White, PieceType.Bishop, 5, 0);
addPiece (ChessColor.Black, PieceType.Bishop, 2, 7);
@@ -1459,13 +1485,15 @@ namespace vkChess
addPiece (ChessColor.White, PieceType.King, 4, 0);
addPiece (ChessColor.Black, PieceType.King, 4, 7);
- whites = board.Cast<Piece> ().Where (p => p?.Player == ChessColor.White).ToArray ();
- blacks = board.Cast<Piece> ().Where (p => p?.Player == ChessColor.Black).ToArray ();
+ whitePieces = board.Cast<Piece> ().Where (p => p?.Player == ChessColor.White).ToArray ();
+ blackPieces = board.Cast<Piece> ().Where (p => p?.Player == ChessColor.Black).ToArray ();
Piece.boardDatas = new InstanceData [64];
+ Model.Node boardNode = renderer.model.FindNode ("Decorations");
+
uint curInstIdx = 32;
- boardCellMesheIndices = new int [65];
+ boardCellMesheIndices = new int [64 + boardNode.Children.Count];
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
@@ -1477,9 +1505,15 @@ namespace vkChess
curInstIdx++;
}
}
- boardCellMesheIndices [64] = renderer.model.Meshes.IndexOf (renderer.model.FindNode ("frame").Mesh);
- instanceBuff.Update (96, new InstanceData (new Vector4 (1), Matrix4x4.Identity));
- Piece.flushEnd = 97;
+ for (int i = 0; i < boardNode.Children.Count; i++) {
+ boardCellMesheIndices [64 + i] = renderer.model.Meshes.IndexOf (boardNode.Children[i].Mesh);
+ instanceBuff.Update (96 + (uint)i, new InstanceData (new Vector4 (1f), Matrix4x4.Identity));
+ }
+ /*boardCellMesheIndices [64] = renderer.model.Meshes.IndexOf (renderer.model.FindNode ("frame").Mesh);
+ instanceBuff.Update (96, new InstanceData (new Vector4 (0.2f,0.2f,0.2f,1f), Matrix4x4.Identity));
+ boardCellMesheIndices [65] = renderer.model.Meshes.IndexOf (renderer.model.FindNode ("decorations").Mesh);
+ instanceBuff.Update (97, new InstanceData (new Vector4 (1), Matrix4x4.CreateTranslation(0,0.001f,0)));*/
+ Piece.flushEnd = 96 + (uint)boardNode.Children.Count;
updateDrawCmdList ();
currentState = GameState.SceneInitialized;
@@ -1487,7 +1521,7 @@ namespace vkChess
void updateDrawCmdList () {
List<Model.InstancedCmd> primitiveCmds = new List<Model.InstancedCmd> ();
- Piece [] pieces = whites.Concat (blacks).ToArray ();
+ Piece [] pieces = whitePieces.Concat (blackPieces).ToArray ();
uint instIdx = 0;
updateDrawCmdList (PieceType.Pawn, ref instIdx, ref pieces, ref primitiveCmds);
@@ -1497,7 +1531,7 @@ namespace vkChess
updateDrawCmdList (PieceType.Queen, ref instIdx, ref pieces, ref primitiveCmds);
updateDrawCmdList (PieceType.King, ref instIdx, ref pieces, ref primitiveCmds);
- foreach (int i in boardCellMesheIndices)
+ foreach (int i in boardCellMesheIndices)
primitiveCmds.Add (new Model.InstancedCmd { count = 1, meshIdx = i });
instancedCmds = primitiveCmds.ToArray ();
@@ -1525,11 +1559,11 @@ namespace vkChess
Active = -1;
board = new Piece [8, 8];
- foreach (Piece p in whites) {
+ foreach (Piece p in whitePieces) {
p.Reset (animate);
board [p.initX, p.initY] = p;
}
- foreach (Piece p in blacks) {
+ foreach (Piece p in blackPieces) {
p.Reset (animate);
board [p.initX, p.initY] = p;
}
@@ -1549,7 +1583,8 @@ namespace vkChess
}
void addPiece (ChessColor player, PieceType _type, int col, int line) {
- Piece p = new Piece (player, _type, col, line);
+ Piece p = new Piece (player, _type, col, line,
+ player == ChessColor.White ? WhiteColor : BlackColor);
board [col, line] = p;
}
@@ -1798,7 +1833,7 @@ namespace vkChess
integrity = false;
}
}
- foreach (Piece p in whites) {
+ foreach (Piece p in whitePieces) {
if (p.Captured)
continue;
if (board[p.BoardCell.X,p.BoardCell.Y] == p)
@@ -1806,7 +1841,7 @@ namespace vkChess
Console.WriteLine ($"incoherence for piece:{p.Player} {p.Type} has cell {p.BoardCell}");
integrity = false;
}
- foreach (Piece p in blacks) {
+ foreach (Piece p in blackPieces) {
if (p.Captured)
continue;
if (board [p.BoardCell.X, p.BoardCell.Y] == p)
@@ -1849,7 +1884,7 @@ namespace vkChess
else
preview_Captured = board [pEnd.X, pEnd.Y];
- if (preview_Captured != null)
+ if (preview_Captured != null)
preview_Captured.Captured = true;
board [pEnd.X, pEnd.Y] = p;
@@ -1875,7 +1910,7 @@ namespace vkChess
preview_Move = null;
preview_Captured = null;
}
-
+ string getChessCell (Point cell) => getChessCell (cell.X, cell.Y);
string getChessCell (int col, int line) {
if (col < 0 || line < 0)
return null;
@@ -2036,7 +2071,7 @@ namespace vkChess
new BezierPath (
pCaptured.Position,
pCapLastPos, Vector3.UnitZ),animationSteps));
- NotifyValueChanged ("board", board);
+ NotifyValueChanged ("board", board);
}
void replaySilently () {
string [] moves = StockfishMoves.ToArray ();
@@ -2060,7 +2095,7 @@ namespace vkChess
CurrentState = GameState.Checkmate;
return;
}
- } else if (!kingIsSafe)
+ } else if (!kingIsSafe)
CurrentState = GameState.Checked;
//if (currentState != GameState.Play) {
@@ -2080,7 +2115,7 @@ namespace vkChess
BestMove = null;
CurrentState = GameState.Play;
- CurrentPlayer = Opponent;
+ CurrentPlayer = Opponent;
startTurn ();
}
diff --git a/src/deferredPbrRendererBase.cs b/src/deferredPbrRendererBase.cs
index 6e85694..a647179 100644
--- a/src/deferredPbrRendererBase.cs
+++ b/src/deferredPbrRendererBase.cs
@@ -118,14 +118,14 @@ namespace vkChess
public DeferredPbrRendererBase (Device dev, SwapChain swapChain, PresentQueue presentQueue, string cubemapPath, float nearPlane, float farPlane) {
this.dev = dev;
this.swapChain = swapChain;
- this.presentQueue = presentQueue;
+ this.presentQueue = presentQueue;
pipelineCache = new PipelineCache (dev);
descriptorPool = new DescriptorPool (dev, 3,
new VkDescriptorPoolSize (VkDescriptorType.UniformBuffer, 3),
new VkDescriptorPoolSize (VkDescriptorType.CombinedImageSampler, 6),
new VkDescriptorPoolSize (VkDescriptorType.InputAttachment, 5)
- );
+ );
uboMatrices = new HostBuffer (dev, VkBufferUsageFlags.UniformBuffer, matrices, true);
uboLights = new HostBuffer<Light> (dev, VkBufferUsageFlags.UniformBuffer, lights, true);
@@ -154,7 +154,7 @@ namespace vkChess
renderPass.AddAttachment (swapChain.ColorFormat, VkImageLayout.ColorAttachmentOptimal, NUM_SAMPLES, VkAttachmentLoadOp.Clear, VkAttachmentStoreOp.DontCare);//GBuff0 (color + roughness) and final color before resolve
renderPass.AddAttachment (VkFormat.R8g8b8a8Unorm, VkImageLayout.ColorAttachmentOptimal, NUM_SAMPLES, VkAttachmentLoadOp.Clear, VkAttachmentStoreOp.DontCare);//GBuff1 (emit + metal)
renderPass.AddAttachment (MRT_FORMAT, VkImageLayout.ShaderReadOnlyOptimal, NUM_SAMPLES, VkAttachmentLoadOp.Clear, VkAttachmentStoreOp.Store, VkImageLayout.ShaderReadOnlyOptimal);//GBuff2 (normals + AO)
- renderPass.AddAttachment (MRT_FORMAT, VkImageLayout.ShaderReadOnlyOptimal, NUM_SAMPLES, VkAttachmentLoadOp.Clear, VkAttachmentStoreOp.Store, VkImageLayout.ShaderReadOnlyOptimal);//GBuff3 (Pos + depth)
+ renderPass.AddAttachment (MRT_FORMAT, VkImageLayout.ShaderReadOnlyOptimal, NUM_SAMPLES, VkAttachmentLoadOp.Clear, VkAttachmentStoreOp.Store, VkImageLayout.ShaderReadOnlyOptimal);//GBuff3 (Pos + depth)
renderPass.ClearValues.Add (new VkClearValue { color = new VkClearColorValue (0.0f, 0.0f, 0.0f) });
renderPass.ClearValues.Add (new VkClearValue { depthStencil = new VkClearDepthStencilValue (1.0f, 0) });
@@ -206,7 +206,7 @@ namespace vkChess
VkAccessFlags.ColorAttachmentWrite, VkAccessFlags.ShaderRead);
renderPass.AddDependency (SP_COMPOSE, Vk.SubpassExternal,
VkPipelineStageFlags.ColorAttachmentOutput, VkPipelineStageFlags.Transfer,
- VkAccessFlags.ColorAttachmentRead | VkAccessFlags.ColorAttachmentWrite, VkAccessFlags.TransferRead);
+ VkAccessFlags.ColorAttachmentRead | VkAccessFlags.ColorAttachmentWrite, VkAccessFlags.TransferRead);
}
void init (float nearPlane, float farPlane, string cubemapPath) {
@@ -238,7 +238,7 @@ namespace vkChess
//renderPass.PNext = new PNextNode<VkRenderPassMultiviewCreateInfo> (ciMultiview);
using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, NUM_SAMPLES)) {
-
+
cfg.rasterizationState.cullMode = VkCullModeFlags.None;
if (NUM_SAMPLES != VkSampleCountFlags.SampleCount1) {
@@ -317,7 +317,7 @@ namespace vkChess
matrices.prefilteredCubeMipLevels = envCube.prefilterCube.CreateInfo.mipLevels;
DescriptorSetWrites dsMainWrite = new DescriptorSetWrites (dsMain, descLayoutMain.Bindings.GetRange (0, 5).ToArray ());
- dsMainWrite.Write (dev,
+ dsMainWrite.Write (dev,
uboMatrices.Descriptor,
envCube.irradianceCube.Descriptor,
envCube.prefilterCube.Descriptor,
@@ -328,7 +328,7 @@ namespace vkChess
dsMainWrite.Write (dev, shadowMapRenderer.shadowMap.Descriptor);
multiViewMasks.Unpin ();
-
+
}
public void LoadModel (Queue transferQ, string path) {
@@ -364,7 +364,7 @@ namespace vkChess
renderPass.BeginSubPass (cmd);
gBuffPipeline.Bind(cmd);
-
+
if (instanceBuf != null)
model.Draw(cmd, gBuffPipeline.Layout, instanceBuf, false, instances);
}
@@ -395,6 +395,7 @@ namespace vkChess
public void MoveLight (Vector4 dir) {
lights[lightNumDebug].position += dir * lightMoveSpeed;
+ shadowMapRenderer.updateLightMatricesRequested = true;
shadowMapRenderer.updateShadowMap = true;
}
@@ -474,7 +475,7 @@ namespace vkChess
public void Dispose () {
dev.WaitIdle ();
-
+
frameBuffers?.Dispose ();
gbColorRough.Dispose ();
@@ -488,7 +489,7 @@ namespace vkChess
debugPipeline.Dispose ();
depthPrepassPipeline.Dispose ();
- descLayoutMain.Dispose ();
+ descLayoutMain.Dispose ();
descLayoutGBuff.Dispose ();
uboMatrices.Dispose ();
diff --git a/src/shadowMapRenderer.cs b/src/shadowMapRenderer.cs
index 2a151a8..c17170e 100644
--- a/src/shadowMapRenderer.cs
+++ b/src/shadowMapRenderer.cs
@@ -21,7 +21,7 @@ namespace vkChess {
public static uint SHADOWMAP_SIZE = 4096;
public static VkFormat SHADOWMAP_FORMAT = VkFormat.D32SfloatS8Uint;
public static VkSampleCountFlags SHADOWMAP_NUM_SAMPLES = VkSampleCountFlags.SampleCount1;
- public bool updateShadowMap = true;
+ public bool updateShadowMap = true, updateLightMatricesRequested = true;
public float depthBiasConstant = 1.5f;
public float depthBiasSlope = 1.75f;
@@ -125,9 +125,11 @@ namespace vkChess {
renderer.uboLights.Update (renderer.lights);
dev.WaitIdle ();
}
-
public void update_shadow_map (CommandPool cmdPool, vke.Buffer instanceBuf, params Model.InstancedCmd[] instances) {
- update_light_matrices ();
+ if (updateLightMatricesRequested) {
+ update_light_matrices ();
+ updateLightMatricesRequested = false;
+ }
PrimaryCommandBuffer cmd = cmdPool.AllocateAndStart ();
@@ -146,10 +148,9 @@ namespace vkChess {
renderer.model.Bind(cmd);
renderer.model.Draw(cmd, shadowPipeline.Layout, instanceBuf, true, instances);
}
-
shadowPass.End (cmd);
-
renderer.presentQueue.EndSubmitAndWait (cmd);
+
updateShadowMap = false;
}
diff --git a/ui/chess.crow b/ui/chess.crow
index 1a0f3da..4227d4d 100644
--- a/ui/chess.crow
+++ b/ui/chess.crow
@@ -8,13 +8,12 @@
<ItemTemplate DataType="Crow.CommandGroup" >
<MenuItem Data="{Commands}" Width="Fit" Height="Stretched" IsEnabled="{CanExecute}"
Template="ui/menuItem.template"
- ItemTemplate="ui/menuItem.itmp">
+ ItemTemplate="ui/menuItem.itmp">
</MenuItem>
- </ItemTemplate>
+ </ItemTemplate>
</Menu>
<CheckBox Caption="Hint" IsChecked="{²EnableHint}" Height="Stretched"
Background="Transparent" Foreground="White"
- Checked="{Background=${ControlHighlight}}"
Unchecked = "{Background=Transparent}"/>
<Widget Width="Stretched"/>
<VerticalStack Style="hsStatus">
diff --git a/ui/chess.style b/ui/chess.style
index 2079d61..66c1db2 100644
--- a/ui/chess.style
+++ b/ui/chess.style
@@ -32,30 +32,30 @@ labStatus2 {
Background="DarkGrey";
Font="serif bold, 16";
Margin="0";
- TextAlignment="Center";
+ TextAlignment="Center";
}
CheckBox {
Template = "ui/checkBox.tmp";
- MinimumSize = "80, 30";
+ MinimumSize = "80, 30";
Width="Fit";
Height= "Fit";
Background="${StateCtrlInactiveBackground}";
Checked="{Background=${ControlHighlight}}";
- Unchecked = "{Background=${StateCtrlInactiveBackground}}";
+ Unchecked = "{Background=${StateCtrlInactiveBackground}}";
}
RadioButton {
Template = "ui/checkBox.tmp";
- MinimumSize = "80, 30";
+ MinimumSize = "80, 30";
Width="Fit";
Height= "Fit";
Background="${StateCtrlInactiveBackground}";
Checked="{Background=${ControlHighlight}}";
- Unchecked = "{Background=${StateCtrlInactiveBackground}}";
+ Unchecked = "{Background=${StateCtrlInactiveBackground}}";
}
-Button {
+Button {
Template = "ui/Button.tmp";
- MinimumSize = "80, 30";
+ MinimumSize = "80, 30";
Width="Fit";
}
MenuItem {
@@ -98,11 +98,11 @@ labValue {
Width="Stretched";
}
labColor {
- Margin="2";
+ Margin="2";
Width="Fit";
}
labColorV {
- Margin="1";
+ Margin="1";
Width="Fit";
}
ColorSlider {
@@ -123,4 +123,17 @@ Vector3Widget {
winBorder {
StickyMouseEnabled="true";
StickyMouse="10";
+}
+
+chessPceButtonMargin = "5";
+chessPceButtonImageMargin = "2";
+
+chessPceButton {
+ Width="Stretched";
+ Margin="5";
+ CornerRadius="5";
+ Focusable="true";
+ Background="${StateCtrlInactiveBackground}";
+ MouseEnter="{Background=${ControlHighlight}}";
+ MouseLeave="{Background=${StateCtrlInactiveBackground}}";
} \ No newline at end of file
diff --git a/ui/newGame.crow b/ui/newGame.crow
index 135c9b6..f4f3e8a 100644
--- a/ui/newGame.crow
+++ b/ui/newGame.crow
@@ -1,26 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Window Font="droid bold, 40" Height="50%" Width="60%" Caption="New Game">
- <Container>
- <VerticalStack Margin="30" Spacing="5">
- <HorizontalStack Height="80%" Margin="3" Spacing="20">
- <Border Width="50%" Margin="5" CornerRadius="5" Focusable="true" Background="DimGrey"
- MouseEnter="{Background=SteelBlue}"
- MouseLeave="{Background=DimGrey}"
- MouseClick="onNewWhiteGame">
+ <VerticalStack Margin="30" Spacing="5">
+ <HorizontalStack Margin="0" Spacing="0">
+ <Container Width="50%" Margin="20">
+ <Border Style="chessPceButton" MouseClick="onNewWhiteGame">
<Image Margin="5"
- Path="data/Pieces.svg" SvgSub="wp"/>
+ Path="data/Pieces.svg" SvgSub="wK"/>
</Border>
- <Border Width="50%" Margin="5" CornerRadius="5" Focusable="true" Background="DimGrey"
- MouseEnter="{Background=SteelBlue}"
- MouseLeave="{Background=DimGrey}"
- MouseClick="onNewBlackGame">
+ </Container>
+ <Container Width="50%" Margin="20">
+ <Border Style="chessPceButton" MouseClick="onNewBlackGame">
<Image Margin="5"
- Path="data/Pieces.svg" SvgSub="bp"/>
+ Path="data/Pieces.svg" SvgSub="bK"/>
</Border>
- </HorizontalStack>
- <Button Height="Fit" Width="40%" Style="#Chess.gui.Button.style" HorizontalAlignment="Right" Caption="Cancel"
- MouseClick="../../../butQuitPress"/>
- </VerticalStack>
- </Container>
+ </Container>
+ </HorizontalStack>
+ </VerticalStack>
</Window>
diff --git a/ui/promote.crow b/ui/promote.crow
index 3df0b48..6d5bf17 100644
--- a/ui/promote.crow
+++ b/ui/promote.crow
@@ -1,12 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<Container>
- <Border Fit="True"
- BorderWidth="1" CornerRadius="25" Background="0.4,0.4,0.4,0.8">
- <VerticalStack Fit="True" Margin="20">
- <Button Caption="Queen" MouseClick="onPromoteToQueenClick"/>
+<Container Width="30%" Height="50%">
+ <Border CornerRadius="25" Background="${WindowBackground}">
+ <VerticalStack Margin="20" Spacing="0">
+ <Container Height="25%" Margin="${chessPceButtonMargin}">
+ <Border Style="chessPceButton" MouseClick="onPromoteToQueenClick">
+ <Image Margin="${chessPceButtonImageMargin}"
+ Path="data/Pieces.svg" SvgSub="wq"/>
+ </Border>
+ </Container>
+ <Container Height="25%" Margin="${chessPceButtonMargin}">
+ <Border Style="chessPceButton" MouseClick="onPromoteToBishopClick">
+ <Image Margin="${chessPceButtonImageMargin}"
+ Path="data/Pieces.svg" SvgSub="wb"/>
+ </Border>
+ </Container>
+ <Container Height="25%" Margin="${chessPceButtonMargin}">
+ <Border Style="chessPceButton" MouseClick="onPromoteToRookClick">
+ <Image Margin="${chessPceButtonImageMargin}"
+ Path="data/Pieces.svg" SvgSub="wr"/>
+ </Border>
+ </Container>
+ <Container Height="25%" Margin="${chessPceButtonMargin}">
+ <Border Style="chessPceButton" MouseClick="onPromoteToKnightClick">
+ <Image Margin="${chessPceButtonImageMargin}"
+ Path="data/Pieces.svg" SvgSub="wk"/>
+ </Border>
+ </Container>
+ <!--<Button Caption="Queen" MouseClick="onPromoteToQueenClick"/>
<Button Caption="Bishop" MouseClick="onPromoteToBishopClick"/>
<Button Caption="Rook" MouseClick="onPromoteToRookClick"/>
- <Button Caption="Knight" MouseClick="onPromoteToKnightClick"/>
+ <Button Caption="Knight" MouseClick="onPromoteToKnightClick"/>-->
</VerticalStack>
</Border>
</Container>
diff --git a/ui/winOptions.crow b/ui/winOptions.crow
index 5929511..050aa98 100644
--- a/ui/winOptions.crow
+++ b/ui/winOptions.crow
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
-<Window Caption="Options" Top="10" Width="30%" Height="Fit" >
+<Window Caption="Options" Top="10" Width="60%" Height="Fit" >
<VerticalStack Spacing="10" Margin="10" >
<VerticalStack Height="Fit" Background="${ContainerBackground}" Margin="5">
<HorizontalStack >
@@ -12,8 +12,8 @@
</HorizontalStack>
</VerticalStack>
<!--<HorizontalStack Height="Fit">-->
- <Expandable Caption="Game" IsExpanded="true">
- <VerticalStack Height="Fit" Spacing="3" >
+ <Expandable Caption="Game" IsExpanded="false">
+ <VerticalStack Height="Fit" Spacing="3" Margin="10">
<HorizontalStack Height="Fit">
<Label Width="Stretched" Text="Whites Level:"/>
<Spinner Width="60" Value="{²WhitesLevel}" Maximum="20" SmallIncrement="1"/>
@@ -25,67 +25,47 @@
<HorizontalStack Height="Fit">
<Label Width="Stretched" Text="AI Search time (ms):" />
<Spinner Width="60" Value="{²AISearchTime}" Maximum="10000" SmallIncrement="10"/>
- </HorizontalStack>
+ </HorizontalStack>
<CheckBox Caption="Whites are AI" IsChecked="{²WhitesAreAI}" Width="Stretched"/>
<CheckBox Caption="Blacks are AI" IsChecked="{²BlacksAreAI}" Width="Stretched"/>
<CheckBox Caption="Enable Hint" IsChecked="{²EnableHint}" Width="Stretched"/>
- <HorizontalStack Style="Slid" >
- <Label Text="Cells Highlighting:" Width="100"/>
- <Slider Style="LightingSlider" Value="{²CellHighlightIntensity}" Maximum="50.0" SmallIncrement="0.1" LargeIncrement="1"/>
- </HorizontalStack>
- <HorizontalStack Style="Slid" >
- <Label Text="Cells Dim:" Width="100"/>
- <Slider Style="LightingSlider" Value="{²CellHighlightDim}" Maximum="50.0" SmallIncrement="0.1" LargeIncrement="1"/>
- </HorizontalStack>
- </VerticalStack>
+ </VerticalStack>
</Expandable>
<!--<VerticalStack Margin="20" Spacing="1">
<HorizontalStack Height="Fit">
<Label Text="Pce Color" Style="GridLabel"/>
<Label Text="{DebugCurColor}" Style="GridValue"/>
- </HorizontalStack>
+ </HorizontalStack>
<HorizontalStack Height="Fit">
<Label Text="Pce Type" Style="GridLabel"/>
<Label Text="{DebugCurType}" Style="GridValue" />
- </HorizontalStack>
+ </HorizontalStack>
<HorizontalStack Height="Fit">
<Label Text="Pce Cell" Style="GridLabel"/>
<Label Text="{DebugCurCell}" Style="GridValue"/>
- </HorizontalStack>
+ </HorizontalStack>
<HorizontalStack Height="Fit">
<Label Text="Pce Cell pos" Style="GridLabel"/>
<Label Text="{DebugCurCellPos}" Style="GridValue"/>
</HorizontalStack>
- </VerticalStack>
+ </VerticalStack>
</HorizontalStack>-->
<Expandable Caption="Camera" IsExpanded="false">
- <VerticalStack Height="Fit">
- <Vector3Widget Caption="Rotation" Value="{²CameraRotation}" SmallIncrement="0.01" LargeIncrement="0.1" Maximum="7.0" Decimals="2"/>
- <Vector3Widget Caption="Position" Value="{²CameraPosition}" SmallIncrement="0.1" LargeIncrement="1.0" Maximum="20.0" Decimals="1"/>
+ <VerticalStack Height="Fit" Margin="10">
+ <Vector3Widget Caption="Rotation" Value="{²CameraRotation}" SmallIncrement="0.01" LargeIncrement="0.1" Minimum="-7.0" Maximum="7.0" Decimals="2"/>
+ <Vector3Widget Caption="Position" Value="{²CameraPosition}" SmallIncrement="0.1" LargeIncrement="1.0" Minimum="-20.0" Maximum="20.0" Decimals="1"/>
<HorizontalStack Style="Slid" >
<Label Text="Camera FOV:" Width="100" />
<Slider Style="LightingSlider" Value="{²CameraFOV}" Decimals="0" Maximum="120" SmallIncrement="1" LargeIncrement="5"/>
- </HorizontalStack>
- <!--<HorizontalStack Style="Slid" >
- <Label Text="Camera Angle:" Width="100" />
- <Slider Style="LightingSlider" Value="{²CameraAngle}" Decimals="1" Maximum="3.0" SmallIncrement="0.1" LargeIncrement="0.1"/>
- </HorizontalStack>
- <HorizontalStack Style="Slid" >
- <Label Text="Camera Y:" Width="100" />
- <Slider Style="LightingSlider" Value="{²CameraY}" Decimals="1" Maximum="30.0" SmallIncrement="0.1" LargeIncrement="1.0"/>
- </HorizontalStack>
- <HorizontalStack Style="Slid" >
- <Label Text="Camera Z:" Width="100" />
- <Slider Style="LightingSlider" Value="{²CameraZ}" Decimals="0" Maximum="30.0" SmallIncrement="1.0" LargeIncrement="5.0"/>
- </HorizontalStack>-->
+ </HorizontalStack>
</VerticalStack>
</Expandable>
- <Expandable Caption="Lighting" IsExpanded="false">
- <VerticalStack Height="Fit">
+ <Expandable Caption="Rendering" IsExpanded="false">
+ <VerticalStack Height="Fit" Margin="10">
<HorizontalStack Style="Slid" >
<Label Text="Exposure:" Width="100"/>
<Slider Style="LightingSlider" Value="{²Exposure}" Maximum="10.0" SmallIncrement="0.01" LargeIncrement="0.1"/>
- </HorizontalStack>
+ </HorizontalStack>
<HorizontalStack Style="Slid" >
<Label Text="Gamma:" Width="100" />
<Slider Style="LightingSlider" Value="{²Gamma}" Maximum="10.0" SmallIncrement="0.01" LargeIncrement="0.1"/>
@@ -93,7 +73,8 @@
<HorizontalStack Style="Slid" >
<Label Text="IBL Ambient:" Width="100" />
<Slider Style="LightingSlider" Value="{²IBLAmbient}" Maximum="50.0" SmallIncrement="0.01" LargeIncrement="0.1"/>
- </HorizontalStack>
+ </HorizontalStack>
+ <CheckBox Caption="Enable Reflections" IsChecked="{²EnableReflections}" />
<EnumSelector Caption="Sample count" EnumValue="{²SampleCount}" Height="Fit" Width="Stretched">
<Template>
<GroupBox Caption="{./Caption}" CornerRadius="{./CornerRadius}" Foreground="{./Foreground}" Background="{./Background}">
@@ -103,6 +84,20 @@
</EnumSelector>
</VerticalStack>
</Expandable>
+ <Expandable Caption="Colors" IsExpanded="false">
+ <VerticalStack Height="Fit" Margin="10">
+ <Vector3Widget Caption="Black color" Value="{²BlackColor}" SmallIncrement="0.01" LargeIncrement="0.1" Maximum="1.0" Decimals="2"/>
+ <Vector3Widget Caption="White color" Value="{²WhiteColor}" SmallIncrement="0.01" LargeIncrement="0.1" Maximum="1.0" Decimals="2"/>
+ <HorizontalStack Style="Slid" >
+ <Label Text="Cells Highlighting:" Width="100"/>
+ <Slider Style="LightingSlider" Value="{²CellHighlightIntensity}" Maximum="50.0" SmallIncrement="0.1" LargeIncrement="1"/>
+ </HorizontalStack>
+ <HorizontalStack Style="Slid" >
+ <Label Text="Cells Dim:" Width="100"/>
+ <Slider Style="LightingSlider" Value="{²CellHighlightDim}" Maximum="50.0" SmallIncrement="0.1" LargeIncrement="1"/>
+ </HorizontalStack>
+ </VerticalStack>
+ </Expandable>
</VerticalStack>
</Window>
diff --git a/vkChess.net.csproj b/vkChess.net.csproj
index 3337014..d030901 100644
--- a/vkChess.net.csproj
+++ b/vkChess.net.csproj
@@ -5,11 +5,11 @@
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFramework>netcoreapp3.1</TargetFramework>
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
- <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
+ <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
<IntermediateOutputPath>$(SolutionDir)build\obj\$(Configuration)\</IntermediateOutputPath>
</PropertyGroup>
-
+
<ItemGroup>
<GLSLShader Include="shaders\**\*.frag;shaders\**\*.vert;shaders\**\*.comp;shaders\**\*.geom" />
<None Include="data\**\*.*;ui\**\*.*">
@@ -20,8 +20,8 @@
<ItemGroup>
<PackageReference Include="VkCrowWindow" Version="0.3.4-beta" />
<PackageReference Include="vke" Version="0.2.2-beta" />
- <PackageReference Include="SpirVTasks" Version="0.1.44" />
- <PackageReference Include="vke.EnvironmentPipeline" Version="0.2.0-beta" />
+ <PackageReference Include="SpirVTasks" Version="0.1.44" />
+ <PackageReference Include="vke.EnvironmentPipeline" Version="0.2.0-beta" />
<PackageReference Include="vke.gltfLoader" Version="0.2.0-beta" />
</ItemGroup>
<ItemGroup>