JSPM

get-attributes-uniforms

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1610
  • Score
    100M100P100Q102303F
  • License MIT

Get the attributes and uniforms from a GLSL shader string

Package Exports

  • get-attributes-uniforms

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (get-attributes-uniforms) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

get-attributes-uniforms npm version Build Status

Get the uniforms and attributes from a GLSL shader string

Background / Initial Motivation

The initial motivation for get-attributes-uniforms was to be used in the browser during runtime when getting attribute and uniform locations from a shader (i.e. calling getAttribLocation & getUniformLocation).

We want get-attributes-uniforms to be tiny since it intends to run in the browser, so instead of depending on a powerful but large glsl AST parser we use the native string functions.

In short.. we just chop out the uniform and attribute names based on our knowledge of the GLSL syntax.

Notes

This API does not use an AST and could very well be overlooking an edge case. If you run into one, feel super free to open an issue or open a PR with a test case.

To Install

$ npm install --save get-attributes-uniforms

Changes to the demo and src files will now live reload in your browser.

Usage

var getAttributesUniformss = require('get-attributes-uniforms')

var fragmentShader = `
precision mediump float;

attribute mat4      someAttrib;
uniform vec4 color;

void main () {
  gl_FragColor = color;
}
`

var vertexShader = `
precision mediump float;

attribute vec2 position;
attribute vec4   foobar    ;

void main () {
  gl_Position = vec4(position, 0, 1);
}
`

console.log(getAttributesUniforms(fragmentShader))
// { attributes: ['someAttrib'], uniforms: ['color'] }

console.log(getAttributesUniforms(vertexShader))
// { attributes: ['position', 'foobar'], uniforms: [] }

API

getAttributesUniforms(shaderString) -> Object

shaderString

Type: String

A string representing a vertex or fragment shader.

var shaderString = `
precision mediump float;

attribute vec3 position;

void main() {
// ...
}
`

See Also

License

MIT