Creates a new program by asynchronously fetching the source contained in the files pointed by the given urls. This method is enables you to write your shaders in separate files and keep your project organized.
LumaGL.addons.makeProgramFromShaderURIs(options);
false.Program instance.Create a Program from the given script files.
In shaders/fragment.glsl
#ifdef GL_ES
precision highp float;
#endif
void main(void) {
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}
In shaders/vertex.glsl
attribute vec3 aVertexPosition;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
void main(void) {
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
}
JavaScript code:
LumaGL.makeProgramFromShaderURIs({
path: 'shaders/',
vs: 'vertex.glsl',
fs: 'fragment.glsl',
onSuccess: function(program) {
alert("Got the program!");
},
onError: function(e) {
alert("An error ocurred while fetching or compiling the shaders");
}
});Creates a new program by fetching the source contained into the DOM scripts with ids provided in the method.
var program = LumaGL.Program.fromShaderIds(vertexShaderId, fragmentShaderId);
Create a Program from the given script ids.
HTML code:
<script id="shader-fs" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif
void main(void) {
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}
</script>
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
void main(void) {
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
}
</script>JavaScript code:
var program = LumaGL.Program.fromShaderIds('shader-vs', 'shader-fs');Creates a new program by using the sources taken from Shaders.Vertex and Shaders.Fragment.
var program = LumaGL.Program.fromShaderIds(vertexDefaultShaderId, fragmentDefaultShaderId);
Default.Default.Extend Shaders.Fragment with a default shader and create a Program from defaults. Taken from [lesson 8]http://uber.github.io/luma.gl/examples/lessons/8/) example.
//Add Blend Fragment Shader
LumaGL.Shaders.Fragment.Blend = [
"#ifdef GL_ES",
"precision highp float;",
"#endif",
"varying vec4 vColor;",
"varying vec2 vTexCoord;",
"varying vec3 lightWeighting;",
"uniform bool hasTexture1;",
"uniform sampler2D sampler1;",
"uniform float alpha;",
"void main(){",
"if (hasTexture1) {",
"gl_FragColor = vec4(texture2D(sampler1, vec2(vTexCoord.s, vTexCoord.t)).rgb * lightWeighting, alpha);",
"}",
"}"
].join("\n");
var program = LumaGL.addons.makeProgramFromDefaultShaders('Default', 'Blend');For more information about the default shader code Default included in the Framework take a look at the Shaders script.