Skip to content

Instantly share code, notes, and snippets.

@THeK3nger
Created October 27, 2016 09:29
Show Gist options
  • Save THeK3nger/300b6a62b923c913223fbd29c8b5ac73 to your computer and use it in GitHub Desktop.
Save THeK3nger/300b6a62b923c913223fbd29c8b5ac73 to your computer and use it in GitHub Desktop.
THREE.js Asynchronous Shader Loader
// This is a basic asyncronous shader loader for THREE.js.
function ShaderLoader(vertex_url, fragment_url, onLoad, onProgress, onError) {
var vertex_loader = new THREE.XHRLoader(THREE.DefaultLoadingManager);
vertex_loader.setResponseType('text');
vertex_loader.load(vertex_url, function (vertex_text) {
var fragment_loader = new THREE.XHRLoader(THREE.DefaultLoadingManager);
fragment_loader.setResponseType('text');
fragment_loader.load(fragment_url, function (fragment_text) {
onLoad(vertex_text, fragment_text);
});
}, onProgress, onError);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment