K
The origins of your problem are that from the web pages that were opened by the protocol. file:// Not managed To obtain from this protocol the resources that lie next to the disk. This opportunity in browsers is off for safety reasons.However, you're absolutely. Not required connect the shepherds as separate files.All you have to do is hand over the necker's original code, in the form of lines, and how will you keep and get those lines where they need it, it's the tenth.So you can create one. html web pagewhich will be opened locally and Web server♪ You can. glsl code directly javascript Line sections:<canvas>
<script>
let started = new Date().getTime();
let canvas = document.querySelector('canvas');
let size = canvas.width = canvas.height = 150;
let gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
let pid = gl.createProgram();
shader( attribute vec2 coords; void main(void) { gl_Position = vec4(coords.xy, 0.0, 1.0); } , gl.VERTEX_SHADER);
shader( precision highp float; uniform float time; void main(void) { vec2 uv = gl_FragCoord.xy / ${size}.; gl_FragColor = vec4(uv,sin(time),1.); } , gl.FRAGMENT_SHADER);
gl.linkProgram(pid);
gl.useProgram(pid);
let array = new Float32Array([-1, 3, -1, -1, 3, -1]);
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
gl.bufferData(gl.ARRAY_BUFFER, array, gl.STATIC_DRAW);
let al = gl.getAttribLocation(pid, "coords");
gl.vertexAttribPointer(al, 2 /*components per vertex */, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(al);
let time = gl.getUniformLocation(pid, 'time');
draw();
function draw() {
requestAnimationFrame(draw);
gl.uniform1f(time, (new Date().getTime() - started)/1000);
gl.viewport(0, 0, size, size);
gl.clearColor(0, 0, 0, 0);
gl.drawArrays(gl.TRIANGLES, 0, 3);
}
function shader(src, type) {
let sid = gl.createShader(type);
gl.shaderSource(sid, src);
gl.compileShader(sid);
gl.attachShader(pid, sid);
}
</script>If any of the possible modern bandlers are used, which pack web applications in one or more js, you can keep the necker's text in a separate file. And import it from the place of use, so it turns out like nothing. modularity in glsl♪The next step is modulation directly inside glsl code, so you don't dig 300 times in different shepherds the same code, there are two ways:
its own bike or a more serious solution, for example, https://github.com/glslify/glslify It's a complete decision and a huge decision. http://stack.gl/ All sorts of slices for shepherds built over the top npmlet glsl = require('glslify')
let shaderCode = glsl( #pragma glslify: noise = require('glsl-noise/simplex/3d') precision mediump float; varying vec3 vpos; void main () { gl_FragColor = vec4(noise(vpos*25.0),1); });
Internet simplicity and a lot of tutorials use tega. <script> different text/javascript type. Indirectly using the fact that such sections will not be automatically carried out by themselves, as in fact javascript:This is an example:<canvas></canvas>
<script type='glsl/vertex'>
attribute vec2 coords;
void main(void) {
gl_Position = vec4(coords.xy, 0.0, 1.0);
}
</script>
<script type='glsl/fragment'>precision highp float;
uniform vec4 mr; // (m)ouse position and screen (r)esolution
void main(void) {
vec2 p = gl_FragCoord.xy;
vec2 q = (p + p - mr.ba) / mr.b;
for(int i = 0; i < 13; i++)
q = abs(q)/dot(q,q) - mr.xy/mr.zw;
gl_FragColor = vec4(q, q.x/q.y, 1.0);
}
</script>
<script>
let canvas = document.querySelector('canvas');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
var h = gl.drawingBufferHeight;
var w = gl.drawingBufferWidth;
let pid = gl.createProgram();
shader('glsl/vertex', gl.VERTEX_SHADER);
shader('glsl/fragment', gl.FRAGMENT_SHADER);
gl.linkProgram(pid);
gl.useProgram(pid);
let array = new Float32Array([-1, 3, -1, -1, 3, -1]);
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
gl.bufferData(gl.ARRAY_BUFFER, array, gl.STATIC_DRAW);
let al = gl.getAttribLocation(pid, "coords");
gl.vertexAttribPointer(al, 2 /*components per vertex */, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(al);
let mr = gl.getUniformLocation(pid, 'mr'); // (m)ouse position and screen (r)esolution
window.addEventListener('mousemove', draw);
window.addEventListener('touchmove', draw);
draw();
function draw(e) {
let ev = e && e.touches ? e.touches[0] : e;
let x = ev ? ev.clientX : 250;
let y = ev ? h - ev.clientY: 111;
gl.uniform4f(mr, x, y, w, h);
gl.viewport(0, 0, w, h);
gl.clearColor(0, 0, 0, 0);
gl.drawArrays(gl.TRIANGLES, 0, 3 /* 3 vertices */);
}
function shader(name, type) {
let src = [...document.scripts].find(s => s.type === name).innerText;
let sid = gl.createShader(type);
gl.shaderSource(sid, src);
gl.compileShader(sid);
gl.attachShader(pid, sid);
}
</script>
<style>
body {
margin: 0;
overflow: hidden;
}
</style>PS: The fractal that paints here and tells the world of some Kali I'm in the middle of something. http://www.fractalforums.com/new-theories-and-research/very-simple-formula-for-fractal-patterns/