Create a shader from a fragment snippet that defines void mainImage(out vec4 c, vec2 uv), and in 3D a vertex
snippet that defines void mainVertex(inout vec3 pos, inout vec3 normal)
fragmentCode string optionalLeft out or empty with vertex code, the 3D plugin's own look
vertexCode string optional3D only
uniforms Object<string, ShaderUniform> optionalValues the snippets read by name, declared for them: a
number is a float, a boolean a bool, a Vector2 a vec2, a Vector3 a vec3, a Color a vec4, and a list of 2, 3,
4, 9 or 16 numbers, or a Matrix4, a vec2, vec3, vec4, mat3 or mat4; change one with setUniform
const fade = new Shader(`
void mainImage(out vec4 c, vec2 uv)
{
c = texture(iChannel0, uv);
float fade = .5 + .5*sin(iTime);
c.a *= fade;
if (premultipliedTexture) c.rgb *= fade; // a tile layer, or any image with tilesPixelated false
}`);
obj.shader = fade;
The mainImage snippet, empty for a 3D Shader of vertex code alone
In 2D, write what mainImage gives as it is, with the draw's alpha, leaving out the
draw's color and additive color, for data rather than a picture, as the light system's normal pass does;
its output is taken as straight color, not premultiplied, whatever the texture; set it before the shader
first draws, its program is built then
The 2D program, compiled by the first draw that needs it, read only
The 3D program, compiled by the 3D plugin the same way, read only
The 3D depth program a Shader with vertex code draws the shadow map
and the camera's depth with, so a vertex it moves casts and hides where it is drawn, read only
The mainVertex snippet, 3D only, empty for none
Let go of this shader: its compiled programs are freed and it leaves the engine's list of shaders, which
keeps every one made for a lost context, so a scene made again and again, or an editor trying snippets, does
not keep them all; calling it again does nothing, and a draw with it afterwards compiles it again and takes it
back, so only let go of one no object still draws with when it should stay freed