shader-tools 0.1.3
A tool to view and download shaders from ShaderToy.
Requires Python: >=3.9

# Shader Viewer and Downloader

## Overview
This project provides two utilities for working with shader files:
- `shader-viewer`: Executes and displays a shader (from ShaderToy or any custom glsl fragment).
- `shader-download`: Downloads shaders from ShaderToy.

Currently, only **single-pass shaders** are supported.

## Installation
Ensure you have Python installed (version 3.x recommended). 

You can install through pypi with:
```sh
pip install shader-tools
```

## Usage

### Viewer
Executes and displays a shader.

```sh
usage: shader-viewer [-h] [--defaultImage DEFAULTIMAGE] [--fps FPS] [-m IMAGESDIRECTORY]
                 [--initialFrames INITIALFRAMES] [--resolution1x1] [--resolutionReal]
                 [--viewportX VIEWPORTX] [--viewportY VIEWPORTY]
                 [shaderFiles ...]
```

#### Positional Arguments:
- `shaderFiles`: Specify one or more shader files.

#### Options:
- `-h, --help`: Show help message and exit.
- `--defaultImage DEFAULTIMAGE`: Set the default image.
- `--fps FPS`: Set frames per second (default: 60).
- `-m, --imagesDirectory IMAGESDIRECTORY`: Specify an image directory (can be used multiple times).
- `--initialFrames INITIALFRAMES`: Set the number of initial frames (default: 30).
- `--resolution1x1`: Enable 1x1 resolution.
- `--resolutionReal`: Enable real resolution.
- `--viewportX VIEWPORTX`: Set the viewport width.
- `--viewportY VIEWPORTY`: Set the viewport height.

### Downloader
Downloads shaders from ShaderToy.

```sh
usage: shader-download [-h] [-b] [-f] [--forceDownloadImages] shaderIds [shaderIds ...]
```

Shaders are by default downloaded to the config folder of the tool.
You can specify custom output folder with the -o option.

#### Positional Arguments:
- `shaderIds`: Specify one or more shader IDs.

#### Options:
- `-h, --help`: Show help message and exit.
- `-b, --backup`: Backup instead of replacing shaders (requires `-f`).
- `-f, --force`: Force download shaders (even if they exist).
- `--forceDownloadImages`: Force download images (even if they exist).
- `-o, --outputFolder`: Specify a custom output folder.

## Notes
- For now, only **single-pass shaders** are supported.
- Ensure dependencies (such as OpenGL, PyOpenGL, etc.) are installed for rendering.

## Passing uniforms and parameters to the shaders
It is possible to set uniform values directly in the shader code using comments.

There is a few configurable options too.

For instance:
```c
// CFG IN myCustomUniform1 1f val(123.456)
// CFG IN myCustomUniform2 4f val(1.0, 2.0, 3.0, 4.0)
// CFG IN myCustomUniform3 1i val(15)
// CFG BLEND_MODE additive
// CFG ICHANNEL 0 "path/to/myCustomImageForChannel0.png"
// CFG ICHANNEL 1 "path/to/myCustomImageForChannel1.jpg"
// CFG BACKGROUND "path/to/myCustomImage.png"
// CFG BACKGROUND_COLOR #FFaa00
// CFG BACKGROUND_COLOR #FFaa00aa
```

It is possible to animate custom uniforms to change after each frame:
```c
// CFG IN myCustomUniform4 1f val(0.0) inc(0.05) max(1.0) mode(loop)
// CFG IN myCustomUniform5 1f val(0.0) inc(0.05) max(1.0) mode(bounce)
// CFG IN myCustomUniform6 1f val(1.0) inc(-0.05) min(0.0) mode(loop)
// CFG IN myCustomUniform7 1f val(1.0) inc(-0.05) min(0.0) mode(bounce)
```


## License
This project is licensed under the MIT License.

## Contributing
Feel free to submit issues or pull requests!

## Author
Samy Sadi - https://github.com/samysadi