Rust-GPU面向 GPU 编程的 Rust
Rust-GPU 是面向 GPU 编程的开源项目,目标是使 Rust 成为 GPU 着色器开发的“一等公民”编程语言和生态系统。
示例
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)
}
评论