StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | // Simple shader for 2D rendering with texture support |
| 2 | // Supports both solid colors and textured rendering |
| 3 | |
| 4 | // Uniform buffer for projection matrix |
| 5 | struct Uniforms { |
| 6 | projection: mat4x4<f32>, |
| 7 | }; |
| 8 | |
| 9 | @group(0) @binding(0) |
| 10 | var<uniform> uniforms: Uniforms; |
| 11 | |
| 12 | // Texture and sampler for text/image rendering (optional) |
| 13 | @group(0) @binding(1) |
| 14 | var texture: texture_2d<f32>; |
| 15 | |
| 16 | @group(0) @binding(2) |
| 17 | var texture_sampler: sampler; |
| 18 | |
| 19 | // Vertex input |
| 20 | struct VertexInput { |
| 21 | @location(0) position: vec2<f32>, |
| 22 | @location(1) color: vec4<f32>, |
| 23 | @location(2) uv: vec2<f32>, |
| 24 | }; |
| 25 | |
| 26 | // Vertex output / Fragment input |
| 27 | struct VertexOutput { |
| 28 | @builtin(position) clip_position: vec4<f32>, |
| 29 | @location(0) color: vec4<f32>, |
| 30 | @location(1) uv: vec2<f32>, |
| 31 | }; |
| 32 | |
| 33 | // Vertex shader |
| 34 | @vertex |
| 35 | fn vs_main(in: VertexInput) -> VertexOutput { |
| 36 | var out: VertexOutput; |
| 37 | out.clip_position = uniforms.projection * vec4<f32>(in.position, 0.0, 1.0); |
| 38 | out.color = in.color; |
| 39 | out.uv = in.uv; |
| 40 | return out; |
| 41 | } |
| 42 | |
| 43 | // Fragment shader |
| 44 | @fragment |
| 45 | fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> { |
| 46 | // Sample texture at UV coordinates |
| 47 | // If UV is (0,0), use solid color (for non-textured geometry) |
| 48 | // Otherwise, modulate texture with vertex color |
| 49 | var tex_color = textureSample(texture, texture_sampler, in.uv); |
| 50 | |
| 51 | // Mix texture and vertex color |
| 52 | // If texture is white (1,1,1,1) or UV is at origin, use vertex color |
| 53 | // Otherwise blend texture with color |
| 54 | return tex_color * in.color; |
| 55 | } |
| 56 |