diff options
| -rw-r--r-- | CrowWindow/CrowWindow.csproj | 4 | ||||
| -rw-r--r-- | CrowWindow/VkCrowWindow.cs | 14 | ||||
| -rw-r--r-- | shaders/GBuffPbrInstanced.vert | 5 | ||||
| -rw-r--r-- | shaders/tone_mapping.frag | 10 | ||||
| -rw-r--r-- | src/VkChess.cs | 76 | ||||
| -rw-r--r-- | src/deferredPbrRenderer.cs | 11 | ||||
| -rw-r--r-- | ui/chess.crow | 45 | ||||
| -rw-r--r-- | ui/chess.style | 6 | ||||
| -rw-r--r-- | ui/debug.crow | 2 | ||||
| -rw-r--r-- | ui/main.crow | 2 |
10 files changed, 96 insertions, 79 deletions
diff --git a/CrowWindow/CrowWindow.csproj b/CrowWindow/CrowWindow.csproj index 1da19de..f579535 100644 --- a/CrowWindow/CrowWindow.csproj +++ b/CrowWindow/CrowWindow.csproj @@ -1,4 +1,4 @@ -<Project Sdk="Microsoft.NET.Sdk"> +<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <AssemblyName>CrowWindow</AssemblyName> @@ -15,7 +15,7 @@ </PropertyGroup> <ItemGroup> - <PackageReference Include="Crow" Version="0.9.4-beta" /> + <PackageReference Include="Crow" Version="0.9.3-beta" /> <PackageReference Include="vke" Version="0.2.0-beta" /> <PackageReference Include="SpirVTasks" Version="0.1.44" /> </ItemGroup> diff --git a/CrowWindow/VkCrowWindow.cs b/CrowWindow/VkCrowWindow.cs index f37fda2..a7e6f74 100644 --- a/CrowWindow/VkCrowWindow.cs +++ b/CrowWindow/VkCrowWindow.cs @@ -23,6 +23,7 @@ namespace vke { } #endregion + protected CrowWindow() : base("vkChess.net", 800, 600,false) {} public bool MouseIsInInterface => iFace.HoverWidget != null; @@ -63,9 +64,11 @@ namespace vke { ui.IsBackground = true; ui.Start (); } - protected virtual void CreateRenderPass () { + protected virtual void CreateRenderPass () { + //renderPass = new RenderPass (dev, swapChain.ColorFormat, VkSampleCountFlags.SampleCount1); renderPass = new RenderPass (dev, VkSampleCountFlags.SampleCount1); - renderPass.AddAttachment (swapChain.ColorFormat, VkImageLayout.PresentSrcKHR, VkSampleCountFlags.SampleCount1, VkAttachmentLoadOp.Load);//final outpout + 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); @@ -236,12 +239,17 @@ namespace vke { w.DataSource = dataSource; } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine (ex.Message); + System.Diagnostics.Debug.WriteLine (ex); } } protected void loadIMLFragment (string imlFragment, object dataSource = null) { iFace.LoadIMLFragment (imlFragment).DataSource = dataSource; } + protected T loadIMLFragment<T> (string imlFragment, object dataSource = null) { + Widget tmp = iFace.LoadIMLFragment (imlFragment); + tmp.DataSource = dataSource; + return (T)Convert.ChangeType (tmp,typeof(T)); + } protected void closeWindow (string path) { Widget g = iFace.FindByName (path); if (g != null) diff --git a/shaders/GBuffPbrInstanced.vert b/shaders/GBuffPbrInstanced.vert index 9a91cfc..1095beb 100644 --- a/shaders/GBuffPbrInstanced.vert +++ b/shaders/GBuffPbrInstanced.vert @@ -28,10 +28,11 @@ out gl_PerVertex void main() { vec4 locPos = ubo.model * inModel * vec4(inPos, 1.0); + //locPos.y = -locPos.y; outNormal = normalize(transpose(inverse(mat3(ubo.model * inModel))) * inNormal); outColor = inColor; outWorldPos = locPos.xyz; outUV0 = inUV0; - outUV1 = inUV1; - gl_Position = ubo.projection * ubo.view * vec4(outWorldPos, 1.0); + outUV1 = inUV1; + gl_Position = ubo.projection * ubo.view * vec4(outWorldPos, 1.0); } diff --git a/shaders/tone_mapping.frag b/shaders/tone_mapping.frag index 5c4d752..fcbd5e4 100644 --- a/shaders/tone_mapping.frag +++ b/shaders/tone_mapping.frag @@ -12,7 +12,7 @@ layout (set = 0, binding = 0) uniform UBO { } ubo; layout (input_attachment_index = 0, set = 1, binding = 4) uniform subpassInputMS samplerHDR; -layout (set = 0, binding = 8) uniform sampler2D samplerUI; +//layout (set = 0, binding = 8) uniform sampler2D samplerUI; layout (location = 0) in vec2 inUV; layout (location = 0) out vec4 outColor; @@ -53,10 +53,10 @@ vec3 SRGBtoLINEAR(vec3 srgbIn) void main() { vec4 hdrColor = subpassLoad(samplerHDR, gl_SampleID); - vec4 ui = texture(samplerUI, inUV); - outColor = (hdrColor.a - ui.a) * vec4(SRGBtoLINEAR(tonemap(hdrColor.rgb)), 1.0) + ui; - /* + //vec4 ui = texture(samplerUI, inUV); + //outColor = (hdrColor.a - ui.a) * vec4(SRGBtoLINEAR(tonemap(hdrColor.rgb)), 1.0) + ui; + vec3 mapped = vec3(1.0) - exp(-hdrColor.rgb * ubo.exposure); mapped = pow(mapped, vec3(1.0 / ubo.gamma)); - outColor = vec4(mapped, hdrColor.a);*/ + outColor = vec4(mapped, hdrColor.a); }
\ No newline at end of file diff --git a/src/VkChess.cs b/src/VkChess.cs index 3264f60..5ac5da8 100644 --- a/src/VkChess.cs +++ b/src/VkChess.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -37,16 +37,17 @@ namespace vkChess System.Runtime.Loader.AssemblyLoadContext.Default.ResolvingUnmanagedDll+=resolveUnmanaged; } #endif + VkChess(){} static void Main (string [] args) { Instance.VALIDATION = true; //Instance.RENDER_DOC_CAPTURE = true; //SwapChain.PREFERED_FORMAT = VkFormat.B8g8r8a8Unorm; DeferredPbrRenderer.NUM_SAMPLES = VkSampleCountFlags.SampleCount1; DeferredPbrRenderer.MAX_MATERIAL_COUNT = 5; - DeferredPbrRenderer.MRT_FORMAT = VkFormat.R32g32b32a32Sfloat; - DeferredPbrRenderer.HDR_FORMAT = VkFormat.R32g32b32a32Sfloat; - PbrModelTexArray.TEXTURE_DIM = 1024; - ShadowMapRenderer.SHADOWMAP_SIZE = 1024; + DeferredPbrRenderer.MRT_FORMAT = VkFormat.R16g16b16a16Sfloat; + DeferredPbrRenderer.HDR_FORMAT = VkFormat.R16g16b16a16Sfloat; + PbrModelTexArray.TEXTURE_DIM = 256; + ShadowMapRenderer.SHADOWMAP_SIZE = 512; using (VkChess app = new VkChess ()) app.Run (); @@ -190,7 +191,7 @@ namespace vkChess #else renderer.recordDraw (cmds [i], i, instanceBuff, instancedCmds?.ToArray ()); - this.recordUICmd (cmds[i], i); + recordUICmd (cmds[i], i); #endif cmds [i].End (); } @@ -411,9 +412,10 @@ namespace vkChess break; case Glfw.Key.F2: /*loadWindow (@"ui/board.crow", this); - NotifyValueChanged ("board", board);*/ + */ //loadWindow (@"ui/scene.crow", this.renderer.model); - loadWindow (@"ui/debug.crow", this); + loadWindow (@"ui/board.crow", this); + NotifyValueChanged ("board", board); break; case Glfw.Key.F3: checkBoardIntegrity (); @@ -492,6 +494,9 @@ namespace vkChess Close (); } void onUndoClick (object sender, MouseButtonEventArgs e) { + undo(); + } + void undo() { lock (movesMutex) { bool hintIsEnabled = EnableHint; EnableHint = false; @@ -507,35 +512,27 @@ namespace vkChess EnableHint = hintIsEnabled; } } - public string StockfishDirectory { - get { - try - { - return System.IO.Path.GetDirectoryName(StockfishPath); - } - catch - { - return Directory.GetCurrentDirectory(); - } - - } - } void onFindStockfishPath (object sender, MouseButtonEventArgs e) { - /*loadIMLFragment (@" - <FileDialog Caption='Select SDK Folder' CurrentDirectory='/home' - ShowFiles='true' ShowHidden='true' OkClicked='onSelectStockfishPath'/> - ",this);*/ + string stockfishDir = string.IsNullOrEmpty(StockfishPath) ? + Directory.GetCurrentDirectory() : System.IO.Path.GetDirectoryName(StockfishPath); + string stockfishExe = string.IsNullOrEmpty(StockfishPath) ? + "" : System.IO.Path.GetFileName(StockfishPath); - loadIMLFragment (@" - <FileDialog/> - ",this); - } - public void onSelectStockfishPath (object sender, EventArgs e) - { - StockfishPath = (sender as FileDialog).SelectedFileFullPath; + 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 ( + new Command (()=>loadWindow ("ui/newGame.crow", this)) {Caption = "New Game"}, + new Command (()=>loadWindow ("ui/main.crow", this)) {Caption = "Options"}, + new Command (()=>undo()) {Caption = "Undo"}, + new Command (()=>Close()) {Caption = "Quit"} + ); void onNewGameClick (object sender, MouseButtonEventArgs e) { loadWindow ("ui/newGame.crow", this); } @@ -1662,7 +1659,7 @@ namespace vkChess new BezierPath ( pCaptured.Position, pCapLastPos, Vector3.UnitZ),animationSteps)); - + NotifyValueChanged ("board", board); } void replaySilently () { string [] moves = StockfishMoves.ToArray (); @@ -1676,6 +1673,7 @@ namespace vkChess void startTurn () { syncStockfish (); + NotifyValueChanged ("board", board); bool kingIsSafe = checkKingIsSafe (); if (getLegalMoves ().Length == 0) { @@ -1693,17 +1691,19 @@ namespace vkChess // BlacksAreAI = false; //} - if (playerIsAi (CurrentPlayer)) - sendToStockfish ("go movetime " + AISearchTime.ToString()); - else if (enableHint) + if (playerIsAi (CurrentPlayer)) { + if (AISearchTime > 0) + sendToStockfish ("go movetime " + AISearchTime.ToString()); + else + sendToStockfish ("go depth 1"); + }else if (enableHint) sendToStockfish ("go infinite"); } void switchPlayer () { BestMove = null; CurrentState = GameState.Play; - CurrentPlayer = Opponent; - + CurrentPlayer = Opponent; startTurn (); } diff --git a/src/deferredPbrRenderer.cs b/src/deferredPbrRenderer.cs index ac9dfc9..1337089 100644 --- a/src/deferredPbrRenderer.cs +++ b/src/deferredPbrRenderer.cs @@ -79,7 +79,7 @@ namespace vkChess } }; - public DescriptorSetWrites UiImageUpdate => new DescriptorSetWrites (dsMain, descLayoutMain.Bindings [8]); + //public DescriptorSetWrites UiImageUpdate => new DescriptorSetWrites (dsMain, descLayoutMain.Bindings [8]); const float lightMoveSpeed = 0.1f; @@ -210,8 +210,9 @@ namespace vkChess new VkDescriptorSetLayoutBinding (4, VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer),//lights new VkDescriptorSetLayoutBinding (5, VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer),//materials new VkDescriptorSetLayoutBinding (6, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),//shadow map - new VkDescriptorSetLayoutBinding (7, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),//texture array - new VkDescriptorSetLayoutBinding (8, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler));//uiImage + new VkDescriptorSetLayoutBinding (7, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)//texture array + //new VkDescriptorSetLayoutBinding (8, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler) + );//uiImage descLayoutGBuff = new DescriptorSetLayout (dev, new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Fragment, VkDescriptorType.InputAttachment),//color + roughness @@ -224,7 +225,9 @@ namespace vkChess descLayoutGBuff.SetName ("GBuff"); using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, NUM_SAMPLES)) { - cfg.rasterizationState.cullMode = VkCullModeFlags.Back; + + cfg.rasterizationState.cullMode = VkCullModeFlags.None; + if (NUM_SAMPLES != VkSampleCountFlags.SampleCount1) { cfg.multisampleState.sampleShadingEnable = true; cfg.multisampleState.minSampleShading = 0.5f; diff --git a/ui/chess.crow b/ui/chess.crow index 6050a36..a813be4 100644 --- a/ui/chess.crow +++ b/ui/chess.crow @@ -1,23 +1,28 @@ -<?xml version="1.0"?> +<?xml version="1.0" encoding="UTF-8"?> <HorizontalStack Height="Fit" Background="vgradient|0:Grey|0.3:Jet|0.7:Jet|1:Black" VerticalAlignment="Bottom" Margin="10"> - <CheckBox Caption="Hint" IsChecked="{²EnableHint}"/> - <Button Caption="Undo" MouseClick="onUndoClick"/> - <Button Caption="New Game" MouseClick="onNewGameClick"/> - <Button Caption="Options" MouseClick="onOptionsClick"/> - <Widget Width="Stretched" Height="1"/> - <Button Caption="Quit" MouseClick="onQuitClick"/> - <VerticalStack Style="hsStatus" > - <Label Style="labStatus" Text="State:"/> - <Label Style="labStatus2" Text="{CurrentState}" /> - </VerticalStack > - <VerticalStack Style="hsStatus" > - <Label Style="labStatus" Text="Hover:"/> - <Label Style="labStatus2" Text="{SelCell}"/> + <CheckBox Caption="Hint" IsChecked="{²EnableHint}" /> + <Menu Data="{Commands}" Height="Stretched" Width="Stretched"> + <Template> + <HorizontalStack Name="ItemsContainer" /> + </Template> + <ItemTemplate> + <Button Command="{}"> + <Label Font="{./Font}" Name="caption" Margin="3" Foreground="LightGrey" Text="{./Caption}" /> + </Button> + </ItemTemplate> + </Menu> + <VerticalStack Style="hsStatus"> + <Label Style="labStatus" Text="State:" /> + <Label Style="labStatus2" Text="{CurrentState}" /> </VerticalStack> - <VerticalStack Style="hsStatus" > - <Label Style="labStatus" Text="Current Player:"/> - <Label Style="labStatus2" Text="{CurrentPlayer}"/> + <VerticalStack Style="hsStatus"> + <Label Style="labStatus" Text="Hover:" /> + <Label Style="labStatus2" Text="{SelCell}" /> </VerticalStack> - <Image Width="30" Height="20" Path="#Crow.Icons.IconAlerte.svg" Visible="{StockfishNotFound}"/> - <Label Text="Stockfish not found" Font="droid bold, 10" Visible="{StockfishNotFound}"/> -</HorizontalStack> + <VerticalStack Style="hsStatus"> + <Label Style="labStatus" Text="Current Player:" /> + <Label Style="labStatus2" Text="{CurrentPlayer}" /> + </VerticalStack> + <Image Width="30" Height="20" Path="#Crow.Icons.IconAlerte.svg" Visible="{StockfishNotFound}" /> + <Label Text="Stockfish not found" Font="droid bold, 10" Visible="{StockfishNotFound}" /> +</HorizontalStack>
\ No newline at end of file diff --git a/ui/chess.style b/ui/chess.style index b79aa91..0c578a1 100644 --- a/ui/chess.style +++ b/ui/chess.style @@ -1,4 +1,4 @@ - + icon { Width="14"; Height="14"; @@ -7,12 +7,12 @@ icon { hsStatus { Height="Fit"; Width="100"; - Background="SeaGreen"; + Background="#2E8BB6"; Margin="3"; } labStatus { Width="Fit"; - Foreground="DarkGrey"; + Foreground="LightGrey"; Font="serif bold, 10"; Margin="0"; } diff --git a/ui/debug.crow b/ui/debug.crow index e4a8476..44669a8 100644 --- a/ui/debug.crow +++ b/ui/debug.crow @@ -44,7 +44,7 @@ </ItemTemplate> </ListBox> </Expandable> - <ColorWheel Name="cw" Width="100" Height="100"/> + <!--<ColorWheel Name="cw" Width="100" Height="100"/>--> <Slider SmallIncrement="0.01" LargeIncrement="0.1" Height="10" Minimum="0.0" Maximum="2.0" Value="{²../cw.InnerRadius}"/> <HueSelector Focusable="true" Height="15" Hue="{²../cw.Hue}"/> <Widget Width="30" Height="16" Background="{CurrentColor}"/> diff --git a/ui/main.crow b/ui/main.crow index 949ae8a..4f685ac 100644 --- a/ui/main.crow +++ b/ui/main.crow @@ -1,5 +1,5 @@ <?xml version="1.0"?> -<Window Caption="Options" Left="10" Top="1" Width="70%" Height="Fit" CornerRadius="5" > +<Window Caption="Options" Left="10" Top="1" Width="70%" Height="Fit" CornerRadius="5" Background="0.1,0.1,0.1,0.8"> <VerticalStack Spacing="1" Margin="10" > <HorizontalStack Height="Fit" Margin="5"> <Label Text="Stockfish executable path:"/> |