New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

get-attributes-uniforms

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-attributes-uniforms

Get the attributes and uniforms from a GLSL shader string

latest
Source
npmnpm
Version
1.1.1
Version published
Maintainers
1
Created
Source

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: 'mat4'}, uniforms: {color: 'vec4' } }

console.log(getAttributesUniforms(vertexShader))
// { attributes: {position: 'vec2', foobar: 'vec4'}, 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() {
// ...
}
`

TODO:

  • Fix when shader code has comments above a uniform. Somehow got a uniform back called uniform

See Also

License

MIT

Keywords

glsl

FAQs

Package last updated on 28 Jan 2017

Did you know?

Socket

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.

Install

Related posts