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();
|
||||
|
||||
/* 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
|
||||
|
|
@ -37,7 +37,7 @@ function loadShader(gl, type, source) {
|
|||
|
||||
// Send the source to the shader object
|
||||
gl.shaderSource(shader, source);
|
||||
|
||||
|
||||
// Compile the shader program
|
||||
gl.compileShader(shader);
|
||||
|
||||
|
|
@ -75,31 +75,41 @@ 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;
|
||||
|
||||
void main() {
|
||||
vec2 uv = gl_FragCoord.xy/vec2(300, 300).xy;
|
||||
// // shadertoy-like parameters
|
||||
// // uniform vec2 uResolution;
|
||||
// uniform float uTime;
|
||||
|
||||
// Time varying pixel color
|
||||
vec3 col = 0.5 + 0.5*cos(uTime+uv.xyx+vec3(0,2,4));
|
||||
// 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));
|
||||
|
||||
// // 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);
|
||||
|
||||
// Collect all the info needed to use the shader program.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue