MCPcopy Index your code
hub / github.com/RayMarch/shame

github.com/RayMarch/shame @v1.0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.1 ↗ · + Follow
940 symbols 2,231 edges 94 files 334 documented · 36%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

logo logo

shame

shader metaprogramming in rust

shame lets you write shader recipes in rust, which can be turned into shaders and pipelines at runtime!

You can generate parts of the shaders based on runtime conditions, use the rust type system, output entire pipeline layouts and more!

shame is very experimental!

a single rust function generates vertex/fragment shaders and pipeline information a single rust function generates vertex/fragment shaders and pipeline information

shame pipelines are written as small rust functions which are "recorded" and return...

  • ...shader Strings
  • vertex/fragment or compute shaders
  • ...pipeline layout information
  • face culling,
  • z-test/z-write,
  • blending,
  • index format/primitive topology,
  • vertex attributes and buffer layouts,
  • color/depth targets and formats,
  • bind group layouts,
  • push constant type

Code example (more in examples folder)

use shame::prelude::*;

fn my_render_pipeline(mut f: RenderFeatures) {
    // use `f` to build your shader

    // define a vertex layout
    #[derive(shame::Fields)]
    struct MyVertex {
        pos: float3,
        color: float4,
    }

    // use the vertex layout in this shader
    let vert: MyVertex = f.io.vertex_buffer();
    // use an index buffer containing u32s
    let topology: TriangleList<u32> = f.io.index_buffer();

    // read from the 0th bind group
    let mut group0 = f.io.group();
    // which has a uniform block at binding #0
    let matrix: float4x4 = group0.uniform_block();

    // use the uniform data in calculations
    let clip_xyzw = matrix * (vert.pos, 1.0);

    // rasterize triangles at clip space positions with clockwise culling
    let polygon = f.raster.rasterize(
        clip_xyzw, Cull::CW, topology,
    );

    // vertex -> fragment interpolation
    let mut frag_color = polygon.lerp(vert.color);

    // read the push constant as a float
    let time: float = f.io.push_constant();
    frag_color += time.sin() * 0.1;

    // write to an sRGB render-target with alpha.
    // use alpha blending with frag_color as src color
    f.io.color::<RGBA_8888_sRGB>().blend(
        Blend::alpha(), 
        frag_color
    );
}

fn main() {
    // generate the shaders and pipeline layout
    let out = shame::record_render_pipeline(my_render_pipeline);

    let (vertex_shader, fragment_shader) = &out.shaders_glsl;
    let pipeline_info = &out.info;

    println!("{out}");
}

// more examples in the examples folder!
Feature Status
GLSL (Vulkan) out ✅🚧 supported, not feature complete yet
GLSL (OpenGL) out ✖️✋ will probably implement if people ask for it
WGSL out 🗓️ planned
render pipeline layout supported, not feature complete yet
compute pipeline layout supported
vertex shaders supported
fragment shaders supported
compute shaders supported
geometry shaders ✖️ unsupported, not planned
hull/domain shaders ✖️ unsupported, not planned
🔥 hot reloading supported, see examples

Community

We have a discord server where you can ask questions, give feedback, contribute or show your creations! https://discord.gg/Xm5Ck7CCJk

you might also like

  • wgpu: recommended graphics library for use with shame
  • naga: if you want to convert shame's GLSL output to SPIR-V etc.
  • other ways to write shaders in rust:
  • rust-gpu: rust as a first-class language and ecosystem for GPU graphics & compute shaders
  • shades: a different approach of a shader EDSL in rust

license

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in shame by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Extension points exported contracts — how you extend this code

IntoRec (Interface)
A trait implemented by recording types (`impl Rec`) and types that can be converted into recording types e.g. rust liter [8 …
shame/src/rec/rec.rs
FloatingPoint (Interface)
(no doc) [2 implementers]
shame_graph/src/expr/glsl_output.rs
IsShapeMat (Interface)
implemented by all `mat` types [9 implementers]
shame/src/rec/shape.rs
CellNonZeroU32Ext (Interface)
(no doc) [1 implementers]
shame_graph/src/common/shorthands.rs
ShapeAtLeastAsWideAs (Interface)
whether the given vec/scalar [`Shape`] is at least as wide as `S` example: `AtLeastAsWideAs ` is implemented by `v [10 …
shame/src/rec/shape.rs
IteratorExt (Interface)
(no doc) [1 implementers]
shame_graph/src/common/shorthands.rs
IsScalarOr (Interface)
unidirectional "same or scalar" relationship, if you want a bidirectional version of this, where `A: IsScalarOr ` OR ` [13 …
shame/src/rec/shape.rs
UniformBlock (Interface)
(no doc)
shame_graph/src/expr/interface.rs

Core symbols most depended-on inside this repo

into_any
called by 91
shame/src/rec/ten.rs
iter
called by 78
shame/src/rec/ten.rs
downcast
called by 70
shame/src/rec/stage.rs
clone
called by 42
shame_graph/src/pool.rs
push
called by 40
shame_graph/src/pool.rs
rec
called by 31
shame/src/rec/ten.rs
narrow_or_push_error
called by 28
shame/src/rec/stage.rs
invalid_arguments
called by 27
shame_graph/src/expr/deduce.rs

Shape

Method 562
Function 164
Class 116
Enum 51
Interface 47

Languages

Rust100%

Modules by API surface

shame_graph/src/any.rs106 symbols
shame/src/rec/functions.rs70 symbols
shame_graph/src/expr/tensor.rs60 symbols
shame_graph/src/expr/glsl_output.rs42 symbols
shame/src/shader/features.rs41 symbols
shame_graph/src/context.rs39 symbols
shame/src/rec/swizzle.rs39 symbols
shame_graph/src/expr/ty.rs31 symbols
shame_graph/src/expr/interface.rs25 symbols
shame/src/rec/array.rs25 symbols
shame/src/rec/shape.rs24 symbols
shame/src/rec/ten.rs21 symbols

For agents

$ claude mcp add shame \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact