Crates.io | wgs_core |
lib.rs | wgs_core |
version | 0.1.2 |
source | src |
created_at | 2023-06-07 07:10:40.585619 |
updated_at | 2023-10-26 02:28:55.551163 |
description | Wgs format |
homepage | https://github.com/fralonra/wgs |
repository | https://github.com/fralonra/wgs |
max_upload_size | |
id | 884541 |
size | 8,665 |
wgs
is a binary format that represents pixel shader programs. Inspired by Shadertoy but uses WGSL instead. It can now runs on native platforms and Web as well thanks to wgpu-rs.
A wgs
file mainly consists of three parts:
The latest version of wgs
is wgs 1.
Notice The very first version of wgs
does not include version
field and uses a texture
function to render textures which is conflicting with the keyword in GLSL
. Thus, this first version is not compatible with any later versions.
WgShadertoy is a cross-platform program helps you read and write your wgs
files.
Maybe Web-based editors in the future.
A wgs
program receives six parameters passed from the runtime as a uniform variable:
cursor
: vec2mouse_down
: u32
0
: left button is up.1
: left button is down.mouse_press
: vec2mouse_release
: vec2resolution
: vec2time
: f32
You can use the above uniform like the following:
fn main_image(frag_color: vec4<f32>, frag_coord: vec2<f32>) -> vec4<f32> {
let uv = frag_coord / u.resolution;
let color = 0.5 + 0.5 * cos(u.time + uv.xyx + vec3(0.0, 2.0, 4.0));
return vec4(color, 1.0);
}
wgs
currently provides one built-in function:
image helps you play with textures:
fn image(t: texture_2d<f32>, spl: sampler, uv: vec2<f32>) -> vec4<f32>
Check this example for usage.
wgs_runtime_wgpu is all you need to run wgs
file on a native platform.
Here's an example about how to integrate wgs
with winit.
You can write your own runtime implementation as long as it implements RuntimeExt
.
wgs_runtime_wgpu
also compiles for Wasm32 architecture.
You can install it from npm or use a high-level library wgs-player
.