Crate rasen [] [src]

Build a SPIR-V module from an operation graph

This library lets you define a shader module as a graph (using the petgraph library) of Node, describing the operations needed to obtain the outputs of the shader.

#[macro_use]
extern crate rasen;

use rasen::*;
use rasen::TypedValue::*;

fn main() {
    let graph = rasen_graph! {
        // The only output of this graph is a vec4, at location 0
        Output(0, TypeName::VEC4) {
            // Multiply the light intensity by the surface color
            Multiply {
                // Restrict the intensity into the ambient light range
                Clamp {
                    // Compute the dot product of the surface normal and the light direction
                    Dot {
                        // Normalize the normal
                        Normalize {
                            // The surface normal, a vec3 input at location 0
                            Input(0, TypeName::VEC3)
                        }
                        // The directional light direction
                        Constant(Vec3(0.3, -0.5, 0.2))
                    }
                    // The minimum / maximum light levels
                    Constant(Float(0.1))
                    Constant(Float(1.0))
                }
                // The Material color
                Constant(Vec4(0.25, 0.625, 1.0, 1.0))
            }
        };
    };

    let bytecode = build_program(&graph, ShaderType::Fragment).unwrap();
    // bytecode is now a Vec<u8> you can pass to Vulkan to create the shader module
}

On a lower level, you can use the Builder struct to build your module by adding instructions directly into it.

Reexports

pub use graph::*;

Modules

errors

Error-related definitions generated by error_chain

glsl

Definitions for the GLSL languages

graph

Graph building helpers

Macros

rasen_graph

Exposes a simple DSL for the construction of a Graph

Structs

Builder

Builder struct used to define a SPIR-V module

Enums

ShaderType

SPIR-V operand kind: ExecutionModel

Functions

build_program

Transform a node graph to SPIR-V bytecode