Scratch for Java

Shader()

A shader: a small program the graphics card runs for every pixel of a sprite (or of the whole stage) to change how it looks. You write only the body; every shader gets the same header:

uniform sampler2D costume;   // the costume (or the stage's picture)
uniform vec2 resolution;     // its size in pixels
uniform float time;          // game time in seconds
in vec2 uv;                  // where in the costume: (0, 0) top left, (1, 1) bottom right
out vec4 color;              // the colour to draw
void main() {
  vec4 c = texture(costume, uv);
  float g = (c.r + c.g + c.b) / 3.0;
  color = vec4(g, g, g, c.a);
}

Colours have straight (not premultiplied) alpha. Values of your own come in through uniforms you declare and set with set(String, double) and friends; the header's time and resolution are filled in for you and cannot be set.

Shader()

Create Shareable URL

Select Sections