Class Shader
java.lang.Object
org.openpatch.scratch.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.
-
Method Summary
Modifier and TypeMethodDescriptiongetName()voidvoidvoidAn array uniform such asuniform vec3 lights[100];.voidvoidvoidvoidvoid
-
Method Details
-
getName
- Returns:
- the shader's name
-
setName
- Parameters:
name- a new name
-
set
- Parameters:
uniform- the uniform's name in the shadervalue- anintorfloatuniform's value
-
set
- Parameters:
uniform- the uniform's namevalue- anintuniform's value
-
set
- Parameters:
uniform- the uniform's namevalue- abooluniform's value
-
set
- Parameters:
uniform- the uniform's namex- avec2's xy- avec2's y
-
set
-
set
-
set
An array uniform such asuniform vec3 lights[100];.- Parameters:
uniform- the uniform's namevalues- all values, one element after the otherperElement- values per element: 1 forfloat[], 3 forvec3[]
-