From 25a26f353ba16cb91446fe27a3d7b43dad3983f0 Mon Sep 17 00:00:00 2001 From: Leonard Francis Coogan Date: Wed, 27 Aug 2025 10:21:47 -0400 Subject: [PATCH] test shader --- shader_test/shader.frag | 6 ++++++ shader_test/shader.vert | 23 +++++++++++++++++++++++ shader_test/sketch.js | 15 +++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 shader_test/shader.frag create mode 100644 shader_test/shader.vert create mode 100644 shader_test/sketch.js diff --git a/shader_test/shader.frag b/shader_test/shader.frag new file mode 100644 index 0000000..12a87ae --- /dev/null +++ b/shader_test/shader.frag @@ -0,0 +1,6 @@ +precision highp float; + +void main() { + vec4 myColor = vec4(1.0, 0.0, 0.0, 1.0); + gl_FragColor = myColor; +} diff --git a/shader_test/shader.vert b/shader_test/shader.vert new file mode 100644 index 0000000..d161189 --- /dev/null +++ b/shader_test/shader.vert @@ -0,0 +1,23 @@ +precision highp float; + +attribute vec3 aPosition; + +// The transform of the object being drawn +uniform mat4 uModelViewMatrix; + +// Transforms 3D coordinates to 2D screen coordinates +uniform mat4 uProjectionMatrix; + +// A custom uniform with the time in milliseconds +uniform float time; + +void main() { + // Apply the camera transform + vec4 viewModelPosition = uModelViewMatrix * vec4(aPosition, 1.0); + + // Use the time to adjust the position of the vertices + viewModelPosition.x += 10.0 * sin(time * 0.01 + viewModelPosition.y * 0.1); + + // Tell WebGL where the vertex goes + gl_Position = uProjectionMatrix * viewModelPosition; +} diff --git a/shader_test/sketch.js b/shader_test/sketch.js new file mode 100644 index 0000000..bc60cbb --- /dev/null +++ b/shader_test/sketch.js @@ -0,0 +1,15 @@ +let myShader; +function preload() { +  // load each shader file (don't worry, we will come back to these!) +  myShader = loadShader('shader.vert', 'shader.frag'); +} +function setup() { +  // the canvas has to be created with WEBGL mode +  createCanvas(windowWidth, windowHeight, WEBGL); +} +function draw() { +  // shader() sets the active shader, which will be applied to what is drawn next +  shader(myShader); +  // apply the shader to a rectangle taking up the full canvas + plane(width, height); +}