Skip to main content

Pure Python ISF shader renderer with PyOpenGL and json5

Project description

Read the Docs GitHub release PyPI version

pyvvisf

Python ISF shader renderer with PyOpenGL. Render images from your shaders, or visualize in a window.

Overview

pyvvisf is a pure Python implementation for parsing and rendering ISF (Interactive Shader Format) shaders. It provides a modern, maintainable alternative to the C++ VVISF-GL library with enhanced error reporting and cross-platform compatibility. The original version of this library tried to build VVISF-GL bindings, but that approach was abandoned.

This library tried to catch all the errors that would trigger the online ISF renderer here: https://editor.isf.video/. It will also try to provide compatibility warnings when appropriate.

The main use of this library is intended to be from https://github.com/jimcortez/ai-shader-tool, which provides ai's the ablility to validate, render, and inspect the results of shaders it generates.

The majority of code in this repository was built with AI.

Features

  • Pure Python: No C++ compilation required
  • Robust JSON parsing: Uses json5 for comment support and trailing commas
  • Modern OpenGL: PyOpenGL with GLFW for cross-platform context management
  • Enhanced error reporting: Detailed Python-native error messages with context
  • Type safety: Pydantic models for metadata validation
  • Auto-coercion: Automatic type conversion for shader inputs
  • Context management: Automatic resource cleanup
  • GLSL version support: Automatic detection and support for multiple GLSL versions
  • ISF 2.0 compliance: Full support for ISF 2.0 specification including multi-pass rendering and imports
  • ISF special functions: Support for IMG_THIS_PIXEL, IMG_PIXEL, IMG_SIZE, and other ISF functions

Installation

pip install pyvvisf

Development Installation

git clone https://github.com/jimcortez/pyvvisf.git
cd pyvvisf
pip install -e .

Quick Start

Here's a minimal example using a well-formed ISF shader:

from pyvvisf import ISFRenderer

# A simple ISF shader (every pixel is the selected color)
test_shader = """
/*{
    \"DESCRIPTION\": \"Every pixel is the selected color.\",
    \"CREDIT\": \"pyvvisf example\",
    \"ISFVSN\": \"2.0\",
    \"CATEGORIES\": [\"Generator\"],
    \"INPUTS\": [
        {\"NAME\": \"color\", \"TYPE\": \"color\", \"DEFAULT\": [1.0, 0.0, 0.0, 1.0]}
    ]
}*/
void main() {
    gl_FragColor = color;
}
"""

with ISFRenderer(test_shader) as renderer:
    # Render with the default color (red)
    buffer = renderer.render(512, 512)
    image = buffer.to_pil_image()
    image.save("output_red.png")

    # Render with a custom color (green)
    renderer.set_input("color", (0.0, 1.0, 0.0, 1.0))
    buffer = renderer.render(512, 512)
    image = buffer.to_pil_image()
    image.save("output_green.png")

GLSL Version Support

pyvvisf supports multiple GLSL versions and can automatically detect which versions are supported on your system:

from pyvvisf import get_supported_glsl_versions, ISFRenderer

# Check which GLSL versions are supported
supported_versions = get_supported_glsl_versions()
print(f"Supported GLSL versions: {supported_versions}")

# Create renderer with specific GLSL version
renderer = ISFRenderer(shader_content, glsl_version='330')

The default GLSL version is '330', but you can specify any supported version. The library will automatically test shader compilation to ensure compatibility.

Examples

See the examples/ directory for complete examples:

  • isf_renderer_demo.py: Render ISF shaders to images, set inputs, and save output.
  • isf_window_demo.py: Render ISF shaders in a window (interactive display).
  • time_offset_demo.py: Render shaders at different time offsets (for animation or frame capture).

Shader examples are in examples/shaders/:

  • simple_color_change.fs: Single color input, fills the screen with the selected color.
  • simple_color_animation.fs: Fades between two user-selected colors over time.
  • shapes.fs: Animated shapes (moving circle, rotating rectangle, pulsating ring).
  • simple.fs: Minimal shader, fills the screen with blue.

Development

Building

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

Project Structure

pyvvisf/
├── src/pyvvisf/
│   ├── renderer.py      # Main renderer
│   ├── parser.py        # ISF parser with json5
│   ├── types.py         # Value types
│   ├── errors.py        # Error handling
│   ├── shader_compiler.py # Shader compilation and processing
│   ├── framebuffer_manager.py # Framebuffer management
│   └── input_manager.py # Input validation and management
├── examples/
├── tests/
└── docs/

License

MIT License - see LICENSE file for details.

Special Thanks

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyvvisf-0.7.1.tar.gz (43.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyvvisf-0.7.1-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

Details for the file pyvvisf-0.7.1.tar.gz.

File metadata

  • Download URL: pyvvisf-0.7.1.tar.gz
  • Upload date:
  • Size: 43.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyvvisf-0.7.1.tar.gz
Algorithm Hash digest
SHA256 789c0bfcf07cc9c396e30028a953d1d0f862df1fdc17d7221e13ef8f26b05ba6
MD5 dba630c1e3688ee2e1fcf8ee8d07bc08
BLAKE2b-256 e44390e46f5e270baaf0057ec8f917cae949d6ed5cd5f5ef2fec376664e3f05a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvvisf-0.7.1.tar.gz:

Publisher: build-wheels.yml on jimcortez/pyvvisf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvvisf-0.7.1-py3-none-any.whl.

File metadata

  • Download URL: pyvvisf-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 27.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyvvisf-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c53dd272a6490981af97c48a0c9780fe16733be691352884896a11e4e820677
MD5 e486f04940226e3aeebbfc1a5bf8738e
BLAKE2b-256 ed1265f315ee6a05c3cadd1bfa967aaff07c1565b8985714863b14efd9fbea01

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvvisf-0.7.1-py3-none-any.whl:

Publisher: build-wheels.yml on jimcortez/pyvvisf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page