kitgit

tirbofish/dropbear · diff

8d20f7f · Thribhu K

damn allat just for me having to return back to wgsl :( at least i did get **some** slang compat to work, but looks like wgsl is the way to go. merging to the ui branch to continue on with ui. i do have a neat little tool tho... Unverified

diff --git a/crates/dropbear-engine/src/pipelines/shaders/blit.wgsl b/crates/dropbear-engine/src/pipelines/shaders/blit.wgsl
deleted file mode 100644
index bd6b79b..0000000
--- a/crates/dropbear-engine/src/pipelines/shaders/blit.wgsl
+++ /dev/null
@@ -1,28 +0,0 @@
-struct VertexOutput {
-    @builtin(position) clip_position: vec4<f32>,
-    @location(0) uv: vec2<f32>,
-}
-
-@group(0) @binding(0)
-var tex: texture_2d<f32>;
-@group(0) @binding(1)
-var tex_sampler: sampler;
-
-@vertex
-fn vs_main(
-    @builtin(vertex_index) in_vertex_index: u32,
-) -> VertexOutput {
-    var out: VertexOutput;
-
-    let x = f32((in_vertex_index << 1u) & 2u);
-    let y = f32(in_vertex_index & 2u);
-    out.clip_position = vec4<f32>(x * 2.0 - 1.0, y * 2.0 - 1.0, 0.0, 1.0);
-    out.uv = vec2<f32>(x, 1.0 - y);
-    return out;
-}
-
-@fragment
-fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
-    let s = textureSample(tex, tex_sampler, in.uv);
-    return s;
-}
\ No newline at end of file
diff --git a/crates/dropbear-engine/src/pipelines/shaders/dropbear.slang b/crates/dropbear-engine/src/pipelines/shaders/dropbear.slang
index 11a2cfe..ff6f1d2 100644
--- a/crates/dropbear-engine/src/pipelines/shaders/dropbear.slang
+++ b/crates/dropbear-engine/src/pipelines/shaders/dropbear.slang
@@ -1,3 +1,8 @@
+struct Globals {
+    uint num_lights;
+    float ambient_strength;
+};
+
 /// A standard light descriptor struct. 
 struct Light {
     float4 position;
@@ -16,6 +21,14 @@ struct CameraUniform {
     float4x4 view_proj;
 };
 
+struct MaterialUniform {
+    // for stuff like tinting
+    float4 colour;
+
+    // scales incoming UVs before sampling
+    float2 uv_tiling;
+};
+
 /// Converts a wgpu matrix (in the form of 4 float4) into a matrix usable for Slang. 
 float4x4 vs_input_matrix(
     float4 mat1, 
diff --git a/crates/slank/src/lib.rs b/crates/slank/src/lib.rs
index 40dc1b4..681bd38 100644
--- a/crates/slank/src/lib.rs
+++ b/crates/slank/src/lib.rs
@@ -24,7 +24,7 @@ macro_rules! include_slang_path {
 pub mod compiled;
 pub mod utils;
 
-use std::path::{Path, PathBuf};
+use std::{fmt::Display, path::{Path, PathBuf}};
 use crate::compiled::CompiledSlangShader;
 
 #[derive(Debug, Clone)]
@@ -77,6 +77,8 @@ pub struct SlangShaderBuilder {
     label: String,
     sources: Vec<SourceFile>,
     entries: Vec<EntryPoint>,
+    profile: Option<Profile>,
+    additional_args: Vec<String>,
 }
 
 impl SlangShaderBuilder {
@@ -86,6 +88,8 @@ impl SlangShaderBuilder {
             sources: Vec::new(),
             entries: Vec::new(),
             label: label.to_string(),
+            profile: None,
+            additional_args: Vec::new(),
         }
     }
 
@@ -212,6 +216,18 @@ impl SlangShaderBuilder {
         self
     }
 
+    pub fn with_profile(mut self, profile: Profile) -> Self {
+        self.profile = Some(profile);
+        self
+    }
+
+    /// In the case that there was an argument not available to this builder, you can
+    /// manually provide it here. 
+    pub fn with_additional_args(mut self, args: &[&str]) -> Self {
+        self.additional_args = args.to_vec().iter().map(|v| v.to_string()).collect::<Vec<_>>();
+        self
+    }
+
     pub fn compile_to_out_dir(self, target: SlangTarget) -> anyhow::Result<()> {
         let label = self.label.clone();
         let compiled = self.build(target)?;
@@ -237,7 +253,7 @@ impl SlangShaderBuilder {
         cmd.arg("-target").arg(target.as_arg());
 
         use std::fmt::Write;
-        write!(&mut args_record, " -target {}", target.as_arg()).unwrap();
+        write!(&mut args_record, " -target {}", target.as_arg())?;
 
         for (source_idx, source) in self.sources.iter().enumerate() {
             let path_to_use = if let Some(path) = &source.path {
@@ -271,6 +287,9 @@ impl SlangShaderBuilder {
             }
         }
 
+        cmd.args(&self.additional_args);
+        write!(&mut args_record, " {}", self.additional_args.join(" "))?;
+
         let temp_dir = tempfile::tempdir()?;
         let output_path = temp_dir.path().join("output");
 
@@ -509,6 +528,31 @@ impl std::str::FromStr for SlangTarget {
     }
 }
 
+pub enum Profile {
+    Sm(String),
+    Glsl(String),
+    Vs(String),
+    Hs(String),
+    Ds(String),
+    Gs(String),
+    Ps(String),
+}
+
+impl Display for Profile {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        let string = match self {
+            Profile::Sm(v) => format!("sm_{v}"),
+            Profile::Glsl(v) => format!("glsl_{v}"),
+            Profile::Vs(v) => format!("vs_{v}"),
+            Profile::Hs(v) => format!("hs_{v}"),
+            Profile::Ds(v) => format!("ds_{v}"),
+            Profile::Gs(v) => format!("gs_{v}"),
+            Profile::Ps(v) => format!("ps_{v}"),
+        };
+        write!(f, "{}", string)
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use super::*;