Crates.io | wgpu-pp |
lib.rs | wgpu-pp |
version | 1.0.0 |
source | src |
created_at | 2024-08-30 01:05:31.755681 |
updated_at | 2024-08-30 01:05:31.755681 |
description | Simple, C-style preprocessor for WGSL using proc macros. |
homepage | |
repository | |
max_upload_size | |
id | 1357275 |
size | 26,157 |
wgpu-pp
Simple, C-style preprocessor for WGSL using proc macros. It also runs compile-time validation via Naga.
include_wgsl!("../shader.wgsl")
shader.wgsl
:
#include "common/color.wgsl"
#define PI f32(3.14159)
@fragment
fn fs_main(
@builtin(position) position: vec4f,
) -> @location(0) vec4f {
let x = 2.0 * (position.x - 0.5) * PI
let y = 2.0 * (position.y - 0.5) * PI
return srgb_to_linear(vec4(
0.5 + 0.5 * sin(x),
0.0,
0.5 + 0.5 * cos(x),
1.0
));
}
Preprocessor statements:
#include
: Ability to share code between shaders.#define
: Work around WGSL 1.0 limitations (such as passing arrays to functions). Works for both constants and macros.wgpu-pp
does not aim to output human-readable WGSL, there may be extraneous newlines—comments are also stripped.
This work is distributed under the MIT License.