#glsl #toml

dsa-lib

A Shader generation tool from TOML to GLSL written in Rust

9 releases

Uses new Rust 2021

0.1.8 Jul 3, 2022
0.1.7 Jul 3, 2022

#8 in Rendering engine

Download history 36/week @ 2022-06-26 164/week @ 2022-07-03 24/week @ 2022-07-10 14/week @ 2022-07-17 27/week @ 2022-07-24 10/week @ 2022-07-31 9/week @ 2022-08-07

60 downloads per month

MIT/Apache

9KB
147 lines

Dynamic Shader Assembler

A Shader generation tool from TOML to GLSL written in Rust

Example

Config

version = 330
profile = "core"

[layout]
a_pos = "vec3"
a_uv = "vec2"

[uniform]
transform = "mat4"
texture_0 = "sampler2D"

[fragment]
output = { result = "vec4" }
source = '''
result = texture(texture_0, uv);
'''

[vertex]
output = { uv = "vec2" }

source = '''
gl_Position = transform * vec4(a_pos, 1.0);
uv = a_uv;
'''

Compiler

let toml = fs::read_to_string("example/textured.toml").unwrap();
let (vertex,fragment, config) = compile_toml(toml.as_str()).unwrap();
println!("Vertex {}",vertex);
println!("Fragment {}",fragment);

Output

Vertex

#version 330 core
layout (location = 0) in vec3 a_pos; 
layout (location = 1) in vec2 a_uv; 

uniform mat4 transform; 
uniform sampler2D texture_0; 

out vec2 uv; 

void main() {
    gl_Position = transform * vec4(a_pos, 1.0);
    uv = a_uv;
}

Fragment

#version 330 core
uniform mat4 transform; 
uniform sampler2D texture_0; 

in vec2 uv; 

out vec4 result; 

void main() {
    result = texture(texture_0, uv);
}

You can specify Functions, Constants and Output per Shader. But Uniforms, Version, Profile and Layout per Program.

Vertex Output are also synced with Fragment Input.

For all examples see examples/textured.toml

License

This project is licensed under either of

at your option.

Contribution

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

Dependencies

~1–1.7MB
~37K SLoC