Package Exports
- three-glslify
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 (three-glslify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
three-glslify
A helper to turn glslify shader into a ThreeJS shader object.
Typical example:
//inline our shader code
var glslify = require('glslify')
var source = glslify({
vertex: './foo.vert',
fragment: './foo.frag',
sourceOnly: true
})
//create a shader that ThreeJS will recognize
var createShader = require('three-glslify')
var myShader = createShader(source)
//we can now use it in ShaderMaterial or EffectComposer
var pass = new THREE.ShaderPass( myShader )
effectComposer.addPass(pass)The returned myShader object looks like this, with new instances of Texture, Vector2, etc. based on the uniform type. Attributes start with empty arrays.
{
vertexShader: '... source ...',
fragmentShader: '... source ...',
uniforms: {
u_tex0: { type: 't', value: new THREE.Texture() },
... etc
},
attributes: {
displacement: { type: 'f', value: [] }
}
}Usage
createShader(source, options)
Creates a shader with the given source (from glslify, using sourceOnly) and options.
Options:
colorsan array of uniform names that should be mapped to THREE.Color typed,'c'. Otherwise these will just be plain THREE.Vector3 types,v3
Gotchas
ThreeJS distinguishes between an array of THREE.Vector3 objects, and a flattened vec3 type represented by floats (v3v vs fv). This module only sees the vec3 array type, and assumes they are to be represented by an array of THREE.Vector3 elements. Same with ivec3, vec4, etc.
License
MIT, see LICENSE.md for details.
