All Projects → leops → rasen

leops / rasen

Licence: MIT license
Generate SPIR-V bytecode from an operation graph

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to rasen

dw-sample-framework
A simple C++ framework for implementing graphics technique samples using OpenGL and Vulkan.
Stars: ✭ 76 (+16.92%)
Mutual labels:  shaders, vulkan
Nova Renderer
Nova Renderer, a custom cross platform render engine written in C++
Stars: ✭ 619 (+852.31%)
Mutual labels:  shaders, vulkan
MoravaEngine
2D/3D graphics engine written in C++ language. It currently supports the following graphics APIs: OpenGL 3.3+, Vulkan 1.2, DirectX 11. Its current purpose is to experiment with various CG concepts and techniques.
Stars: ✭ 129 (+98.46%)
Mutual labels:  shaders, vulkan
cs paint
Vulkan rendering library for graphics and text
Stars: ✭ 79 (+21.54%)
Mutual labels:  shaders, vulkan
Spvgentwo
SpvGenTwo is a SPIR-V building and parsing library written in plain C++17 without any dependencies. No STL or other 3rd-Party library needed.
Stars: ✭ 74 (+13.85%)
Mutual labels:  shaders, vulkan
Camera2GLPreview
Android camera preview application using Camera2 API and OpenGL ES/Vulkan
Stars: ✭ 140 (+115.38%)
Mutual labels:  shaders, vulkan
Shadergen
Proof-of-concept library for generating HLSL, GLSL, and Metal shader code from C#,
Stars: ✭ 395 (+507.69%)
Mutual labels:  shaders, vulkan
spirv cross
Safe Rust wrapper around SPIRV-Cross
Stars: ✭ 75 (+15.38%)
Mutual labels:  vulkan, spirv
3d Game Shaders For Beginners
🎮 A step-by-step guide to implementing SSAO, depth of field, lighting, normal mapping, and more for your 3D game.
Stars: ✭ 11,698 (+17896.92%)
Mutual labels:  shaders, vulkan
Raw Vulkan
🔥 Experiments building Vulkan applications, libraries, and abstractions.
Stars: ✭ 42 (-35.38%)
Mutual labels:  shaders, vulkan
pilka
Another live-coding tool for creating shader demos, Vulkan+Wgpu powered.
Stars: ✭ 84 (+29.23%)
Mutual labels:  shaders, vulkan
The Forge
The Forge Cross-Platform Rendering Framework PC Windows, Linux, Ray Tracing, macOS / iOS, Android, XBOX, PS4, PS5, Switch, Quest 2
Stars: ✭ 2,710 (+4069.23%)
Mutual labels:  shaders, vulkan
RavEngine
A fast, easy to use C++20 3D game library for modern computers
Stars: ✭ 122 (+87.69%)
Mutual labels:  shaders, vulkan
YALCT
Yet Another Live Coding Tool - Powered by Veldrid and elbow grease
Stars: ✭ 25 (-61.54%)
Mutual labels:  shaders, vulkan
Tvm
Open deep learning compiler stack for cpu, gpu and specialized accelerators
Stars: ✭ 7,494 (+11429.23%)
Mutual labels:  vulkan, spirv
Diligentcore
Core functionality of Diligent Engine
Stars: ✭ 263 (+304.62%)
Mutual labels:  shaders, vulkan
Slang
Making it easier to work with shaders
Stars: ✭ 627 (+864.62%)
Mutual labels:  shaders, vulkan
Reshade
A generic post-processing injector for games and video software.
Stars: ✭ 2,285 (+3415.38%)
Mutual labels:  shaders, vulkan
Yave
Yet Another Vulkan Engine
Stars: ✭ 211 (+224.62%)
Mutual labels:  shaders, vulkan
godot-psx-style-demo
Demo project featuring a collection of PS1 style shaders and materials for Godot engine.
Stars: ✭ 266 (+309.23%)
Mutual labels:  shaders

Rasen

crates.io AppVeyor Status Travis Status

What is Rasen ?

Rasen is an umbrella project for a bunch of SPIR-V and Rust related experiments. The core idea of Rasen is to provide a fast and safe compiler for SPIR-V modules, however the core compiler only provide a backend to generate a shader program from an intermediate representation, specifically a "dataflow graph". In traditional, text-based languages such a graph is a usually a metadata generated by the compiler, but some game engine (eg. Unreal) provide an editor to directly edit such a graph, which proved to be a very useful way of quickly prototyping materials.

In practice, Rasen as a whole is designed with two (seemingly unrelated) use case in mind:

  1. To be used as an online shader compiler embedded in a game engine (or any other application doing 3D rendering). Rasen aims to be fast enough to recompile a shader within a frame's budget, and the resulting SPIR-V bytecode can then be retargeted to GLSL, HLSL or MSL using SPIRV-Cross to accomodate the current platform.
  2. To provide a fallback environment for compute shaders in Rust. Rasen uses a special DSL crate to parse Rust code "from the inside" and generate a dataflow graph for execution on the GPU, but on constrained platforms where this capability is unavailable the Rust code is still valid and can be run on the CPU instead (and ultimately should be just as fast as raw rust code). As a sidenote, this should also help making shaders more testable and debuggable as they can be now be run on the CPU too.

Core

The rasen crate contains the core graph compiler itself. It provides graph building utilities (the Graph struct), various types (rasen::types::*) and operations (rasen::node::*) definitions, and SPIR-V compilation utilities (the ModuleBuilder struct).

The API is intentionally low-level, as the use case for the core compiler is to act as a backend for a graph-based material editor in a game engine. It's perfectly possible to use this crate as-is by creating a Graph struct and building the module node-by-node, however this method tends to be quite verbose for "static" shaders:

extern crate rasen;

use rasen::prelude::*;

fn main() {
    let mut graph = Graph::new();

    // A vec3 input at location 0
    let normal = graph.add_node(Node::Input(0, TypeName::VEC3, VariableName::Named(String::from("a_normal"))));

    // Some ambient light constants
    let min_light = graph.add_node(Node::Constant(TypedValue::Float(0.1)));
    let max_light = graph.add_node(Node::Constant(TypedValue::Float(1.0)));
    let light_dir = graph.add_node(Node::Constant(TypedValue::Vec3(0.3, -0.5, 0.2)));

    // The Material color (also a constant)
    let mat_color = graph.add_node(Node::Constant(TypedValue::Vec4(0.25, 0.625, 1.0, 1.0)));

    // Some usual function calls
    let normalize = graph.add_node(Node::Normalize);
    let dot = graph.add_node(Node::Dot);
    let clamp = graph.add_node(Node::Clamp);
    let multiply = graph.add_node(Node::Multiply);

    // And a vec4 output at location 0
    let color = graph.add_node(Node::Output(0, TypeName::VEC4, VariableName::Named(String::from("o_color"))));

    // Normalize the normal
    graph.add_edge(normal, normalize, 0);

    // Compute the dot product of the surface normal and the light direction
    graph.add_edge(normalize, dot, 0);
    graph.add_edge(light_dir, dot, 1);

    // Restrict the result into the ambient light range
    graph.add_edge(dot, clamp, 0);
    graph.add_edge(min_light, clamp, 1);
    graph.add_edge(max_light, clamp, 2);

    // Multiply the light intensity by the surface color
    graph.add_edge(clamp, multiply, 0);
    graph.add_edge(mat_color, multiply, 1);

    // Write the result to the output
    graph.add_edge(multiply, color, 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
}

DSL

To reduce the amount of boilerplate, the rasen_dsl crate provides a bunch of utility function to write shaders as perfectly valid Rust code:

extern crate rasen;
extern crate rasen_dsl;

use rasen_dsl::prelude::*;

fn main() {
    let shader = Module::new();

    let normal: Value<Vec3> = normalize(shader.input(0, "a_normal"));
    let light = vec3(0.3, -0.5, 0.2);
    let color = vec4(0.25, 0.625, 1.0, 1.0);

    let res = clamp(dot(normal, light), 0.1f32, 1.0f32) * color;
    shader.output(0, "o_color", res);

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

This crate is even more experimental than the Rasen compiler itself, it already provides all the features exposed by the compiler but they might not be completely spec compliant (for instance the typings constraint on the various GLSL functions may be more, or less strict than required by the OpenGL specification).

Ultimately, the goal for the DSL crate (beside being a statically-checked equivalent of the graph builder) is to expose an API to test the execution of a shader on the CPU, with all the debugging tools that such an environment provides. The library currently provides all the conversion primitives to turn your scalar / vectors / matrices into Value<_> types to test your program, however most GLSL operations are left unimplemented.

Plugin

Finally, the rasen_plugin crate is a compiler plugin exposing a few utility macro and attributes to make writing shaders in Rust event easier:

use rasen_dsl::prelude::*;

#[rasen(module)]
pub fn basic_vert(a_pos: Value<Vec3>, projection: Value<Mat4>, view: Value<Mat4>, model: Value<Mat4>) -> Value<Vec4> {
   let mvp = projection * view * model;
   mvp * vec4!(a_pos, 1.0f32)
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].