This page does not represent the most current semester of this course; it is present merely as an archive.
This assignment is really more about making sure you are ready for the WebGL homeworks that follow. It is much more straightforward than other homeworks.
Unlike other assignments
This assignment has a due date, but you are strongly encouraged to finish it as early as you can.
Note: you’ll likely need to run a local server to bypass CORS limitations and test your code locally.
For this and the other WebGL assignments, you should plan to submit
.html
endingimplemented.txt
listing what parts you
believe you completed; for this assignment, that is just the name of
your HTML file.js
, .css
, and
.glsl
files to support that .html
fileIf all of your files are in the same directory, you can submit them as-is (but must submit all of them in one go; piecemeal uploads will not work).
If you need a specific directory structure, upload a
.zip
or .tar
that contains those files. The
logic for handling submissions is
zip
or tar
, we extract
it
.html
files, we remove the outer directory.html
file, we use thatYour fragment shader should be the following
#version 300 es
precision highp float;
out vec4 color;
void main() {
= vec4(1, 0, 0.5, 1);
color }
Your vertex shader should be the following
#version 300 es
uniform float seconds;
uniform int count;
void main() {
float rad = sqrt((float(gl_VertexID)+0.5)/float(count));
float ang = 2.399963229728653 * float(gl_VertexID) + seconds;
gl_Position = vec4(rad*cos(ang), rad*sin(ang), 0, 1);
gl_PointSize = 4.0;
}
Your rendering function should be the following
function draw(milliseconds) {
.clear(gl.COLOR_BUFFER_BIT)
gl.useProgram(program)
gllet secondsBindPoint = gl.getUniformLocation(program, 'seconds')
.uniform1f(secondsBindPoint, milliseconds/1000)
glconst connection = gl.POINTS
const offset = 0 // unused here, but required
const count = 6+(0|milliseconds/100)%100 // number of vertices to draw
let countBindPoint = gl.getUniformLocation(program, 'count')
.uniform1i(countBindPoint, count)
gl.drawArrays(connection, offset, count)
glwindow.animation = requestAnimationFrame(draw)
}
Your HTML file should have the following canvas:
<canvas width="300" height="300" style="background:yellow"></canvas>
You should submit four files: one .html
, one
.js
and two .glsl
, using fetch
to
get the .glsl
files. You should compile and link the
shaders and initialize the drawing by calling
requestAnimationFrame(draw)
after they are successfully
compiled.
The resulting animation should look like this: