Compiler for visual shader graphs to WGSL (WebGPU Shading Language) code.
- Compiles visual shader node graphs to WGSL code
- Support for vertex, fragment, and compute shaders
- Built-in shader nodes (math, textures, vectors)
- Shares infrastructure with PBGC via Graphy library
- Type-safe shader compilation
use psgc::{compile_shader, ShaderStage};
use graphy::GraphDescription;
let graph = GraphDescription::new("my_shader");
// ... build graph with shader nodes
match compile_shader(&graph) {
Ok(wgsl_code) => std::fs::write("shader.wgsl", wgsl_code)?,
Err(e) => eprintln!("Error: {}", e),
}add(a, b)- Add two floatsmultiply(a, b)- Multiply two floatsdot(a, b)- Dot product of vec3snormalize(v)- Normalize a vector
vec3(x, y, z)- Create vec3vec4(x, y, z, w)- Create vec4
sample_texture(tex, sampler, uv)- Sample 2D texture
vertex_main- Vertex shader entryfragment_main- Fragment shader entry
use psgc::*;
use graphy::*;
let mut graph = GraphDescription::new("gradient_shader");
// Fragment entry
let mut fragment = NodeInstance::new("frag", "fragment_main", Position::zero());
fragment.add_output_pin("Body", DataType::Execution);
graph.add_node(fragment);
// The compiler generates valid WGSL:
let wgsl = compile_fragment_shader(&graph)?;Output WGSL:
// Auto-generated WGSL shader from Pulsar Shader Graph
@fragment
fn fragment_main(
@builtin(position) frag_coord: vec4<f32>,
) -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 0.0, 1.0, 1.0);
}Built on Graphy library with shader-specific:
- WGSL node metadata
- WGSL code generation
- Shader stage handling
- Texture/uniform support
Add custom shader nodes by extending the metadata:
use psgc::metadata::get_shader_nodes;
// Add your custom nodes to the registry
// See metadata.rs for examplesPSGC supports three shader stages:
- Vertex -
compile_vertex_shader() - Fragment -
compile_fragment_shader() - Compute - Coming soon
PSGC is designed to integrate with Pulsar's shader system, providing visual shader authoring with production-ready compilation.