Thin wrapper for the glslify nodejs tool, use stack.gl shader modules in Python.
Project description
pyglslify
A very thin wrapper for the glslify nodejs tool, to use stack.gl shader modules in Python during development.
(after development you're probably best just compiling the shaders with nodejs glslify
cli tool to a file and using the result)
Installation
The whole point is to be able to download and use GLSL shader modules from the WebGL community, which are distributed via npm
.
So first you need to install nodejs/npm: https://www.npmjs.com/get-npm
Then install the glslify
tool globally and verify it is on your path:
npm install -g glslify
glslify --help
Then add pyglslify
in your Python project virtualenv:
pip install pyglslify
Usage
We're still going to use npm
to install stack.gl shaders. For example:
npm install glsl-noise
This will create package.json
and package-lock.json
files in your project root, which will track the npm
dependencies of your project. These should be committed to source control along with the rest of your project. By default the modules will be downloaded to a node_modules
dir in your project root, that dir should be added to .gitignore
.
If you checkout your project repo on a new machine you can just run npm install
to fetch the modules specified as dependencies in package.json
.
On the Python side you can write GLSL shaders which make use of the glslify require
pragma:
#pragma glslify: noise = require('glsl-noise/simplex/3d')
precision mediump float;
varying vec3 vpos;
void main () {
gl_FragColor = vec4(noise(vpos*25.0),1);
}
fshader.glsl
And then in your Python code, when you want to pass the shader to your rendering pipeline, use pyglslify
to resolve the pragmas:
import moderngl_window as mglw
from pyglslify import glslify
class RenderWindow(mglw.WindowConfig):
def __init__(self, **kwargs):
super().__init__(**kwargs)
vertex_shader = self.load_text("shaders/vshader.glsl")
fragment_shader = self.load_text(
glslify("shaders/fshader.glsl")
)
self.pipeline = self.ctx.program(
vertex_shader=vertex_shader,
fragment_shader=fragment_shader,
)
You can also use glslify Source Transforms.
e.g. npm install glslify-hex
allows use of CSS-style hex strings for colors in place of vec3
s.
See the glslify docs - they recommend specifying these as configuration in your package.json
.
You can also apply local transforms to the shader file at runtime from Python, by passing their module names as args like:
from pyglslify import glslify
fragment_shader = glslify("shaders/fshader.glsl", "glslify-hex", "glslify-import")
Happy shading!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pyglslify-0.1.1.tar.gz
.
File metadata
- Download URL: pyglslify-0.1.1.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.9.2 Darwin/20.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4925d8ecabae79fab2148124f67ed3665404cb09066a3fff3eeebed9e0a3a54d |
|
MD5 | b12f6397b944a43dc840ef6fb9d4cd3b |
|
BLAKE2b-256 | df590c1b7e8962bf8376369f12b011dab0a1ce0c1476f7722628f23ccf538029 |
File details
Details for the file pyglslify-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: pyglslify-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.9.2 Darwin/20.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72627b1d6a853df4239b1ebde7d27a6e68bdee2644bb813db60f1e71afb4563a |
|
MD5 | 9b0a74f219608e6e2ca98d0d9bd25ca4 |
|
BLAKE2b-256 | 554abf70ff7238faba760a485f3e84206c2b943243bda075f468aee8d8813024 |