An effective method for incorporating your shaders is by placing them within <script>
tags:
<script id="vertexShader" type="x-shader/x-vertex">
void main() {
...
}
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
void main() {
...
}
</script>
Subsequently, within your init
function:
// It is recommended to define uniforms as a global variable,
// allowing for easy modification from other functions
// such as animate() or render()
var uniforms = {
// Add your shader's uniform variables here
};
var material = new THREE.ShaderMaterial( {
uniforms: uniforms,
vertexShader: document.getElementById( 'vertexShader' ).textContent,
fragmentShader: document.getElementById( 'fragmentShader' ).textContent
});
In your loader callback:
var mesh = event.content;
mesh.material = material;
Take a look at this straightforward shader example