A simple C# like pre-processor for any source file.
With a build script you can pre-preprocess your shaders and output the needed variants
```rust // build.rs use std::{env, fs};
fn main() { let outdir = env::var("OUTDIR").unwrap(); let cratedir = env::var("CARGOMANIFEST_DIR").unwrap();
let mut pp = preproc::PP::default().search_path(crate_dir + "/shaders/include");
println!("cargo:rerun-if-changed=shaders/vertex_lit.wgsl");
fs::write(out_dir + "/unlit_vertex_color.wgsl", pp.parse_file(crate_dir + "/shaders/vertex_color.wgsl"));
fs::write(out_dir + "/lambert_vertex_color.wgsl", pp.define("LAMBERT").parse_file(crate_dir + "/shaders/vertex_color.wgsl"));
} ```
```wgsl // vertex_color.wgsl
@fragment
fn fsmain(in: VertOut) -> @location(0) vec4
```wgsl // shading.wgsl
fn shading(normal: vec3
fn shading(normal: vec3
```
outputs:
``wgsl
// unlit_vertex_color.wgsl
fn shading(normal: vec3<f32>, light_dir: vec3<f32>) -> f32 {
// unlit
1.0
}
//
vert.wgsl` contents ...
@fragment
fn fsmain(in: VertOut) -> @location(0) vec4
``wgsl
// lambert_vertex_color.wgsl
fn shading(normal: vec3<f32>, light_dir: vec3<f32>) -> f32 {
// lambert
max(dot(normal, light_dir), 0.0)
}
//
vert.wgsl` contents ...
@fragment
fn fsmain(in: VertOut) -> @location(0) vec4
#include
, #if
, #elif
, #else
and endif
#define
and #undef