fetch vertex shader source
This commit is contained in:
parent
dee511cd02
commit
4a8b395cf2
1 changed files with 35 additions and 25 deletions
|
|
@ -3,8 +3,8 @@ import { drawScene } from "./draw-scene.js";
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
||||||
/* TODO: Avoid using alerts! Check return values instead,
|
/* XXX: TODO: Avoid using alerts! Check return values instead,
|
||||||
* TODO: or create/use a Result like object.
|
* XXX: TODO: or create/use a Result like object.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Initialize a shader program, so WebGL knows how to draw our data
|
// Initialize a shader program, so WebGL knows how to draw our data
|
||||||
|
|
@ -37,7 +37,7 @@ function loadShader(gl, type, source) {
|
||||||
|
|
||||||
// Send the source to the shader object
|
// Send the source to the shader object
|
||||||
gl.shaderSource(shader, source);
|
gl.shaderSource(shader, source);
|
||||||
|
|
||||||
// Compile the shader program
|
// Compile the shader program
|
||||||
gl.compileShader(shader);
|
gl.compileShader(shader);
|
||||||
|
|
||||||
|
|
@ -75,31 +75,41 @@ function main() {
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const fsSource = `
|
// const fsSource = `
|
||||||
// is highp wasteful for this shader?
|
// // is highp wasteful for this shader?
|
||||||
#ifdef GL_FRAGMENT_PRECISION_HIGH
|
// #ifdef GL_FRAGMENT_PRECISION_HIGH
|
||||||
precision highp float;
|
// precision highp float;
|
||||||
#else
|
// #else
|
||||||
precision mediump float;
|
// precision mediump float;
|
||||||
#endif
|
// #endif
|
||||||
|
|
||||||
// shadertoy-like parameters
|
// // shadertoy-like parameters
|
||||||
// uniform vec2 uResolution;
|
// // uniform vec2 uResolution;
|
||||||
uniform float uTime;
|
// uniform float uTime;
|
||||||
|
|
||||||
void main() {
|
|
||||||
vec2 uv = gl_FragCoord.xy/vec2(300, 300).xy;
|
|
||||||
|
|
||||||
// Time varying pixel color
|
// void main() {
|
||||||
vec3 col = 0.5 + 0.5*cos(uTime+uv.xyx+vec3(0,2,4));
|
// vec2 uv = gl_FragCoord.xy/vec2(300, 300).xy;
|
||||||
|
|
||||||
|
// // Time varying pixel color
|
||||||
|
// vec3 col = 0.5 + 0.5*cos(uTime+uv.xyx+vec3(0,2,4));
|
||||||
|
|
||||||
|
// // Output to screen
|
||||||
|
// gl_FragColor = vec4(col,1.0);
|
||||||
|
|
||||||
|
// // gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||||
|
// }
|
||||||
|
// `;
|
||||||
|
const fsSource = (async () => {
|
||||||
|
const res = await fetch("../shaders/segfault.glsl");
|
||||||
|
if (!res.ok) {
|
||||||
|
const error = `Failed to load fragment shader source ${url}: ${res.status}`;
|
||||||
|
alert(error);
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await res.text()
|
||||||
|
})();
|
||||||
|
|
||||||
// Output to screen
|
|
||||||
gl_FragColor = vec4(col,1.0);
|
|
||||||
|
|
||||||
// gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const shaderProgram = initShaderProgram(gl, vsSource, fsSource);
|
const shaderProgram = initShaderProgram(gl, vsSource, fsSource);
|
||||||
|
|
||||||
// Collect all the info needed to use the shader program.
|
// Collect all the info needed to use the shader program.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue