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(); 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
@ -75,30 +75,40 @@ 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() { // void main() {
vec2 uv = gl_FragCoord.xy/vec2(300, 300).xy; // vec2 uv = gl_FragCoord.xy/vec2(300, 300).xy;
// Time varying pixel color // // Time varying pixel color
vec3 col = 0.5 + 0.5*cos(uTime+uv.xyx+vec3(0,2,4)); // vec3 col = 0.5 + 0.5*cos(uTime+uv.xyx+vec3(0,2,4));
// Output to screen // // Output to screen
gl_FragColor = vec4(col,1.0); // 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); const shaderProgram = initShaderProgram(gl, vsSource, fsSource);