
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
glsl-shader-loader
Advanced tools
A static shader source bundler for WebGL program, provide a possibility for management shader source by creating separate files.
This is a static shader source bundler for WebGL program, provide a possibility for management shader source by creating separate files.
glsl-shader-loader for Webpack, supports for import GLSL functions from file and generates a shader string for WebGL program.
GLSL Shader Loader provids many features as following.
.glsl source file as a Javacript string for WebGL programimport statement in .glsl file that can extract GLSL functions from other files (includes nested reference)npm install --save-dev glsl-shader-loader
In your webpack configuration:
module: {
rules: [{
test: /\.(frag|vert|glsl)$/,
use: [
{
loader: 'glsl-shader-loader',
options: {}
}
]
}]
}
You can import GLSL functions with #pragma loader: statements in .glsl file
Import specified function by name
#pragma loader: import {nameA, nameB} from './file.glsl';
Import the only function in file by a new name
#pragma loader: import rename from './file.glsl';
NOTE:
.glsl file will you be able to rename it| Name | Type | Default | Description |
|---|---|---|---|
| root | {String} | undefined | Specify the root path of source |
rootconfiguration:
{
loader: 'glsl-shader-loader',
options: {
root: '/src/shaders'
}
}
Use / redirect to the specified directory.
e.g.
#pragma loader: import {light} from '/lights.glsl';will searchlights.glslunder the pathprojectRoot/src/shaders/
A directory structured like this:
.
├─ app.js
├─ fragmentShaderSource.glsl
└─ /collections/
├─ light.glsl
└─ random.glsl
Setting up shaders in app.js you might write code like this:
import fragmentShaderSource from './fragmentShaderSource.glsl'
gl.shaderSource(fragmentShader, fragmentShaderSource)
...
In shader code fragmentShaderSource.glsl, import randomDirection and spotLight from file:
precision mediump float;
varying vec4 v_color;
varying vec3 v_normal;
#pragma loader: import randomDirection from './collections/random.glsl';
#pragma loader: import {spotLight} from './collections/spotLight.glsl';
...
void main() {
vec3 direction = randomDirection(range);
vec3 spot = spotLight(direction, v_normal);
...
gl_FragColor = v_result_color;
}
light.glsl
vec3 spotLight (vec3 direction vec3 normal) {
...
return spot;
}
vec3 ambientLight (vec3 direction vec3 normal) {
...
return ambient;
}
random.glsl
vec3 random(vec2 range) {
...
return random;
}
import fragmentShaderSource from './fragmentShaderSource.glsl' Will return this JavaScript string:
precision mediump float;
varying vec4 v_color;
varying vec3 v_normal;
vec3 randomDirection(vec2 range) {
...
return random;
}
vec3 spotLight (vec3 direction vec3 normal) {
...
return spot;
}
...
void main() {
vec3 direction = randomDirection(range);
vec3 spot = spotLight(direction, v_normal);
...
gl_FragColor = v_result_color;
}
FAQs
A static shader source bundler for WebGL program, provide a possibility for management shader source by creating separate files.
The npm package glsl-shader-loader receives a total of 176 weekly downloads. As such, glsl-shader-loader popularity was classified as not popular.
We found that glsl-shader-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.