Rastercaster
In this project, you will create a sandbox for experimenting with fragment shaders and the OpenGL Shading Language (GLSL). You will render a single, screen-filling quadrilateral and paint designs on it using only algorithms that can be expressed in the fragment shader. This project is inspired by ShaderToy.
Requirements
To receive credit for this project, you must meet all of the following requirements. No partial credit is given. Submit on a later ready date if a requirement is not yet met.
- Complete this project as an individual, not in a group.
-
Place your renderer in
apps/rastercaster
in your individual Git repository. - Render a square that fills the viewport.
-
Write a fragment shader that computes each fragment's color according to a function
f
with this interface:The comment will be replaced by one or more statements that define the color. Call this function fromvec3 f() { // TODO: define a vec3 named color. return color; }
vec3 f() { // TODO: define a vec3 named color. return color; }
main
and use its return value to set thefragmentColor
variable. -
Vary the color according to the fragment's coordinates, which are provided by the builtin
gl_FragCoords
. -
Display a textarea in the HTML in which the user can type in the body of function
f
. Expect the user to only enter the code that replaces the comment in the snippet above. They will not enter the function signature or return statement. - On each change to the textarea, inject the user's code into your fragment shader, recompile, and re-render.
-
Allow the user to reference a
vec2
uniform nameddimensions
that holds the viewport's width and height in pixels. -
Allow the user to reference a
vec2
uniform namedmouse
that holds the mouse's position in pixels. Add a mouse listener to your renderer to track this value. Have it callrender
on every event—or use continuous rendering described next. -
Allow the user to reference a
float
uniform namedtime
that holds the number of seconds that have elapsed since the page was loaded. Use the browser'srequestAnimationFrame
to callrender
continuously so that the uniform will be actively updated. -
Design four algorithmic pieces of art using different bodies for the function
f
. Use any builtin GLSL functions or your own helper functions. Art is a subjective term. In general, each piece should be interesting in some aesthetic or algorithmic way and feel like it was crafted by a human artist. -
At least one design must reference
mouse
and be interactive. -
At least one design must reference
time
and animate. - Your code must be cleanly formatted, the variable names must be meaningful, and comments should explain non-obvious code.
- Ensure that you can paste others' designs into your renderer to reproduce their results.
Submission
Share in the Discord #rastercaster channel screenshots of your designs and their accompanying bodies of f
as text (between triple backticks) so that others can copy and paste. Each design must be unique amongst both your own designs and others' designs.
Commit and push your work to GitHub.