Glslify Guide
What is Glslify?
Glslify is a GLSL module management tool that allows you to break down GLSL code into reusable modules. It's similar to JavaScript's module system, allowing you to import and export GLSL functions and variables.
Why Use Glslify?
- Code reuse: Avoid rewriting the same functions
- Modularity: Break complex shaders into small, manageable parts
- Maintainability: Easier to update and maintain code
- Community libraries: Use community-contributed GLSL modules
Basic Usage
1. Install Glslify
npm install -g glslify
2. Create a Module
// noise.glsl float random(vec2 st) { return fract(sin(dot(st.xy, vec2(12.9898,78.233))) * 43758.5453123); } #pragma glslify: export(random)
3. Use the Module
// main.glsl #pragma glslify: random = require('./noise.glsl') void main() { vec2 uv = gl_FragCoord.xy / resolution.xy; float noise = random(uv); gl_FragColor = vec4(vec3(noise), 1.0); }
Application in This Project
This learning platform has integrated Glslify, and you can see how to use it to organize and reuse GLSL code in the tutorials. We provide some common GLSL modules, including math functions, noise functions, and color utilities.