fetch vertex shader source

This commit is contained in:
do butterflies cry? 2026-01-31 11:14:12 +10:00
parent dee511cd02
commit 4a8b395cf2

View file

@ -3,8 +3,8 @@ import { drawScene } from "./draw-scene.js";
main();
/* TODO: Avoid using alerts! Check return values instead,
* TODO: or create/use a Result like object.
/* XXX: TODO: Avoid using alerts! Check return values instead,
* XXX: TODO: or create/use a Result like object.
*/
// Initialize a shader program, so WebGL knows how to draw our data
@ -75,30 +75,40 @@ function main() {
}
`;
const fsSource = `
// is highp wasteful for this shader?
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
// const fsSource = `
// // is highp wasteful for this shader?
// #ifdef GL_FRAGMENT_PRECISION_HIGH
// precision highp float;
// #else
// precision mediump float;
// #endif
// shadertoy-like parameters
// uniform vec2 uResolution;
uniform float uTime;
// // shadertoy-like parameters
// // uniform vec2 uResolution;
// uniform float uTime;
void main() {
vec2 uv = gl_FragCoord.xy/vec2(300, 300).xy;
// void main() {
// 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));
// // 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);
// // Output to screen
// gl_FragColor = vec4(col,1.0);
// gl_FragColor = vec4(1.0, 1.0, 1.0, 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()
})();
const shaderProgram = initShaderProgram(gl, vsSource, fsSource);