rust-gpu/crates/spirv-std
Christian Legnitto f955221493
Add ignore and no_run to get cargo test to pass. (#1101)
* Add changelog entry and failing CI.

* Add ignore and no_run to get `cargo test` to pass.
2024-01-24 12:55:58 +01:00
..
macros builder: aggressively pointercast/bitcast to paper over opaque pointers. 2023-11-21 18:25:34 +02:00
shared Add rustfmt.toml with version = "Two" to enable formatting array patterns. 2023-06-03 10:46:57 +03:00
src Address new rustc/clippy lints. 2023-11-21 18:25:34 +02:00
Cargo.toml Apply suggestions from code review 2023-05-30 10:38:51 +03:00
README.md Add ignore and no_run to get cargo test to pass. (#1101) 2024-01-24 12:55:58 +01:00

spirv-std

Core functions, traits, and more that make up a “standard library” for SPIR-V for use in rust-gpu.

This crate gives a rust-gpu shader access to the required #![spirv(..)] attribute, as well as povide all kinds of APIs that allows a shader to access GPU resources such as textures and buffers. Optionally, through the use of the "glam" feature, it includes some boilerplate trait implementations to make glam vector types compatible with these APIs.

Example

Sky shader

Here is a small excerpt to see what a shader would look like. See source for full details of the shader that generates above image.

use spirv_std::spirv;
use glam::{Vec3, Vec4, vec2, vec3};

#[spirv(fragment)]
pub fn main(
    #[spirv(frag_coord)] in_frag_coord: &Vec4,
    #[spirv(push_constant)] constants: &ShaderConstants,
    output: &mut Vec4,
) {
    let frag_coord = vec2(in_frag_coord.x, in_frag_coord.y);
    let mut uv = (frag_coord - 0.5 * vec2(constants.width as f32, constants.height as f32))
        / constants.height as f32;
    uv.y = -uv.y;

    let eye_pos = vec3(0.0, 0.0997, 0.2);
    let sun_pos = vec3(0.0, 75.0, -1000.0);
    let dir = get_ray_dir(uv, eye_pos, sun_pos);

    // evaluate Preetham sky model
    let color = sky(dir, sun_pos);

    *output = tonemap(color).extend(1.0)
}

Getting started

Check out The rust-gpu Dev Guide for information on how to get started with using it in your projects.

Experiment with rust-gpu shaders in-browser at SHADERed.