test shader

master
Leo Coogan 4 months ago
parent a3d5fc12b1
commit 25a26f353b
Signed by: lcoogan
GPG Key ID: 54DBD17B0D75ABB0

@ -0,0 +1,6 @@
precision highp float;
void main() {
vec4 myColor = vec4(1.0, 0.0, 0.0, 1.0);
gl_FragColor = myColor;
}

@ -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;
}

@ -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);
}
Loading…
Cancel
Save