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 vec3s.
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!
Metadata
Release files for pyglslify 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyglslify-0.1.1.tar.gz | 3.4 kB | Without provenance | Details for pyglslify-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyglslify-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for pyglslify-0.1.1-py3-none-any.whl |
Total release size: 6.8 kB
Release files / pyglslify-0.1.1.tar.gz
| Download URL | pyglslify-0.1.1.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4925d8ecabae79fab2148124f67ed3665404cb09066a3fff3eeebed9e0a3a54d
|
|
BLAKE2b-256 checksum How to use checksums |
df590c1b7e8962bf8376369f12b011dab0a1ce0c1476f7722628f23ccf538029
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.9.2 Darwin/20.4.0
|
Release files / pyglslify-0.1.1-py3-none-any.whl
| Download URL | pyglslify-0.1.1-py3-none-any.whl |
|---|---|
| Size | 3.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
72627b1d6a853df4239b1ebde7d27a6e68bdee2644bb813db60f1e71afb4563a
|
|
BLAKE2b-256 checksum How to use checksums |
554abf70ff7238faba760a485f3e84206c2b943243bda075f468aee8d8813024
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.9.2 Darwin/20.4.0
|
Security for pyglslify 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.