From 45286b8178dda33a7a99922c3ffa45de52331660 Mon Sep 17 00:00:00 2001 From: Asuro Date: Thu, 25 Feb 2021 22:43:28 +0100 Subject: [PATCH] remove scripts --- shaders/compile.bat | 2 -- shaders/compile.ps1 | 33 ------------------------------ shaders/triangle.frag | 2 +- shaders/triangle.frag.spv | Bin 3608 -> 3536 bytes src/vulkan/pipelines.rs | 41 +++++++++++++++++++++++++++++++------- 5 files changed, 35 insertions(+), 43 deletions(-) delete mode 100644 shaders/compile.bat delete mode 100644 shaders/compile.ps1 diff --git a/shaders/compile.bat b/shaders/compile.bat deleted file mode 100644 index 2c88e69..0000000 --- a/shaders/compile.bat +++ /dev/null @@ -1,2 +0,0 @@ -for %%i in (*.frag) do glslangValidator -V %%i -o %%i.spv -for %%i in (*.vert) do glslangValidator -V %%i -o %%i.spv \ No newline at end of file diff --git a/shaders/compile.ps1 b/shaders/compile.ps1 deleted file mode 100644 index 1d22125..0000000 --- a/shaders/compile.ps1 +++ /dev/null @@ -1,33 +0,0 @@ -$compileHashFile = "compilehashes.xml" - -if (Get-ChildItem -File $compileHashFile -ErrorAction SilentlyContinue) { - $hashes = Import-Clixml $compileHashFile -} else { - $hashes = @{} -} - -function CompileShader($fileName) { - $spvFileName = "$fileName.spv" - $newHash = Get-FileHash -Path $fileName -Algorithm SHA1 - - $spvExists = $false - if (Get-ChildItem -File $spvFileName -ErrorAction SilentlyContinue) { - $spvExists = $true - } - - if ($spvExists -and $hashes.ContainsKey($fileName) -and $hashes[$fileName] -eq $newHash.Hash) { - Write-Output "Skipping $fileName" - } else { - glslangValidator -V $fileName -o $spvFileName - $hashes.$fileName = $newHash.Hash - } -} - -Get-ChildItem -Filter *.vert | ForEach-Object { - CompileShader $_.Name -} -Get-ChildItem -Filter *.frag | ForEach-Object { - CompileShader $_.Name -} - -Export-Clixml -Path $compileHashFile -InputObject $hashes diff --git a/shaders/triangle.frag b/shaders/triangle.frag index 2290422..34a17d2 100644 --- a/shaders/triangle.frag +++ b/shaders/triangle.frag @@ -26,7 +26,7 @@ void main() { normal_cam_u = normalize(tbn * normal_cam_u); // vec3 light_direction_cam_u = normalize(ubo.light_position - position_wld); - vec3 light_direction_cam_u = normalize(vec3(sin(ubo.time), 1.0, cos(ubo.time))); + vec3 light_direction_cam_u = normalize(vec3(1.0, 1.0, 1.0)); float ambient_strength = 0.1; vec3 light_color = vec3(1.0, 1.0, 1.0); diff --git a/shaders/triangle.frag.spv b/shaders/triangle.frag.spv index 8b419f3f469b208c5cd7b64957072ae740c2fcbe..b312f522c8da2a8f12ee7c2f27c83adf479ea1a7 100644 GIT binary patch delta 1832 zcmbOsb3vMynMs+Qfq{{Mi-CioVj{0Uryc_XLk0r_L;1$kRz_(y1`xj>zc{lbGe0lB zJST;Lfq{XQft|s4@>@n}QBwv6hMdgwjFR}|{G9wE237_(2J^|XOyaWE3=9k@nQ3XI z#i{YdB}J)u=_Mdz!73al2QrCEx-u{@6c?l>m*ylE#g`@Kl%|4AW@B)h+{h%#%+3%x zc_WiFW7OocOwy8x$Z8>0F|abQGGt68sW1fsrt^GcTKjIqoN3=9ekEDTyuqu8N*U8qtJ z-T0A#Dj3o+@LGg?%?}#Q3ie+SZ zHzawG`Jo8D7z4<_D1-n5NI~LeSq@{ydXO19U>`Fu*fOwyLr$N80h~UY!6}k~!GM8* z0i*^b&I1iyLud?v+yRoeV_;@bW?*0diG$c6|AJx!#0L4*i~(XkD5fkJ7#KkEwhS!w zU<)mw0n!Jx(29Y90VD=e2r>W^I3O{Y18o@?7&xH@f;?cyzyP*<3OE}uFxZ3T7#Kj} zJPhpM3=AM~ zka3`hi-S556vH5SP%Ojb5}N6P_7(huH#?NA4U;w3} zMriWSW?*2*WTY%+$P+ z_~MeH)V%bP3XrQ!Cs38680$l4D?CU}9ikaA#lv zdk(}0c>=@-X;lJopzvDh7th&g`!BApd~k9A*~>0|SE@)Q=#wAU-I@Ve%mLHfZvo zI7gOuLz4%^I!qp9UIap3i~(d|EJA<*q#$LpEQc{;J;@UOol}29R6;G`c_yq z0Fnb`g+Qps{23S+K;j_#8DN3|P(e^0fQbb{#Xxx#7MDQ`3=ALxK6$F8tS3(8a4SLw{Sfu zqCk-VGA0IU3`l1b0|P@eIHH&tK*=5?2Qw*-fdMQAsFo4v6#6f0* zA}$eXHYkEY@}NlOVPLNZ$9^(YQVLW;GcYiK$_S7bK-mi<2eJrcNGbyZ11J(<{4@pz z29TOoXauA)Fff4BfW$#+K%N3s0-z)gOTL*53=AMKkXk#2dS(VtfejLbX~kJGGFf|1X3=AN3AaPiv7cwv~fW$$C8BDAQ zlvF^1$f=_kst}So*ulxIgn@wpWB{nn0?C7tG01XmP`v~#B|&_C1_p+51_lN}1_p+3 pXi}|!ssV|ELJCycRx&U!fXtKtNrHkJRP2HT|1vN#STHa$000*@q?Z5y diff --git a/src/vulkan/pipelines.rs b/src/vulkan/pipelines.rs index 2fd00c1..23f04a9 100644 --- a/src/vulkan/pipelines.rs +++ b/src/vulkan/pipelines.rs @@ -1,4 +1,4 @@ -use std::{convert::TryInto, io::{Read, Write}, sync::Arc}; +use std::{convert::TryInto, io::{self, ErrorKind, Read, Write}, path::PathBuf, sync::Arc}; use vulkano::{command_buffer::AutoCommandBufferBuilder, descriptor::{descriptor::ShaderStages, descriptor_set::PersistentDescriptorSet}, pipeline::shader::ShaderModule}; use vulkano::command_buffer::DynamicState; @@ -53,6 +53,38 @@ fn shader_module_from_file(device: Arc, path: &str) -> Arc } } +fn matches_extension(path: &PathBuf, extensions: &Vec<&str>) -> bool { + if let Some(Some(path_extension)) = path.extension().map(|e| e.to_str()) { + for extension in extensions { + if *extension == path_extension { return true; } + } + } + return false; +} + +fn compile_shaders() -> io::Result<()> { + for file_maybe in std::fs::read_dir("./shaders")? { + let path = file_maybe?.path(); + if !path.is_dir() && matches_extension(&path, &vec!["frag", "vert"]) { + let mut target_path = path.to_str().ok_or(ErrorKind::Other)?.to_string(); + target_path.push_str(".spv"); + + let output = std::process::Command::new("glslangValidator") + .arg("-V") + .arg(path.to_str().ok_or(ErrorKind::Other)?) + .arg("-o") + .arg(target_path) + .output().unwrap(); + std::io::stdout().write_all(&output.stdout)?; + + if !output.status.success() { + eprintln!("Shader compiler {:?}", output.status); + } + } + } + Ok(()) +} + impl DefaultShader { pub fn new(device: Arc, render_pass: RP) -> Self { DefaultShader { @@ -66,12 +98,7 @@ impl DefaultShader { #[cfg(debug_assertions)] { println!("Compiling shaders..."); - let output = std::process::Command::new("cmd.exe") - .arg("/c") - .arg("compile.bat") - .current_dir("shaders") - .output().unwrap(); - std::io::stdout().write_all(&output.stdout).unwrap(); + compile_shaders().unwrap(); } unsafe {