isf

Crates.ioisf
lib.rsisf
version0.1.0
sourcesrc
created_at2020-03-22 20:32:50.477256
updated_at2020-03-22 20:32:50.477256
descriptionParsing, Deserialization and Serialization of the Interactive Shader Format.
homepagehttps://github.com/nannou-org/isf
repositoryhttps://github.com/nannou-org/isf.git
max_upload_size
id221536
size1,097,412
(mitchmindtree)

documentation

README

isf Build Status Crates.io Crates.io docs.rs

Parsing, deserialization and serialization of ISF - the Interactive Shader Format.

Implementation is as described under "The ISF Specification Vsn 2.0" part of the spec site.

The parse function can parse a given GLSL string to produce an Isf instance. The Isf type represents a fully structured representation of the format, including typed Inputs.

Tests

The repo includes all shaders from the "ISF Test/Tutorial filters" collection provided by the specification site along with all shaders within the "Vidvox/ISF-Files" repository for automated testing. These tests do a full roundtrip on every shader in the following steps:

  1. Read the GLSL string from file.
  2. Parse the GLSL string for the top-level dictionary.
  3. Deserialize the JSON to an Isf struct.
  4. Serialize the Isf struct back to a JSON string.
  5. Deserialize the new JSON string to an Isf struct again.
  6. Assert the first Isf instance is identical to the second.

Thanks to the Vidvox crew for allowing us to include these tests in the repo for easy automated testing!

Example

Parsing a GLSL string to an ISF struct looks like this:

let isf = isf::parse(&glsl_str).unwrap();

See the Isf struct docs to get an idea of what you can do with it!

Here's a copy of the tests/roundtrip.rs test as described above:

let test_files_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("test_files");
assert!(test_files_path.exists());
assert!(test_files_path.is_dir());
for entry in std::fs::read_dir(test_files_path).unwrap() {
    let entry = entry.unwrap();
    let path = entry.path();
    let ext = path.extension().and_then(|s| s.to_str());
    if ext == Some("fs") || ext == Some("vs") {
        let glsl_str = std::fs::read_to_string(&path).unwrap();
        let isf = match isf::parse(&glsl_str) {
            // Ignore non-ISF vertex shaders.
            Err(isf::ParseError::MissingTopComment) if ext == Some("vs") => continue,
            Err(err) => panic!("err while parsing {}: {}", path.display(), err),
            Ok(isf) => isf,
        };
        let isf_string = serde_json::to_string_pretty(&isf).unwrap();
        let isf2 = serde_json::from_str(&isf_string).unwrap();
        assert_eq!(isf, isf2);
    }
}

About

This crate has been developed as a step towards creating an ISF live-coding environment based on nannou, the creative coding framework.

Commit count: 2

cargo fmt