Access shader file contents for three.js file using jquery

I need to access the text of a string that I import using HTML from another script.

I include the text file in the html file:

<script src="shaders/fragmentshader.fs" id=fragmentshader></script>

Then I want to put the contents of this file into a variable in another script file and use it as a shader for three, js:

var fShader = $('#fragmentshader');

var shader = new THREE.ShaderMaterial({
    vertexShader: vShader.text(),
    fragmentShader: fShader.text()
});

This code works fine if I just write the necessary shader code between the script tags in the html file, but only access the string URL (not the data) if it is used as described above.

My question is: how do I access the text inside the file after downloading it, as shown above?

+4
source share
1

src script.

ShaderLoader.js, :

<script data-src="shaders/name/vertex.js" data-name="shader" 
type="x-shader/x-vertex"></script>

js:

SHADER_LOADER.load(function(data) {
    var particlesVertexShader = data.shader.vertex;
});
+4

All Articles